00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef VIENNADATA_INTERFACE_HPP
00014 #define VIENNADATA_INTERFACE_HPP
00015
00016 #include "forwards.h"
00017 #include "viennadata/data_container.hpp"
00018 #include "viennadata/key_value_registration.hpp"
00019 #include "viennadata/config/default_data_for_key.hpp"
00020
00031 namespace viennadata
00032 {
00033
00035
00040 template <typename KeyType,
00041 typename DataType>
00042 class data_accessor_with_key
00043 {
00044 public:
00045 data_accessor_with_key(KeyType const & key) : key_(key) {}
00046
00047 template <typename ObjectType>
00048 DataType & operator()(ObjectType const & el)
00049 {
00050
00051 return data_container<KeyType, DataType, ObjectType>::instance().access(el, key_);
00052 }
00053
00054 private:
00055 KeyType const & key_;
00056 };
00057
00063 template <typename KeyType,
00064 typename DataType>
00065 class data_accessor_no_key
00066 {
00067 public:
00068 data_accessor_no_key() {}
00069
00070 template <typename ObjectType>
00071 typename data_container<KeyType, DataType, ObjectType>::reference
00072 operator()(ObjectType const & el)
00073 {
00074
00075
00076 return data_container<KeyType, DataType, ObjectType>::instance().access(el);
00077 }
00078 };
00079
00080
00081
00094 template <typename KeyType,
00095 typename DataType>
00096 data_accessor_with_key<KeyType, DataType> access(KeyType const & key)
00097 {
00098 return data_accessor_with_key<KeyType, DataType>(key);
00099 }
00100
00114 template <typename KeyType>
00115 data_accessor_with_key<KeyType, typename config::default_data_for_key<KeyType>::type> access(KeyType const & key)
00116 {
00117 return data_accessor_with_key<KeyType, typename config::default_data_for_key<KeyType>::type>(key);
00118 }
00119
00120
00121
00134 template <typename KeyType,
00135 typename DataType>
00136 data_accessor_no_key<KeyType, DataType> access()
00137 {
00138 return data_accessor_no_key<KeyType, DataType>();
00139 }
00140
00152 template <typename KeyType>
00153 data_accessor_no_key<KeyType, typename config::default_data_for_key<KeyType>::type > access()
00154 {
00155 return data_accessor_no_key<KeyType, typename config::default_data_for_key<KeyType>::type >();
00156 }
00157
00159
00164 template <typename KeyType,
00165 typename DataType>
00166 class data_erasor_with_key
00167 {
00168 public:
00169 data_erasor_with_key(KeyType const & k) : key(k) {}
00170
00171 template <typename ObjectType>
00172 void operator()(ObjectType const & el)
00173 {
00174 data_container<KeyType, DataType, ObjectType>::instance().erase(el, key);
00175 }
00176 private:
00177 KeyType const & key;
00178 };
00179
00180
00182 template <typename KeyType>
00183 class data_erasor_with_key<KeyType, all>
00184 {
00185 typedef typename error_indicator<KeyType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_ERASE_FUNCTION_WITH_ALL error_type;
00186 };
00187
00189 template <typename DataType>
00190 class data_erasor_with_key<all, DataType>
00191 {
00192 typedef typename error_indicator<DataType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_ERASE_FUNCTION_WITH_ALL error_type;
00193 };
00194
00196 template <>
00197 class data_erasor_with_key<all, all>
00198 {
00199
00200 };
00201
00207 template <typename KeyType,
00208 typename DataType>
00209 class data_erasor_no_key
00210 {
00211 public:
00212 data_erasor_no_key() {}
00213
00214 template <typename ObjectType>
00215 void operator()(ObjectType const & el)
00216 {
00217 data_container<KeyType, DataType, ObjectType>::instance().erase(el);
00218 }
00219 };
00220
00222 template <typename KeyType>
00223 class data_erasor_no_key <KeyType, all>
00224 {
00225 public:
00226 data_erasor_no_key() {}
00227
00228 template <typename ObjectType>
00229 void operator()(ObjectType const & el)
00230 {
00231 key_value_registration<ObjectType>::instance().template erase_key_all<KeyType>(el);
00232 }
00233 };
00234
00236 template <typename DataType>
00237 class data_erasor_no_key <all, DataType>
00238 {
00239 public:
00240 data_erasor_no_key() {}
00241
00242 template <typename ObjectType>
00243 void operator()(ObjectType const & el)
00244 {
00245 key_value_registration<ObjectType>::instance().template erase_all_value<DataType>(el);
00246 }
00247 };
00248
00250 template <>
00251 class data_erasor_no_key <all, all>
00252 {
00253 public:
00254 data_erasor_no_key() {}
00255
00256 template <typename ObjectType>
00257 void operator()(ObjectType const & el)
00258 {
00259 key_value_registration<ObjectType>::instance().erase_all_all(el);
00260 }
00261 };
00262
00273 template <typename KeyType,
00274 typename DataType>
00275 data_erasor_with_key<KeyType, DataType> erase(KeyType const & key)
00276 {
00277 return data_erasor_with_key<KeyType, DataType>(key);
00278 }
00279
00291 template <typename KeyType>
00292 data_erasor_with_key<KeyType, typename config::default_data_for_key<KeyType>::type> erase(KeyType const & key)
00293 {
00294 return data_erasor_with_key<KeyType, typename config::default_data_for_key<KeyType>::type>(key);
00295 }
00296
00307 template <typename KeyType,
00308 typename DataType>
00309 data_erasor_no_key<KeyType, DataType> erase()
00310 {
00311 return data_erasor_no_key<KeyType, DataType>();
00312 }
00313
00325 template <typename KeyType>
00326 data_erasor_no_key<KeyType, typename config::default_data_for_key<KeyType>::type> erase()
00327 {
00328 return data_erasor_no_key<KeyType, typename config::default_data_for_key<KeyType>::type>();
00329 }
00330
00331
00332
00334
00339 template <typename KeyType,
00340 typename DataType>
00341 class data_copy_with_key
00342 {
00343 public:
00344 data_copy_with_key(KeyType const & key) : key_(key) {}
00345
00346 template <typename ObjectSrcType,
00347 typename ObjectDestType>
00348 void operator()(ObjectSrcType const & el_src,
00349 ObjectDestType const & el_dest)
00350 {
00351 access<KeyType, DataType>(key_)(el_dest) = access<KeyType, DataType>(key_)(el_src);
00352 }
00353 private:
00354 KeyType const & key_;
00355 };
00356
00357
00359 template <typename KeyType>
00360 class data_copy_with_key<KeyType, all>
00361 {
00362 typedef typename error_indicator<KeyType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_COPY_FUNCTION_WITH_ALL error_type;
00363 };
00364
00366 template <typename DataType>
00367 class data_copy_with_key<all, DataType>
00368 {
00369 typedef typename error_indicator<DataType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_COPY_FUNCTION_WITH_ALL error_type;
00370 };
00371
00373 template <>
00374 class data_copy_with_key<all, all>
00375 {
00376
00377 };
00378
00389 template <typename KeyType,
00390 typename DataType>
00391 data_copy_with_key<KeyType, DataType> copy(KeyType const & key)
00392 {
00393 return data_copy_with_key<KeyType, DataType>(key);
00394 }
00395
00407 template <typename KeyType>
00408 data_copy_with_key<KeyType, typename config::default_data_for_key<KeyType>::type> copy(KeyType const & key)
00409 {
00410 return data_copy_with_key<KeyType, typename config::default_data_for_key<KeyType>::type>(key);
00411 }
00412
00413
00419 template <typename KeyType,
00420 typename DataType>
00421 class data_copy_no_key
00422 {
00423 public:
00424 data_copy_no_key() {}
00425
00426 template <typename object_src_type, typename object_dest_type>
00427 void operator()(object_src_type const & el_src, object_dest_type const & el_dest)
00428 {
00429 data_container<KeyType, DataType, object_src_type>::instance().copy(el_src, el_dest);
00430 }
00431 };
00432
00434 template <typename KeyType>
00435 class data_copy_no_key <KeyType, all>
00436 {
00437 public:
00438 data_copy_no_key() {}
00439
00440 template <typename ObjectType>
00441 void operator()(ObjectType const & el_src, ObjectType const & el_dest)
00442 {
00443 key_value_registration<ObjectType>::instance().template copy_key_all<KeyType>(el_src, el_dest);
00444 }
00445
00446 template <typename object_src_type, typename object_dest_type>
00447 void operator()(object_src_type const & el_src, object_dest_type const & el_dest)
00448 {
00449 typedef typename error_indicator<object_src_type>::ERROR_SOURCE_AND_DESTINATION_MUST_BE_OF_SAME_TYPE_WHEN_USING_COPY_WITH_ALL error_type;
00450 }
00451 };
00452
00454 template <typename DataType>
00455 class data_copy_no_key <all, DataType>
00456 {
00457 public:
00458 data_copy_no_key() {}
00459
00460 template <typename ObjectType>
00461 void operator()(ObjectType const & el_src,
00462 ObjectType const & el_dest)
00463 {
00464 key_value_registration<ObjectType>::instance().template copy_all_value<DataType>(el_src, el_dest);
00465 }
00466
00467 template <typename object_src_type,
00468 typename object_dest_type>
00469 void operator()(object_src_type const & el_src, object_dest_type const & el_dest)
00470 {
00471 typedef typename error_indicator<object_src_type>::ERROR_SOURCE_AND_DESTINATION_MUST_BE_OF_SAME_TYPE_WHEN_USING_COPY_WITH_ALL error_type;
00472 }
00473 };
00474
00476 template <>
00477 class data_copy_no_key <all, all>
00478 {
00479 public:
00480 data_copy_no_key() {}
00481
00482 template <typename ObjectType>
00483 void operator()(ObjectType const & el_src,
00484 ObjectType const & el_dest)
00485 {
00486 key_value_registration<ObjectType>::instance().copy_all_all(el_src, el_dest);
00487 }
00488
00489 template <typename object_src_type, typename object_dest_type>
00490 void operator()(object_src_type const & el_src,
00491 object_dest_type const & el_dest)
00492 {
00493 typedef typename error_indicator<object_src_type>::ERROR_SOURCE_AND_DESTINATION_MUST_BE_OF_SAME_TYPE_WHEN_USING_COPY_WITH_ALL error_type;
00494 }
00495 };
00496
00497
00498
00509 template <typename KeyType, typename DataType>
00510 data_copy_no_key<KeyType, DataType> copy()
00511 {
00512 return data_copy_no_key<KeyType, DataType>();
00513 }
00514
00526 template <typename KeyType>
00527 data_copy_no_key<KeyType, typename config::default_data_for_key<KeyType>::type> copy()
00528 {
00529 return data_copy_no_key<KeyType, typename config::default_data_for_key<KeyType>::type>();
00530 }
00531
00532
00534
00539 template <typename KeyType,
00540 typename DataType>
00541 class data_mover_with_key
00542 {
00543 public:
00544 data_mover_with_key(KeyType const & key) : key_(key) {}
00545
00546 template <typename ObjectSrcType,
00547 typename ObjectDestType>
00548 void operator()(ObjectSrcType const & el_src,
00549 ObjectDestType const & el_dest)
00550 {
00551
00552 access<KeyType, DataType>(key_)(el_dest) = access<KeyType, DataType>(key_)(el_src);
00553 erase<KeyType, DataType>(key_)(el_src);
00554 }
00555 private:
00556 KeyType const & key_;
00557 };
00558
00559
00560
00562 template <typename KeyType>
00563 class data_mover_with_key<KeyType, all>
00564 {
00565 typedef typename error_indicator<KeyType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_COPY_FUNCTION_WITH_ALL error_type;
00566 };
00567
00569 template <typename DataType>
00570 class data_mover_with_key<all, DataType>
00571 {
00572 typedef typename error_indicator<DataType>::ERROR_NO_KEY_ARGUMENT_ALLOWED_WHEN_USING_COPY_FUNCTION_WITH_ALL error_type;
00573 };
00574
00576 template <>
00577 class data_mover_with_key<all, all>
00578 {
00579
00580 };
00581
00582
00593 template <typename KeyType,
00594 typename DataType>
00595 data_mover_with_key<KeyType, DataType> move(KeyType const & key)
00596 {
00597 return data_mover_with_key<KeyType, DataType>(key);
00598 }
00599
00611 template <typename KeyType>
00612 data_mover_with_key<KeyType, typename config::default_data_for_key<KeyType>::type> move(KeyType const & key)
00613 {
00614 return data_mover_with_key<KeyType, typename config::default_data_for_key<KeyType>::type>(key);
00615 }
00616
00617
00623 template <typename KeyType,
00624 typename DataType>
00625 class data_mover_no_key
00626 {
00627 public:
00628 data_mover_no_key() {}
00629
00630 template <typename object_src_type, typename object_dest_type>
00631 void operator()(object_src_type const & el_src, object_dest_type const & el_dest)
00632 {
00633 data_copy_no_key<KeyType, DataType>()(el_src, el_dest);
00634 data_erasor_no_key<KeyType, DataType>()(el_src);
00635 }
00636 };
00637
00648 template <typename KeyType,
00649 typename DataType>
00650 data_mover_no_key<KeyType, DataType> move()
00651 {
00652 return data_mover_no_key<KeyType, DataType>();
00653 }
00654
00666 template <typename KeyType>
00667 data_mover_no_key<KeyType, typename config::default_data_for_key<KeyType>::type> move()
00668 {
00669 return data_mover_no_key<KeyType, typename config::default_data_for_key<KeyType>::type>();
00670 }
00671
00672
00674
00680 template <typename KeyType,
00681 typename DataType>
00682 class data_reservation_proxy
00683 {
00684 public:
00685 data_reservation_proxy(long num) : num_(num) {}
00686
00687 template <typename ObjectType>
00688 void operator()(ObjectType const & e)
00689 {
00690 data_container<KeyType, DataType, ObjectType>::instance().reserve(num_);
00691 }
00692
00693 private:
00694 long num_;
00695 };
00696
00697
00709 template <typename KeyType,
00710 typename DataType>
00711 data_reservation_proxy<KeyType, DataType> reserve(long num)
00712 {
00713 return data_reservation_proxy<KeyType, DataType>(num);
00714 }
00715
00728 template <typename KeyType>
00729 data_reservation_proxy<KeyType, typename config::default_data_for_key<KeyType>::type> reserve(long num)
00730 {
00731 return data_reservation_proxy<KeyType, typename config::default_data_for_key<KeyType>::type>(num);
00732 }
00733
00735
00740 template <typename KeyType, typename DataType>
00741 class data_find_proxy_with_key
00742 {
00743 public:
00744 data_find_proxy_with_key(KeyType const & key) : key_(key) {}
00745
00746 template <typename ObjectType>
00747 DataType * operator()(ObjectType const & el)
00748 {
00749 return data_container<KeyType, DataType, ObjectType>::instance().find(el, key_);
00750 }
00751
00752 private:
00753 KeyType const & key_;
00754 };
00755
00767 template <typename KeyType, typename DataType>
00768 data_find_proxy_with_key<KeyType, DataType> find(KeyType const & key)
00769 {
00770 return data_find_proxy_with_key<KeyType, DataType>(key);
00771 }
00772
00785 template <typename KeyType>
00786 data_find_proxy_with_key<KeyType, typename config::default_data_for_key<KeyType>::type> find(KeyType const & key)
00787 {
00788 return data_find_proxy_with_key<KeyType, typename config::default_data_for_key<KeyType>::type>(key);
00789 }
00790
00791
00792
00798 template <typename KeyType, typename DataType>
00799 class data_find_proxy_no_key
00800 {
00801 public:
00802 data_find_proxy_no_key() {}
00803
00804 template <typename ObjectType>
00805 DataType * operator()(ObjectType const & el)
00806 {
00807 return data_container<KeyType, DataType, ObjectType>::instance().find(el);
00808 }
00809 };
00810
00822 template <typename KeyType, typename DataType>
00823 data_find_proxy_no_key<KeyType, DataType> find()
00824 {
00825 return data_find_proxy_no_key<KeyType, DataType>();
00826 }
00827
00828 }
00829
00830
00831 #endif
00832