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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
28namespace ola {
29
30namespace messaging {
31class Descriptor;
32}
33
34namespace rdm {
35
36
41 class VariableFieldSizeCalculator
42 : public ola::messaging::FieldDescriptorVisitor {
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) {}
56 ~VariableFieldSizeCalculator() {}
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
86 ola::messaging::FieldDescriptorGroup*);
87};
88} // namespace rdm
89} // namespace ola
90#endif // COMMON_RDM_VARIABLEFIELDSIZECALCULATOR_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::VariableFieldSizeCalculator::CalculateFieldSize
calculator_state CalculateFieldSize(unsigned int data_size, const class ola::messaging::Descriptor *, unsigned int *variable_field_repeat_count)
Definition VariableFieldSizeCalculator.cpp:47
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