2 #include <samchon/protocol/Entity.hpp> 3 #include <samchon/protocol/IEntityGroup.hpp> 51 template <
typename _Container,
typename _ETy = Entity,
typename T = _Container::value_type>
58 typedef _Container container_type;
60 typedef _ETy entity_type;
90 virtual void construct(std::shared_ptr<library::XML> xml)
96 std::shared_ptr<library::XMLList> &xmlList = xml->get(
CHILD_TAG());
98 if (std::is_same<_Container, std::vector<_Container::value_type, _Container::allocator_type>>::value ==
true)
101 assign(xmlList->size(),
nullptr);
102 erase(begin(), end());
105 for (
size_t i = 0; i < xmlList->size(); i++)
107 std::shared_ptr<library::XML> &xmlElement = xmlList->at(i);
110 if (entity !=
nullptr)
112 entity->construct(xmlList->at(i));
113 emplace_back(entity);
129 virtual auto createChild(std::shared_ptr<library::XML>)->entity_type* = 0;
135 using _Container::erase;
137 void erase(
const std::string &
key)
139 for (_Container::iterator it = begin(); it != end();)
140 if ((*it)->key() ==
key)
155 auto has(
const std::string &key)
const ->
bool 157 for (
auto it = begin(); it != end(); it++)
158 if ((*it)->key() ==
key)
170 auto get(
const std::string &
key) -> value_type&
172 for (
auto it = begin(); it != end(); it++)
173 if ((*it)->key() ==
key)
176 throw std::exception(
"out of range");
185 auto get(
const std::string &
key)
const ->
const value_type&
187 for (
auto it = begin(); it != end(); it++)
188 if ((*it)->key() ==
key)
191 throw std::exception(
"out of range");
212 virtual auto toXML() const ->
std::shared_ptr<library::XML>
217 xmlList->reserve(this->size());
219 for (
auto it = begin(); it != end(); it++)
220 xmlList->push_back((*it)->toXML());
An entity, a standard data class.
std::vector< std::shared_ptr< XML > > XMLList
A list of XML, tags are same.
auto has(const std::string &key) const -> bool
Indicates whether a container has an object having the specified identifier.
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
An iternface for entity group.
An Entity and a container of children Entity objects.
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
virtual auto key() const -> std::string
Get a key that can identify the Entity uniquely.
EntityGroup()
Default Constructor.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
virtual auto CHILD_TAG() const -> std::string=0
A tag name of children.
Top level namespace of products built from samchon.
virtual auto createChild(std::shared_ptr< library::XML >) -> entity_type *=0
Factory method of a child Entity.