Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef VIENNADATA_KEY_VALUE_REGISTRATION_HPP
00017 #define VIENNADATA_KEY_VALUE_REGISTRATION_HPP
00018
00019 #include <assert.h>
00020 #include <map>
00021 #include <vector>
00022 #include <list>
00023 #include <set>
00024 #include <iostream>
00025 #include <algorithm>
00026 #include <memory>
00027
00028 #include "viennadata/key_value_pair.hpp"
00029
00030
00036 namespace viennadata
00037 {
00042 template <typename ObjectType>
00043 class key_value_registration
00044 {
00045 typedef std::vector<key_value_pair<ObjectType> > container_type;
00046
00048 key_value_registration() {}
00050 key_value_registration(key_value_registration const &) {}
00052 ~key_value_registration() {}
00053
00054 public:
00055
00057 static key_value_registration & instance()
00058 {
00059 static key_value_registration * kvr = NULL;
00060 if (kvr == NULL)
00061 kvr = new key_value_registration();
00062
00063 return *kvr;
00064 }
00065
00067 template <typename KeyType,
00068 typename DataType>
00069 void add()
00070 {
00071 key_value_pair<ObjectType> kve;
00072 kve.template add<KeyType, DataType>();
00073
00074
00075 if (std::find(container.begin(), container.end(), kve) == container.end())
00076 container.push_back(kve);
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00093
00094 template <typename KeyType>
00095 void erase_key_all(ObjectType const & obj) const
00096 {
00097 typedef typename container_type::const_iterator ContIter;
00098
00099 key_value_pair<ObjectType> kve;
00100 kve.template add<KeyType, all>();
00101
00102 for (ContIter it = container.begin();
00103 it != container.end();
00104 ++it)
00105 {
00106 if (*it == kve)
00107 it->erase(obj);
00108 }
00109 }
00110
00112 template <typename DataType>
00113 void erase_all_value(ObjectType const & obj) const
00114 {
00115 typedef typename container_type::const_iterator ContIter;
00116
00117 key_value_pair<ObjectType> kve;
00118 kve.template add<all, DataType>();
00119
00120 for (ContIter it = container.begin();
00121 it != container.end();
00122 ++it)
00123 {
00124 if (*it == kve)
00125 it->erase(obj);
00126 }
00127 }
00128
00130 void erase_all_all(ObjectType const & obj) const
00131 {
00132 typedef typename container_type::const_iterator ContIter;
00133
00134 for (ContIter it = container.begin();
00135 it != container.end();
00136 ++it)
00137 {
00138 it->erase(obj);
00139 }
00140 }
00141
00142
00144
00149 template <typename KeyType>
00150 void copy_key_all(ObjectType const & src,
00151 ObjectType const & dest) const
00152 {
00153 typedef typename container_type::const_iterator ContIter;
00154
00155 key_value_pair<ObjectType> kve;
00156 kve.template add<KeyType, all>();
00157
00158 for (ContIter it = container.begin();
00159 it != container.end();
00160 ++it)
00161 {
00162 if (*it == kve)
00163 it->copy(src, dest);
00164 }
00165 }
00166
00172 template <typename value_type>
00173 void copy_all_value(ObjectType const & src,
00174 ObjectType const & dest) const
00175 {
00176 typedef typename container_type::const_iterator ContIter;
00177
00178 key_value_pair<ObjectType> kve;
00179 kve.template add<all, value_type>();
00180
00181 for (ContIter it = container.begin();
00182 it != container.end();
00183 ++it)
00184 {
00185 if (*it == kve)
00186 it->copy(src, dest);
00187 }
00188 }
00189
00195 void copy_all_all(ObjectType const & src,
00196 ObjectType const & dest) const
00197 {
00198 typedef typename container_type::const_iterator ContIter;
00199
00200 for (ContIter it = container.begin();
00201 it != container.end();
00202 ++it)
00203 {
00204 it->copy(src, dest);
00205 }
00206 }
00207
00208
00209 private:
00210 container_type container;
00211 };
00212
00213 }
00214
00215 #endif