blob: d3d5cb4348fe01db40542f29dc5b3a5b99262939 [file] [log] [blame]
copilot-swe-agent[bot]c3cdacf2026-02-09 21:30:16 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_TPRINTTO_H_
21#define _THRIFT_TPRINTTO_H_ 1
22
23#include <map>
24#include <set>
25#include <vector>
26
27namespace apache {
28namespace thrift {
29
30// Generic printTo template - streams value directly to output
31template <typename OStream, typename T>
32void printTo(OStream& out, const T& t) {
33 out << t;
34}
35
36// Special handling of i8 datatypes (THRIFT-5272) - cast to int to avoid char output
37template <typename OStream>
38void printTo(OStream& out, const int8_t& t) {
39 out << static_cast<int>(t);
40}
41
42// Forward declarations for collection types
43template <typename OStream, typename K, typename V>
44void printTo(OStream& out, const std::map<K, V>& m);
45
46template <typename OStream, typename T>
47void printTo(OStream& out, const std::set<T>& s);
48
49template <typename OStream, typename T>
50void printTo(OStream& out, const std::vector<T>& t);
51
52// Pair support
53template <typename OStream, typename K, typename V>
54void printTo(OStream& out, const std::pair<K, V>& v) {
55 printTo(out, v.first);
56 out << ": ";
57 printTo(out, v.second);
58}
59
60// Iterator range support
61template <typename OStream, typename Iterator>
62void printTo(OStream& out, Iterator beg, Iterator end) {
63 for (Iterator it = beg; it != end; ++it) {
64 if (it != beg)
65 out << ", ";
66 printTo(out, *it);
67 }
68}
69
70// Vector support
71template <typename OStream, typename T>
72void printTo(OStream& out, const std::vector<T>& t) {
73 out << "[";
74 printTo(out, t.begin(), t.end());
75 out << "]";
76}
77
78// Map support
79template <typename OStream, typename K, typename V>
80void printTo(OStream& out, const std::map<K, V>& m) {
81 out << "{";
82 printTo(out, m.begin(), m.end());
83 out << "}";
84}
85
86// Set support
87template <typename OStream, typename T>
88void printTo(OStream& out, const std::set<T>& s) {
89 out << "{";
90 printTo(out, s.begin(), s.end());
91 out << "}";
92}
93
94} // namespace thrift
95} // namespace apache
96
97#endif // _THRIFT_TPRINTTO_H_