| copilot-swe-agent[bot] | c3cdacf | 2026-02-09 21:30:16 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | namespace apache { |
| 28 | namespace thrift { |
| 29 | |
| 30 | // Generic printTo template - streams value directly to output |
| 31 | template <typename OStream, typename T> |
| 32 | void 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 |
| 37 | template <typename OStream> |
| 38 | void printTo(OStream& out, const int8_t& t) { |
| 39 | out << static_cast<int>(t); |
| 40 | } |
| 41 | |
| 42 | // Forward declarations for collection types |
| 43 | template <typename OStream, typename K, typename V> |
| 44 | void printTo(OStream& out, const std::map<K, V>& m); |
| 45 | |
| 46 | template <typename OStream, typename T> |
| 47 | void printTo(OStream& out, const std::set<T>& s); |
| 48 | |
| 49 | template <typename OStream, typename T> |
| 50 | void printTo(OStream& out, const std::vector<T>& t); |
| 51 | |
| 52 | // Pair support |
| 53 | template <typename OStream, typename K, typename V> |
| 54 | void 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 |
| 61 | template <typename OStream, typename Iterator> |
| 62 | void 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 |
| 71 | template <typename OStream, typename T> |
| 72 | void printTo(OStream& out, const std::vector<T>& t) { |
| 73 | out << "["; |
| 74 | printTo(out, t.begin(), t.end()); |
| 75 | out << "]"; |
| 76 | } |
| 77 | |
| 78 | // Map support |
| 79 | template <typename OStream, typename K, typename V> |
| 80 | void 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 |
| 87 | template <typename OStream, typename T> |
| 88 | void 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_ |