Enhancement - Object rename prior to integration

- T -> T2
- TDB -> TDB2
This commit is contained in:
Paul Beckingham 2009-05-31 01:10:39 -04:00
parent 766c2d3620
commit fe4c8f3a9d
12 changed files with 96 additions and 81 deletions

View file

@ -161,6 +161,12 @@ void Att::addMod (const Mod& mod)
mMods.push_back (mod); mMods.push_back (mod);
} }
////////////////////////////////////////////////////////////////////////////////
void Att::mods (std::vector <Mod>& all)
{
all = mMods;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Att::name () const std::string Att::name () const
{ {

View file

@ -46,7 +46,7 @@ public:
std::string composeF4 () const; std::string composeF4 () const;
void addMod (const Mod&); void addMod (const Mod&);
// TODO Need method to access mods. void mods (std::vector <Mod>&);
std::string name () const; std::string name () const;
void name (const std::string&); void name (const std::string&);

View file

@ -53,12 +53,6 @@ Record::Record (const std::string& input)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Record& Record::operator= (const Record& other) Record& Record::operator= (const Record& other)
{ {
throw std::string ("unimplemented Record:operator=");
if (this != &other)
{
*this = other;
}
return *this; return *this;
} }
@ -88,25 +82,23 @@ std::string Record::composeF4 ()
// //
// start --> name --> : --> " --> value --> " --> end // start --> name --> : --> " --> value --> " --> end
// ^ | // ^ |
// |________________________________| // +------------- \s <--------------+
// //
void Record::parse (const std::string& input) void Record::parse (const std::string& input)
{ {
Nibbler n (input); Nibbler n (input);
std::string line; std::string line;
if (n.skip ('[') && n.getUntil (']', line)) if (n.skip ('[') &&
n.getUntil (']', line) &&
n.skip (']') &&
n.depleted ())
{ {
Nibbler nl (line); Nibbler nl (line);
bool first = true;
Att a; Att a;
while (a.parse (nl)) while (a.parse (nl))
{ {
if (first) nl.skip (' ');
first = false;
else
nl.skip (' ');
(*this)[a.name ()] = a; (*this)[a.name ()] = a;
} }

View file

@ -31,8 +31,8 @@
#include "Keymap.h" #include "Keymap.h"
#include "Config.h" #include "Config.h"
#include "Sequence.h" #include "Sequence.h"
#include "T.h" #include "T2.h"
#include "TDB.h" #include "TDB2.h"
#include "StringTable.h" #include "StringTable.h"
class Context class Context
@ -55,8 +55,8 @@ public:
Filter filter; Filter filter;
Keymap keymap; Keymap keymap;
Sequence sequence; Sequence sequence;
T task; T2 task;
TDB tdb; TDB2 tdb;
StringTable stringtable; StringTable stringtable;
private: private:

View file

@ -2,7 +2,7 @@ PROJECT = 1.8
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fno-stack-check CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fno-stack-check
LFLAGS = LFLAGS =
LIBS = LIBS =
OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \ OBJECTS = main.o Context.o TDB2.o T2.o ../Sequence.o ../Filter.o ../Att.o \
../Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o \ ../Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o \
../text.o ../Date.o ../Config.o ../Location.o ../Subst.o ../Nibbler.o ../text.o ../Date.o ../Config.o ../Location.o ../Subst.o ../Nibbler.o

View file

@ -26,23 +26,23 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <string> #include <string>
#include "T.h" #include "T2.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
T::T () T2::T2 ()
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
T::T (const std::string& input) T2::T2 (const std::string& input)
{ {
parse (input); parse (input);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
T& T::operator= (const T& other) T2& T2::operator= (const T2& other)
{ {
throw std::string ("unimplemented T::operator="); throw std::string ("unimplemented T2::operator=");
if (this != &other) if (this != &other)
{ {
// mOne = other.mOne; // mOne = other.mOne;
@ -52,27 +52,27 @@ T& T::operator= (const T& other)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
T::~T () T2::~T2 ()
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// [name:value, name:"value",name:[name:value,name:value]] // [name:value, name:"value",name:[name:value,name:value]]
std::string T::composeF4 () std::string T2::composeF4 ()
{ {
throw std::string ("unimplemented T::composeF4"); throw std::string ("unimplemented T2::composeF4");
return ""; return "";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string T::composeCSV () std::string T2::composeCSV ()
{ {
throw std::string ("unimplemented T::composeCSV"); throw std::string ("unimplemented T2::composeCSV");
return ""; return "";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool T::validate () const bool T2::validate () const
{ {
// TODO Verify until > due // TODO Verify until > due
// TODO Verify entry < until, due, start, end // TODO Verify entry < until, due, start, end

View file

@ -24,19 +24,19 @@
// USA // USA
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_T #ifndef INCLUDED_T2
#define INCLUDED_T #define INCLUDED_T2
#include <string> #include <string>
#include "Record.h" #include "Record.h"
class T : public Record class T2 : public Record
{ {
public: public:
T (); // Default constructor T2 (); // Default constructor
T (const std::string&); // Parse T2 (const std::string&); // Parse
T& operator= (const T&); // Assignment operator T2& operator= (const T2&); // Assignment operator
~T (); // Destructor ~T2 (); // Destructor
std::string composeF4 (); std::string composeF4 ();
std::string composeCSV (); std::string composeCSV ();

View file

@ -31,7 +31,7 @@
#include <sys/file.h> #include <sys/file.h>
#include "text.h" #include "text.h"
#include "util.h" #include "util.h"
#include "TDB.h" #include "TDB2.h"
#include "task.h" #include "task.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -64,16 +64,16 @@
// +- TDB::~TDB // +- TDB::~TDB
// [TDB::unlock] // [TDB::unlock]
// //
TDB::TDB () TDB2::TDB2 ()
: mLock (true) : mLock (true)
, mAllOpenAndLocked (false) , mAllOpenAndLocked (false)
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TDB::TDB (const TDB& other) TDB2::TDB2 (const TDB2& other)
{ {
throw std::string ("unimplemented TDB::TDB"); throw std::string ("unimplemented TDB2::TDB2");
// mLocations = other.mLocations; // mLocations = other.mLocations;
// mFiles = other.mFiles; // mFiles = other.mFiles;
// mLock = other.mLock; // mLock = other.mLock;
@ -85,9 +85,9 @@ TDB::TDB (const TDB& other)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TDB& TDB::operator= (const TDB& other) TDB2& TDB2::operator= (const TDB2& other)
{ {
throw std::string ("unimplemented TDB::operator="); throw std::string ("unimplemented TDB2::operator=");
// if (this != &other) // if (this != &other)
// { // {
// mLocations = other.mLocations; // mLocations = other.mLocations;
@ -104,14 +104,14 @@ TDB& TDB::operator= (const TDB& other)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TDB::~TDB () TDB2::~TDB2 ()
{ {
if (mAllOpenAndLocked) if (mAllOpenAndLocked)
unlock (); unlock ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TDB::location (const std::string& path) void TDB2::location (const std::string& path)
{ {
if (access (expandPath (path).c_str (), F_OK)) if (access (expandPath (path).c_str (), F_OK))
throw std::string ("Data location '") + throw std::string ("Data location '") +
@ -122,7 +122,7 @@ void TDB::location (const std::string& path)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TDB::lock (bool lockFile /* = true */) void TDB2::lock (bool lockFile /* = true */)
{ {
mLock = lockFile; mLock = lockFile;
@ -136,7 +136,7 @@ void TDB::lock (bool lockFile /* = true */)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TDB::unlock () void TDB2::unlock ()
{ {
if (mAllOpenAndLocked) if (mAllOpenAndLocked)
{ {
@ -154,7 +154,7 @@ void TDB::unlock ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Returns number of filtered tasks. // Returns number of filtered tasks.
int TDB::load (std::vector <T>& tasks, Filter& filter) int TDB2::load (std::vector <T2>& tasks, Filter& filter)
{ {
std::string file; std::string file;
int line_number; int line_number;
@ -176,7 +176,7 @@ int TDB::load (std::vector <T>& tasks, Filter& filter)
line[length - 1] = '\0'; // Kill \n line[length - 1] = '\0'; // Kill \n
std::cout << "# line: " << line << std::endl; std::cout << "# line: " << line << std::endl;
T task (line); T2 task (line);
if (filter.pass (task)) if (filter.pass (task))
{ {
@ -198,7 +198,7 @@ int TDB::load (std::vector <T>& tasks, Filter& filter)
line[length - 1] = '\0'; // Kill \n line[length - 1] = '\0'; // Kill \n
std::cout << "# line: " << line << std::endl; std::cout << "# line: " << line << std::endl;
T task (line); T2 task (line);
if (filter.pass (task)) if (filter.pass (task))
{ {
@ -224,9 +224,9 @@ int TDB::load (std::vector <T>& tasks, Filter& filter)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO Write to transaction log. // TODO Write to transaction log.
void TDB::add (T& after) void TDB2::add (T2& after)
{ {
throw std::string ("unimplemented TDB::add"); throw std::string ("unimplemented TDB2::add");
// TODO Seek to end of pending. // TODO Seek to end of pending.
// TODO write after.composeFF4 (). // TODO write after.composeFF4 ().
@ -234,27 +234,27 @@ void TDB::add (T& after)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO Write to transaction log. // TODO Write to transaction log.
void TDB::update (T& before, T& after) void TDB2::update (T2& before, T2& after)
{ {
throw std::string ("unimplemented TDB::update"); throw std::string ("unimplemented TDB2::update");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO writes all, including comments // TODO writes all, including comments
int TDB::commit () int TDB2::commit ()
{ {
throw std::string ("unimplemented TDB::commit"); throw std::string ("unimplemented TDB2::commit");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO -> FF4 // TODO -> FF4
void TDB::upgrade () void TDB2::upgrade ()
{ {
throw std::string ("unimplemented TDB::upgrade"); throw std::string ("unimplemented TDB2::upgrade");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FILE* TDB::openAndLock (const std::string& file) FILE* TDB2::openAndLock (const std::string& file)
{ {
// Check for access. // Check for access.
if (access (file.c_str (), F_OK | R_OK | W_OK)) if (access (file.c_str (), F_OK | R_OK | W_OK))

View file

@ -24,35 +24,35 @@
// USA // USA
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_TDB #ifndef INCLUDED_TDB2
#define INCLUDED_TDB #define INCLUDED_TDB2
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
#include <Location.h> #include <Location.h>
#include <Filter.h> #include <Filter.h>
#include <T.h> #include <T2.h>
// Length of longest line. // Length of longest line.
#define T_LINE_MAX 32768 #define T_LINE_MAX 32768
class TDB class TDB2
{ {
public: public:
TDB (); // Default constructor TDB2 (); // Default constructor
TDB (const TDB&); // Copy constructor TDB2 (const TDB2&); // Copy constructor
TDB& operator= (const TDB&); // Assignment operator TDB2& operator= (const TDB2&); // Assignment operator
~TDB (); // Destructor ~TDB2 (); // Destructor
void location (const std::string&); void location (const std::string&);
void lock (bool lockFile = true); void lock (bool lockFile = true);
void unlock (); void unlock ();
int load (std::vector <T>&, Filter&); int load (std::vector <T2>&, Filter&);
void add (T&); void add (T2&);
void update (T&, T&); void update (T2&, T2&);
int commit (); int commit ();
void upgrade (); void upgrade ();

View file

@ -17,7 +17,7 @@ int main (int argc, char** argv)
c.filter.push_back (Att ("priority", "L")); c.filter.push_back (Att ("priority", "L"));
std::vector <T> tasks; std::vector <T2> tasks;
int quantity = c.tdb.load (tasks, c.filter); int quantity = c.tdb.load (tasks, c.filter);
std::cout << "# " << quantity << " <-- c.tdb.load" << std::endl; std::cout << "# " << quantity << " <-- c.tdb.load" << std::endl;

View file

@ -30,7 +30,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (36); UnitTest t (38);
Att a1 ("name", "value"); Att a1 ("name", "value");
t.is (a1.name (), "name", "Att::Att (name, value), Att.name"); t.is (a1.name (), "name", "Att::Att (name, value), Att.name");
@ -73,6 +73,12 @@ int main (int argc, char** argv)
try {a6.addMod (Mod ("fartwizzle"));} catch (...) {good = false;} try {a6.addMod (Mod ("fartwizzle"));} catch (...) {good = false;}
t.notok (good, "Att::addMod (fartwizzle)"); t.notok (good, "Att::addMod (fartwizzle)");
// Att::mods
std::vector <Mod> mods;
a6.mods (mods);
t.is (mods.size (), (size_t)1, "Att::mods () size == 1");
t.is (mods[0], "is", "Att::mods [0] == 'is'");
// Att::parse // Att::parse
Nibbler n (""); Nibbler n ("");
Att a7; Att a7;

View file

@ -32,11 +32,26 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Record parseRecord (const std::string& input) Record parseRecord (const std::string& input)
{ {
try { Record r (input); return r; } try
catch (...) {} {
Record r (input);
return r;
}
catch (std::string& e)
{
std::cout << "# Exception: " << e << std::endl;
}
catch (...)
{
std::cout << "# Exception!" << std::endl;
}
return Record (); return Record ();
} }
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (4); UnitTest t (4);
@ -49,8 +64,8 @@ int main (int argc, char** argv)
record = parseRecord ("[]"); record = parseRecord ("[]");
t.is (record.size (), (size_t)0, "Record []"); t.is (record.size (), (size_t)0, "Record []");
// [name:value] // [name:"value"]
record = parseRecord ("[name:value]"); record = parseRecord ("[name:\"value\"]");
t.is (record.size (), (size_t)1, "Record [name:value]"); t.is (record.size (), (size_t)1, "Record [name:value]");
if (record.size () == 1) if (record.size () == 1)
{ {
@ -66,10 +81,6 @@ int main (int argc, char** argv)
// TODO [name:"one two"] // TODO [name:"one two"]
// TODO [one:two three:four] // TODO [one:two three:four]
// TODO FF3
// TODO FF2
// TODO FF1
return 0; return 0;
} }