forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.cpp
More file actions
98 lines (83 loc) · 1.51 KB
/
value.cpp
File metadata and controls
98 lines (83 loc) · 1.51 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Aseprite CSS Library
// Copyright (C) 2013 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "css/value.h"
namespace css {
Value::Value() :
m_type(None)
{
}
Value::Value(double value, const std::string& unit) :
m_type(Number),
m_number(value),
m_string(unit)
{
}
Value::Value(const std::string& value) :
m_type(String),
m_string(value)
{
}
double Value::number() const
{
if (m_type == Number)
return m_number;
else
return 0.0;
}
std::string Value::string() const
{
if (m_type == String)
return m_string;
else
return std::string();
}
std::string Value::unit() const
{
if (m_type == Number)
return m_string;
else
return std::string();
}
void Value::setNumber(double value)
{
if (m_type != Number) {
m_type = Number;
m_string = "";
}
m_number = value;
}
void Value::setString(const std::string& value)
{
m_type = String;
m_string = value;
}
void Value::setUnit(const std::string& unit)
{
if (m_type != Number) {
m_type = Number;
m_number = 0.0;
}
m_string = unit;
}
bool Value::operator==(const Value& other) const
{
if (m_type != other.m_type)
return false;
switch (m_type) {
case None:
return true;
case Number:
return m_number == other.m_number && m_string == other.m_string;
case String:
return m_string == other.m_string;
default:
return false;
}
}
} // namespace css