28 #ifndef _mpqc_src_lib_chemistry_qc_mbptr12_registry_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_registry_h
33 #include <util/group/thread.h>
34 #include <util/state/state.h>
35 #include <util/state/statein.h>
36 #include <util/state/stateout.h>
50 if (!instance_restored_) {
51 instance_ =
new T(si);
52 instance_restored_ =
true;
57 if (!instance_saved_) {
58 instance_->save_data_state(so);
59 instance_saved_ =
true;
63 static bool instance_restored_;
64 static bool instance_saved_;
79 bool nonnull; si.
get(nonnull);
88 instance->save_data_state(so);
108 template <
typename Key,
typename Value,
template <
typename>
class CreationPolicy,
109 typename KeyEqual = std::equal_to<Key>,
110 typename ValueEqual = std::equal_to<Value>
112 class Registry :
public RefCount,
public CreationPolicy< Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> > {
123 template <
typename Pred>
void remove_if(
const Pred& p) {
125 typename Map::iterator i = map_.begin();
126 for(; i != map_.end(); ) {
139 const Value&
value(
const Key&
key)
const;
141 const Key&
key(
const Value& obj)
const;
146 void add(
const std::pair<Key,Value>& keyval_pair);
148 void print(std::ostream& os =
ExEnv::out0())
const;
152 not_found(
const char* what) : std::logic_error(what) {}
157 friend class CreationPolicy<
Registry<Key,Value,CreationPolicy,KeyEqual,ValueEqual> >;
166 typedef std::map<Key,Value> Map;
167 typedef typename Map::const_iterator const_iterator;
168 typedef typename Map::iterator iterator;
172 const_iterator find_by_key(
const Key&
key)
const;
174 iterator find_by_key(
const Key&
key);
176 const_iterator find_by_value(
const Value&
value)
const;
182 template <
typename T1,
typename T2>
struct SameType {
183 static const bool result =
false;
185 template <
typename T>
struct SameType<T,T> {
186 static const bool result =
true;
193 #include <util/misc/registry.timpl.h>
195 #endif // end of header guard
void add(const Key &key, const Value &obj)
registers this object
Definition: registry.timpl.h:206
A template class that maintains references counts.
Definition: ref.h:361
const Value & value(const Key &key) const
returns object that corresponds to this key. If key is not known, throws
Definition: registry.timpl.h:187
void clear()
erases all entries
Definition: registry.timpl.h:82
NonsingletonCreationPolicy is used to create non-Singletons on heap.
Definition: registry.h:73
void remove_if(const Pred &p)
removes all objects whose keys evaluate predicate to true: p(key) == true
Definition: registry.h:123
SingletonCreationPolicy is used to create Singletons.
Definition: registry.h:44
const Key & key(const Value &obj) const
returns key that corresponds to this object. If obj is not known, throws
Definition: registry.timpl.h:170
Definition: stateout.h:71
bool value_exists(const Value &value) const
value exists?
Definition: registry.timpl.h:155
static std::ostream & out0()
Return an ostream that writes from node 0.
void remove(const Key &key)
removes the object corresponding to key
Definition: registry.timpl.h:226
virtual int put(const ClassDesc *)
Write out information about the given ClassDesc.
Acquire a lock on creation and release it on destruction.
Definition: thread.h:56
The base class for all reference counted objects.
Definition: ref.h:192
Definition: registry.h:150
virtual int get(const ClassDesc **)
This restores ClassDesc's.
bool key_exists(const Key &key) const
key exists?
Definition: registry.timpl.h:140
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
Registry wraps std::map and can be policy-configured to act as a Singleton or a regular object.
Definition: registry.h:112
Generated at Sun Jan 26 2020 23:24:01 for MPQC
3.0.0-alpha using the documentation package Doxygen
1.8.16.