]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/compiler/cpp/src/thrift/parse/t_enum.h
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
25 #include "thrift/parse/t_enum_value.h"
26 #include "thrift/parse/t_type.h"
29 * An enumerated type. A list of constant objects with a name for the type.
32 class t_enum
: public t_type
{
34 t_enum(t_program
* program
) : t_type(program
) {}
36 void set_name(const std::string
& name
) override
{ name_
= name
; }
38 void append(t_enum_value
* constant
) { constants_
.push_back(constant
); }
40 const std::vector
<t_enum_value
*>& get_constants() const { return constants_
; }
42 t_enum_value
* get_constant_by_name(const std::string
& name
) const {
43 const std::vector
<t_enum_value
*>& enum_values
= get_constants();
44 std::vector
<t_enum_value
*>::const_iterator c_iter
;
45 for (c_iter
= enum_values
.begin(); c_iter
!= enum_values
.end(); ++c_iter
) {
46 if ((*c_iter
)->get_name() == name
) {
53 t_enum_value
* get_constant_by_value(int64_t value
) const {
54 const std::vector
<t_enum_value
*>& enum_values
= get_constants();
55 std::vector
<t_enum_value
*>::const_iterator c_iter
;
56 for (c_iter
= enum_values
.begin(); c_iter
!= enum_values
.end(); ++c_iter
) {
57 if ((*c_iter
)->get_value() == value
) {
64 t_enum_value
* get_min_value() const {
65 const std::vector
<t_enum_value
*>& enum_values
= get_constants();
66 std::vector
<t_enum_value
*>::const_iterator c_iter
;
67 t_enum_value
* min_value
;
68 if (enum_values
.size() == 0) {
72 min_value
= enum_values
.front();
73 min_value_value
= min_value
->get_value();
74 for (c_iter
= enum_values
.begin(); c_iter
!= enum_values
.end(); ++c_iter
) {
75 if ((*c_iter
)->get_value() < min_value_value
) {
76 min_value
= (*c_iter
);
77 min_value_value
= min_value
->get_value();
84 t_enum_value
* get_max_value() const {
85 const std::vector
<t_enum_value
*>& enum_values
= get_constants();
86 std::vector
<t_enum_value
*>::const_iterator c_iter
;
87 t_enum_value
* max_value
;
88 if (enum_values
.size() == 0) {
92 max_value
= enum_values
.back();
93 max_value_value
= max_value
->get_value();
94 for (c_iter
= enum_values
.begin(); c_iter
!= enum_values
.end(); ++c_iter
) {
95 if ((*c_iter
)->get_value() > max_value_value
) {
96 max_value
= (*c_iter
);
97 max_value_value
= max_value
->get_value();
104 bool is_enum() const override
{ return true; }
107 std::vector
<t_enum_value
*> constants_
;