Samchon Framework for CPP  1.0.0
NTCriteria.cpp
1 #include <samchon/namtree/NTCriteria.hpp>
2 # include <samchon/namtree/NTSide.hpp>
3 
4 #include <samchon/namtree/NTFactory.hpp>
5 #include <samchon/namtree/NTIterator.hpp>
6 
7 #include <samchon/library/XML.hpp>
8 
9 using namespace std;
10 
11 using namespace samchon;
12 using namespace samchon::library;
13 using namespace samchon::protocol;
14 using namespace samchon::namtree;
15 
16 auto NTCriteria::TAG() const -> string { return "criteria"; }
17 auto NTCriteria::CHILD_TAG() const -> string { return "criteria"; }
18 
19 NTCriteria::NTCriteria(NTFactory *factory, NTCriteria *parent)
20  : super()
21 {
22  this->factory = factory;
23  this->parent = parent;
24 
25  leftSide = new NTSide(factory);
26  rightSide = new NTSide(factory);
27 }
28 NTCriteria::~NTCriteria()
29 {
30  delete leftSide;
31  delete rightSide;
32 }
33 
34 void NTCriteria::construct(shared_ptr<XML> xml)
35 {
36  super::construct(xml);
37 
38  leftSide->construct(xml->get("side")->at(0));
39  rightSide->construct(xml->get("side")->at(1));
40 
41  operator_ = xml->getProperty<int>("operator");
42  weight = xml->getProperty<int>("weight");
43 }
44 auto NTCriteria::createChild(shared_ptr<XML> xml) -> NTCriteria*
45 {
46  return factory->createCriteria(this, xml);
47 }
48 
49 void NTCriteria::initRetrieve()
50 {
51  leftSide->initRetrieve();
52  rightSide->initRetrieve();
53 
54  for (size_t i = 0; i < size(); i++)
55  at(i)->initRetrieve();
56 }
57 auto NTCriteria::calcRetrieved(NTIterator &iterator) const -> double
58 {
59  double left = leftSide->calcRetrieved(iterator);
60  double right = rightSide->calcRetrieved(iterator);
61 
62  return
63  (
64  (operator_ <= LESS_EQUAL && left < right) || //LEFT IS SMALLER
65  ((LESS_EQUAL <= operator_ && operator_ <= LARGER_EQUAL) && left == right) || //VALUES ARE EQUAL
66  (LARGER_EQUAL <= operator_) //
67  ) ? weight : 0.0;
68 }
69 
70 auto NTCriteria::toXML() const -> shared_ptr<XML>
71 {
72  shared_ptr<XML> &xml = super::toXML();
73  xml->push_back( leftSide->toXML() );
74  xml->push_back( rightSide->toXML() );
75 
76  xml->setProperty("operator", operator_);
77  xml->setProperty("weight", weight);
78 
79  return xml;
80 }
A factory for Nam-Tree objects.
Definition: NTFactory.hpp:52
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:52
Iterator of historical data.
Definition: NTIterator.hpp:26
Package of network protocol and libraries.
Definition: protocol.hpp:185
Package of Nam-Tree.
Definition: namtree.hpp:93
virtual auto createCriteria(NTCriteria *, std::shared_ptr< library::XML >) -> NTCriteria *
Factory method of a NTCriteria.
Definition: NTFactory.cpp:26
XML is a class representing xml object.
Definition: XML.hpp:72
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7
A side of a conditional expresson.
Definition: NTSide.hpp:32
Criteria, a conditional expression with weight.
Definition: NTCriteria.hpp:77