DCCL v4
oneof.h
1 // Copyright 2009-2017 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (for 2013-)
3 // Massachusetts Institute of Technology (for 2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Dynamic Compact Control Language Library
8 // ("DCCL").
9 //
10 // DCCL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // DCCL is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCCLONEOF20210702H
23 #define DCCLONEOF20210702H
24 
25 #include <google/protobuf/descriptor.pb.h>
26 #include <google/protobuf/descriptor.h>
27 #include "dccl/binary.h"
28 
29 namespace dccl {
30 
34  inline bool is_part_of_oneof(const google::protobuf::FieldDescriptor* field_desc)
35  { return field_desc->containing_oneof(); }
36 
41  inline int containing_oneof_index(const google::protobuf::FieldDescriptor* field_desc)
42  { if(is_part_of_oneof(field_desc)) return field_desc->containing_oneof()->index(); return -1;}
43 
49  inline int oneof_size(const google::protobuf::OneofDescriptor* oneof_desc)
50  { return dccl::ceil_log2(oneof_desc->field_count()+1); }
51 }
52 
53 #endif
dccl::containing_oneof_index
int containing_oneof_index(const google::protobuf::FieldDescriptor *field_desc)
Returns the index of the containing oneof of the given field, or -1 if the field is not part of a one...
Definition: oneof.h:41
dccl
Dynamic Compact Control Language namespace.
Definition: gen_units_class_plugin.h:49
dccl::oneof_size
int oneof_size(const google::protobuf::OneofDescriptor *oneof_desc)
Returns the number of bits needed to represent the oneof cases (including the unset case).
Definition: oneof.h:49
dccl::ceil_log2
unsigned ceil_log2(dccl::uint64 v)
Definition: binary.h:180
dccl::is_part_of_oneof
bool is_part_of_oneof(const google::protobuf::FieldDescriptor *field_desc)
Checks whether a given field is part to a oneof or not.
Definition: oneof.h:34