190class IntegerFieldDescriptor:
public FieldDescriptor {
192 typedef std::pair<type, type> Interval;
193 typedef std::vector<std::pair<type, type> > IntervalVector;
194 typedef std::map<std::string, type> LabeledValues;
196 IntegerFieldDescriptor(
const std::string &name,
197 bool little_endian =
false,
198 int8_t multiplier = 0)
199 : FieldDescriptor(name),
200 m_little_endian(little_endian),
201 m_multiplier(multiplier) {
204 IntegerFieldDescriptor(
const std::string &name,
205 const IntervalVector &intervals,
206 const LabeledValues &labels,
207 bool little_endian =
false,
208 int8_t multiplier = 0)
209 : FieldDescriptor(name),
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;
320class FieldDescriptorGroup:
public FieldDescriptor {
322 static const int16_t UNLIMITED_BLOCKS;
324 FieldDescriptorGroup(
const std::string &name,
325 const std::vector<const FieldDescriptor*> &fields,
328 : FieldDescriptor(name),
330 m_min_blocks(min_blocks),
331 m_max_blocks(max_blocks),
334 m_limited_size(
true),
336 m_max_block_size(0) {
338 virtual ~FieldDescriptorGroup();
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; }
374 const class FieldDescriptor *GetField(
unsigned int index)
const {
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;