aseprite/src/css/value.cpp
David Capello 8e81fb808d Add css library
This is a base library that will be used by SkinTheme to draw parts
with CSS styles (or something similar).
2013-12-03 19:31:36 -03:00

99 lines
1.5 KiB
C++

// Aseprite CSS Library
// Copyright (C) 2013 David Capello
//
// This source file is distributed under MIT license,
// please 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