forked from mia/Aegisub
Pull some of OptionValue to a cpp file
This commit is contained in:
parent
5089499e8b
commit
e485c469e2
5 changed files with 59 additions and 21 deletions
|
@ -156,6 +156,7 @@
|
|||
<ClCompile Include="$(SrcDir)common\log.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\mru.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\option.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\option_value.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\parser.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\path.cpp" />
|
||||
<ClCompile Include="$(SrcDir)common\thesaurus.cpp" />
|
||||
|
|
|
@ -253,6 +253,9 @@
|
|||
<ClCompile Include="$(SrcDir)common\option.cpp">
|
||||
<Filter>Source Files\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)common\option_value.cpp">
|
||||
<Filter>Source Files\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)common\thesaurus.cpp">
|
||||
<Filter>Source Files\Common</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -30,6 +30,7 @@ aegisub_OBJ := \
|
|||
$(d)common/log.o \
|
||||
$(d)common/mru.o \
|
||||
$(d)common/option.o \
|
||||
$(d)common/option_value.o \
|
||||
$(d)common/path.o \
|
||||
$(d)common/thesaurus.o \
|
||||
$(d)common/util.o \
|
||||
|
|
50
libaegisub/common/option_value.cpp
Normal file
50
libaegisub/common/option_value.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
#include <libaegisub/option_value.h>
|
||||
|
||||
namespace agi {
|
||||
std::string OptionValue::TypeToString(OptionType type) const {
|
||||
switch (type) {
|
||||
case OptionType::String: return "String";
|
||||
case OptionType::Int: return "Integer";
|
||||
case OptionType::Double: return "Double";
|
||||
case OptionType::Color: return "Color";
|
||||
case OptionType::Bool: return "Bool";
|
||||
case OptionType::ListString: return "List of Strings";
|
||||
case OptionType::ListInt: return "List of Integers";
|
||||
case OptionType::ListDouble: return "List of Doubles";
|
||||
case OptionType::ListColor: return "List of Colors";
|
||||
case OptionType::ListBool: return "List of Bools";
|
||||
}
|
||||
throw agi::InternalError("Invalid option type");
|
||||
}
|
||||
|
||||
InternalError OptionValue::TypeError(OptionType type) const {
|
||||
return InternalError("Invalid type for option " + name + ": expected " +
|
||||
TypeToString(type) + ", got " + TypeToString(GetType()));
|
||||
}
|
||||
|
||||
#define CONFIG_DEFINE_SET(type_name, type) \
|
||||
void OptionValue##type_name::Set(const OptionValue *nv) { SetValue(nv->Get##type_name()); } \
|
||||
void OptionValueList##type_name::Set(const OptionValue *nv) { SetValue(nv->GetList##type_name()); }
|
||||
|
||||
CONFIG_DEFINE_SET(String, std::string)
|
||||
CONFIG_DEFINE_SET(Int, int64_t)
|
||||
CONFIG_DEFINE_SET(Double, double)
|
||||
CONFIG_DEFINE_SET(Color, Color)
|
||||
CONFIG_DEFINE_SET(Bool, bool)
|
||||
}
|
|
@ -48,25 +48,8 @@ class OptionValue {
|
|||
agi::signal::Signal<OptionValue const&> ValueChanged;
|
||||
std::string name;
|
||||
|
||||
std::string TypeToString(OptionType type) const {
|
||||
switch (type) {
|
||||
case OptionType::String: return "String";
|
||||
case OptionType::Int: return "Integer";
|
||||
case OptionType::Double: return "Double";
|
||||
case OptionType::Color: return "Color";
|
||||
case OptionType::Bool: return "Bool";
|
||||
case OptionType::ListString: return "List of Strings";
|
||||
case OptionType::ListInt: return "List of Integers";
|
||||
case OptionType::ListDouble: return "List of Doubles";
|
||||
case OptionType::ListColor: return "List of Colors";
|
||||
case OptionType::ListBool: return "List of Bools";
|
||||
}
|
||||
throw agi::InternalError("Invalid option type");
|
||||
}
|
||||
|
||||
InternalError TypeError(OptionType type) const {
|
||||
return InternalError("Invalid type for option " + name + ": expected " + TypeToString(type) + ", got " + TypeToString(GetType()));
|
||||
}
|
||||
std::string TypeToString(OptionType type) const;
|
||||
InternalError TypeError(OptionType type) const;
|
||||
|
||||
template<typename T>
|
||||
T *As(OptionType type) {
|
||||
|
@ -138,7 +121,7 @@ public:
|
|||
OptionType GetType() const { return OptionType::type_name; } \
|
||||
void Reset() { value = value_default; NotifyChanged(); } \
|
||||
bool IsDefault() const { return value == value_default; } \
|
||||
void Set(const OptionValue *new_val) { SetValue(new_val->Get##type_name()); } \
|
||||
void Set(const OptionValue *nv); \
|
||||
};
|
||||
|
||||
CONFIG_OPTIONVALUE(String, std::string)
|
||||
|
@ -162,7 +145,7 @@ CONFIG_OPTIONVALUE(Bool, bool)
|
|||
OptionType GetType() const { return OptionType::List##type_name; } \
|
||||
void Reset() { array = array_default; NotifyChanged(); } \
|
||||
bool IsDefault() const { return array == array_default; } \
|
||||
void Set(const OptionValue *nv) { SetValue(nv->GetList##type_name()); } \
|
||||
void Set(const OptionValue *nv); \
|
||||
};
|
||||
|
||||
CONFIG_OPTIONVALUE_LIST(String, std::string)
|
||||
|
|
Loading…
Reference in a new issue