Open Lighting Architecture  Latest Git
GroupSizeCalculator.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  * GroupSizeCalculator.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_GROUPSIZECALCULATOR_H_
22 #define COMMON_RDM_GROUPSIZECALCULATOR_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:
45  : m_variable_sized_group_encountered(false) {
46  }
48 
49  bool Descend() const { return true; }
50  bool CalculateTokensRequired(
52  unsigned int *token_count);
53 
54  void Visit(const ola::messaging::BoolFieldDescriptor*);
55  void Visit(const ola::messaging::IPV4FieldDescriptor*);
56  void Visit(const ola::messaging::MACFieldDescriptor*);
57  void Visit(const ola::messaging::UIDFieldDescriptor*);
58  void Visit(const ola::messaging::StringFieldDescriptor*);
59  void Visit(const ola::messaging::UInt8FieldDescriptor*);
60  void Visit(const ola::messaging::UInt16FieldDescriptor*);
61  void Visit(const ola::messaging::UInt32FieldDescriptor*);
62  void Visit(const ola::messaging::Int8FieldDescriptor*);
63  void Visit(const ola::messaging::Int16FieldDescriptor*);
64  void Visit(const ola::messaging::Int32FieldDescriptor*);
65  void Visit(const ola::messaging::FieldDescriptorGroup*);
66  void PostVisit(const ola::messaging::FieldDescriptorGroup*);
67 
68  private:
69  std::stack<unsigned int> m_token_count;
70  bool m_variable_sized_group_encountered;
71 };
72 
73 
79  public:
80  typedef enum {
81  INSUFFICIENT_TOKENS,
82  EXTRA_TOKENS,
83  NO_VARIABLE_GROUPS,
84  SINGLE_VARIABLE_GROUP,
85  MULTIPLE_VARIABLE_GROUPS,
86  NESTED_VARIABLE_GROUPS,
87  MISMATCHED_TOKENS,
88  } calculator_state;
89 
92 
93  bool Descend() const { return false; }
94  calculator_state CalculateGroupSize(
95  unsigned int token_count,
96  const class ola::messaging::Descriptor *descriptor,
97  unsigned int *group_repeat_count);
98 
99  void Visit(const ola::messaging::BoolFieldDescriptor*);
100  void Visit(const ola::messaging::IPV4FieldDescriptor*);
101  void Visit(const ola::messaging::MACFieldDescriptor*);
102  void Visit(const ola::messaging::UIDFieldDescriptor*);
103  void Visit(const ola::messaging::StringFieldDescriptor*);
104  void Visit(const ola::messaging::UInt8FieldDescriptor*);
105  void Visit(const ola::messaging::UInt16FieldDescriptor*);
106  void Visit(const ola::messaging::UInt32FieldDescriptor*);
107  void Visit(const ola::messaging::Int8FieldDescriptor*);
108  void Visit(const ola::messaging::Int16FieldDescriptor*);
109  void Visit(const ola::messaging::Int32FieldDescriptor*);
110  void Visit(const ola::messaging::FieldDescriptorGroup*);
111  void PostVisit(const ola::messaging::FieldDescriptorGroup*);
112 
113  private:
114  std::vector<const ola::messaging::FieldDescriptorGroup*> m_groups;
115  std::vector<const ola::messaging::FieldDescriptorInterface*> m_non_groups;
116  StaticGroupTokenCalculator m_simple_calculator;
117 
118  unsigned int DetermineGroupSize(const
120 };
121 } // namespace rdm
122 } // namespace ola
123 #endif // COMMON_RDM_GROUPSIZECALCULATOR_H_
Definition: Descriptor.h:84
Definition: GroupSizeCalculator.h:78
Definition: DescriptorVisitor.h:43
Definition: Descriptor.h:122
Definition: Descriptor.h:324
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
Definition: GroupSizeCalculator.h:41