From fe4c8f3a9dc74518606d141d900f6de2a9f198c9 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 31 May 2009 01:10:39 -0400 Subject: [PATCH] Enhancement - Object rename prior to integration - T -> T2 - TDB -> TDB2 --- src/Att.cpp | 6 +++++ src/Att.h | 2 +- src/Record.cpp | 20 +++++--------- src/sandbox/Context.h | 8 +++--- src/sandbox/Makefile | 2 +- src/sandbox/{T.cpp => T2.cpp} | 22 ++++++++-------- src/sandbox/{T.h => T2.h} | 14 +++++----- src/sandbox/{TDB.cpp => TDB2.cpp} | 44 +++++++++++++++---------------- src/sandbox/{TDB.h => TDB2.h} | 22 ++++++++-------- src/sandbox/main.cpp | 2 +- src/tests/att.t.cpp | 8 +++++- src/tests/record.t.cpp | 27 +++++++++++++------ 12 files changed, 96 insertions(+), 81 deletions(-) rename src/sandbox/{T.cpp => T2.cpp} (85%) rename src/sandbox/{T.h => T2.h} (84%) rename src/sandbox/{TDB.cpp => TDB2.cpp} (89%) rename src/sandbox/{TDB.h => TDB2.h} (81%) diff --git a/src/Att.cpp b/src/Att.cpp index b956210ac..2d5eb9edd 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -161,6 +161,12 @@ void Att::addMod (const Mod& mod) mMods.push_back (mod); } +//////////////////////////////////////////////////////////////////////////////// +void Att::mods (std::vector & all) +{ + all = mMods; +} + //////////////////////////////////////////////////////////////////////////////// std::string Att::name () const { diff --git a/src/Att.h b/src/Att.h index b185744b8..a6b5316b2 100644 --- a/src/Att.h +++ b/src/Att.h @@ -46,7 +46,7 @@ public: std::string composeF4 () const; void addMod (const Mod&); - // TODO Need method to access mods. + void mods (std::vector &); std::string name () const; void name (const std::string&); diff --git a/src/Record.cpp b/src/Record.cpp index 7d31e074a..5c185dad2 100644 --- a/src/Record.cpp +++ b/src/Record.cpp @@ -53,12 +53,6 @@ Record::Record (const std::string& input) //////////////////////////////////////////////////////////////////////////////// Record& Record::operator= (const Record& other) { - throw std::string ("unimplemented Record:operator="); - if (this != &other) - { - *this = other; - } - return *this; } @@ -88,25 +82,23 @@ std::string Record::composeF4 () // // start --> name --> : --> " --> value --> " --> end // ^ | -// |________________________________| +// +------------- \s <--------------+ // void Record::parse (const std::string& input) { Nibbler n (input); std::string line; - if (n.skip ('[') && n.getUntil (']', line)) + if (n.skip ('[') && + n.getUntil (']', line) && + n.skip (']') && + n.depleted ()) { Nibbler nl (line); - bool first = true; Att a; while (a.parse (nl)) { - if (first) - first = false; - else - nl.skip (' '); - + nl.skip (' '); (*this)[a.name ()] = a; } diff --git a/src/sandbox/Context.h b/src/sandbox/Context.h index 25557f8fe..eebcaf96f 100644 --- a/src/sandbox/Context.h +++ b/src/sandbox/Context.h @@ -31,8 +31,8 @@ #include "Keymap.h" #include "Config.h" #include "Sequence.h" -#include "T.h" -#include "TDB.h" +#include "T2.h" +#include "TDB2.h" #include "StringTable.h" class Context @@ -55,8 +55,8 @@ public: Filter filter; Keymap keymap; Sequence sequence; - T task; - TDB tdb; + T2 task; + TDB2 tdb; StringTable stringtable; private: diff --git a/src/sandbox/Makefile b/src/sandbox/Makefile index e897e7f1d..80c752d77 100644 --- a/src/sandbox/Makefile +++ b/src/sandbox/Makefile @@ -2,7 +2,7 @@ PROJECT = 1.8 CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fno-stack-check LFLAGS = 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 \ ../text.o ../Date.o ../Config.o ../Location.o ../Subst.o ../Nibbler.o diff --git a/src/sandbox/T.cpp b/src/sandbox/T2.cpp similarity index 85% rename from src/sandbox/T.cpp rename to src/sandbox/T2.cpp index 2620e4899..dae3b4baf 100644 --- a/src/sandbox/T.cpp +++ b/src/sandbox/T2.cpp @@ -26,23 +26,23 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include "T.h" +#include "T2.h" //////////////////////////////////////////////////////////////////////////////// -T::T () +T2::T2 () { } //////////////////////////////////////////////////////////////////////////////// -T::T (const std::string& input) +T2::T2 (const std::string& 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) { // 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]] -std::string T::composeF4 () +std::string T2::composeF4 () { - throw std::string ("unimplemented T::composeF4"); + throw std::string ("unimplemented T2::composeF4"); return ""; } //////////////////////////////////////////////////////////////////////////////// -std::string T::composeCSV () +std::string T2::composeCSV () { - throw std::string ("unimplemented T::composeCSV"); + throw std::string ("unimplemented T2::composeCSV"); return ""; } //////////////////////////////////////////////////////////////////////////////// -bool T::validate () const +bool T2::validate () const { // TODO Verify until > due // TODO Verify entry < until, due, start, end diff --git a/src/sandbox/T.h b/src/sandbox/T2.h similarity index 84% rename from src/sandbox/T.h rename to src/sandbox/T2.h index 97706b4f9..5f59337ea 100644 --- a/src/sandbox/T.h +++ b/src/sandbox/T2.h @@ -24,19 +24,19 @@ // USA // //////////////////////////////////////////////////////////////////////////////// -#ifndef INCLUDED_T -#define INCLUDED_T +#ifndef INCLUDED_T2 +#define INCLUDED_T2 #include #include "Record.h" -class T : public Record +class T2 : public Record { public: - T (); // Default constructor - T (const std::string&); // Parse - T& operator= (const T&); // Assignment operator - ~T (); // Destructor + T2 (); // Default constructor + T2 (const std::string&); // Parse + T2& operator= (const T2&); // Assignment operator + ~T2 (); // Destructor std::string composeF4 (); std::string composeCSV (); diff --git a/src/sandbox/TDB.cpp b/src/sandbox/TDB2.cpp similarity index 89% rename from src/sandbox/TDB.cpp rename to src/sandbox/TDB2.cpp index da96d2180..825237086 100644 --- a/src/sandbox/TDB.cpp +++ b/src/sandbox/TDB2.cpp @@ -31,7 +31,7 @@ #include #include "text.h" #include "util.h" -#include "TDB.h" +#include "TDB2.h" #include "task.h" //////////////////////////////////////////////////////////////////////////////// @@ -64,16 +64,16 @@ // +- TDB::~TDB // [TDB::unlock] // -TDB::TDB () +TDB2::TDB2 () : mLock (true) , 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; // mFiles = other.mFiles; // 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) // { // mLocations = other.mLocations; @@ -104,14 +104,14 @@ TDB& TDB::operator= (const TDB& other) } //////////////////////////////////////////////////////////////////////////////// -TDB::~TDB () +TDB2::~TDB2 () { if (mAllOpenAndLocked) unlock (); } //////////////////////////////////////////////////////////////////////////////// -void TDB::location (const std::string& path) +void TDB2::location (const std::string& path) { if (access (expandPath (path).c_str (), F_OK)) 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; @@ -136,7 +136,7 @@ void TDB::lock (bool lockFile /* = true */) } //////////////////////////////////////////////////////////////////////////////// -void TDB::unlock () +void TDB2::unlock () { if (mAllOpenAndLocked) { @@ -154,7 +154,7 @@ void TDB::unlock () //////////////////////////////////////////////////////////////////////////////// // Returns number of filtered tasks. -int TDB::load (std::vector & tasks, Filter& filter) +int TDB2::load (std::vector & tasks, Filter& filter) { std::string file; int line_number; @@ -176,7 +176,7 @@ int TDB::load (std::vector & tasks, Filter& filter) line[length - 1] = '\0'; // Kill \n std::cout << "# line: " << line << std::endl; - T task (line); + T2 task (line); if (filter.pass (task)) { @@ -198,7 +198,7 @@ int TDB::load (std::vector & tasks, Filter& filter) line[length - 1] = '\0'; // Kill \n std::cout << "# line: " << line << std::endl; - T task (line); + T2 task (line); if (filter.pass (task)) { @@ -224,9 +224,9 @@ int TDB::load (std::vector & tasks, Filter& filter) //////////////////////////////////////////////////////////////////////////////// // 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 write after.composeFF4 (). @@ -234,27 +234,27 @@ void TDB::add (T& after) //////////////////////////////////////////////////////////////////////////////// // 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 -int TDB::commit () +int TDB2::commit () { - throw std::string ("unimplemented TDB::commit"); + throw std::string ("unimplemented TDB2::commit"); } //////////////////////////////////////////////////////////////////////////////// // 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. if (access (file.c_str (), F_OK | R_OK | W_OK)) diff --git a/src/sandbox/TDB.h b/src/sandbox/TDB2.h similarity index 81% rename from src/sandbox/TDB.h rename to src/sandbox/TDB2.h index 40afcfdc7..90c26bc21 100644 --- a/src/sandbox/TDB.h +++ b/src/sandbox/TDB2.h @@ -24,35 +24,35 @@ // USA // //////////////////////////////////////////////////////////////////////////////// -#ifndef INCLUDED_TDB -#define INCLUDED_TDB +#ifndef INCLUDED_TDB2 +#define INCLUDED_TDB2 #include #include #include #include #include -#include +#include // Length of longest line. #define T_LINE_MAX 32768 -class TDB +class TDB2 { public: - TDB (); // Default constructor - TDB (const TDB&); // Copy constructor - TDB& operator= (const TDB&); // Assignment operator - ~TDB (); // Destructor + TDB2 (); // Default constructor + TDB2 (const TDB2&); // Copy constructor + TDB2& operator= (const TDB2&); // Assignment operator + ~TDB2 (); // Destructor void location (const std::string&); void lock (bool lockFile = true); void unlock (); - int load (std::vector &, Filter&); - void add (T&); - void update (T&, T&); + int load (std::vector &, Filter&); + void add (T2&); + void update (T2&, T2&); int commit (); void upgrade (); diff --git a/src/sandbox/main.cpp b/src/sandbox/main.cpp index 4977b15c7..22e56c672 100644 --- a/src/sandbox/main.cpp +++ b/src/sandbox/main.cpp @@ -17,7 +17,7 @@ int main (int argc, char** argv) c.filter.push_back (Att ("priority", "L")); - std::vector tasks; + std::vector tasks; int quantity = c.tdb.load (tasks, c.filter); std::cout << "# " << quantity << " <-- c.tdb.load" << std::endl; diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index 1f03bebab..939ed1487 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (36); + UnitTest t (38); Att a1 ("name", "value"); 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;} t.notok (good, "Att::addMod (fartwizzle)"); + // Att::mods + std::vector 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 Nibbler n (""); Att a7; diff --git a/src/tests/record.t.cpp b/src/tests/record.t.cpp index f78b7d690..8b238dea1 100644 --- a/src/tests/record.t.cpp +++ b/src/tests/record.t.cpp @@ -32,11 +32,26 @@ //////////////////////////////////////////////////////////////////////////////// Record parseRecord (const std::string& input) { - try { Record r (input); return r; } - catch (...) {} + try + { + Record r (input); + return r; + } + + catch (std::string& e) + { + std::cout << "# Exception: " << e << std::endl; + } + + catch (...) + { + std::cout << "# Exception!" << std::endl; + } + return Record (); } +//////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { UnitTest t (4); @@ -49,8 +64,8 @@ int main (int argc, char** argv) record = parseRecord ("[]"); t.is (record.size (), (size_t)0, "Record []"); - // [name:value] - record = parseRecord ("[name:value]"); + // [name:"value"] + record = parseRecord ("[name:\"value\"]"); t.is (record.size (), (size_t)1, "Record [name:value]"); if (record.size () == 1) { @@ -66,10 +81,6 @@ int main (int argc, char** argv) // TODO [name:"one two"] // TODO [one:two three:four] - // TODO FF3 - // TODO FF2 - // TODO FF1 - return 0; }