Kill TrivialType_T as it's completely pointless

Originally committed to SVN as r5748.
This commit is contained in:
Thomas Goyne 2011-10-17 21:59:59 +00:00
parent 9dc9047c11
commit 36280b7a2b
7 changed files with 34 additions and 119 deletions

View file

@ -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++) {
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);
} // for arr_index
} // for index

View file

@ -80,26 +80,26 @@ LogSink::~LogSink() {
for (unsigned int i=0; i < sink.size(); i++) {
json::Object entry;
entry["sec"] = json::Number(sink[i]->tv.tv_sec);
entry["usec"] = json::Number(sink[i]->tv.tv_usec);
entry["severity"] = json::Number(sink[i]->severity),
entry["section"] = json::String(sink[i]->section);
entry["file"] = json::String(sink[i]->file);
entry["func"] = json::String(sink[i]->func);
entry["line"] = json::Number(sink[i]->line);
entry["message"] = json::String(std::string(sink[i]->message, sink[i]->len));
entry["sec"] = (double)sink[i]->tv.tv_sec;
entry["usec"] = (double)sink[i]->tv.tv_usec;
entry["severity"] = (double)sink[i]->severity,
entry["section"] = (std::string)sink[i]->section;
entry["file"] = (std::string)sink[i]->file;
entry["func"] = (std::string)sink[i]->func;
entry["line"] = (double)sink[i]->line;
entry["message"] = std::string(sink[i]->message, sink[i]->len);
array.push_back(entry);
}
json::Array timeval_open;
timeval_open.push_back(json::Number(time_start.tv_sec));
timeval_open.push_back(json::Number(time_start.tv_usec));
timeval_open.push_back((double)time_start.tv_sec);
timeval_open.push_back((double)time_start.tv_usec);
root["timeval"]["open"] = timeval_open;
json::Array timeval_close;
timeval_close.push_back(json::Number(time_close.tv_sec));
timeval_close.push_back(json::Number(time_close.tv_usec));
timeval_close.push_back((double)time_close.tv_sec);
timeval_close.push_back((double)time_close.tv_usec);
root["timeval"]["close"] = timeval_close;

View file

@ -106,29 +106,27 @@ void ConfigVisitor::Visit(const json::Array& array) {
void ConfigVisitor::Visit(const json::Number& number) {
double val = number.Value();
if (int64_t(val) == ceil(val)) {
OptionValue *opt = new OptionValueInt(name, int64_t(val));
if (int64_t(number) == ceil(number)) {
OptionValue *opt = new OptionValueInt(name, int64_t(number));
AddOptionValue(opt);
} else {
OptionValue *opt = new OptionValueDouble(name, val);
OptionValue *opt = new OptionValueDouble(name, number);
AddOptionValue(opt);
}
}
void ConfigVisitor::Visit(const json::String& string) {
OptionValue *opt;
if (string.Value().find("rgb(") == 0) {
opt = new OptionValueColour(name, string.Value());
if (string.find("rgb(") == 0) {
opt = new OptionValueColour(name, string);
} else {
opt = new OptionValueString(name, string.Value());
opt = new OptionValueString(name, string);
}
AddOptionValue(opt);
}
void ConfigVisitor::Visit(const json::Boolean& boolean) {
OptionValue *opt = new OptionValueBool(name, boolean.Value());
OptionValue *opt = new OptionValueBool(name, boolean);
AddOptionValue(opt);
}

View file

@ -13,19 +13,9 @@ Author: Terry Caton
#include <string>
#include <stdexcept>
/*
TODO:
* better documentation (doxygen?)
* Unicode support
* parent element accessors
*/
namespace json
{
/////////////////////////////////////////////////
// forward declarations (more info further below)
class Visitor;
@ -34,9 +24,9 @@ class ConstVisitor;
template <typename ValueTypeT>
class TrivialType_T;
typedef TrivialType_T<double> Number;
typedef TrivialType_T<bool> Boolean;
typedef TrivialType_T<std::string> String;
typedef double Number;
typedef bool Boolean;
typedef std::string String;
class Object;
class Array;
@ -100,6 +90,8 @@ public:
operator Null& ();
// 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);
const UnknownElement& operator[] (const std::string& key) const;
@ -213,44 +205,15 @@ private:
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
// element type of UnknownElement
class Null
{
public:
bool operator == (const Null& trivial) const;
bool operator == (const Null& trivial) const { return true; }
};
} // end namespace

View file

@ -236,49 +236,4 @@ inline const UnknownElement& Array::operator[] (size_t index) const
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

View file

@ -97,21 +97,20 @@ inline void Writer::Write_i(const Object& object)
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)
{
m_ostr << (booleanElement.Value() ? "true" : "false");
m_ostr << (booleanElement ? "true" : "false");
}
inline void Writer::Write_i(const String& stringElement)
{
m_ostr << '"';
const std::string& s = stringElement.Value();
std::string::const_iterator it(s.begin()),
itend(s.end());
const std::string& s = stringElement;
std::string::const_iterator it(s.begin()), itend(s.end());
for (; it != itend; ++it)
{
switch (*it)

View file

@ -107,16 +107,16 @@ namespace {
for (json::Array::const_iterator it = arr.begin(); it != arr.end(); ++it) {
json::String const& command_name = *it;
if (command_name.Value().empty()) {
if (command_name.empty()) {
AddSeparator();
}
else {
cmd::Command *command;
try {
command = cmd::get(command_name.Value());
command = cmd::get(command_name);
}
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;
}