21 #include "SheafSystem/name_multimap.h" 23 #include "SheafSystem/sheaf_dll_spec.h" 24 #include "SheafSystem/assert_contract.h" 25 #include "SheafSystem/deep_size.h" 65 ensure(*
this == xother);
81 if(!xnames[i].empty())
83 _index_to_name_map[i].push_back(xnames[i]);
84 _name_to_index_map[xnames[i]] = i;
91 ensure_for_all(i, 0, xnames_ub, !xnames[i].empty() ? name(
index_type(i)) == xnames[i] :
true);
122 index_to_name_map_type::const_iterator map_result =
123 _index_to_name_map.find(xindex);
125 if(map_result != _index_to_name_map.end())
131 return map_result->second.front();
141 ensure(result.empty() == !contains_index(xindex));
163 while(litr != lnames.end())
176 ensure((!result.empty()) == ((0 <= xi) && (xi < name_ct(xindex))) );
196 (map_result != _index_to_name_map.end()) ? map_result->second : empty_list;
225 ensure(xresult.
ct() == name_ct(xindex));
234 index(
const std::string& xname)
const 240 require(!xname.empty());
246 typedef name_to_index_map_type::const_iterator itr_type;
248 itr_type litr = _name_to_index_map.find(xname);
250 if(litr != _name_to_index_map.end())
254 result = litr->second;
267 ensure(unexecutable(
is_valid(result) == !contains_name(xname)));
280 require(!xentry.second.empty());
281 require(!contains_name(xentry.second));
289 delete_index(xentry.first);
293 _index_to_name_map[xentry.first].push_back(xentry.second);
294 _name_to_index_map[xentry.second] = xentry.first;
298 ensure(contains_entry(xentry));
309 require(!xname.empty());
310 require(!contains_name(xname));
315 put_entry(ltmp, xunique);
319 ensure(contains_entry(xindex, xname));
334 require(!xname.empty());
338 result = _name_to_index_map.find(xname) != _name_to_index_map.end();
359 return _index_to_name_map.find(xindex) != _index_to_name_map.end();
368 require(!xname.empty());
376 result = contains_entry(entry);
391 require(!xentry.second.empty());
397 result = contains_name(xentry.second) && (index(xentry.second) == xentry.first);
420 _name_to_index_map.erase(*itr);
425 _index_to_name_map.erase(xindex);
429 ensure(!contains_index(xindex));
442 require(!xname.empty());
446 name_to_index_map_type::iterator itr = _name_to_index_map.find(xname);
448 if(itr != _name_to_index_map.end())
453 iterator lindex_entry = _index_to_name_map.find(itr->second);
457 while(lname_itr != lnames.end())
459 if((*lname_itr) == xname)
461 lnames.erase(lname_itr);
472 _index_to_name_map.erase(lindex_entry);
477 _name_to_index_map.erase(itr);
482 ensure(!contains_name(xname));
500 _name_to_index_map.clear();
501 _index_to_name_map.clear();
524 bool result = (_name_to_index_map.empty() && _index_to_name_map.empty());
541 return _index_to_name_map.begin();
548 return _index_to_name_map.end();
555 return _index_to_name_map.size();
574 while(itr != xm.
end())
576 xos <<
"index: " << itr->first <<
"\tnames: " ;
580 while(name_itr != lnames.end())
582 xos <<
" \"" << *name_itr <<
"\"";
600 return all_names(xindex).size();
629 ensure(is_same_type(result));
648 result = result && any::invariant();
650 if(invariant_check())
654 disable_invariant_check();
656 invariance(_index_to_name_map.size() <= _name_to_index_map.size());
660 enable_invariant_check();
677 require(xother != 0);
683 bool result =
dynamic_cast<const name_multimap*
>(xother) != 0;
699 (_name_to_index_map == xother._name_to_index_map) &&
700 (_index_to_name_map == xother._index_to_name_map);
718 _name_to_index_map = xother._name_to_index_map;
719 _index_to_name_map = xother._index_to_name_map;
724 ensure(*
this == xother);
768 result = xinclude_shallow ?
sizeof(xp) : 0;
775 result += deep_size<string, index_type, name_to_index_policy>
776 (xp._name_to_index_map,
false);
779 result += deep_size<index_type, list<string>, index_to_name_policy>
780 (xp._index_to_name_map,
false);
bool contains_entry(const entry_type &xentry) const
True if this already contains an entry equal to xentry.
size_type name_ct(const index_type &xindex) const
The number of names associated with key xindex.
name_list_type::iterator name_iterator
The iterator type for names.
size_type ct() const
The number of items currently in use.
const_iterator begin() const
The initial value for iterators over this map.
pod_index_type index_type
The type of the index in the map.
index_type index(const std::string &xname) const
The index associated with name xname.
void delete_name(const std::string &xname)
Removes the entry for name xname.
name_list_type::const_iterator const_name_iterator
The const iterator type for names.
const name_list_type & all_names(index_type xindex) const
All names associated with index xindex.
void clear()
Removes all entries.
std::list< std::string > name_list_type
The type of name list for this map.
std::map< index_type, name_list_type >::iterator iterator
The iterator type for this map.
A partial multi-valued relation with total injective inverse between names and indices of type index_...
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
Call deep_size on the key.
const_iterator end() const
The final value for iterators over this map.
Abstract base class with useful features for all objects.
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
std::pair< index_type, std::string > entry_type
The type of an entry in the map.
virtual name_multimap * clone() const
Virtual constructor; makes a new instance of the same type as this.
int ct() const
The number of index values in the map.
void set_ct(size_type xct)
Sets ct() == xct.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
virtual ~name_multimap()
Destructor.
bool contains_name(const std::string &xname) const
True if this already contains an entry with name xname.
bool operator==(const name_multimap &xother)
Equality test; true if other has the same contents as this.
Call deep_size on the value.
bool contains_index(index_type xindex) const
True if this already contains an entry with index xindex.
name_multimap()
Default constructor.
bool empty() const
True if and only if the map contains no entries.
virtual bool invariant() const
Class invariant.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
void put_entry(const entry_type &xentry, bool xunique)
Sets (xindex, xname) as an entry in the map. If xunique, deletes all other entries for xindex...
void print() const
Prints the data members of this on cout. Intended for use debugging.
std::string name(index_type xindex) const
The primary (0-th) name associated with index xindex.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
std::map< index_type, name_list_type >::const_iterator const_iterator
The const iterator type for this map.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
void delete_index(index_type xindex)
Removes all entires for index xindex.
name_multimap & operator=(const name_multimap &xother)
Assignment operator; make this a copy of xother.