LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
endomap.hxx
Go to the documentation of this file.
1 
6 #ifndef MISC_ENDOMAP_HXX
7 # define MISC_ENDOMAP_HXX
8 
9 #include <misc/endomap.hh>
10 
11 namespace misc
12 {
13 
14  template <class T>
16  : map<T, T>(), strictness_(nonstrict)
17  {
18  }
19 
20  template <class T>
23  {
24  return new endo_map<T>(*this);
25  }
26 
27  template <class T>
29  {
30  }
31 
32  template <class T>
33  T
34  endo_map<T>::operator()(const T& t) const
35  {
36  typename super_type::map_type::const_iterator ires = this->find(t);
37  if (ires != this->map_.end())
38  return ires->second;
39  else if (this->strictness_ == nonstrict)
40  return t;
41  std::ostringstream err;
42  err << "map: no mapping for " << t;
43  throw std::range_error(err.str());
44  }
45 
46  template <class T>
47  T&
49  {
50  // Inspired by ``Efficient STL'' on efficient insert_or_update
51  // for maps. See also misc::put.
52  typename super_type::map_type::iterator i = this->map_.lower_bound(t);
53  if (i == this->map_.end() || this->map_.key_comp()(t, i->first))
54  i = this->map_.emplace(t, t).first;
55  return i->second;
56  }
57 
58 }
59 
60 #endif // !MISC_ENDOMAP_HXX