Samchon Framework for CPP  1.0.0
Instance.hpp
1 #pragma once
2 #include <samchon/protocol/Entity.hpp>
3 
4 #include <samchon/library/StringUtil.hpp>
5 #include <samchon/library/XML.hpp>
6 
7 namespace samchon
8 {
9 namespace examples
10 {
11 namespace packer
12 {
13  using namespace std;
14 
15  using namespace library;
16  using namespace protocol;
17 
29  class Instance
30  : public virtual Entity<std::string>
31  {
32  private:
33  typedef Entity<std::string> super;
34 
35  protected:
39  string name;
40 
44  int price;
45 
49  int volume;
50 
54  int weight;
55 
56  public:
57  /* ---------------------------------------------------------
58  CONSTRUCTORS
59  --------------------------------------------------------- */
64  : super()
65  {
66  };
67 
76  Instance(const string &name, int price, int volume, int weight)
77  : super()
78  {
79  this->name = name;
80  this->price = price;
81  this->volume = volume;
82  this->weight = weight;
83  };
84 
85  virtual ~Instance() = default;
86 
87  virtual void construct(shared_ptr<XML> xml) override
88  {
89  this->name = xml->getProperty("name");
90  this->price = xml->getProperty<int>("price");
91  this->volume = xml->getProperty<int>("volume");
92  this->weight = xml->getProperty<int>("weight");
93  };
94 
95  /* ---------------------------------------------------------
96  GETTERS
97  --------------------------------------------------------- */
101  auto get_name() const -> string
102  {
103  return name;
104  };
105 
109  auto getPrice() const -> int
110  {
111  return price;
112  };
113 
117  auto getVolume() const -> int
118  {
119  return volume;
120  };
121 
125  auto getWeight() const -> int
126  {
127  return weight;
128  };
129 
130  /* ---------------------------------------------------------
131  EXPORT
132  --------------------------------------------------------- */
133  virtual auto toXML() const -> shared_ptr<XML> override
134  {
135  shared_ptr<XML> &xml = super::toXML();
136  xml->setProperty("name", name);
137  xml->setProperty("price", price);
138  xml->setProperty("volume", volume);
139  xml->setProperty("weight", weight);
140 
141  return xml;
142  };
143 
147  virtual auto toString() const -> string
148  {
150  (
151  "{1}: ${2}, {3}cm^3, {4}g",
152  name, price, volume, weight
153  );
154  };
155  };
156 };
157 };
158 };
An entity, a standard data class.
Definition: Entity.hpp:115
auto get_name() const -> string
Get name.
Definition: Instance.hpp:101
int price
Price of an instance -> 1,000 won.
Definition: Instance.hpp:44
Instance(const string &name, int price, int volume, int weight)
Construct from instance.
Definition: Instance.hpp:76
Instance()
Default Constructor.
Definition: Instance.hpp:63
auto getPrice() const -> int
Get price.
Definition: Instance.hpp:109
auto getVolume() const -> int
Get volume.
Definition: Instance.hpp:117
auto getWeight() const -> int
Get weight.
Definition: Instance.hpp:125
string name
Name represent the Instance.
Definition: Instance.hpp:39
static auto substitute(const std::string &format, const T &val, const _Args &...args) -> std::string
Substitutes "{n}" tokens within the specified string with the respective arguments passed in...
Definition: StringUtil.hpp:54
int volume
Volume of an instance -> 130 cm^3.
Definition: Instance.hpp:49
int weight
Weight of an instance -> 1,200 g.
Definition: Instance.hpp:54
virtual auto toString() const -> string
Return a string represents the Instance.
Definition: Instance.hpp:147