Samchon Framework for CPP  1.0.0
EntityArray.hpp
1 #pragma once
2 #include <samchon/protocol/Entity.hpp>
3 #include <samchon/protocol/IEntityGroup.hpp>
4 #include <vector>
5 
6 #include <samchon/library/XML.hpp>
7 #include <memory>
8 
9 namespace samchon
10 {
11 namespace protocol
12 {
46  template <typename T>
48  : public virtual Entity, public std::vector<T>, //CLASSES
49  public virtual IEntityGroup //INTERFACE
50  {
51  protected:
52  typedef Entity super;
53  typedef T entity_type;
54 
55  public:
60  virtual ~EntityArray() = default;
61 
76  virtual void construct(std::shared_ptr<library::XML> xml) override
77  {
78  clear();
79  if (xml->has(CHILD_TAG()) == false)
80  return;
81 
82  std::shared_ptr<library::XMLList> &xmlList = xml->get(CHILD_TAG());
83  assign(xmlList->size());
84 
85  for (size_t i = 0; i < xmlList->size(); i++)
86  at(i).construct(xmlList->at(i));
87  }
88 
104  virtual auto toXML() const -> std::shared_ptr<library::XML> override
105  {
106  std::shared_ptr<library::XML> &xml = super::toXML();
107 
108  std::shared_ptr<library::XMLList> xmlList(new XMLList());
109  xmlList->reserve(this->size());
110 
111  for (size_t i = 0; i < size(); i++)
112  xmlList->push_back(at(i).toXML());
113 
114  xml->set(CHILD_TAG(), xmlList);
115  return xml;
116  };
117  };
118 };
119 };
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 Entity and a static array containing Entity objects.
Definition: EntityArray.hpp:47
EntityArray()
Default Constructor.
Definition: EntityArray.hpp:59
An iternface for entity group.
Definition: RWMutex.hpp:4
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
Definition: EntityArray.hpp:76
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityArray.
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