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_multiplier(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_multiplier(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_multiplier; }
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;
326 static const int16_t UNLIMITED_BLOCKS;
329 const std::vector<const FieldDescriptor*> &fields,
334 m_min_blocks(min_blocks),
335 m_max_blocks(max_blocks),
338 m_limited_size(
true),
340 m_max_block_size(0) {
346 bool FixedSize()
const {
return FixedBlockSize() && FixedBlockCount(); }
350 bool LimitedSize()
const;
354 unsigned int MaxSize()
const;
358 unsigned int FieldCount()
const {
return m_fields.size(); }
361 bool FixedBlockSize()
const;
364 unsigned int BlockSize()
const;
366 unsigned int MaxBlockSize()
const;
370 uint16_t MinBlocks()
const {
return m_min_blocks; }
373 int16_t MaxBlocks()
const {
return m_max_blocks; }
375 bool FixedBlockCount()
const {
return m_min_blocks == m_max_blocks; }
379 if (index < m_fields.size())
380 return m_fields[index];
387 std::vector<const class FieldDescriptor *> m_fields;
390 uint16_t m_min_blocks;
391 int16_t m_max_blocks;
392 mutable bool m_populated;
393 mutable bool m_fixed_size, m_limited_size;
394 mutable unsigned int m_block_size, m_max_block_size;
396 void PopulateIfRequired()
const;
406 const std::vector<const FieldDescriptor*> &fields)
414 #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:324
Definition: Descriptor.h:41
Definition: Descriptor.h:141
Definition: Descriptor.h:103
Represents an IPv4 Address.
Definition: Descriptor.h:160
Definition: Descriptor.h:403
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Represents a MAC Address.
Definition: Descriptor.h:190