25 for (
unsigned int i = 0; i <
str.size(); ++i) {
26 if (!isdigit(
str[i]))
return(
false);
28 if (0 ==
str.size())
return(
false);
38 const std::string&
date ,
39 const std::string& author )
62 return it->second.get();
80 return it->second.get();
87 if (!idField)
return nullptr;
95 if (!idLabel || !idLabel->
valued())
return(1);
97 value = idLabel->
value();
102 if (!field)
return nullptr;
103 return m_fields.emplace (field->name(), std::move(field)).first->second.get();
110 return it->second.get();
122 if ((group_name !=
"") && (
region->group_name() != group_name))
continue;
123 if ((region_name !=
"") && (
region->name() != region_name))
continue;
133 if ((group_name !=
"") && (
region->group_name() != group_name))
continue;
134 if ((region_name !=
"") && (
region->name() != region_name))
continue;
143 if (g && g->name() == group_name)
return g.get();
151 if (g && g->name() == group_name)
return g.get();
158 if (!subregion)
return nullptr;
159 return m_subregions.emplace (subregion->name(), std::move(subregion)).first->second.get();
176 m_groups.push_back(std::make_unique<IdDictGroup>(
region->group_name()));
179 group->add_dictentry(std::move(
region));
188 p.second->resolve_references(idd, *
this);
192 g->resolve_references(idd, *
this,
index);
197 const std::string& tag) {
199 std::cout <<
"IdDictDictionary::generate_implementation>" << std::endl;
206 g->generate_implementation(idd, *
this, tag);
221 if (
"dummy" == g->name())
continue;
230 g->build_region_tree();
236 (*itr)->find_neighbours(*
this);
247 g->reset_implementation();
265 if (range.match(
id) && range.fields() >=
id.fields()) {
287 if ((group_name !=
"") && (
region.group_name() != group_name))
continue;
291 if (range.match(
id) && range.fields() >=
id.fields()) {
313 MultiRange group_mr = group->build_multirange();
315 for (
unsigned int i = 0; i < group_mr.
size(); ++i) {
316 const Range& range = group_mr[i];
326 const std::string& last_field)
const {
330 if (
"" == last_field) {
336 if (
"dummy" ==
region.name())
continue;
340 if (
region.is_empty())
continue;
344 if (range.match(region_id))
result.add(std::move(range));
352 if (
"dummy" ==
region.name())
continue;
356 if (
region.is_empty())
continue;
360 if (range.match(region_id)) {
363 Range new_range(prefix);
365 size_t nimpl =
region.n_implementation();
366 for (
size_t i = 0; i < nimpl; ++i) {
370 new_range.
add(
impl.range()->build_range());
372 if (last_field ==
impl.range()->field()->name()) {
376 result.add(std::move(new_range));
385 const std::string& group_name,
387 const std::string& last_field)
const {
391 if (
"" == last_field) {
397 if (
"dummy" ==
region.name())
continue;
401 if (
region.is_empty())
continue;
405 if (range.match(region_id) &&
region.group_name() == group_name)
result.add(std::move(range));
413 if (
"dummy" ==
region.name())
continue;
417 if (
region.is_empty())
continue;
421 if (range.match(region_id) &&
region.group_name() == group_name) {
424 Range new_range(prefix);
426 size_t nimpl =
region.n_implementation();
427 for (
size_t i = 0; i < nimpl; ++i) {
431 new_range.
add(
impl.range()->build_range());
433 if (last_field ==
impl.range()->field()->name()) {
437 result.add(std::move(new_range));
468 if (index2 < index1) {
473 if (index1 >=
id.fields()) {
478 if (index2 >=
id.fields()) {
492 for (
size_t k = 0; k <
m_regions.size(); ++k) {
493 bool selected =
true;
499 if (
region.is_empty())
continue;
501 for (
size_t i = 0; i <
region.n_implementation(); ++i) {
502 if (i >=
id.fields())
break;
506 if (!
impl.field().match(
id[i])) {
513 size_t position = Identifier::NBITS;
515 for (
size_t i = index1; i <= index2; ++i) {
518 Identifier::value_type
index =
impl.ored_field().get_value_index(
id[i]);
520 if (0 == position &&
impl.bits() > 0) {
524 position -=
impl.bits();
525 packedId |= (
index << position);
541 size_t first_field_index)
const {
545 if (index2 < index1) {
547 std::cout <<
"IdDictDictionary::pack32 - index2 < index1 - 1,2"
548 << index1 <<
" " << index2 << std::endl;
554 std::cout <<
"IdDictDictionary::pack32 - region index incorrect - index,size"
555 << region_index <<
" " <<
m_regions.size() << std::endl;
566 std::cout <<
"IdDictDictionary::pack32 - region id empty" << std::endl;
570 if (index1 < first_field_index) {
571 std::cout <<
"IdDictDictionary::pack32 - first_field_index > index1 "
572 << first_field_index <<
" " << index1 << std::endl;
578 size_t position = Identifier::NBITS;
579 if (!first_field_index) {
581 position -=
impl.bits_offset();
584 size_t field_index = 0;
585 for (
size_t i = index1; i <= index2; ++i, ++field_index) {
590 if (!
impl.ored_field().match(fields[field_index])) {
591 std::cout <<
"IdDictDictionary::pack32 - field does NOT match: value, allowed values "
592 << fields[field_index] <<
" " << (std::string)
impl.ored_field()
599 if (0 == position &&
impl.bits() > 0) {
600 std::cout <<
"IdDictDictionary::pack32 - going past 0" << std::endl;
605 Identifier::value_type
index;
606 if (
impl.decode_index()) {
607 index =
impl.ored_field().get_value_index(fields[field_index]);
609 index = (Identifier::value_type) fields[field_index];
612 position -=
impl.bits();
613 packedId |= (
index << position);
630 if (index2 < index1) {
632 std::cout <<
"IdDictDictionary::pack32 - index2 < index1 - 1,2"
633 << index1 <<
" " << index2 << std::endl;
639 std::cout <<
"IdDictDictionary::pack32 - region index incorrect - index,size"
640 << region_index <<
" " <<
m_regions.size() << std::endl;
651 std::cout <<
"IdDictDictionary::pack32 - region id empty" << std::endl;
657 size_t field_index = 0;
658 for (
size_t i = index1; i <= index2; ++i, ++field_index) {
661 size_t position = Identifier::NBITS -
impl.bits_offset() -
impl.bits();
663 Identifier::value_type mask = (((Identifier::value_type) 1 <<
impl.bits()) - 1) << position;
665 mask ^= Identifier::ALL_BITS;
688 ret = g->unpack (
id, prefix, index2, unpackedId);
704 const std::string& sep,
705 std::string& unpackedId)
const
709 std::vector<const IdDictFieldImplementation*> impls;
712 ret = g->unpack (
id, prefix, index2, unpacked, &impls);
715 assert (unpacked.
fields() == impls.size());
716 for (
size_t i = 0; i < unpacked.
fields(); ++i) {
719 std::string str_value(
"nil");
733 switch (range->specification()) {
736 str_value = range->field()->name() +
' '+std::to_string(value);
744 str_value += range->field()->name() +
' ';
746 str_value += range->label();
755 if (
label->valued()) {
756 str_value += range->label();
763 unsigned int index1 = 0;
764 for (
int v : range->values()) {
765 if (value == v)
break;
769 if (index1 < range->labels().size()) {
770 if (
isNumber(range->labels()[index1])) {
771 str_value += range->field()->name() +
' ';
773 str_value += range->labels()[index1];
775 std::cout <<
"IdDictDictionary::unpack - Could not find value." << std::endl;
776 std::cout <<
"value " << value << std::endl;
777 std::cout <<
"field values " << std::endl;
778 for (
int v : range->values()) {
779 std::cout << v <<
" ";
781 std::cout << std::endl;
788 std::cout <<
"unknown" << std::endl;
793 if (i > 0) unpackedId += sep;
794 unpackedId += str_value;
811 size_t first_field_index,
820 std::cout <<
"IdDictDictionary::unpack - region index too large. Index, nregions "
821 << region_index <<
" " <<
m_regions.size() << std::endl;
830 if (field_index >=
region.n_implementation()) {
831 std::cout <<
"IdDictDictionary::unpack - field index too large. Index, nfields "
832 << field_index <<
" " <<
region.n_implementation()
839 size_t prefix_offset = 0;
841 size_t position = Identifier::NBITS;
844 if (first_field_index) {
846 if (first_field_index >=
region.n_implementation()) {
847 std::cout <<
"IdDictDictionary::unpack - first_field_index too large. Index, nfields "
848 << first_field_index <<
" " <<
region.n_implementation()
855 prefix_offset =
region.implementation(first_field_index).bits_offset();
859 if (
impl.bits() == 0) {
860 std::cout <<
"IdDictDictionary::unpack - no bits for this field. Region, field indexes "
861 << region_index <<
" " << field_index << std::endl;
866 if (
impl.bits() +
impl.bits_offset() - prefix_offset > position) {
867 std::cout <<
"IdDictDictionary::unpack - bits + offset too large. Region, field indexes, bits, offset "
868 << region_index <<
" " << field_index <<
" "
869 <<
impl.bits() <<
" " <<
impl.bits_offset() <<
" " << prefix_offset
876 Identifier::value_type mask = (
static_cast<Identifier::value_type
>(1) <<
impl.bits()) - 1;
878 size_t index =
id.extract(position -=
impl.bits() +
impl.bits_offset() - prefix_offset, mask);
881 if (
impl.decode_index()) field =
impl.ored_field().get_value_at(
index);
898 size_t first_field_index,
899 size_t begin_field_index,
900 size_t end_field_index,
905 std::cout <<
"IdDictDictionary::copy - region index too large. Index, nregions "
906 << region_index <<
" " <<
m_regions.size() << std::endl;
912 if (first_field_index >=
region.n_implementation() ||
913 begin_field_index >=
region.n_implementation() ||
914 end_field_index >=
region.n_implementation()) {
915 std::cout <<
"IdDictDictionary::copy - field index too large. Indexes first, begin, end, nfields "
916 << first_field_index <<
" "
917 << begin_field_index <<
" "
918 << end_field_index <<
" "
919 <<
region.n_implementation()
924 size_t missing_offset = 0;
925 if (first_field_index) {
926 if (first_field_index > begin_field_index) {
927 std::cout <<
"IdDictDictionary::copy - first_field_index > begin_field_index. Indexes "
928 << first_field_index <<
" " << begin_field_index << std::endl;
932 missing_offset =
region.implementation(first_field_index).bits_offset();
935 size_t prefix_offset = 0;
936 if (begin_field_index) {
937 if (begin_field_index > end_field_index) {
938 std::cout <<
"IdDictDictionary::copy - begin_field_index > end_field_index. Indexes "
939 << begin_field_index <<
" " << end_field_index << std::endl;
943 prefix_offset =
region.implementation(begin_field_index).bits_offset();
947 size_t suffix_offset =
impl.bits() +
impl.bits_offset();
949 size_t position = Identifier::NBITS;
951 if (position < prefix_offset - missing_offset) {
952 std::cout <<
"IdDictDictionary::copy - position < prefix + missing. "
953 << prefix_offset <<
" " << missing_offset << std::endl;
958 if (position < suffix_offset + missing_offset) {
959 std::cout <<
"IdDictDictionary::copy - position < suffix + missing. "
960 << suffix_offset <<
" " << missing_offset << std::endl;
967 Identifier::value_type mask = Identifier::ALL_BITS;
969 Identifier::value_type prefix_mask =
970 prefix_offset ? (
static_cast<Identifier::value_type
>(1) << (position - prefix_offset + missing_offset)) - 1 : 0;
972 Identifier::value_type suffix_mask =
973 (
static_cast<Identifier::value_type
>(1) << (position - suffix_offset + missing_offset)) - 1;
975 mask -= prefix_mask + suffix_mask;
977 idout = idin.
mask_shift(mask, missing_offset);
1032 if (mr.has_overlap())
return(
false);
1051 std::map< ExpandedIdentifier, IdDictDictEntry* >
regions;
1057 std::cout <<
"IdDictDictionary::sort - WARNING verify is FALSE - cannot sort "
1072 std::cout <<
"=== IdDictDictionary " <<
m_name <<
" " <<
m_version <<
" "
const boost::regex re(r_e)
void get_bits(const RV ®ions, size_t level, const std::string &group)
static bool isNumber(const std::string &str)
static const std::vector< std::string > regions
bool isNumber(const std::string &s)
bool verify() const
Here, we verify global constraints : (this must only be applied after the resolve_references and gene...
std::vector< std::unique_ptr< IdDictGroup > > m_groups
bool do_checks() const
Checks are performed by default in debug compilation and NOT in optimized compilation.
IdDictSubRegion * add_subregion(std::unique_ptr< IdDictSubRegion > subregion)
int unpack(const std::string &group, const Identifier &id, const ExpandedIdentifier &prefix, size_t index2, ExpandedIdentifier &unpackedId) const
Unpack the value_type id to an expanded Identifier for a given group, considering the provided prefix...
std::map< std::string, std::unique_ptr< IdDictField > > m_fields
void resolve_references(IdDictMgr &idd)
void dump() const
Dump regions and trees for each group.
void add_dictentry(std::unique_ptr< IdDictDictEntry > entry)
regions_type::iterator regions_it
const IdDictLabel * find_label(const std::string &field, const std::string &label) const
IdDictDictionary * m_parent_dict
void set_do_checks(bool do_checks)
void reset_implementation()
bool m_generated_implementation
Identifier::size_type size_type
MultiRange build_multirange() const
Get MultiRange for full dictionary.
void set_do_neighbours(bool do_neighbours)
std::map< std::string, std::unique_ptr< IdDictSubRegion > > m_subregions
const std::string & version() const
Dictionary version.
int get_label_value(const std::string &field, const std::string &label, int &value) const
void generate_implementation(const IdDictMgr &idd, const std::string &tag="")
IdDictSubRegion * find_subregion(const std::string &subregion_name)
std::vector< IdDictRegion * > m_regions
IdDictGroup * find_group(const std::string &group_name)
int copy(const Identifier &idin, size_t first_field_index, size_t begin_field_index, size_t end_field_index, size_t region_index, Identifier &idout) const
Copy a number of fields of the value_type id into another value_type id.
void integrate_bits()
Set up integral of bits for efficient unpacking.
const std::string & name() const
Dictionary name.
void set_parent_dict(IdDictDictionary *parent_dict)
std::vector< IdDictRegion * > m_all_regions
IdDictField * add_field(std::unique_ptr< IdDictField > field)
const IdDictField * find_field(const std::string &name) const
int pack32(const ExpandedIdentifier &id, size_t index1, size_t index2, Identifier &packedId) const
Pack to 32bits the subset of id between (inclusive) index1 and index2 - this is generic,...
int reset(size_t index1, size_t index2, size_t region_index, Identifier &packedId) const
Reset fields from index1 to index2.
const IdDictRegion * find_region(const std::string ®ion_name) const
std::vector< std::string > m_subdictionary_names
const IdDictRegion & region(size_t i) const
Region at index i.
void add_region(IdDictRegion *region)
void add_subdictionary_name(const std::string &name)
regions_type::const_iterator regions_const_it
bool do_neighbours() const
Neighbour initialization is performed by default One can switch or query this mode for any idHelper w...
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
const IdDictLabel * find_label(const std::string &name) const
value_type mask_shift(value_type mask, size_type shift) const
extract field(s) by masking first, then shifting
A MultiRange combines several Ranges.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
void add(element_type value)
Add a required value. (ie. low = high = value)
std::string date()
sadly, includes a return at the end
std::string label(const std::string &format, int i)
void get_bits(const RV ®ions, size_t level, const std::string &group)