Samchon Framework for CPP  1.0.0
SystemRole.cpp
1 #include <samchon/protocol/SystemRole.hpp>
2 
3 #include <samchon/library/XML.hpp>
4 
5 using namespace std;
6 using namespace samchon::library;
7 using namespace samchon::protocol;
8 
9 /* ------------------------------------------------------------------
10  CONSTRUCTORS
11 ------------------------------------------------------------------ */
12 SystemRole::SystemRole()
13  : super(),
14  IProtocol()
15 {
16 }
17 void SystemRole::construct(shared_ptr<XML> xml)
18 {
19  this->name = xml->getProperty("name");
20 
21  listeners.clear();
22  if(xml->has("listenerArray") == false || xml->get("listenerArray")->at(0)->has("listener") == false)
23  return;
24 
25  shared_ptr<XMLList> &xmlList = xml->get("listenerArray")->at(0)->get("listener");
26  for(size_t i = 0; i < xmlList->size(); i++)
27  listeners.insert(xmlList->at(i)->getValue());
28 }
29 
30 /* ------------------------------------------------------------------
31  GETTERS
32 ------------------------------------------------------------------ */
33 auto SystemRole::key() const -> string
34 {
35  return name;
36 }
37 
38 auto SystemRole::hasListener(const string &name) const -> bool
39 {
40  return listeners.count(name) >= 1;
41 }
42 
43 /* ------------------------------------------------------------------
44  EXPORTERS
45 ------------------------------------------------------------------ */
46 auto SystemRole::TAG() const -> string
47 {
48  return "role";
49 }
50 
51 auto SystemRole::toXML() const -> shared_ptr<XML>
52 {
53  shared_ptr<XML> &xml = super::toXML();
54  xml->setProperty("name", name);
55 
56  if (listeners.empty() == false)
57  {
58  shared_ptr<XML> listenerArray(new XML());
59  listenerArray->setTag("listenerArray");
60 
61  for (auto it = listeners.begin(); it != listeners.end(); it++)
62  {
63  shared_ptr<XML> listener(new XML());
64  listener->setTag("listener");
65  listener->setValue(*it);
66 
67  listenerArray->push_back(listener);
68  }
69  xml->push_back(listenerArray);
70  }
71 
72  return xml;
73 }
An entity, a standard data class.
Definition: Entity.hpp:48
virtual auto key() const -> std::string override
Get a key that can identify the Entity uniquely.
Definition: SystemRole.cpp:33
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
std::set< std::string > listeners
Listeners belongs to the role.
Definition: SystemRole.hpp:38
std::string name
A name representing the role.
Definition: SystemRole.hpp:33
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
Package of network protocol and libraries.
Definition: protocol.hpp:185
auto hasListener(const std::string &) const -> bool
Test whether has a listener in the role.
Definition: SystemRole.cpp:38
An interface of Invoke message chain.
Definition: IProtocol.hpp:31
XML is a class representing xml object.
Definition: XML.hpp:72
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
Definition: SystemRole.cpp:46
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
Definition: SystemRole.cpp:17
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the Entity.
Definition: SystemRole.cpp:51