Samchon Framework for CPP  1.0.0
EntityList.hpp
1 #pragma once
2 #include <samchon/protocol/Entity.hpp>
3 #include <samchon/protocol/IEntityGroup.hpp>
4 #include <list>
5 
6 #include <samchon/library/XML.hpp>
7 #include <memory>
8 
9 namespace samchon
10 {
11 namespace protocol
12 {
51  template <typename T>
52  class EntityList
53  : public virtual Entity, public std::list<T>, //CLASSES
54  public virtual IEntityGroup //INTERFACE
55  {
56  protected:
57  typedef Entity super;
58  typedef T entity_type;
59 
60  public:
64  EntityList();
65  virtual ~EntityList() = default;
66 
81  virtual void construct(std::shared_ptr<library::XML> xml) override
82  {
83  clear();
84  if (xml->has(CHILD_TAG()) == false)
85  return;
86 
87  std::shared_ptr<library::XMLList> &xmlList = xml->get(CHILD_TAG());
88  assign(xmlList->size());
89 
90  for (size_t i = 0; i < xmlList->size(); i++)
91  at(i).construct(xmlList->at(i));
92  }
93 
109  virtual auto toXML() const -> std::shared_ptr<library::XML> override
110  {
111  std::shared_ptr<library::XML> &xml = super::toXML();
112 
113  std::shared_ptr<library::XMLList> xmlList(new XMLList());
114  xmlList->reserve(this->size());
115 
116  for (size_t i = 0; i < size(); i++)
117  xmlList->push_back(at(i).toXML());
118 
119  xml->set(CHILD_TAG(), xmlList);
120  return xml;
121  };
122  };
123 };
124 };
An entity, a standard data class.
Definition: Entity.hpp:48
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
An iternface for entity group.
Definition: RWMutex.hpp:4
EntityList()
Default Constructor.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityList.
Definition: EntityList.hpp:109
An Entity and a static list containing Entity objects.
Definition: EntityList.hpp:52
virtual auto CHILD_TAG() const -> std::string=0
A tag name of children.
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
Definition: EntityList.hpp:81