mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
DOM
- Added more variables. - Removed unnecessary API.
This commit is contained in:
parent
0240ffa1d2
commit
9d0037bc78
3 changed files with 60 additions and 58 deletions
97
src/DOM.cpp
97
src/DOM.cpp
|
@ -25,7 +25,9 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <sstream>
|
||||
#include <Context.h>
|
||||
#include <text.h>
|
||||
#include <DOM.h>
|
||||
#include "../cmake.h"
|
||||
|
||||
|
@ -48,36 +50,13 @@ DOM::~DOM ()
|
|||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const int DOM::getInteger (const std::string& name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const double DOM::getReal (const std::string& name)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const bool DOM::getBoolean (const std::string& name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const time_t DOM::getDate (const std::string& name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO <id>. <-- context.tdb2
|
||||
// TODO <uuid>. <-- context.tdb2
|
||||
// rc.<name> <-- context.config
|
||||
// TODO report.<name>. <-- context.reports
|
||||
// TODO stats.<name> <-- context.stats
|
||||
// TODO context.<name> <-- args, ...
|
||||
//
|
||||
// system.<name> <-- context.system
|
||||
// system.version
|
||||
|
@ -94,6 +73,35 @@ const std::string DOM::get (const std::string& name)
|
|||
return context.config.get (name.substr (3));
|
||||
}
|
||||
|
||||
else if (len > 8 &&
|
||||
name.substr (0, 8) == "context.")
|
||||
{
|
||||
if (name == "context.program")
|
||||
return context.program;
|
||||
|
||||
else if (name == "context.args")
|
||||
{
|
||||
std::string combined;
|
||||
join (combined, " ", context.args);
|
||||
return combined;
|
||||
}
|
||||
else if (name == "context.width")
|
||||
{
|
||||
std::stringstream s;
|
||||
s << context.terminal_width;
|
||||
return s.str ();
|
||||
}
|
||||
else if (name == "context.height")
|
||||
{
|
||||
std::stringstream s;
|
||||
s << context.terminal_height;
|
||||
return s.str ();
|
||||
}
|
||||
|
||||
else
|
||||
throw std::string ("DOM: Cannot get unrecognized name '") + name + "'.";
|
||||
}
|
||||
|
||||
// TODO <id>.
|
||||
// TODO <uuid>.
|
||||
// TODO report.
|
||||
|
@ -104,17 +112,17 @@ const std::string DOM::get (const std::string& name)
|
|||
name.substr (0, 7) == "system.")
|
||||
{
|
||||
// Taskwarrior version number.
|
||||
if (name.substr (7) == "version")
|
||||
if (name == "system.version")
|
||||
return VERSION;
|
||||
|
||||
#ifdef HAVE_LIBLUA
|
||||
// Lua version number.
|
||||
else if (name.substr (7) == "lua.version")
|
||||
else if (name == "system.lua.version")
|
||||
return LUA_RELEASE;
|
||||
#endif
|
||||
|
||||
// OS type.
|
||||
else if (name.substr (7) == "os")
|
||||
else if (name == "system.os")
|
||||
#if defined (DARWIN)
|
||||
return "Darwin";
|
||||
#elif defined (SOLARIS)
|
||||
|
@ -132,34 +140,29 @@ const std::string DOM::get (const std::string& name)
|
|||
#else
|
||||
return "<unknown>";
|
||||
#endif
|
||||
|
||||
else
|
||||
throw std::string ("DOM: Cannot get unrecognized name '") + name + "'.";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const bool value)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const int value)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const double value)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const time_t value)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const std::string& value)
|
||||
{
|
||||
int len = name.length ();
|
||||
|
||||
// rc. --> context.config
|
||||
if (len > 3 &&
|
||||
name.substr (0, 3) == "rc.")
|
||||
{
|
||||
return context.config.set (name.substr (3), value);
|
||||
}
|
||||
|
||||
// Unrecognized --> error.
|
||||
else
|
||||
throw std::string ("DOM: Cannot set '") + name + "'.";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
11
src/DOM.h
11
src/DOM.h
|
@ -36,16 +36,7 @@ public:
|
|||
DOM ();
|
||||
~DOM ();
|
||||
|
||||
const int getInteger (const std::string&);
|
||||
const double getReal (const std::string&);
|
||||
const bool getBoolean (const std::string&);
|
||||
const time_t getDate (const std::string&);
|
||||
const std::string get (const std::string&);
|
||||
|
||||
void set (const std::string&, const bool);
|
||||
void set (const std::string&, const int);
|
||||
void set (const std::string&, const double);
|
||||
void set (const std::string&, const time_t);
|
||||
const std::string get (const std::string&);
|
||||
void set (const std::string&, const std::string&);
|
||||
|
||||
private:
|
||||
|
|
|
@ -42,14 +42,22 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (2);
|
||||
UnitTest t (7);
|
||||
|
||||
try
|
||||
{
|
||||
DOM dom;
|
||||
|
||||
// TODO dom.get rc.name
|
||||
t.is (dom.get ("system.version"), VERSION, "DOM system.version -> VERSION");
|
||||
t.is (dom.get ("system.lua.version"), LUA_RELEASE, "DOM system.lua.version -> LUA_RELEASE");
|
||||
t.ok (dom.get ("system.os") != "<unknown>", "DOM system.os -> != Unknown");
|
||||
t.is (dom.get ("context.program"), "", "DOM context.program -> ''");
|
||||
t.is (dom.get ("context.args"), "", "DOM context.args -> ''");
|
||||
t.is (dom.get ("context.width"), "0", "DOM context.width -> '0'");
|
||||
t.is (dom.get ("context.height"), "0", "DOM context.height -> '0'");
|
||||
|
||||
// TODO dom.set rc.name
|
||||
}
|
||||
|
||||
catch (std::string& error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue