| Leonetienne/Hazelnupp Simple, easy to use, command line parameter interface

ListValue.cpp
Go to the documentation of this file.
1 #include "ListValue.h"
2 #include "HazelnuppException.h"
3 #include <sstream>
4
5 using namespace Hazelnp;
6
7 ListValue::ListValue() :
8 Value(DATA_TYPE::LIST)
9 {
10 return;
11 }
12
13 ListValue::~ListValue()
14 {
15 for (Value* val : value)
16 delete val;
17
18 value.clear();
19
20 return;
21 }
22
23 Value* ListValue::Deepcopy() const
24 {
25 ListValue* newList = new ListValue();
26
27 for (const Value* val : value)
28 newList->AddValue(val);
29
30 return newList;
31 }
32
33 void ListValue::AddValue(const Value* value)
34 {
35 this->value.emplace_back(value->Deepcopy());
36 return;
37 }
38
39 const std::vector<Value*>& ListValue::GetValue() const
40 {
41 return value;
42 }
43
44 std::string ListValue::GetAsOsString() const
45 {
46 std::stringstream ss;
47
48 ss << "ListValue: [";
49
50 for (const Value* val : value)
51 {
52 ss << *val;
53 if (val != value.back())
54 ss << ", ";
55 }
56
57 ss << "]";
58
59 return ss.str();
60 }
61
62 ListValue::operator std::vector<Value*>() const
63 {
64 return value;
65 }
66
67
68
69 long long int ListValue::GetInt64() const
70 {
71 throw HazelnuppValueNotConvertibleException();
72 }
73
74 int ListValue::GetInt32() const
75 {
76 throw HazelnuppValueNotConvertibleException();
77 }
78
79 long double ListValue::GetFloat64() const
80 {
81 throw HazelnuppValueNotConvertibleException();
82 }
83
84 double ListValue::GetFloat32() const
85 {
86 throw HazelnuppValueNotConvertibleException();
87 }
88
89 std::string ListValue::GetString() const
90 {
91 throw HazelnuppValueNotConvertibleException();
92 }
93
94 const std::vector<Value*>& ListValue::GetList() const
95 {
96 return value;
97 }
Hazelnp::ListValue::GetAsOsString
std::string GetAsOsString() const override
Will return a string suitable for an std::ostream;.
Definition: ListValue.cpp:44
HazelnuppException.h
Hazelnp
Definition: CmdArgsInterface.h:7
Hazelnp::ListValue::GetFloat32
double GetFloat32() const override
Throws HazelnuppValueNotConvertibleException.
Definition: ListValue.cpp:84
Hazelnp::ListValue::GetString
std::string GetString() const override
Throws HazelnuppValueNotConvertibleException.
Definition: ListValue.cpp:89
Hazelnp::ListValue::GetList
const std::vector< Value * > & GetList() const override
Will return this values list.
Definition: ListValue.cpp:94
Hazelnp::ListValue::GetValue
const std::vector< Value * > & GetValue() const
Will return the raw value.
Definition: ListValue.cpp:39
Hazelnp::Value
Abstract class for values.
Definition: Value.h:10
Hazelnp::DATA_TYPE::LIST
@ LIST
Hazelnp::ListValue::GetInt64
long long int GetInt64() const override
Throws HazelnuppValueNotConvertibleException.
Definition: ListValue.cpp:69
Hazelnp::ListValue::GetInt32
int GetInt32() const override
Throws HazelnuppValueNotConvertibleException.
Definition: ListValue.cpp:74
ListValue.h
Hazelnp::ListValue::AddValue
void AddValue(const Value *value)
Will add this value to the list.
Definition: ListValue.cpp:33
Hazelnp::ListValue::~ListValue
~ListValue() override
Definition: ListValue.cpp:13
Hazelnp::DATA_TYPE
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:8
Hazelnp::ListValue::ListValue
ListValue()
Definition: ListValue.cpp:7
Hazelnp::ListValue::Deepcopy
Value * Deepcopy() const override
Will return a deeopopy of this object.
Definition: ListValue.cpp:23
Hazelnp::Value::Deepcopy
virtual Value * Deepcopy() const =0
Will return a deeopopy of this object.
Hazelnp::ListValue::GetFloat64
long double GetFloat64() const override
Throws HazelnuppValueNotConvertibleException.
Definition: ListValue.cpp:79
Hazelnp::ListValue
Specializations for list values (uses std::vector<Value*>)
Definition: ListValue.h:9
Hazelnp::HazelnuppValueNotConvertibleException
Gets thrown when an attempt is made to retrieve the wrong data type from a value, when the value not ...
Definition: HazelnuppException.h:38