forked from dulikvor/cppKin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleTag.cpp
More file actions
63 lines (54 loc) · 1.97 KB
/
Copy pathSimpleTag.cpp
File metadata and controls
63 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "SimpleTag.h"
#include "Exception.h"
#include "boost/variant/get.hpp"
namespace cppkin
{
SimpleTag::SimpleTag(const char* key, bool value) :
m_key(key), m_valueType(ValueTypes::Boolean), m_value(value)
{
}
SimpleTag::SimpleTag(const char* key, const char* value) :
m_key(key), m_valueType(ValueTypes::String), m_value(std::string(value))
{
}
SimpleTag::SimpleTag(const char* key, std::string value) :
m_key(key), m_valueType(ValueTypes::String), m_value(std::move(value))
{
}
SimpleTag::SimpleTag(const char* key, int value) :
m_key(key), m_valueType(ValueTypes::Int), m_value(value)
{
}
SimpleTag::SimpleTag(const char* key, float value) :
m_key(key), m_valueType(ValueTypes::Float), m_value(value)
{
}
SimpleTag::SimpleTag(const SimpleTag& object) :
m_key(object.m_key), m_valueType(object.m_valueType), m_value(object.m_value)
{
}
void SimpleTag::GetValue(bool& value) const
{
if(m_valueType != ValueTypes::Boolean)
throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type");
value = boost::get<bool>(m_value);
}
void SimpleTag::GetValue(std::string& value) const
{
if(m_valueType != ValueTypes::String)
throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type");
value = boost::get<std::string>(m_value);
}
void SimpleTag::GetValue(int& value) const
{
if(m_valueType != ValueTypes::Int)
throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type");
value = boost::get<int>(m_value);
}
void SimpleTag::GetValue(float& value) const
{
if(m_valueType != ValueTypes::Float)
throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type");
value = boost::get<float>(m_value);
}
}