]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/compiler/cpp/src/thrift/parse/t_type.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / compiler / cpp / src / thrift / parse / t_type.h
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 T_TYPE_H
21 #define T_TYPE_H
22
23 #include <string>
24 #include <map>
25 #include <cstring>
26 #include <stdint.h>
27 #include "thrift/parse/t_doc.h"
28
29 class t_program;
30
31 /**
32 * Generic representation of a thrift type. These objects are used by the
33 * parser module to build up a tree of object that are all explicitly typed.
34 * The generic t_type class exports a variety of useful methods that are
35 * used by the code generator to branch based upon different handling for the
36 * various types.
37 *
38 */
39 class t_type : public t_doc {
40 public:
41 ~t_type() override = default;
42
43 virtual void set_name(const std::string& name) { name_ = name; }
44
45 virtual const std::string& get_name() const { return name_; }
46
47 virtual bool is_void() const { return false; }
48 virtual bool is_base_type() const { return false; }
49 virtual bool is_string() const { return false; }
50 virtual bool is_binary() const { return false; }
51 virtual bool is_bool() const { return false; }
52 virtual bool is_typedef() const { return false; }
53 virtual bool is_enum() const { return false; }
54 virtual bool is_struct() const { return false; }
55 virtual bool is_xception() const { return false; }
56 virtual bool is_container() const { return false; }
57 virtual bool is_list() const { return false; }
58 virtual bool is_set() const { return false; }
59 virtual bool is_map() const { return false; }
60 virtual bool is_service() const { return false; }
61
62 t_program* get_program() { return program_; }
63
64 const t_program* get_program() const { return program_; }
65
66 t_type* get_true_type();
67 const t_type* get_true_type() const;
68
69 // This function will break (maybe badly) unless 0 <= num <= 16.
70 static char nybble_to_xdigit(int num) {
71 if (num < 10) {
72 return '0' + num;
73 } else {
74 return 'A' + num - 10;
75 }
76 }
77
78 static std::string byte_to_hex(uint8_t byte) {
79 std::string rv;
80 rv += nybble_to_xdigit(byte >> 4);
81 rv += nybble_to_xdigit(byte & 0x0f);
82 return rv;
83 }
84
85 std::map<std::string, std::string> annotations_;
86
87 protected:
88 t_type() : program_(nullptr) { ; }
89
90 t_type(t_program* program) : program_(program) { ; }
91
92 t_type(t_program* program, std::string name) : program_(program), name_(name) { ; }
93
94 t_type(std::string name) : program_(nullptr), name_(name) { ; }
95
96 t_program* program_;
97 std::string name_;
98 };
99
100 /**
101 * Placeholder struct for returning the key and value of an annotation
102 * during parsing.
103 */
104 struct t_annotation {
105 std::string key;
106 std::string val;
107 };
108
109 #endif