DCCL v4
oneof.h
1 // Copyright 2021-2022:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Davide Fenucci <davfen@noc.ac.uk>
6 //
7 //
8 // This file is part of the Dynamic Compact Control Language Library
9 // ("DCCL").
10 //
11 // DCCL is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // DCCL is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef DCCLONEOF20210702H
24 #define DCCLONEOF20210702H
25 
26 #include "binary.h"
27 #include <google/protobuf/descriptor.h>
28 #include <google/protobuf/descriptor.pb.h>
29 
30 namespace dccl
31 {
35 inline bool is_part_of_oneof(const google::protobuf::FieldDescriptor* field_desc)
36 {
37  return field_desc->containing_oneof();
38 }
39 
44 inline int containing_oneof_index(const google::protobuf::FieldDescriptor* field_desc)
45 {
46  if (is_part_of_oneof(field_desc))
47  return field_desc->containing_oneof()->index();
48  return -1;
49 }
50 
56 inline int oneof_size(const google::protobuf::OneofDescriptor* oneof_desc)
57 {
58  return dccl::ceil_log2(oneof_desc->field_count() + 1);
59 }
60 } // namespace dccl
61 
62 #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:44
dccl
Dynamic Compact Control Language namespace.
Definition: any.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:56
dccl::ceil_log2
unsigned ceil_log2(dccl::uint64 v)
Definition: binary.h:178
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:35