File indexing completed on 2026-04-17 08:35:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef _THRIFT_THRIFT_H_
0021 #define _THRIFT_THRIFT_H_ 1
0022
0023 #include <thrift/transport/PlatformSocket.h>
0024
0025 #include <thrift/thrift-config.h>
0026
0027 #include <stdio.h>
0028 #include <assert.h>
0029
0030 #include <sys/types.h>
0031 #ifdef HAVE_NETINET_IN_H
0032 #include <netinet/in.h>
0033 #endif
0034 #ifdef HAVE_INTTYPES_H
0035 #include <inttypes.h>
0036 #endif
0037 #include <string>
0038 #include <map>
0039 #include <list>
0040 #include <set>
0041 #include <vector>
0042 #include <exception>
0043 #include <typeinfo>
0044
0045 #include <thrift/TLogging.h>
0046 #include <thrift/TOutput.h>
0047
0048 #define THRIFT_UNUSED_VARIABLE(x) ((void)(x))
0049
0050 namespace apache {
0051 namespace thrift {
0052
0053 class TEnumIterator
0054 : public std::iterator<std::forward_iterator_tag, std::pair<int, const char*> > {
0055 public:
0056 TEnumIterator(int n, int* enums, const char** names)
0057 : ii_(0), n_(n), enums_(enums), names_(names) {}
0058
0059 int operator++() { return ++ii_; }
0060
0061 bool operator!=(const TEnumIterator& end) {
0062 THRIFT_UNUSED_VARIABLE(end);
0063 assert(end.n_ == -1);
0064 return (ii_ != n_);
0065 }
0066
0067 std::pair<int, const char*> operator*() const { return std::make_pair(enums_[ii_], names_[ii_]); }
0068
0069 private:
0070 int ii_;
0071 const int n_;
0072 int* enums_;
0073 const char** names_;
0074 };
0075
0076 class TException : public std::exception {
0077 public:
0078 TException() : message_() {}
0079
0080 TException(const std::string& message) : message_(message) {}
0081
0082 virtual ~TException() noexcept override = default;
0083
0084 const char* what() const noexcept override {
0085 if (message_.empty()) {
0086 return "Default TException.";
0087 } else {
0088 return message_.c_str();
0089 }
0090 }
0091
0092 protected:
0093 std::string message_;
0094 };
0095
0096 class TDelayedException {
0097 public:
0098 template <class E>
0099 static TDelayedException* delayException(const E& e);
0100 virtual void throw_it() = 0;
0101 virtual ~TDelayedException() = default;
0102 };
0103
0104 template <class E>
0105 class TExceptionWrapper : public TDelayedException {
0106 public:
0107 TExceptionWrapper(const E& e) : e_(e) {}
0108 void throw_it() override {
0109 E temp(e_);
0110 delete this;
0111 throw temp;
0112 }
0113
0114 private:
0115 E e_;
0116 };
0117
0118 template <class E>
0119 TDelayedException* TDelayedException::delayException(const E& e) {
0120 return new TExceptionWrapper<E>(e);
0121 }
0122
0123 #if T_GLOBAL_DEBUG_VIRTUAL > 1
0124 void profile_virtual_call(const std::type_info& info);
0125 void profile_generic_protocol(const std::type_info& template_type, const std::type_info& prot_type);
0126 void profile_print_info(FILE* f);
0127 void profile_print_info();
0128 void profile_write_pprof(FILE* gen_calls_f, FILE* virtual_calls_f);
0129 #endif
0130 }
0131 }
0132
0133 #endif