Kill TrivialType_T as it's completely pointless
Originally committed to SVN as r5748.
This commit is contained in:
parent
9dc9047c11
commit
36280b7a2b
7 changed files with 34 additions and 119 deletions
|
@ -95,9 +95,9 @@ void Hotkey::BuildHotkey(std::string const& context, const json::Object& object)
|
||||||
|
|
||||||
for (json::Array::const_iterator arr_mod_index(arr_mod.begin()); arr_mod_index != arr_mod.end(); arr_mod_index++) {
|
for (json::Array::const_iterator arr_mod_index(arr_mod.begin()); arr_mod_index != arr_mod.end(); arr_mod_index++) {
|
||||||
const json::String& key_mod = *arr_mod_index;
|
const json::String& key_mod = *arr_mod_index;
|
||||||
combo.KeyInsert(key_mod.Value());
|
combo.KeyInsert(key_mod);
|
||||||
}
|
}
|
||||||
combo.KeyInsert(static_cast<const json::String&>(obj["key"]).Value());
|
combo.KeyInsert(static_cast<const json::String&>(obj["key"]));
|
||||||
ComboInsert(combo);
|
ComboInsert(combo);
|
||||||
} // for arr_index
|
} // for arr_index
|
||||||
} // for index
|
} // for index
|
||||||
|
|
|
@ -80,26 +80,26 @@ LogSink::~LogSink() {
|
||||||
|
|
||||||
for (unsigned int i=0; i < sink.size(); i++) {
|
for (unsigned int i=0; i < sink.size(); i++) {
|
||||||
json::Object entry;
|
json::Object entry;
|
||||||
entry["sec"] = json::Number(sink[i]->tv.tv_sec);
|
entry["sec"] = (double)sink[i]->tv.tv_sec;
|
||||||
entry["usec"] = json::Number(sink[i]->tv.tv_usec);
|
entry["usec"] = (double)sink[i]->tv.tv_usec;
|
||||||
entry["severity"] = json::Number(sink[i]->severity),
|
entry["severity"] = (double)sink[i]->severity,
|
||||||
entry["section"] = json::String(sink[i]->section);
|
entry["section"] = (std::string)sink[i]->section;
|
||||||
entry["file"] = json::String(sink[i]->file);
|
entry["file"] = (std::string)sink[i]->file;
|
||||||
entry["func"] = json::String(sink[i]->func);
|
entry["func"] = (std::string)sink[i]->func;
|
||||||
entry["line"] = json::Number(sink[i]->line);
|
entry["line"] = (double)sink[i]->line;
|
||||||
entry["message"] = json::String(std::string(sink[i]->message, sink[i]->len));
|
entry["message"] = std::string(sink[i]->message, sink[i]->len);
|
||||||
|
|
||||||
array.push_back(entry);
|
array.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
json::Array timeval_open;
|
json::Array timeval_open;
|
||||||
timeval_open.push_back(json::Number(time_start.tv_sec));
|
timeval_open.push_back((double)time_start.tv_sec);
|
||||||
timeval_open.push_back(json::Number(time_start.tv_usec));
|
timeval_open.push_back((double)time_start.tv_usec);
|
||||||
root["timeval"]["open"] = timeval_open;
|
root["timeval"]["open"] = timeval_open;
|
||||||
|
|
||||||
json::Array timeval_close;
|
json::Array timeval_close;
|
||||||
timeval_close.push_back(json::Number(time_close.tv_sec));
|
timeval_close.push_back((double)time_close.tv_sec);
|
||||||
timeval_close.push_back(json::Number(time_close.tv_usec));
|
timeval_close.push_back((double)time_close.tv_usec);
|
||||||
root["timeval"]["close"] = timeval_close;
|
root["timeval"]["close"] = timeval_close;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,29 +106,27 @@ void ConfigVisitor::Visit(const json::Array& array) {
|
||||||
|
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Number& number) {
|
void ConfigVisitor::Visit(const json::Number& number) {
|
||||||
double val = number.Value();
|
if (int64_t(number) == ceil(number)) {
|
||||||
|
OptionValue *opt = new OptionValueInt(name, int64_t(number));
|
||||||
if (int64_t(val) == ceil(val)) {
|
|
||||||
OptionValue *opt = new OptionValueInt(name, int64_t(val));
|
|
||||||
AddOptionValue(opt);
|
AddOptionValue(opt);
|
||||||
} else {
|
} else {
|
||||||
OptionValue *opt = new OptionValueDouble(name, val);
|
OptionValue *opt = new OptionValueDouble(name, number);
|
||||||
AddOptionValue(opt);
|
AddOptionValue(opt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::String& string) {
|
void ConfigVisitor::Visit(const json::String& string) {
|
||||||
OptionValue *opt;
|
OptionValue *opt;
|
||||||
if (string.Value().find("rgb(") == 0) {
|
if (string.find("rgb(") == 0) {
|
||||||
opt = new OptionValueColour(name, string.Value());
|
opt = new OptionValueColour(name, string);
|
||||||
} else {
|
} else {
|
||||||
opt = new OptionValueString(name, string.Value());
|
opt = new OptionValueString(name, string);
|
||||||
}
|
}
|
||||||
AddOptionValue(opt);
|
AddOptionValue(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Boolean& boolean) {
|
void ConfigVisitor::Visit(const json::Boolean& boolean) {
|
||||||
OptionValue *opt = new OptionValueBool(name, boolean.Value());
|
OptionValue *opt = new OptionValueBool(name, boolean);
|
||||||
AddOptionValue(opt);
|
AddOptionValue(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,19 +13,9 @@ Author: Terry Caton
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
TODO:
|
|
||||||
* better documentation (doxygen?)
|
|
||||||
* Unicode support
|
|
||||||
* parent element accessors
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace json
|
namespace json
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// forward declarations (more info further below)
|
// forward declarations (more info further below)
|
||||||
class Visitor;
|
class Visitor;
|
||||||
|
@ -34,9 +24,9 @@ class ConstVisitor;
|
||||||
template <typename ValueTypeT>
|
template <typename ValueTypeT>
|
||||||
class TrivialType_T;
|
class TrivialType_T;
|
||||||
|
|
||||||
typedef TrivialType_T<double> Number;
|
typedef double Number;
|
||||||
typedef TrivialType_T<bool> Boolean;
|
typedef bool Boolean;
|
||||||
typedef TrivialType_T<std::string> String;
|
typedef std::string String;
|
||||||
|
|
||||||
class Object;
|
class Object;
|
||||||
class Array;
|
class Array;
|
||||||
|
@ -100,6 +90,8 @@ public:
|
||||||
operator Null& ();
|
operator Null& ();
|
||||||
|
|
||||||
// provides quick access to children when real element type is object
|
// provides quick access to children when real element type is object
|
||||||
|
UnknownElement& operator[] (const char *key) { return operator[](std::string(key)); }
|
||||||
|
const UnknownElement& operator[] (const char *key) const { return operator[](std::string(key)); }
|
||||||
UnknownElement& operator[] (const std::string& key);
|
UnknownElement& operator[] (const std::string& key);
|
||||||
const UnknownElement& operator[] (const std::string& key) const;
|
const UnknownElement& operator[] (const std::string& key) const;
|
||||||
|
|
||||||
|
@ -213,44 +205,15 @@ private:
|
||||||
Members m_Members;
|
Members m_Members;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// TrivialType_T - class template for encapsulates a simple data type, such as
|
|
||||||
// a string, number, or boolean. Provides implicit const & noncost cast operators
|
|
||||||
// for that type, allowing "DataTypeT type = trivialType;"
|
|
||||||
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
class TrivialType_T
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TrivialType_T(const DataTypeT& t = DataTypeT());
|
|
||||||
|
|
||||||
operator DataTypeT&();
|
|
||||||
operator const DataTypeT&() const;
|
|
||||||
|
|
||||||
DataTypeT& Value();
|
|
||||||
const DataTypeT& Value() const;
|
|
||||||
|
|
||||||
bool operator == (const TrivialType_T<DataTypeT>& trivial) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
DataTypeT m_tValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// Null - doesn't do much of anything but satisfy the JSON spec. It is the default
|
// Null - doesn't do much of anything but satisfy the JSON spec. It is the default
|
||||||
// element type of UnknownElement
|
// element type of UnknownElement
|
||||||
|
|
||||||
class Null
|
class Null
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator == (const Null& trivial) const;
|
bool operator == (const Null& trivial) const { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -236,49 +236,4 @@ inline const UnknownElement& Array::operator[] (size_t index) const
|
||||||
return m_Elements[index];
|
return m_Elements[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////
|
|
||||||
// TrivialType_T members
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
TrivialType_T<DataTypeT>::TrivialType_T(const DataTypeT& t) :
|
|
||||||
m_tValue(t) {}
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
TrivialType_T<DataTypeT>::operator DataTypeT&()
|
|
||||||
{
|
|
||||||
return Value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
TrivialType_T<DataTypeT>::operator const DataTypeT&() const
|
|
||||||
{
|
|
||||||
return Value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
DataTypeT& TrivialType_T<DataTypeT>::Value()
|
|
||||||
{
|
|
||||||
return m_tValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
const DataTypeT& TrivialType_T<DataTypeT>::Value() const
|
|
||||||
{
|
|
||||||
return m_tValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataTypeT>
|
|
||||||
bool TrivialType_T<DataTypeT>::operator == (const TrivialType_T<DataTypeT>& trivial) const
|
|
||||||
{
|
|
||||||
return m_tValue == trivial.m_tValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////
|
|
||||||
// Null members
|
|
||||||
|
|
||||||
inline bool Null::operator == (const Null& trivial) const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
|
@ -97,21 +97,20 @@ inline void Writer::Write_i(const Object& object)
|
||||||
|
|
||||||
inline void Writer::Write_i(const Number& numberElement)
|
inline void Writer::Write_i(const Number& numberElement)
|
||||||
{
|
{
|
||||||
m_ostr << std::setprecision(20) << numberElement.Value();
|
m_ostr << std::setprecision(20) << numberElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Writer::Write_i(const Boolean& booleanElement)
|
inline void Writer::Write_i(const Boolean& booleanElement)
|
||||||
{
|
{
|
||||||
m_ostr << (booleanElement.Value() ? "true" : "false");
|
m_ostr << (booleanElement ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Writer::Write_i(const String& stringElement)
|
inline void Writer::Write_i(const String& stringElement)
|
||||||
{
|
{
|
||||||
m_ostr << '"';
|
m_ostr << '"';
|
||||||
|
|
||||||
const std::string& s = stringElement.Value();
|
const std::string& s = stringElement;
|
||||||
std::string::const_iterator it(s.begin()),
|
std::string::const_iterator it(s.begin()), itend(s.end());
|
||||||
itend(s.end());
|
|
||||||
for (; it != itend; ++it)
|
for (; it != itend; ++it)
|
||||||
{
|
{
|
||||||
switch (*it)
|
switch (*it)
|
||||||
|
|
|
@ -107,16 +107,16 @@ namespace {
|
||||||
for (json::Array::const_iterator it = arr.begin(); it != arr.end(); ++it) {
|
for (json::Array::const_iterator it = arr.begin(); it != arr.end(); ++it) {
|
||||||
json::String const& command_name = *it;
|
json::String const& command_name = *it;
|
||||||
|
|
||||||
if (command_name.Value().empty()) {
|
if (command_name.empty()) {
|
||||||
AddSeparator();
|
AddSeparator();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmd::Command *command;
|
cmd::Command *command;
|
||||||
try {
|
try {
|
||||||
command = cmd::get(command_name.Value());
|
command = cmd::get(command_name);
|
||||||
}
|
}
|
||||||
catch (CommandNotFound const&) {
|
catch (CommandNotFound const&) {
|
||||||
LOG_W("toolbar/command/not_found") << "Command '" << command_name.Value() << "' not found; skipping";
|
LOG_W("toolbar/command/not_found") << "Command '" << command_name << "' not found; skipping";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue