00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef VIENNADATA_DATA_CONTAINER_HPP
00014 #define VIENNADATA_DATA_CONTAINER_HPP
00015
00016
00017 #include <map>
00018
00019 #include "viennadata/forwards.h"
00020 #include "viennadata/config/object_identifier.hpp"
00021 #include "viennadata/traits/data_container.hpp"
00022 #include "viennadata/key_value_registration.hpp"
00023
00029 namespace viennadata
00030 {
00031
00039 template <typename KeyType,
00040 typename DataType,
00041 typename ObjectType>
00042 class data_container
00043 {
00044 private:
00046 typedef typename traits::container<KeyType, DataType, ObjectType>::container_type container_type;
00047
00048 container_type container;
00049
00051 data_container() {}
00053 data_container(data_container const & other) {}
00055 ~data_container() {}
00056
00057 public:
00058 typedef typename traits::data_type_reference<DataType, container_type>::type reference;
00059
00061 static data_container & instance()
00062 {
00063 static data_container * da = NULL;
00064 if (da == NULL)
00065 {
00066 da = new data_container();
00067 key_value_registration<ObjectType>::instance().template add<KeyType, DataType>();
00068 }
00069
00070 return *da;
00071 }
00072
00074 reference access(ObjectType const & obj,
00075 KeyType const & key)
00076 {
00077 return traits::container<KeyType, DataType, ObjectType>::access(container, obj, key);
00078 }
00079
00081 reference access(ObjectType const & obj)
00082 {
00083 return traits::container<KeyType, DataType, ObjectType>::access(container, obj);
00084 }
00085
00087
00088
00094 template <typename ObjectDestType>
00095 void copy(ObjectType const & obj_src,
00096 ObjectDestType const & obj_dest)
00097 {
00098 data_container<KeyType, DataType, ObjectDestType>::instance().copy(container, obj_src, obj_dest);
00099 }
00100
00101
00102
00109 template <typename ContainerSrcType,
00110 typename ObjectSrcType>
00111 void copy(ContainerSrcType & cont_src,
00112 ObjectSrcType const & obj_src,
00113 ObjectType const & obj_dest)
00114 {
00115 traits::container<KeyType, DataType, ObjectType>::copy(cont_src, obj_src, container, obj_dest);
00116 }
00117
00119
00124 void erase(ObjectType const & obj,
00125 KeyType const & key)
00126 {
00127 traits::container<KeyType, DataType, ObjectType>::erase(container, obj, key);
00128 }
00129
00130
00135 void erase(ObjectType const & obj)
00136 {
00137 traits::container<KeyType, DataType, ObjectType>::erase(container, obj);
00138 }
00139
00140
00142 void reserve(long num)
00143 {
00144
00145 traits::container<KeyType, DataType, ObjectType>::reserve(container, num);
00146 }
00147
00152 DataType * find(ObjectType const & obj,
00153 KeyType const & key)
00154 {
00155 return traits::container<KeyType, DataType, ObjectType>::find(container, obj, key);
00156 }
00157
00162 DataType * find(ObjectType const & obj)
00163 {
00164 return traits::container<KeyType, DataType, ObjectType>::find(container, obj);
00165 }
00166
00167 };
00168
00169 }
00170
00171 #endif