Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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:
46 
47  bool Descend() const { return true; }
50  unsigned int *token_count);
51 
52  void Visit(const ola::messaging::BoolFieldDescriptor*);
53  void Visit(const ola::messaging::IPV4FieldDescriptor*);
54  void Visit(const ola::messaging::UIDFieldDescriptor*);
55  void Visit(const ola::messaging::StringFieldDescriptor*);
56  void Visit(const ola::messaging::UInt8FieldDescriptor*);
57  void Visit(const ola::messaging::UInt16FieldDescriptor*);
58  void Visit(const ola::messaging::UInt32FieldDescriptor*);
59  void Visit(const ola::messaging::Int8FieldDescriptor*);
60  void Visit(const ola::messaging::Int16FieldDescriptor*);
61  void Visit(const ola::messaging::Int32FieldDescriptor*);
62  void Visit(const ola::messaging::FieldDescriptorGroup*);
63  void PostVisit(const ola::messaging::FieldDescriptorGroup*);
64 
65  private:
66  std::stack<unsigned int> m_token_count;
67  bool m_variable_sized_group_encountered;
68 };
69 
70 
76  public:
77  typedef enum {
78  INSUFFICIENT_TOKENS,
79  EXTRA_TOKENS,
80  NO_VARIABLE_GROUPS,
81  SINGLE_VARIABLE_GROUP,
82  MULTIPLE_VARIABLE_GROUPS,
83  NESTED_VARIABLE_GROUPS,
84  MISMATCHED_TOKENS,
85  } calculator_state;
86 
89 
90  bool Descend() const { return false; }
91  calculator_state CalculateGroupSize(
92  unsigned int token_count,
93  const class ola::messaging::Descriptor*,
94  unsigned int *group_repeat_count);
95 
96  void Visit(const ola::messaging::BoolFieldDescriptor*);
97  void Visit(const ola::messaging::IPV4FieldDescriptor*);
98  void Visit(const ola::messaging::UIDFieldDescriptor*);
99  void Visit(const ola::messaging::StringFieldDescriptor*);
100  void Visit(const ola::messaging::UInt8FieldDescriptor*);
101  void Visit(const ola::messaging::UInt16FieldDescriptor*);
102  void Visit(const ola::messaging::UInt32FieldDescriptor*);
103  void Visit(const ola::messaging::Int8FieldDescriptor*);
104  void Visit(const ola::messaging::Int16FieldDescriptor*);
105  void Visit(const ola::messaging::Int32FieldDescriptor*);
106  void Visit(const ola::messaging::FieldDescriptorGroup*);
107  void PostVisit(const ola::messaging::FieldDescriptorGroup*);
108 
109  private:
110  std::vector<const ola::messaging::FieldDescriptorGroup*> m_groups;
111  std::vector<const ola::messaging::FieldDescriptorInterface*> m_non_groups;
112  StaticGroupTokenCalculator m_simple_calculator;
113 
114  unsigned int DetermineGroupSize(const
116 };
117 } // namespace rdm
118 } // namespace ola
119 #endif // COMMON_RDM_GROUPSIZECALCULATOR_H_