Samchon Framework for CPP  1.0.0
SharedEntityArray.hpp
1 #pragma once
2 #include <samchon/protocol/EntityGroup.hpp>
3 #include <vector>
4 
5 namespace samchon
6 {
7 namespace protocol
8 {
25  template <typename T, typename Key = std::string>
26  using SharedEntityArray = EntityGroup<std::vector<std::shared_ptr<T>>, T, Key>;
27 };
28 };
29 
30 /* ------------------------------------------------------------------------------
31  MACROS
32 ------------------------------------------------------------------------------ */
33 // INLINE
34 #define SHARED_ENTITY_ARRAY_ELEMENT_ACCESSOR_INLINE(CHILD_TYPE) \
35 auto operator[](size_t x) const -> std::shared_ptr<CHILD_TYPE> \
36 { \
37  return std::dynamic_pointer_cast<CHILD_TYPE>(container_type::operator[](x)); \
38 }; \
39 auto at(size_t x) const -> std::shared_ptr<CHILD_TYPE> \
40 { \
41  return std::dynamic_pointer_cast<CHILD_TYPE>(container_type::at(x)); \
42 }; \
43 auto get(const typename child_type::key_type &key) const -> std::shared_ptr<CHILD_TYPE> \
44 { \
45  return std::dynamic_pointer_cast<CHILD_TYPE>(samchon::protocol::EntityGroup<container_type, child_type, key_type>::get(key)); \
46 };
47 
48 // HEADER
49 #define SHARED_ENTITY_ARRAY_ELEMENT_ACCESSOR_HEADER(CHILD_TYPE) \
50 auto operator[](size_t) const -> std::shared_ptr<CHILD_TYPE>; \
51 auto at(size_t) const -> std::shared_ptr<CHILD_TYPE>; \
52 auto get(const typename child_type::key_type&) const -> std::shared_ptr<CHILD_TYPE>;
53 
54 // BODY
55 #define SHARED_ENTITY_ARRAY_ELEMENT_ACCESSOR_BODY(THIS_TYPE, CHILD_TYPE) \
56 auto THIS_TYPE::operator[](size_t x) const -> std::shared_ptr<CHILD_TYPE> \
57 { \
58  return std::dynamic_pointer_cast<CHILD_TYPE>(container_type::operator[](x)); \
59 } \
60 auto THIS_TYPE::at(size_t x) const -> std::shared_ptr<CHILD_TYPE> \
61 { \
62  return std::dynamic_pointer_cast<CHILD_TYPE>(container_type::at(x)); \
63 } \
64 auto THIS_TYPE::get(const typename child_type::key_type &key) const -> std::shared_ptr<CHILD_TYPE> \
65 { \
66  return std::dynamic_pointer_cast<CHILD_TYPE>(samchon::protocol::EntityGroup<container_type, child_type, key_type>::get(key)); \
67 }