Open Lighting Architecture  Latest Git
VariableFieldSizeCalculator.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * VariableFieldSizeCalculator.h
17  * Calculate the number of items in a group, given a fixed number of tokens.
18  * Copyright (C) 2011 Simon Newton
19  */
20 
21 #ifndef COMMON_RDM_VARIABLEFIELDSIZECALCULATOR_H_
22 #define COMMON_RDM_VARIABLEFIELDSIZECALCULATOR_H_
23 
24 #include <ola/messaging/DescriptorVisitor.h>
25 #include <stack>
26 #include <vector>
27 
28 namespace ola {
29 
30 namespace messaging {
31 class Descriptor;
32 }
33 
34 namespace rdm {
35 
36 
43  public:
44  typedef enum {
45  TOO_SMALL,
46  TOO_LARGE,
47  FIXED_SIZE,
48  VARIABLE_STRING,
49  VARIABLE_GROUP,
50  MULTIPLE_VARIABLE_FIELDS,
51  NESTED_VARIABLE_GROUPS,
52  MISMATCHED_SIZE,
53  } calculator_state;
54 
55  VariableFieldSizeCalculator() : m_fixed_size_sum(0) {}
57 
58  bool Descend() const { return false; }
59  calculator_state CalculateFieldSize(
60  unsigned int data_size,
61  const class ola::messaging::Descriptor*,
62  unsigned int *variable_field_repeat_count);
63 
64  void Visit(const ola::messaging::BoolFieldDescriptor*);
65  void Visit(const ola::messaging::IPV4FieldDescriptor*);
66  void Visit(const ola::messaging::MACFieldDescriptor*);
67  void Visit(const ola::messaging::UIDFieldDescriptor*);
68  void Visit(const ola::messaging::StringFieldDescriptor*);
69  void Visit(const ola::messaging::UInt8FieldDescriptor*);
70  void Visit(const ola::messaging::UInt16FieldDescriptor*);
71  void Visit(const ola::messaging::UInt32FieldDescriptor*);
72  void Visit(const ola::messaging::Int8FieldDescriptor*);
73  void Visit(const ola::messaging::Int16FieldDescriptor*);
74  void Visit(const ola::messaging::Int32FieldDescriptor*);
75  void Visit(const ola::messaging::FieldDescriptorGroup*);
76  void PostVisit(const ola::messaging::FieldDescriptorGroup*) {}
77 
78  private:
79  unsigned int m_fixed_size_sum;
80  std::vector<const ola::messaging::StringFieldDescriptor*>
81  m_variable_string_fields;
82  std::vector<const ola::messaging::FieldDescriptorGroup*>
83  m_variable_group_fields;
84 
85  unsigned int DetermineGroupSize(const
87 };
88 } // namespace rdm
89 } // namespace ola
90 #endif // COMMON_RDM_VARIABLEFIELDSIZECALCULATOR_H_
Definition: Descriptor.h:84
Definition: DescriptorVisitor.h:43
Definition: Descriptor.h:122
Definition: Descriptor.h:324
Definition: VariableFieldSizeCalculator.h:41
Definition: Descriptor.h:141
Definition: Descriptor.h:103
Definition: Descriptor.h:160
Definition: Descriptor.h:403
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: Descriptor.h:190