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 for (
size_t i = index1; i <= index2; ++i) {
660 size_t position = Identifier::NBITS -
impl.bits_offset() -
impl.bits();
662 Identifier::value_type mask = (((Identifier::value_type) 1 <<
impl.bits()) - 1) << position;
664 mask ^= Identifier::ALL_BITS;
687 ret = g->unpack (
id, prefix, index2, unpackedId);
703 const std::string& sep,
704 std::string& unpackedId)
const
708 std::vector<const IdDictFieldImplementation*> impls;
711 ret = g->unpack (
id, prefix, index2, unpacked, &impls);
714 assert (unpacked.
fields() == impls.size());
715 for (
size_t i = 0; i < unpacked.
fields(); ++i) {
718 std::string str_value(
"nil");
732 switch (range->specification()) {
735 str_value = range->field()->name() +
' '+std::to_string(value);
743 str_value += range->field()->name() +
' ';
745 str_value += range->label();
754 if (
label->valued()) {
755 str_value += range->label();
762 unsigned int index1 = 0;
763 for (
int v : range->values()) {
764 if (value == v)
break;
768 if (index1 < range->labels().size()) {
769 if (
isNumber(range->labels()[index1])) {
770 str_value += range->field()->name() +
' ';
772 str_value += range->labels()[index1];
774 std::cout <<
"IdDictDictionary::unpack - Could not find value." << std::endl;
775 std::cout <<
"value " << value << std::endl;
776 std::cout <<
"field values " << std::endl;
777 for (
int v : range->values()) {
778 std::cout << v <<
" ";
780 std::cout << std::endl;
787 std::cout <<
"unknown" << std::endl;
792 if (i > 0) unpackedId += sep;
793 unpackedId += str_value;
810 size_t first_field_index,
819 std::cout <<
"IdDictDictionary::unpack - region index too large. Index, nregions "
820 << region_index <<
" " <<
m_regions.size() << std::endl;
829 if (field_index >=
region.n_implementation()) {
830 std::cout <<
"IdDictDictionary::unpack - field index too large. Index, nfields "
831 << field_index <<
" " <<
region.n_implementation()
838 size_t prefix_offset = 0;
840 size_t position = Identifier::NBITS;
843 if (first_field_index) {
845 if (first_field_index >=
region.n_implementation()) {
846 std::cout <<
"IdDictDictionary::unpack - first_field_index too large. Index, nfields "
847 << first_field_index <<
" " <<
region.n_implementation()
854 prefix_offset =
region.implementation(first_field_index).bits_offset();
858 if (
impl.bits() == 0) {
859 std::cout <<
"IdDictDictionary::unpack - no bits for this field. Region, field indexes "
860 << region_index <<
" " << field_index << std::endl;
865 if (
impl.bits() +
impl.bits_offset() - prefix_offset > position) {
866 std::cout <<
"IdDictDictionary::unpack - bits + offset too large. Region, field indexes, bits, offset "
867 << region_index <<
" " << field_index <<
" "
868 <<
impl.bits() <<
" " <<
impl.bits_offset() <<
" " << prefix_offset
875 Identifier::value_type mask = (
static_cast<Identifier::value_type
>(1) <<
impl.bits()) - 1;
877 size_t index =
id.extract(position -=
impl.bits() +
impl.bits_offset() - prefix_offset, mask);
880 if (
impl.decode_index()) field =
impl.ored_field().get_value_at(
index);
897 size_t first_field_index,
898 size_t begin_field_index,
899 size_t end_field_index,
904 std::cout <<
"IdDictDictionary::copy - region index too large. Index, nregions "
905 << region_index <<
" " <<
m_regions.size() << std::endl;
911 if (first_field_index >=
region.n_implementation() ||
912 begin_field_index >=
region.n_implementation() ||
913 end_field_index >=
region.n_implementation()) {
914 std::cout <<
"IdDictDictionary::copy - field index too large. Indexes first, begin, end, nfields "
915 << first_field_index <<
" "
916 << begin_field_index <<
" "
917 << end_field_index <<
" "
918 <<
region.n_implementation()
923 size_t missing_offset = 0;
924 if (first_field_index) {
925 if (first_field_index > begin_field_index) {
926 std::cout <<
"IdDictDictionary::copy - first_field_index > begin_field_index. Indexes "
927 << first_field_index <<
" " << begin_field_index << std::endl;
931 missing_offset =
region.implementation(first_field_index).bits_offset();
934 size_t prefix_offset = 0;
935 if (begin_field_index) {
936 if (begin_field_index > end_field_index) {
937 std::cout <<
"IdDictDictionary::copy - begin_field_index > end_field_index. Indexes "
938 << begin_field_index <<
" " << end_field_index << std::endl;
942 prefix_offset =
region.implementation(begin_field_index).bits_offset();
946 size_t suffix_offset =
impl.bits() +
impl.bits_offset();
948 size_t position = Identifier::NBITS;
950 if (position < prefix_offset - missing_offset) {
951 std::cout <<
"IdDictDictionary::copy - position < prefix + missing. "
952 << prefix_offset <<
" " << missing_offset << std::endl;
957 if (position < suffix_offset + missing_offset) {
958 std::cout <<
"IdDictDictionary::copy - position < suffix + missing. "
959 << suffix_offset <<
" " << missing_offset << std::endl;
966 Identifier::value_type mask = Identifier::ALL_BITS;
968 Identifier::value_type prefix_mask =
969 prefix_offset ? (
static_cast<Identifier::value_type
>(1) << (position - prefix_offset + missing_offset)) - 1 : 0;
971 Identifier::value_type suffix_mask =
972 (
static_cast<Identifier::value_type
>(1) << (position - suffix_offset + missing_offset)) - 1;
974 mask -= prefix_mask + suffix_mask;
976 idout = idin.
mask_shift(mask, missing_offset);
1031 if (mr.has_overlap())
return(
false);
1050 std::map< ExpandedIdentifier, IdDictDictEntry* >
regions;
1056 std::cout <<
"IdDictDictionary::sort - WARNING verify is FALSE - cannot sort "
1071 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)