28 #ifndef _mpqc_src_lib_chemistry_qc_mbptr12_registrytimpl_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_registrytimpl_h
33 #include <util/state/statein.h>
34 #include <util/state/stateout.h>
35 #include <util/misc/registry.h>
39 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
40 Ref< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >
41 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::instance()
43 return CreationPolicy< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >::instance();
46 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
48 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::save_instance(
const Ref<Registry>& obj, StateOut& so)
50 CreationPolicy< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >::save_instance(obj, so);
53 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
54 Ref< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >
55 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::restore_instance(StateIn& si)
57 return CreationPolicy< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >::instance(si);
60 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
61 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::Registry() :
62 lock_(ThreadGrp::get_default_threadgrp()->new_lock())
66 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
67 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::Registry(StateIn& si) :
68 lock_(ThreadGrp::get_default_threadgrp()->new_lock())
73 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
75 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::save_data_state(StateOut& so)
80 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
88 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
89 typename Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::const_iterator
93 if (SameType<KeyEqual,std::equal_to<Key> >::result) {
94 const_iterator result = map_.find(
key);
99 for(const_iterator v=map_.begin(); v!= map_.end(); ++v)
100 if (keyeq(v->first,
key))
106 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
107 typename Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::iterator
108 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::find_by_key(
const Key&
key)
111 if (SameType<KeyEqual,std::equal_to<Key> >::result) {
112 iterator result = map_.find(
key);
117 for(iterator v=map_.begin(); v!= map_.end(); ++v)
118 if (keyeq(v->first,
key))
124 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
125 typename Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::const_iterator
126 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::find_by_value(
const Value&
value)
const
128 const_iterator result;
131 for(const_iterator v=map_.begin(); v!= map_.end(); ++v)
132 if (valeq(v->second,
value))
138 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
145 const_iterator v = find_by_key(
key);
153 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
161 const_iterator v = find_by_value(
value);
168 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
174 const_iterator v = find_by_value(
value);
175 if (v != map_.end()) {
185 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
191 const_iterator v = find_by_key(
key);
192 if (v != map_.end()) {
204 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
212 throw std::logic_error(
"key already exists");
217 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
221 this->
add(keyval_pair.first,keyval_pair.second);
224 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
229 iterator v = find_by_key(
key);
234 template <
typename T1,
typename T2>
235 std::ostream&
operator<<(std::ostream& os,
const std::pair<T1, T2>& val) {
236 os <<
"{ " << val.first <<
", " << val.second <<
" }";
240 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
typename KeyEqual,
typename ValueEqual >
242 Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual>::print(std::ostream& os)
const
244 ThreadLockHolder lh(lock_);
245 for(
typename Map::const_iterator iter = map_.begin();
248 os << iter->first <<
" " << iter->second << std::endl;
254 #endif // end of header guard