From 69fbeed3ad3812f66db21bce52ef06f1f0549579 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 28 Mar 2013 17:51:07 +0000 Subject: skip 1 shuffle of code out of common --- project2/Jamfile.jam | 1 + project2/basics/Jamfile.jam | 21 +++++++ project2/basics/aggregates/count.cpp | 28 +++++++++ project2/basics/aggregates/countDistinct.cpp | 26 ++++++++ project2/basics/aggregates/distinct.cpp | 28 +++++++++ project2/basics/aggregates/max.cpp | 27 +++++++++ project2/basics/aggregates/min.cpp | 32 ++++++++++ project2/basics/functions/dates.cpp | 90 ++++++++++++++++++++++++++++ project2/basics/functions/strings.cpp | 28 +++++++++ project2/basics/pch.hpp | 28 +++++++++ project2/basics/tests/compoundTest.cpp | 79 ++++++++++++++++++++++++ project2/basics/tests/compoundTest.h | 16 +++++ project2/basics/tests/equals.cpp | 24 ++++++++ project2/basics/tests/isdistinct.cpp | 40 +++++++++++++ project2/basics/tests/isuniq.cpp | 48 +++++++++++++++ project2/basics/tests/validDateCheck.cpp | 66 ++++++++++++++++++++ project2/common/Jamfile.jam | 1 + project2/common/aggregates/count.cpp | 28 --------- project2/common/aggregates/countDistinct.cpp | 26 -------- project2/common/aggregates/distinct.cpp | 28 --------- project2/common/aggregates/max.cpp | 27 --------- project2/common/aggregates/min.cpp | 32 ---------- project2/common/functions/dates.cpp | 90 ---------------------------- project2/common/functions/strings.cpp | 28 --------- project2/common/tests/compoundTest.cpp | 79 ------------------------ project2/common/tests/compoundTest.h | 16 ----- project2/common/tests/equals.cpp | 24 -------- project2/common/tests/isdistinct.cpp | 40 ------------- project2/common/tests/isuniq.cpp | 48 --------------- project2/common/tests/validDateCheck.cpp | 66 -------------------- 30 files changed, 583 insertions(+), 532 deletions(-) create mode 100644 project2/basics/Jamfile.jam create mode 100644 project2/basics/aggregates/count.cpp create mode 100644 project2/basics/aggregates/countDistinct.cpp create mode 100644 project2/basics/aggregates/distinct.cpp create mode 100644 project2/basics/aggregates/max.cpp create mode 100644 project2/basics/aggregates/min.cpp create mode 100644 project2/basics/functions/dates.cpp create mode 100644 project2/basics/functions/strings.cpp create mode 100644 project2/basics/pch.hpp create mode 100644 project2/basics/tests/compoundTest.cpp create mode 100644 project2/basics/tests/compoundTest.h create mode 100644 project2/basics/tests/equals.cpp create mode 100644 project2/basics/tests/isdistinct.cpp create mode 100644 project2/basics/tests/isuniq.cpp create mode 100644 project2/basics/tests/validDateCheck.cpp delete mode 100644 project2/common/aggregates/count.cpp delete mode 100644 project2/common/aggregates/countDistinct.cpp delete mode 100644 project2/common/aggregates/distinct.cpp delete mode 100644 project2/common/aggregates/max.cpp delete mode 100644 project2/common/aggregates/min.cpp delete mode 100644 project2/common/functions/dates.cpp delete mode 100644 project2/common/functions/strings.cpp delete mode 100644 project2/common/tests/compoundTest.cpp delete mode 100644 project2/common/tests/compoundTest.h delete mode 100644 project2/common/tests/equals.cpp delete mode 100644 project2/common/tests/isdistinct.cpp delete mode 100644 project2/common/tests/isuniq.cpp delete mode 100644 project2/common/tests/validDateCheck.cpp diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index ed25f40..441c47c 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -17,6 +17,7 @@ alias p2parts : : : : json//p2json compression//p2compression streams//p2streams + basics//p2basics ; build-project console ; diff --git a/project2/basics/Jamfile.jam b/project2/basics/Jamfile.jam new file mode 100644 index 0000000..66ec12c --- /dev/null +++ b/project2/basics/Jamfile.jam @@ -0,0 +1,21 @@ +alias glibmm : : : : + "`pkg-config --cflags glibmm-2.4`" + "`pkg-config --libs glibmm-2.4`" + ; +lib boost_filesystem : : boost_filesystem ; + +cpp-pch pch : pch.hpp : + ../../libmisc + glibmm + ../common//p2common + ; + +lib p2basics : + [ glob-tree *.cpp ] + : + ../../libmisc + glibmm + boost_filesystem + ../common//p2common + ; + diff --git a/project2/basics/aggregates/count.cpp b/project2/basics/aggregates/count.cpp new file mode 100644 index 0000000..fb3b899 --- /dev/null +++ b/project2/basics/aggregates/count.cpp @@ -0,0 +1,28 @@ +#include + +class Count : public ValueAggregate { + public: + Count(ScriptNodePtr s) : + ValueAggregate(s), + c(0) + { + } + void reset() const + { + c = 0; + } + void pushValue(const VariableType &) const + { + c += 1; + } + VariableType resultValue() const + { + return c; + } + private: + mutable int c; +}; + +DECLARE_LOADER("count", Count); + + diff --git a/project2/basics/aggregates/countDistinct.cpp b/project2/basics/aggregates/countDistinct.cpp new file mode 100644 index 0000000..b471911 --- /dev/null +++ b/project2/basics/aggregates/countDistinct.cpp @@ -0,0 +1,26 @@ +#include + +class CountDistinct : public ValueAggregate { + public: + CountDistinct(ScriptNodePtr s) : + ValueAggregate(s) + { + } + void reset() const + { + result.clear(); + } + void pushValue(const VariableType & v) const + { + result.insert(v); + } + VariableType resultValue() const + { + return result.size(); + } + private: + mutable std::set result; +}; + +DECLARE_LOADER("countdistinct", CountDistinct); + diff --git a/project2/basics/aggregates/distinct.cpp b/project2/basics/aggregates/distinct.cpp new file mode 100644 index 0000000..ebac934 --- /dev/null +++ b/project2/basics/aggregates/distinct.cpp @@ -0,0 +1,28 @@ +#include +#include + +class Distinct : public SetAggregate { + public: + Distinct(ScriptNodePtr s) : + SetAggregate(s) + { + } + void reset() const + { + result.clear(); + } + void pushValue(const VariableType & v) const + { + result.insert(v); + } + void onResultValues(const SetAggregate::UseAgg & u) const + { + BOOST_FOREACH(const VariableType & v, result) { + u(v); + } + } + private: + mutable std::set result; +}; + +DECLARE_LOADER("distinct", Distinct); diff --git a/project2/basics/aggregates/max.cpp b/project2/basics/aggregates/max.cpp new file mode 100644 index 0000000..ef904ed --- /dev/null +++ b/project2/basics/aggregates/max.cpp @@ -0,0 +1,27 @@ +#include + +class Max : public ValueAggregate { + public: + Max(ScriptNodePtr s) : ValueAggregate(s) { } + + void reset() const + { + result = VariableType(); + } + void pushValue(const VariableType & v) const + { + if (result < v) { + result = v; + } + } + VariableType resultValue() const + { + return result; + } + private: + mutable VariableType result; +}; + +DECLARE_LOADER("max", Max); + + diff --git a/project2/basics/aggregates/min.cpp b/project2/basics/aggregates/min.cpp new file mode 100644 index 0000000..ee0bf3d --- /dev/null +++ b/project2/basics/aggregates/min.cpp @@ -0,0 +1,32 @@ +#include + +class Min : public ValueAggregate { + public: + Min(ScriptNodePtr s) : + ValueAggregate(s), + first(true) + { + } + void reset() const + { + result = VariableType(); + first = true; + } + void pushValue(const VariableType & v) const + { + if (first || v < result) { + result = v; + } + first = false; + } + VariableType resultValue() const + { + return result; + } + private: + mutable VariableType result; + mutable bool first; +}; + +DECLARE_LOADER("min", Min); + diff --git a/project2/basics/functions/dates.cpp b/project2/basics/functions/dates.cpp new file mode 100644 index 0000000..f2dcb20 --- /dev/null +++ b/project2/basics/functions/dates.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +SimpleMessage2Exception(DateParseError); +/// Variable implementation to access platform configuration values +class ParseDate : public VariableImpl { + public: + ParseDate(ScriptNodePtr e) : + string(e, "string"), + format(e, "format") + { + } + VariableType value() const + { + const char * s = string(); + const char * f = format(); + struct tm tm; + memset(&tm, 0, sizeof(struct tm)); + mktime(&tm); + const char * e = strptime(s, f, &tm); + if (!e || *e) { + Logger()->messagef(LOG_ERR, "%s: check failed (parse) for '%s' against '%s' (remaining chars='%s')", + __PRETTY_FUNCTION__, s, f, e); + throw DateParseError(string(), format()); + } + return boost::posix_time::ptime(boost::posix_time::ptime_from_tm(tm)); + } + private: + Variable string; + Variable format; +}; +DECLARE_COMPONENT_LOADER("parsedate", ParseDate, VariableLoader); + +class FormatDate : public VariableImpl { + public: + FormatDate(ScriptNodePtr e) : + date(e, "date"), + format(e, "format") + { + } + VariableType value() const + { + std::stringstream ss; + boost::date_time::time_facet * ft = new boost::date_time::time_facet(); + ss.imbue(std::locale(ss.getloc(), ft)); + ft->format(format()); + ss << boost::get(date()); + return ss.str(); + } + private: + Variable date; + Variable format; +}; +DECLARE_COMPONENT_LOADER("formatdate", FormatDate, VariableLoader); + +class AdjustDate : public VariableImpl { + public: + AdjustDate(ScriptNodePtr e) : + date(e, "date"), + offset(e, "offset") + { + } + VariableType value() const + { + return boost::get(date()) + boost::posix_time::duration_from_string(offset()); + } + private: + Variable date; + Variable offset; +}; +DECLARE_COMPONENT_LOADER("adjustdate", AdjustDate, VariableLoader); + +class CurrentDate : public VariableImpl { + public: + CurrentDate(ScriptNodePtr) + { + } + VariableType value() const + { + return boost::posix_time::microsec_clock::universal_time(); + } +}; +DECLARE_COMPONENT_LOADER("currentdate", CurrentDate, VariableLoader); + diff --git a/project2/basics/functions/strings.cpp b/project2/basics/functions/strings.cpp new file mode 100644 index 0000000..d4ba7b7 --- /dev/null +++ b/project2/basics/functions/strings.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +/// Variable implementation to access platform configuration values +class Trim : public VariableImpl { + public: + Trim(ScriptNodePtr e) : + string(e, "string") + { + } + VariableType value() const + { + Glib::ustring str = string(); + Glib::ustring::const_iterator b = str.begin(); + while (Glib::Unicode::isspace(*b)) ++b; + Glib::ustring::const_iterator e = str.end(); + while (Glib::Unicode::isspace(*--e)) ; + ++e; + return Glib::ustring(b, e); + } + private: + Variable string; +}; +DECLARE_COMPONENT_LOADER("trim", Trim, VariableLoader); + + diff --git a/project2/basics/pch.hpp b/project2/basics/pch.hpp new file mode 100644 index 0000000..d52b275 --- /dev/null +++ b/project2/basics/pch.hpp @@ -0,0 +1,28 @@ +#ifdef BOOST_BUILD_PCH_ENABLED +#ifndef COMMON_PCH +#define COMMON_PCH + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif +#endif diff --git a/project2/basics/tests/compoundTest.cpp b/project2/basics/tests/compoundTest.cpp new file mode 100644 index 0000000..b361db5 --- /dev/null +++ b/project2/basics/tests/compoundTest.cpp @@ -0,0 +1,79 @@ +#include +#include "compoundTest.h" +#include +#include +#include +#include + +StaticMessageException(NoTestsToPerform, "No tests to perform"); + +CompoundTest::CompoundTest(ScriptNodePtr s) : + SourceObject(s), + Test(s) +{ + s->script->loader.addLoadTarget(s, Storer::into(&tests)); +} + +class All : public CompoundTest { + public: + All(ScriptNodePtr s) : + SourceObject(s), + CompoundTest(s) { + } + bool passes() const { + if (tests.empty()) { + throw NoTestsToPerform(); + } + return (std::find_if(tests.begin(), tests.end(), !boost::bind(&Test::passes, _1)) == tests.end()); + } +}; +DECLARE_LOADER("all", All); + +class Any : public CompoundTest { + public: + Any(ScriptNodePtr s) : + SourceObject(s), + CompoundTest(s) { + } + bool passes() const { + if (tests.empty()) { + throw NoTestsToPerform(); + } + return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1)) != tests.end()); + } +}; +DECLARE_LOADER("any", Any); + +class None : public CompoundTest { + public: + None(ScriptNodePtr s) : + SourceObject(s), + CompoundTest(s) { + } + bool passes() const { + if (tests.empty()) { + throw NoTestsToPerform(); + } + return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1)) == tests.end()); + } +}; +DECLARE_LOADER("none", None); + +class Not : public Test { + public: + Not(ScriptNodePtr s) : + SourceObject(s), + Test(s) + { + s->script->loader.addLoadTarget(s, Storer::into(&test)); + } + bool passes() const { + if (!test) { + throw NoTestsToPerform(); + } + return !test->passes(); + } + private: + TestPtr test; +}; +DECLARE_LOADER("not", Not); diff --git a/project2/basics/tests/compoundTest.h b/project2/basics/tests/compoundTest.h new file mode 100644 index 0000000..f65e954 --- /dev/null +++ b/project2/basics/tests/compoundTest.h @@ -0,0 +1,16 @@ +#ifndef IF_H +#define IF_H + +#include + +class CompoundTest : public Test { + public: + CompoundTest(ScriptNodePtr); + + protected: + typedef ANONORDEREDSTORAGEOF(Test) Tests; + Tests tests; +}; + +#endif + diff --git a/project2/basics/tests/equals.cpp b/project2/basics/tests/equals.cpp new file mode 100644 index 0000000..ba8c695 --- /dev/null +++ b/project2/basics/tests/equals.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +class Equals : public Test { + public: + Equals(ScriptNodePtr s) : + SourceObject(s), + Test(s), + a(s, "a"), + b(s, "b") + { + } + + bool passes() const { + return (a() == b()); + } + + private: + Variable a, b; +}; +DECLARE_LOADER("equals", Equals); + diff --git a/project2/basics/tests/isdistinct.cpp b/project2/basics/tests/isdistinct.cpp new file mode 100644 index 0000000..06d887e --- /dev/null +++ b/project2/basics/tests/isdistinct.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +class IsDistinct : public Test, IHaveParameters { + public: + IsDistinct(ScriptNodePtr s) : + SourceObject(s), + Test(s), + IHaveParameters(s), + scope(s, "scope") + { + } + + void loadComplete(const CommonObjects *) + { + findComponent(scope())->registerFor(RowProcessor::Complete, boost::bind(&IsDistinct::reset, this)); + } + + bool passes() const { + Vars row; + BOOST_FOREACH(const Parameters::value_type & p, parameters) { + row.push_back(p.second()); + } + return previous.insert(row).second; + } + + void reset() const { + previous.clear(); + } + + private: + Variable scope; + typedef std::vector Vars; + typedef std::set Rows; + mutable Rows previous; +}; +DECLARE_LOADER("isdistinct", IsDistinct); diff --git a/project2/basics/tests/isuniq.cpp b/project2/basics/tests/isuniq.cpp new file mode 100644 index 0000000..548be14 --- /dev/null +++ b/project2/basics/tests/isuniq.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +class IsUniq : public Test, IHaveParameters { + public: + IsUniq(ScriptNodePtr s) : + SourceObject(s), + Test(s), + IHaveParameters(s), + scope(s, "scope") + { + } + + void loadComplete(const CommonObjects *) + { + findComponent(scope())->registerFor(RowProcessor::Complete, boost::bind(&IsUniq::reset, this)); + } + + bool passes() const { + if (previous.size() > 0) { + Vars row; + BOOST_FOREACH(const Parameters::value_type & p, parameters) { + row.push_back(p.second()); + } + std::swap(row, previous); + return row != previous; + } + else { + BOOST_FOREACH(const Parameters::value_type & p, parameters) { + previous.push_back(p.second()); + } + return true; + } + } + + void reset() const { + previous.clear(); + } + + private: + Variable scope; + typedef std::vector Vars; + mutable Vars previous; +}; +DECLARE_LOADER("isuniq", IsUniq); diff --git a/project2/basics/tests/validDateCheck.cpp b/project2/basics/tests/validDateCheck.cpp new file mode 100644 index 0000000..8dffd9d --- /dev/null +++ b/project2/basics/tests/validDateCheck.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include + +class ValidDateTest : public Test { + public: + ValidDateTest(ScriptNodePtr p) : + SourceObject(p), + Test(p), + applyTo(p, "apply-to"), + format(p, "format"), + warnLev(p->value("warn", true).as() ? LOG_WARNING : LOG_INFO) + { + } + + ~ValidDateTest() + { + } + + bool + passes() const + { + struct tm tm, ftm; + memset(&tm, 0, sizeof(struct tm)); + mktime(&tm); + const char * at = applyTo(); + const char * f = format(); + const char * s = strptime(at, f, &tm); + if (!s || *s) { + Logger()->messagef(warnLev, "%s: check failed (parse) for '%s' against '%s'", + __PRETTY_FUNCTION__, at, f); + return false; + } + ftm = tm; + if (mktime(&ftm) == -1) { + Logger()->messagef(warnLev, "%s: check failed (normalise) for '%s' against '%s'", + __PRETTY_FUNCTION__, at, f); + return false; + } + if (tm.tm_year != ftm.tm_year || + tm.tm_mon != ftm.tm_mon || + tm.tm_mday != ftm.tm_mday || + tm.tm_hour != (ftm.tm_hour - ftm.tm_isdst) || + tm.tm_min != ftm.tm_min || + tm.tm_sec != ftm.tm_sec) { + Logger()->messagef(LOG_INFO, "tm: %d %d %d %d %d %d", + tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + Logger()->messagef(LOG_INFO, "ftm: %d %d %d %d %d %d", + ftm.tm_year, ftm.tm_mon, ftm.tm_mday, ftm.tm_hour, ftm.tm_min, ftm.tm_sec); + Logger()->messagef(warnLev, "%s: check failed (verify) for '%s' against '%s'", + __PRETTY_FUNCTION__, at, f); + return false; + } + return true; + } + Variable applyTo; + Variable format; + int warnLev; +}; + +DECLARE_LOADER("validdatetest", ValidDateTest); + diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam index 7e00700..1559f25 100644 --- a/project2/common/Jamfile.jam +++ b/project2/common/Jamfile.jam @@ -11,6 +11,7 @@ cpp-pch pch : pch.hpp : ../../libmisc glibmm ; + lib p2common : pch [ glob-tree *.cpp ] diff --git a/project2/common/aggregates/count.cpp b/project2/common/aggregates/count.cpp deleted file mode 100644 index 9bdb47c..0000000 --- a/project2/common/aggregates/count.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "../aggregate.h" - -class Count : public ValueAggregate { - public: - Count(ScriptNodePtr s) : - ValueAggregate(s), - c(0) - { - } - void reset() const - { - c = 0; - } - void pushValue(const VariableType &) const - { - c += 1; - } - VariableType resultValue() const - { - return c; - } - private: - mutable int c; -}; - -DECLARE_LOADER("count", Count); - - diff --git a/project2/common/aggregates/countDistinct.cpp b/project2/common/aggregates/countDistinct.cpp deleted file mode 100644 index 4a2c540..0000000 --- a/project2/common/aggregates/countDistinct.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "../aggregate.h" - -class CountDistinct : public ValueAggregate { - public: - CountDistinct(ScriptNodePtr s) : - ValueAggregate(s) - { - } - void reset() const - { - result.clear(); - } - void pushValue(const VariableType & v) const - { - result.insert(v); - } - VariableType resultValue() const - { - return result.size(); - } - private: - mutable std::set result; -}; - -DECLARE_LOADER("countdistinct", CountDistinct); - diff --git a/project2/common/aggregates/distinct.cpp b/project2/common/aggregates/distinct.cpp deleted file mode 100644 index 85e69c2..0000000 --- a/project2/common/aggregates/distinct.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "../aggregate.h" -#include - -class Distinct : public SetAggregate { - public: - Distinct(ScriptNodePtr s) : - SetAggregate(s) - { - } - void reset() const - { - result.clear(); - } - void pushValue(const VariableType & v) const - { - result.insert(v); - } - void onResultValues(const SetAggregate::UseAgg & u) const - { - BOOST_FOREACH(const VariableType & v, result) { - u(v); - } - } - private: - mutable std::set result; -}; - -DECLARE_LOADER("distinct", Distinct); diff --git a/project2/common/aggregates/max.cpp b/project2/common/aggregates/max.cpp deleted file mode 100644 index a6e528a..0000000 --- a/project2/common/aggregates/max.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "../aggregate.h" - -class Max : public ValueAggregate { - public: - Max(ScriptNodePtr s) : ValueAggregate(s) { } - - void reset() const - { - result = VariableType(); - } - void pushValue(const VariableType & v) const - { - if (result < v) { - result = v; - } - } - VariableType resultValue() const - { - return result; - } - private: - mutable VariableType result; -}; - -DECLARE_LOADER("max", Max); - - diff --git a/project2/common/aggregates/min.cpp b/project2/common/aggregates/min.cpp deleted file mode 100644 index 14c63ae..0000000 --- a/project2/common/aggregates/min.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "../aggregate.h" - -class Min : public ValueAggregate { - public: - Min(ScriptNodePtr s) : - ValueAggregate(s), - first(true) - { - } - void reset() const - { - result = VariableType(); - first = true; - } - void pushValue(const VariableType & v) const - { - if (first || v < result) { - result = v; - } - first = false; - } - VariableType resultValue() const - { - return result; - } - private: - mutable VariableType result; - mutable bool first; -}; - -DECLARE_LOADER("min", Min); - diff --git a/project2/common/functions/dates.cpp b/project2/common/functions/dates.cpp deleted file mode 100644 index 43878c6..0000000 --- a/project2/common/functions/dates.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include "../variables.h" -#include "../scriptLoader.h" -#include "../scriptStorage.h" -#include "../logger.h" -#include -#include -#include - -SimpleMessage2Exception(DateParseError); -/// Variable implementation to access platform configuration values -class ParseDate : public VariableImpl { - public: - ParseDate(ScriptNodePtr e) : - string(e, "string"), - format(e, "format") - { - } - VariableType value() const - { - const char * s = string(); - const char * f = format(); - struct tm tm; - memset(&tm, 0, sizeof(struct tm)); - mktime(&tm); - const char * e = strptime(s, f, &tm); - if (!e || *e) { - Logger()->messagef(LOG_ERR, "%s: check failed (parse) for '%s' against '%s' (remaining chars='%s')", - __PRETTY_FUNCTION__, s, f, e); - throw DateParseError(string(), format()); - } - return boost::posix_time::ptime(boost::posix_time::ptime_from_tm(tm)); - } - private: - Variable string; - Variable format; -}; -DECLARE_COMPONENT_LOADER("parsedate", ParseDate, VariableLoader); - -class FormatDate : public VariableImpl { - public: - FormatDate(ScriptNodePtr e) : - date(e, "date"), - format(e, "format") - { - } - VariableType value() const - { - std::stringstream ss; - boost::date_time::time_facet * ft = new boost::date_time::time_facet(); - ss.imbue(std::locale(ss.getloc(), ft)); - ft->format(format()); - ss << boost::get(date()); - return ss.str(); - } - private: - Variable date; - Variable format; -}; -DECLARE_COMPONENT_LOADER("formatdate", FormatDate, VariableLoader); - -class AdjustDate : public VariableImpl { - public: - AdjustDate(ScriptNodePtr e) : - date(e, "date"), - offset(e, "offset") - { - } - VariableType value() const - { - return boost::get(date()) + boost::posix_time::duration_from_string(offset()); - } - private: - Variable date; - Variable offset; -}; -DECLARE_COMPONENT_LOADER("adjustdate", AdjustDate, VariableLoader); - -class CurrentDate : public VariableImpl { - public: - CurrentDate(ScriptNodePtr) - { - } - VariableType value() const - { - return boost::posix_time::microsec_clock::universal_time(); - } -}; -DECLARE_COMPONENT_LOADER("currentdate", CurrentDate, VariableLoader); - diff --git a/project2/common/functions/strings.cpp b/project2/common/functions/strings.cpp deleted file mode 100644 index 6616bba..0000000 --- a/project2/common/functions/strings.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "../variables.h" -#include "../scriptLoader.h" -#include "../scriptStorage.h" - -/// Variable implementation to access platform configuration values -class Trim : public VariableImpl { - public: - Trim(ScriptNodePtr e) : - string(e, "string") - { - } - VariableType value() const - { - Glib::ustring str = string(); - Glib::ustring::const_iterator b = str.begin(); - while (Glib::Unicode::isspace(*b)) ++b; - Glib::ustring::const_iterator e = str.end(); - while (Glib::Unicode::isspace(*--e)) ; - ++e; - return Glib::ustring(b, e); - } - private: - Variable string; -}; -DECLARE_COMPONENT_LOADER("trim", Trim, VariableLoader); - - diff --git a/project2/common/tests/compoundTest.cpp b/project2/common/tests/compoundTest.cpp deleted file mode 100644 index c3babf7..0000000 --- a/project2/common/tests/compoundTest.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include "compoundTest.h" -#include "../scriptLoader.h" -#include -#include -#include - -StaticMessageException(NoTestsToPerform, "No tests to perform"); - -CompoundTest::CompoundTest(ScriptNodePtr s) : - SourceObject(s), - Test(s) -{ - s->script->loader.addLoadTarget(s, Storer::into(&tests)); -} - -class All : public CompoundTest { - public: - All(ScriptNodePtr s) : - SourceObject(s), - CompoundTest(s) { - } - bool passes() const { - if (tests.empty()) { - throw NoTestsToPerform(); - } - return (std::find_if(tests.begin(), tests.end(), !boost::bind(&Test::passes, _1)) == tests.end()); - } -}; -DECLARE_LOADER("all", All); - -class Any : public CompoundTest { - public: - Any(ScriptNodePtr s) : - SourceObject(s), - CompoundTest(s) { - } - bool passes() const { - if (tests.empty()) { - throw NoTestsToPerform(); - } - return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1)) != tests.end()); - } -}; -DECLARE_LOADER("any", Any); - -class None : public CompoundTest { - public: - None(ScriptNodePtr s) : - SourceObject(s), - CompoundTest(s) { - } - bool passes() const { - if (tests.empty()) { - throw NoTestsToPerform(); - } - return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1)) == tests.end()); - } -}; -DECLARE_LOADER("none", None); - -class Not : public Test { - public: - Not(ScriptNodePtr s) : - SourceObject(s), - Test(s) - { - s->script->loader.addLoadTarget(s, Storer::into(&test)); - } - bool passes() const { - if (!test) { - throw NoTestsToPerform(); - } - return !test->passes(); - } - private: - TestPtr test; -}; -DECLARE_LOADER("not", Not); diff --git a/project2/common/tests/compoundTest.h b/project2/common/tests/compoundTest.h deleted file mode 100644 index 38aadea..0000000 --- a/project2/common/tests/compoundTest.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef IF_H -#define IF_H - -#include "../test.h" - -class CompoundTest : public Test { - public: - CompoundTest(ScriptNodePtr); - - protected: - typedef ANONORDEREDSTORAGEOF(Test) Tests; - Tests tests; -}; - -#endif - diff --git a/project2/common/tests/equals.cpp b/project2/common/tests/equals.cpp deleted file mode 100644 index b2a1bf4..0000000 --- a/project2/common/tests/equals.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include "../test.h" -#include "../scriptLoader.h" -#include "../rowProcessor.h" - -class Equals : public Test { - public: - Equals(ScriptNodePtr s) : - SourceObject(s), - Test(s), - a(s, "a"), - b(s, "b") - { - } - - bool passes() const { - return (a() == b()); - } - - private: - Variable a, b; -}; -DECLARE_LOADER("equals", Equals); - diff --git a/project2/common/tests/isdistinct.cpp b/project2/common/tests/isdistinct.cpp deleted file mode 100644 index b754d2d..0000000 --- a/project2/common/tests/isdistinct.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include "../test.h" -#include "../scriptLoader.h" -#include "../iHaveParameters.h" -#include "../rowProcessor.h" - -class IsDistinct : public Test, IHaveParameters { - public: - IsDistinct(ScriptNodePtr s) : - SourceObject(s), - Test(s), - IHaveParameters(s), - scope(s, "scope") - { - } - - void loadComplete(const CommonObjects *) - { - findComponent(scope())->registerFor(RowProcessor::Complete, boost::bind(&IsDistinct::reset, this)); - } - - bool passes() const { - Vars row; - BOOST_FOREACH(const Parameters::value_type & p, parameters) { - row.push_back(p.second()); - } - return previous.insert(row).second; - } - - void reset() const { - previous.clear(); - } - - private: - Variable scope; - typedef std::vector Vars; - typedef std::set Rows; - mutable Rows previous; -}; -DECLARE_LOADER("isdistinct", IsDistinct); diff --git a/project2/common/tests/isuniq.cpp b/project2/common/tests/isuniq.cpp deleted file mode 100644 index 6966985..0000000 --- a/project2/common/tests/isuniq.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "../test.h" -#include "../scriptLoader.h" -#include "../iHaveParameters.h" -#include "../rowProcessor.h" - -class IsUniq : public Test, IHaveParameters { - public: - IsUniq(ScriptNodePtr s) : - SourceObject(s), - Test(s), - IHaveParameters(s), - scope(s, "scope") - { - } - - void loadComplete(const CommonObjects *) - { - findComponent(scope())->registerFor(RowProcessor::Complete, boost::bind(&IsUniq::reset, this)); - } - - bool passes() const { - if (previous.size() > 0) { - Vars row; - BOOST_FOREACH(const Parameters::value_type & p, parameters) { - row.push_back(p.second()); - } - std::swap(row, previous); - return row != previous; - } - else { - BOOST_FOREACH(const Parameters::value_type & p, parameters) { - previous.push_back(p.second()); - } - return true; - } - } - - void reset() const { - previous.clear(); - } - - private: - Variable scope; - typedef std::vector Vars; - mutable Vars previous; -}; -DECLARE_LOADER("isuniq", IsUniq); diff --git a/project2/common/tests/validDateCheck.cpp b/project2/common/tests/validDateCheck.cpp deleted file mode 100644 index dabbdaa..0000000 --- a/project2/common/tests/validDateCheck.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include "../logger.h" -#include "../scriptLoader.h" -#include "../commonObjects.h" -#include "../test.h" -#include "../variables.h" -#include "../scripts.h" - -class ValidDateTest : public Test { - public: - ValidDateTest(ScriptNodePtr p) : - SourceObject(p), - Test(p), - applyTo(p, "apply-to"), - format(p, "format"), - warnLev(p->value("warn", true).as() ? LOG_WARNING : LOG_INFO) - { - } - - ~ValidDateTest() - { - } - - bool - passes() const - { - struct tm tm, ftm; - memset(&tm, 0, sizeof(struct tm)); - mktime(&tm); - const char * at = applyTo(); - const char * f = format(); - const char * s = strptime(at, f, &tm); - if (!s || *s) { - Logger()->messagef(warnLev, "%s: check failed (parse) for '%s' against '%s'", - __PRETTY_FUNCTION__, at, f); - return false; - } - ftm = tm; - if (mktime(&ftm) == -1) { - Logger()->messagef(warnLev, "%s: check failed (normalise) for '%s' against '%s'", - __PRETTY_FUNCTION__, at, f); - return false; - } - if (tm.tm_year != ftm.tm_year || - tm.tm_mon != ftm.tm_mon || - tm.tm_mday != ftm.tm_mday || - tm.tm_hour != (ftm.tm_hour - ftm.tm_isdst) || - tm.tm_min != ftm.tm_min || - tm.tm_sec != ftm.tm_sec) { - Logger()->messagef(LOG_INFO, "tm: %d %d %d %d %d %d", - tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - Logger()->messagef(LOG_INFO, "ftm: %d %d %d %d %d %d", - ftm.tm_year, ftm.tm_mon, ftm.tm_mday, ftm.tm_hour, ftm.tm_min, ftm.tm_sec); - Logger()->messagef(warnLev, "%s: check failed (verify) for '%s' against '%s'", - __PRETTY_FUNCTION__, at, f); - return false; - } - return true; - } - Variable applyTo; - Variable format; - int warnLev; -}; - -DECLARE_LOADER("validdatetest", ValidDateTest); - -- cgit v1.2.3