2 #include <samchon/protocol/Entity.hpp> 3 #include <samchon/protocol/EntityGroupBase.hpp> 39 template <
typename Container,
typename T,
typename Key = std::
string>
42 public virtual Entity<Key>,
46 typedef Container container_type;
53 using container_type::container_type;
71 virtual void construct(std::shared_ptr<library::XML> xml)
77 std::shared_ptr<library::XMLList> &xml_list = xml->get(
CHILD_TAG());
79 if (std::is_same<container_type, std::vector<container_type::value_type, container_type::allocator_type>>::value ==
true)
82 assign(xml_list->size(),
nullptr);
83 erase(begin(), end());
86 for (
size_t i = 0; i < xml_list->size(); i++)
88 std::shared_ptr<library::XML> &xmlElement = xml_list->at(i);
91 if (entity !=
nullptr)
93 entity->construct(xml_list->at(i));
110 virtual auto createChild(std::shared_ptr<library::XML>) -> child_type* = 0;
116 using container_type::erase;
118 void erase(
const typename child_type::key_type &
key)
120 for (
auto it = begin(); it != end(); )
121 if ((*it)->key() ==
key)
144 auto find(
const typename child_type::key_type &key) ->
typename container_type::iterator
149 [key](
const container_type::value_type &entity) ->
bool 151 return entity->key() ==
key;
173 auto find(
const typename child_type::key_type &key)
const ->
typename container_type::const_iterator
178 [key](
const container_type::value_type &entity) ->
bool 180 return entity->key() ==
key;
191 auto has(
const typename child_type::key_type &key)
const ->
bool 196 [key](
const container_type::value_type &entity) ->
bool 198 return entity->key() ==
key;
209 auto count(
const typename child_type::key_type &key)
const ->
size_t 214 [key](
const container_type::value_type &entity) ->
bool 216 return entity->key() ==
key;
227 auto get(
const typename child_type::key_type &
key) ->
typename container_type::value_type&
229 auto it = std::find_if
232 [key](
const container_type::value_type &entity) ->
bool 234 return entity->key() ==
key;
239 throw std::out_of_range(
"out of range");
250 auto get(
const typename child_type::key_type &
key)
const ->
const typename container_type::value_type&
252 auto it = std::find_if
255 [key](
const container_type::value_type &entity) ->
bool 257 return entity->key() ==
key;
262 throw std::out_of_range(
"out of range");
285 virtual auto toXML() const ->
std::shared_ptr<library::XML>
287 std::shared_ptr<library::XML> &xml = Entity::toXML();
289 std::shared_ptr<library::XMLList> xmlList(
new library::XMLList());
290 xmlList->reserve(this->size());
292 for (
auto it = begin(); it != end(); it++)
293 xmlList->push_back((*it)->toXML());
An entity, a standard data class.
virtual auto createChild(std::shared_ptr< library::XML >) -> child_type *=0
Factory method of a child Entity.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
auto find(const typename child_type::key_type &key) -> typename container_type::iterator
Get iterator to element.
auto count(const typename child_type::key_type &key) const -> size_t
Count elements with a specific key.
auto has(const typename child_type::key_type &key) const -> bool
Indicates whether a container has an object having the specified identifier.
auto find(const typename child_type::key_type &key) const -> typename container_type::const_iterator
Get const iterator to element.
virtual auto CHILD_TAG() const -> std::string=0
A tag name of children.
An Entity and a container of children Entity objects.
virtual auto key() const -> Key
Get a key that can identify the Entity uniquely.
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
An iternface for entity group.