18 #ifndef VCSN_AUTOMATA_CONCEPT_SMART_LABEL_HXX_
19 # define VCSN_AUTOMATA_CONCEPT_SMART_LABEL_HXX_
25 struct SmartLabel_ref_dec
27 SmartLabel_ref_dec (
const SmartLabel<T>&)
30 int operator() (SmartLabel<T>& sl)
37 struct SmartLabel_ref_inc
39 SmartLabel_ref_inc (
const SmartLabel<T>&)
42 int operator() (SmartLabel<T>& sl)
53 SmartLabel<T>::SmartLabel(
const boost::shared_ptr<T>& p)
60 SmartLabel<T>::value()
const
67 SmartLabel<T>::ref()
const
74 SmartLabel<T>::ref_dec()
81 SmartLabel<T>::ref_inc()
87 SmartLabel<T>::operator
const T&()
98 typename SmartLabelContainer<T>::hlabel_t
99 SmartLabelContainer<T>::insert (
const T& l)
101 typename label_container_t::iterator i = data_.find (l);
103 if (i != data_.end ())
105 data_.modify (i, SmartLabel_ref_inc<T> (*i));
106 return hlabel_t (&*i);
110 ::boost::shared_ptr<T> p(
new T(l));
111 return hlabel_t (&*data_.insert (SmartLabel<T> (p)).first);
115 template <
typename T>
117 SmartLabelContainer<T>::erase (
const hlabel_t& h)
119 if (h.value()->ref () > 1)
121 typename label_container_t::iterator i = data_.find (h.value()->value());
122 data_.modify (i, SmartLabel_ref_dec<T> (*i));
125 data_.erase (h.value()->value());
128 template <
typename T>
129 typename SmartLabelContainer<T>::hlabel_t
130 SmartLabelContainer<T>::update (
const hlabel_t& h,
const T& l)
136 template <
typename T>
138 SmartLabelContainer<T>::get_label (
const hlabel_t& h)
const
140 return h.value()->value();
143 template <
typename T>
144 typename SmartLabelContainer<T>::hlabel_t
145 SmartLabelContainer<T>::get_hlabel (
const T& l)
const
147 return hlabel_t (&*data_.find (l));
152 #endif // ! VCSN_AUTOMATA_CONCEPT_SMART_LABEL_HXX_ //