Open Lighting Architecture: common/rdm/GroupSizeCalculator.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
28namespace ola {
29
30namespace messaging {
31class Descriptor;
32}
33
34namespace rdm {
35
36
41 class StaticGroupTokenCalculator
42 : public ola::messaging::FieldDescriptorVisitor {
43 public:
44 StaticGroupTokenCalculator()
45 : m_variable_sized_group_encountered(false) {
46 }
47 ~StaticGroupTokenCalculator() {}
48
49 bool Descend() const { return true; }
50 bool CalculateTokensRequired(
51 const class ola::messaging::FieldDescriptorGroup*,
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
78 class GroupSizeCalculator: public ola::messaging::FieldDescriptorVisitor {
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
90 GroupSizeCalculator() {}
91 ~GroupSizeCalculator() {}
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
119 ola::messaging::FieldDescriptorGroup*);
120};
121} // namespace rdm
122} // namespace ola
123#endif // COMMON_RDM_GROUPSIZECALCULATOR_H_
ola::messaging::BoolFieldDescriptor
Definition Descriptor.h:84
ola::messaging::Descriptor
Definition Descriptor.h:399
ola::messaging::FieldDescriptorGroup
Definition Descriptor.h:320
ola::messaging::FieldDescriptorVisitor
Definition DescriptorVisitor.h:43
ola::messaging::IPV4FieldDescriptor
Definition Descriptor.h:103
ola::messaging::MACFieldDescriptor
Definition Descriptor.h:122
ola::messaging::StringFieldDescriptor
Definition Descriptor.h:160
ola::messaging::UIDFieldDescriptor
Definition Descriptor.h:141
ola::rdm::GroupSizeCalculator::CalculateGroupSize
calculator_state CalculateGroupSize(unsigned int token_count, const class ola::messaging::Descriptor *descriptor, unsigned int *group_repeat_count)
Definition GroupSizeCalculator.cpp:44
ola::rdm::StaticGroupTokenCalculator
Definition GroupSizeCalculator.h:42
ola::rdm::StaticGroupTokenCalculator::CalculateTokensRequired
bool CalculateTokensRequired(const class ola::messaging::FieldDescriptorGroup *, unsigned int *token_count)
Definition GroupSizeCalculator.cpp:213
ola::messaging
A framework for serializing simple message structures.
Definition Descriptor.cpp:25
ola::rdm
PLASA E1.20 Remote Device Management.
Definition AckTimerResponder.cpp:38
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44