21 #ifndef INCLUDE_OLA_MESSAGING_DESCRIPTOR_H_
22 #define INCLUDE_OLA_MESSAGING_DESCRIPTOR_H_
24 #include <ola/messaging/DescriptorVisitor.h>
36 class FieldDescriptorVisitor;
46 virtual const std::string& Name()
const = 0;
52 virtual bool FixedSize()
const = 0;
55 virtual bool LimitedSize()
const = 0;
59 virtual unsigned int MaxSize()
const = 0;
74 const std::string& Name()
const {
return m_name; }
90 bool FixedSize()
const {
return true; }
91 bool LimitedSize()
const {
return true; }
92 unsigned int MaxSize()
const {
return 1; }
109 bool FixedSize()
const {
return true; }
110 bool LimitedSize()
const {
return true; }
111 unsigned int MaxSize()
const {
return ola::network::IPV4Address::LENGTH; }
114 visitor->Visit(
this);
128 bool FixedSize()
const {
return true; }
129 bool LimitedSize()
const {
return true; }
130 unsigned int MaxSize()
const {
return ola::network::MACAddress::LENGTH; }
133 visitor->Visit(
this);
147 bool FixedSize()
const {
return true; }
148 bool LimitedSize()
const {
return true; }
149 unsigned int MaxSize()
const {
return ola::rdm::UID::LENGTH; }
152 visitor->Visit(
this);
166 m_min_size(min_size),
167 m_max_size(max_size) {
170 bool FixedSize()
const {
return m_min_size == m_max_size; }
171 bool LimitedSize()
const {
return true; }
172 unsigned int MinSize()
const {
return m_min_size; }
173 unsigned int MaxSize()
const {
return m_max_size; }
176 visitor->Visit(
this);
180 uint8_t m_min_size, m_max_size;
189 template <
typename type>
192 typedef std::pair<type, type> Interval;
193 typedef std::vector<std::pair<type, type> > IntervalVector;
194 typedef std::map<std::string, type> LabeledValues;
197 bool little_endian =
false,
198 int8_t multiplier = 0)
200 m_little_endian(little_endian),
201 m_multipler(multiplier) {
205 const IntervalVector &intervals,
206 const LabeledValues &labels,
207 bool little_endian =
false,
208 int8_t multiplier = 0)
210 m_little_endian(little_endian),
211 m_multipler(multiplier),
212 m_intervals(intervals),
216 bool FixedSize()
const {
return true; }
217 bool LimitedSize()
const {
return true; }
218 unsigned int MaxSize()
const {
return sizeof(type); }
219 int8_t Multiplier()
const {
return m_multipler; }
220 bool IsLittleEndian()
const {
return m_little_endian; }
222 const IntervalVector &Intervals()
const {
return m_intervals; }
224 bool IsValid(type value)
const {
225 if (m_intervals.empty())
228 typename IntervalVector::const_iterator iter = m_intervals.begin();
229 for (; iter != m_intervals.end(); ++iter) {
230 if (value >= iter->first && value <= iter->second)
236 const LabeledValues &Labels()
const {
return m_labels; }
238 bool LookupLabel(
const std::string &label, type *value)
const {
239 typename LabeledValues::const_iterator iter = m_labels.find(label);
240 if (iter == m_labels.end())
242 *value = iter->second;
246 const std::string LookupValue(type value)
const {
247 typename LabeledValues::const_iterator iter = m_labels.begin();
248 for (; iter != m_labels.end(); ++iter) {
249 if (iter->second == value)
256 visitor->Visit(
this);
260 bool m_little_endian;
262 IntervalVector m_intervals;
263 LabeledValues m_labels;
322 static const int16_t UNLIMITED_BLOCKS;
325 const std::vector<const FieldDescriptor*> &fields,
330 m_min_blocks(min_blocks),
331 m_max_blocks(max_blocks),
334 m_limited_size(
true),
336 m_max_block_size(0) {
342 bool FixedSize()
const {
return FixedBlockSize() && FixedBlockCount(); }
346 bool LimitedSize()
const;
350 unsigned int MaxSize()
const;
354 unsigned int FieldCount()
const {
return m_fields.size(); }
357 bool FixedBlockSize()
const;
360 unsigned int BlockSize()
const;
362 unsigned int MaxBlockSize()
const;
366 uint16_t MinBlocks()
const {
return m_min_blocks; }
369 int16_t MaxBlocks()
const {
return m_max_blocks; }
371 bool FixedBlockCount()
const {
return m_min_blocks == m_max_blocks; }
375 if (index < m_fields.size())
376 return m_fields[index];
383 std::vector<const class FieldDescriptor *> m_fields;
386 uint16_t m_min_blocks;
387 int16_t m_max_blocks;
388 mutable bool m_populated;
389 mutable bool m_fixed_size, m_limited_size;
390 mutable unsigned int m_block_size, m_max_block_size;
392 void PopulateIfRequired()
const;
402 const std::vector<const FieldDescriptor*> &fields)
410 #endif // INCLUDE_OLA_MESSAGING_DESCRIPTOR_H_
Definition: Descriptor.h:84
Definition: DescriptorVisitor.h:43
Definition: Descriptor.h:66
A RDM unique identifier (UID).
Definition: Descriptor.h:122
Definition: Descriptor.h:320
Definition: Descriptor.h:41
Definition: Descriptor.h:141
Definition: Descriptor.h:103
Represents an IPv4 Address.
Definition: Descriptor.h:160
Definition: Descriptor.h:399
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Represents a MAC Address.
Definition: Descriptor.h:190