diff options
Diffstat (limited to 'project2/basics')
52 files changed, 315 insertions, 165 deletions
diff --git a/project2/basics/Jamfile.jam b/project2/basics/Jamfile.jam index 19726d9..3a53d54 100644 --- a/project2/basics/Jamfile.jam +++ b/project2/basics/Jamfile.jam @@ -2,25 +2,24 @@ alias glibmm : : : : <cflags>"`pkg-config --cflags glibmm-2.4`" <linkflags>"`pkg-config --libs glibmm-2.4`" ; -lib boost_filesystem : : <name>boost_filesystem ; +lib stdc++fs ; lib dl ; build-project unittests ; cpp-pch pch : pch.hpp : - <include>../../libmisc - <library>glibmm + <library>glibmm <library>../common//p2common ; lib p2basics : + pch [ glob-tree *.cpp : unittests ] : <include>. - <include>../../libmisc <library>glibmm <library>dl - <library>boost_filesystem + <library>stdc++fs <library>../common//p2common : : <include>. diff --git a/project2/basics/aggregates/avg.cpp b/project2/basics/aggregates/avg.cpp index 900bc5f..0547120 100644 --- a/project2/basics/aggregates/avg.cpp +++ b/project2/basics/aggregates/avg.cpp @@ -26,5 +26,5 @@ class Average : public ValueAggregate { mutable std::list<double> vals; }; -DECLARE_LOADER("average", Average); +NAMEDFACTORY("average", Average, ValueAggregateFactory); diff --git a/project2/basics/aggregates/count.cpp b/project2/basics/aggregates/count.cpp index be22783..3d47b34 100644 --- a/project2/basics/aggregates/count.cpp +++ b/project2/basics/aggregates/count.cpp @@ -25,6 +25,5 @@ class Count : public ValueAggregate { mutable int c; }; -DECLARE_LOADER("count", Count); - +NAMEDFACTORY("count", Count, ValueAggregateFactory); diff --git a/project2/basics/aggregates/countDistinct.cpp b/project2/basics/aggregates/countDistinct.cpp index 205b932..9acba4c 100644 --- a/project2/basics/aggregates/countDistinct.cpp +++ b/project2/basics/aggregates/countDistinct.cpp @@ -22,5 +22,5 @@ class CountDistinct : public ValueAggregate { mutable std::set<VariableType> result; }; -DECLARE_LOADER("countdistinct", CountDistinct); +NAMEDFACTORY("countdistinct", CountDistinct, ValueAggregateFactory); diff --git a/project2/basics/aggregates/distinct.cpp b/project2/basics/aggregates/distinct.cpp index 33d71b0..c7f5fe0 100644 --- a/project2/basics/aggregates/distinct.cpp +++ b/project2/basics/aggregates/distinct.cpp @@ -24,4 +24,5 @@ class Distinct : public SetAggregate { mutable std::set<VariableType> result; }; -DECLARE_LOADER("distinct", Distinct); +NAMEDFACTORY("distinct", Distinct, SetAggregateFactory); + diff --git a/project2/basics/aggregates/join.cpp b/project2/basics/aggregates/join.cpp index 405c093..695626f 100644 --- a/project2/basics/aggregates/join.cpp +++ b/project2/basics/aggregates/join.cpp @@ -31,5 +31,5 @@ class Join : public ValueAggregate { Variable sep; }; -DECLARE_LOADER("join", Join); +NAMEDFACTORY("join", Join, ValueAggregateFactory); diff --git a/project2/basics/aggregates/max.cpp b/project2/basics/aggregates/max.cpp index 6304647..a193ed4 100644 --- a/project2/basics/aggregates/max.cpp +++ b/project2/basics/aggregates/max.cpp @@ -22,6 +22,5 @@ class Max : public ValueAggregate { mutable VariableType result; }; -DECLARE_LOADER("max", Max); - +NAMEDFACTORY("max", Max, ValueAggregateFactory); diff --git a/project2/basics/aggregates/min.cpp b/project2/basics/aggregates/min.cpp index 75b0b87..f5e442c 100644 --- a/project2/basics/aggregates/min.cpp +++ b/project2/basics/aggregates/min.cpp @@ -28,5 +28,5 @@ class Min : public ValueAggregate { mutable bool first; }; -DECLARE_LOADER("min", Min); +NAMEDFACTORY("min", Min, ValueAggregateFactory); diff --git a/project2/basics/aggregates/sum.cpp b/project2/basics/aggregates/sum.cpp index 68a9cd4..bdbf229 100644 --- a/project2/basics/aggregates/sum.cpp +++ b/project2/basics/aggregates/sum.cpp @@ -23,5 +23,5 @@ class Sum : public ValueAggregate { mutable double sum; }; -DECLARE_LOADER("sum", Sum); +NAMEDFACTORY("sum", Sum, ValueAggregateFactory); diff --git a/project2/basics/caches/memoryCache.cpp b/project2/basics/caches/memoryCache.cpp index 6e5aab6..04f5344 100644 --- a/project2/basics/caches/memoryCache.cpp +++ b/project2/basics/caches/memoryCache.cpp @@ -24,17 +24,18 @@ class MemoryCache : public RowSetCache { return *columns; } RowAttribute resolveAttr(const Glib::ustring & attrName) const { - return boost::bind(&safeMapLookup<AttributeDoesNotExist, AttrMap>, attrs, attrName); + return boost::bind(&AdHoc::safeMapLookup<AttributeDoesNotExist, AttrMap>, attrs, attrName); } private: friend class CachedRowSet; const Columns * columns; AttrMap attrs; }; - typedef boost::shared_ptr<MemoryCacheRow> MemoryCacheRowPtr; + typedef std::shared_ptr<MemoryCacheRow> MemoryCacheRowPtr; typedef std::list<MemoryCacheRowPtr> DataCache; CachedRowSet(const std::vector<VariableType> & k) : + SourceObject(ScriptNodePtr()), RowSet(NULL), key(k), createdAt(time(NULL)), @@ -55,14 +56,14 @@ class MemoryCache : public RowSetCache { void addNamedValue(const Glib::ustring & name, const VariableType & value) const { if (cur->fields.size() <= col) { cur->fields.resize(col + 1); - columns.insert(new Column(col, name)); + columns.insert(std::make_shared<Column>(col, name)); } cur->fields[col++] = value; } void addNewRow(const Glib::ustring&) const { col = 0; - cur = MemoryCacheRowPtr(new MemoryCacheRow(&columns)); + cur = std::make_shared<MemoryCacheRow>(&columns); } void finishRow() const { @@ -80,8 +81,8 @@ class MemoryCache : public RowSetCache { mutable MemoryCacheRowPtr cur; }; - typedef boost::intrusive_ptr<CachedRowSet> CachedRowSetPtr; - typedef boost::intrusive_ptr<const CachedRowSet> CachedRowSetCPtr; + typedef std::shared_ptr<CachedRowSet> CachedRowSetPtr; + typedef std::shared_ptr<const CachedRowSet> CachedRowSetCPtr; struct IndexByKey { }; struct IndexByTime { }; @@ -95,6 +96,7 @@ class MemoryCache : public RowSetCache { > > CacheStore; MemoryCache(ScriptNodePtr p) : + SourceObject(p), RowSetCache(p) { } @@ -113,7 +115,7 @@ class MemoryCache : public RowSetCache { } RowSetPresenterPtr openFor(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) { - return (cur = new CachedRowSet(makeKey(ec, n, f, ps))); + return (cur = std::make_shared<CachedRowSet>(makeKey(ec, n, f, ps))); } void save(ExecContext *, const Glib::ustring & , const Glib::ustring & , const IHaveParameters * ) { @@ -138,14 +140,14 @@ class MemoryCache : public RowSetCache { CachedRowSetPtr cur; - friend class CustomMemoryCacheLoader; + friend class CustomMemoryCacheFactory; static time_t CacheLife; static CacheStore Store; }; time_t MemoryCache::CacheLife; MemoryCache::CacheStore MemoryCache::Store; -class CustomMemoryCacheLoader : public ElementLoader::For<MemoryCache> { +class CustomMemoryCacheFactory : public RowSetCacheFactory::For<MemoryCache>, public LifeCycle { public: void onPeriodic() override { typedef MemoryCache::CacheStore::index<MemoryCache::IndexByTime>::type::iterator iter; @@ -156,10 +158,10 @@ class CustomMemoryCacheLoader : public ElementLoader::For<MemoryCache> { INITOPTIONS; }; -DECLARE_CUSTOM_LOADER("memorycache", CustomMemoryCacheLoader); +NAMEDPLUGIN("memorycache", CustomMemoryCacheFactory, RowSetCacheFactory); -DECLARE_OPTIONS(CustomMemoryCacheLoader, "Memory Cache options") +DECLARE_OPTIONS(CustomMemoryCacheFactory, "Memory Cache options") ("cache.memory.life", Options::value(&MemoryCache::CacheLife, 3600), "The age of cache entries after which they are removed (seconds)") -END_OPTIONS(CustomMemoryCacheLoader); +END_OPTIONS(CustomMemoryCacheFactory); diff --git a/project2/basics/functions/dates.cpp b/project2/basics/functions/dates.cpp index b19b921..90708d3 100644 --- a/project2/basics/functions/dates.cpp +++ b/project2/basics/functions/dates.cpp @@ -18,14 +18,14 @@ class ParseDate : public VariableImpl { } VariableType value(ExecContext * ec) const { - const char * s = string(ec); - const char * f = format(ec); + const std::string s = string(ec); + const std::string f = format(ec); struct tm tm; memset(&tm, 0, sizeof(struct tm)); mktime(&tm); - const char * e = strptime(s, f, &tm); + const char * e = strptime(s.c_str(), f.c_str(), &tm); if (!e || *e) { - Logger()->messagef(LOG_ERR, "%s: check failed (parse) for '%s' against '%s' (remaining chars='%s')", + Logger()->messagebf(LOG_ERR, "%s: check failed (parse) for '%s' against '%s' (remaining chars='%s')", __PRETTY_FUNCTION__, s, f, e); throw DateParseError(string(ec), format(ec)); } @@ -35,7 +35,7 @@ class ParseDate : public VariableImpl { Variable string; Variable format; }; -DECLARE_COMPONENT_LOADER("parsedate", ParseDate, VariableLoader); +NAMEDFACTORY("parsedate", ParseDate, VariableFactory); class FormatDate : public VariableImpl { public: @@ -49,7 +49,7 @@ class FormatDate : public VariableImpl { std::stringstream ss; boost::date_time::time_facet<boost::posix_time::ptime, char> * ft = new boost::date_time::time_facet<boost::posix_time::ptime, char>(); ss.imbue(std::locale(ss.getloc(), ft)); - ft->format(format(ec)); + ft->format(format(ec).as<std::string>().c_str()); ss << boost::get<boost::posix_time::ptime>(date(ec)); return ss.str(); } @@ -57,7 +57,7 @@ class FormatDate : public VariableImpl { Variable date; Variable format; }; -DECLARE_COMPONENT_LOADER("formatdate", FormatDate, VariableLoader); +NAMEDFACTORY("formatdate", FormatDate, VariableFactory); class AdjustDate : public VariableImpl { public: @@ -74,7 +74,7 @@ class AdjustDate : public VariableImpl { Variable date; Variable offset; }; -DECLARE_COMPONENT_LOADER("adjustdate", AdjustDate, VariableLoader); +NAMEDFACTORY("adjustdate", AdjustDate, VariableFactory); class CurrentDate : public VariableImpl { public: @@ -86,5 +86,5 @@ class CurrentDate : public VariableImpl { return boost::posix_time::microsec_clock::universal_time(); } }; -DECLARE_COMPONENT_LOADER("currentdate", CurrentDate, VariableLoader); +NAMEDFACTORY("currentdate", CurrentDate, VariableFactory); diff --git a/project2/basics/functions/strings.cpp b/project2/basics/functions/strings.cpp index 735a781..640cfb3 100644 --- a/project2/basics/functions/strings.cpp +++ b/project2/basics/functions/strings.cpp @@ -23,6 +23,6 @@ class Trim : public VariableImpl { private: Variable string; }; -DECLARE_COMPONENT_LOADER("trim", Trim, VariableLoader); +NAMEDFACTORY("trim", Trim, VariableFactory); diff --git a/project2/basics/if.cpp b/project2/basics/if.cpp new file mode 100644 index 0000000..4500335 --- /dev/null +++ b/project2/basics/if.cpp @@ -0,0 +1,51 @@ +#include <pch.hpp> +#include "if.h" +#include "logger.h" +#include "scriptLoader.h" +#include <boost/bind.hpp> +#include <algorithm> +#include <task.h> + +NAMEDFACTORY("if", If, ViewFactory); +NAMEDFACTORY("if", If, TaskFactory); +StaticMessageException(NoTestsToPerform, "No tests to perform"); + +If::If(ScriptNodePtr e) : + SourceObject(e), + IHaveSubTasks(e), + View(e) +{ + e->script.lock()->loader.addLoadTarget(e, Storer::into<TaskFactory>(&normal)); + e->script.lock()->loader.addLoadTarget(e, Storer::into<ViewFactory>(&subViews)); + e->script.lock()->loader.addLoadTarget(e, Storer::into<TestFactory>(&test)); +} + +bool +If::passes(ExecContext * ec) const +{ + if (!test) { + throw NoTestsToPerform(); + } + return test->passes(ec); +} + +void +If::execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const +{ + if (passes(ec)) { + Logger()->messagef(LOG_DEBUG, "Test passed; showing %zu views", subViews.size()); + for (const SubViews::value_type & sq : subViews) { + sq->execute(presenter, ec); + } + } +} + +void +If::execute(ExecContext * ec) const +{ + if (passes(ec)) { + Logger()->messagef(LOG_DEBUG, "Test passed; executing %zu tasks", normal.size()); + run(normal, ec); + } +} + diff --git a/project2/basics/if.h b/project2/basics/if.h new file mode 100644 index 0000000..a626bcc --- /dev/null +++ b/project2/basics/if.h @@ -0,0 +1,25 @@ +#ifndef IF_H +#define IF_H + +#include "iHaveSubTasks.h" +#include "view.h" +#include "test.h" + +/// Project2 component to conditionally execute its children +class DLL_PUBLIC If : public IHaveSubTasks, public View { + public: + If(ScriptNodePtr); + + virtual void execute(const MultiRowSetPresenter *, ExecContext *) const; + virtual void execute(ExecContext *) const; + + private: + bool passes(ExecContext *) const; + + typedef ANONSTORAGEOF(View) SubViews; + SubViews subViews; + TestPtr test; +}; + +#endif + diff --git a/project2/basics/loggers/consoleLog.cpp b/project2/basics/loggers/consoleLog.cpp index de45245..a88e6b2 100644 --- a/project2/basics/loggers/consoleLog.cpp +++ b/project2/basics/loggers/consoleLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes to the console class ConsoleLogDriver : public LogDriverBase { @@ -25,5 +25,5 @@ END_OPTIONS(ConsoleLogDriver); int ConsoleLogDriver::level; -DECLARE_LOGGER_LOADER("console", ConsoleLogDriver); +DECLARE_LOGGER("console", ConsoleLogDriver); diff --git a/project2/basics/loggers/syslogLog.cpp b/project2/basics/loggers/syslogLog.cpp index 8e58326..cb026c6 100644 --- a/project2/basics/loggers/syslogLog.cpp +++ b/project2/basics/loggers/syslogLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes to syslog class SyslogLogDriver : public LogDriverBase { @@ -35,5 +35,5 @@ END_OPTIONS(SyslogLogDriver); int SyslogLogDriver::level; std::string SyslogLogDriver::ident; -DECLARE_LOGGER_LOADER("syslog", SyslogLogDriver); +DECLARE_LOGGER("syslog", SyslogLogDriver); diff --git a/project2/basics/options/flagSet.h b/project2/basics/options/flagSet.h index 0e7830f..e956e8a 100644 --- a/project2/basics/options/flagSet.h +++ b/project2/basics/options/flagSet.h @@ -2,8 +2,9 @@ #define OPTIONS_FLAGSET_H #include <options.h> +#include <visibility.h> -class OptionFlagSet : public Options::Target { +class DLL_PUBLIC OptionFlagSet : public Options::Target { public: OptionFlagSet(bool * target); diff --git a/project2/basics/options/preload.cpp b/project2/basics/options/preload.cpp index 5cf42e8..1968023 100644 --- a/project2/basics/options/preload.cpp +++ b/project2/basics/options/preload.cpp @@ -2,12 +2,12 @@ #include <options.h> #include <library.h> #include <appInstance.h> -#include <boost/filesystem/path.hpp> +#include <filesystem> #include <map> #include <dlfcn.h> #include <logger.h> -using namespace boost::filesystem; +using namespace std::filesystem; class Preload { public: @@ -19,23 +19,24 @@ class Preload { static void LoadLibrary(const VariableType & librarypath) { - const auto beforeOpts = InstanceSet<Options>::GetAll(); + const auto beforeOpts = AdHoc::PluginManager::getDefault()->getAll<Options>(); - void * handle = dlopen(librarypath, RTLD_GLOBAL | RTLD_NOW); + std::string path(librarypath.as<std::string>()); + void * handle = dlopen(path.c_str(), RTLD_GLOBAL | RTLD_NOW); if (handle) { - Logger()->messagebf(LOG_DEBUG, "Loaded library '%s'", librarypath.as<std::string>()); + Logger()->messagebf(LOG_DEBUG, "Loaded library '%s'", path); } else { const char * dlerr = dlerror(); - Logger()->messagebf(LOG_ERR, "Failed to load library '%s' (%s)", librarypath.as<std::string>(), dlerr); + Logger()->messagebf(LOG_ERR, "Failed to load library '%s' (%s)", path, dlerr); throw LoadLibraryFailed(librarypath, dlerr); } libs[librarypath.as<std::string>()] = boost::shared_ptr<void>(handle, &dlclose); - const auto afterOpts = InstanceSet<Options>::GetAll(); + const auto afterOpts = AdHoc::PluginManager::getDefault()->getAll<Options>(); for (const auto & opt : afterOpts) { if (std::find(beforeOpts.begin(), beforeOpts.end(), opt) == beforeOpts.end()) { - opt->reset(); + opt->implementation()->reset(); } } } diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index 86dbc6f..0b32043 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -8,11 +8,13 @@ void ShowHelpComponent::onConfigLoad() if (!showHelp) return; fprintf(stdout, "Help\n"); - InstanceSet<Options>::OnAll(boost::bind(&ShowHelpComponent::outputOptions, this, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) { + outputOptions(opts->implementation()); + } exit(1); } -void ShowHelpComponent::outputOptions(const Options * options) const +void ShowHelpComponent::outputOptions(std::shared_ptr<const Options> options) const { fprintf(stdout, " * %s\n", options->name.c_str()); for (const auto & option : options->allOptions()) { @@ -23,9 +25,9 @@ void ShowHelpComponent::outputOptions(const Options * options) const Options::TargetPtr ShowHelpComponent::Option() { - return new OptionFlagSet(&showHelp); + return std::make_shared<OptionFlagSet>(&showHelp); } bool ShowHelpComponent::showHelp; -DECLARE_COMPONENT("ShowHelpComponent", ShowHelpComponent); +NAMEDPLUGIN("ShowHelpComponent", ShowHelpComponent, LifeCycle); diff --git a/project2/basics/options/showHelp.h b/project2/basics/options/showHelp.h index 75fb4cb..a0878fe 100644 --- a/project2/basics/options/showHelp.h +++ b/project2/basics/options/showHelp.h @@ -1,16 +1,17 @@ #ifndef SHOWHELP_H #define SHOWHELP_H -#include <componentLoader.h> #include <options.h> +#include <lifeCycle.h> +#include <visibility.h> -class ShowHelpComponent : public ComponentLoader { +class DLL_PUBLIC ShowHelpComponent : public LifeCycle { public: void onConfigLoad() override; static Options::TargetPtr Option(); private: - void outputOptions(const Options * options) const; + void outputOptions(std::shared_ptr<const Options> options) const; static bool showHelp; }; diff --git a/project2/basics/pch.hpp b/project2/basics/pch.hpp index 67ec9b4..2bbfaf4 100644 --- a/project2/basics/pch.hpp +++ b/project2/basics/pch.hpp @@ -2,25 +2,14 @@ #ifndef COMMON_PCH #define COMMON_PCH -#include <aggregate.h> #include <algorithm> #include <boost/algorithm/string/predicate.hpp> #include <boost/bind.hpp> #include <boost/date_time.hpp> -#include <boost/filesystem/operations.hpp> -#include <commonObjects.h> -#include <iHaveParameters.h> #include <iostream> #include <list> -#include <logger.h> -#include <rowProcessor.h> -#include <rowSet.h> -#include <safeMapFind.h> -#include <scriptLoader.h> -#include <scripts.h> -#include <scriptStorage.h> -#include <test.h> -#include <variables.h> +#include <boost/variant/variant_fwd.hpp> +#include <boost/function/function_fwd.hpp> #endif #endif diff --git a/project2/basics/tasks/iterate.cpp b/project2/basics/tasks/iterate.cpp new file mode 100644 index 0000000..6ab1260 --- /dev/null +++ b/project2/basics/tasks/iterate.cpp @@ -0,0 +1,40 @@ +#include <pch.hpp> +#include "iterate.h" +#include "logger.h" +#include <boost/bind.hpp> +#include "scriptLoader.h" + +NAMEDFACTORY("iterate", Iterate, TaskFactory); + +Iterate::Iterate(ScriptNodePtr p) : + SourceObject(p), + IHaveSubTasks(p), + RowProcessor(p) +{ + p->script.lock()->loader.addLoadTarget(p, Storer::into<TaskFactory>(&normal)); +} + +Iterate::~Iterate() +{ +} + +void +Iterate::loadComplete(const CommonObjects * co) +{ + RowProcessor::loadComplete(co); +} + +void +Iterate::execute(ExecContext * ec) const +{ + RowProcessor::execute(ec, boost::bind(&Iterate::executeChildren, this, ec)); +} + +void +Iterate::executeChildren(ExecContext * ec) const +{ + for (const Tasks::value_type & sq : normal) { + sq->execute(ec); + } +} + diff --git a/project2/basics/tasks/iterate.h b/project2/basics/tasks/iterate.h new file mode 100644 index 0000000..ca3a7ba --- /dev/null +++ b/project2/basics/tasks/iterate.h @@ -0,0 +1,26 @@ +#ifndef ITERATE_H +#define ITERATE_H + +#include "rowProcessor.h" +#include "iHaveSubTasks.h" +#include "scriptStorage.h" + +class Iterate; +typedef std::shared_ptr<Iterate> IteratePtr; + +/// Project2 component to iterate over a row set, executing its children for each record +class DLL_PUBLIC Iterate : public IHaveSubTasks, public RowProcessor { + public: + Iterate(ScriptNodePtr p); + virtual ~Iterate(); + + void loadComplete(const CommonObjects *); + void execute(ExecContext *) const; + + protected: + void executeChildren(ExecContext *) const; +}; + +#endif + + diff --git a/project2/basics/tasks/session/sessionClearTask.cpp b/project2/basics/tasks/session/sessionClearTask.cpp index 8a21791..2b016be 100644 --- a/project2/basics/tasks/session/sessionClearTask.cpp +++ b/project2/basics/tasks/session/sessionClearTask.cpp @@ -4,7 +4,7 @@ #include "session.h" #include "execContext.h" -DECLARE_LOADER("sessionclear", SessionClearTask); +NAMEDFACTORY("sessionclear", SessionClearTask, TaskFactory); SessionClearTask::SessionClearTask(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/tasks/session/sessionClearTask.h b/project2/basics/tasks/session/sessionClearTask.h index ead88bf..d5103a5 100644 --- a/project2/basics/tasks/session/sessionClearTask.h +++ b/project2/basics/tasks/session/sessionClearTask.h @@ -10,7 +10,7 @@ class CommonObjects; /// Project2 component to remove a variable from the session -class SessionClearTask : public Task { +class DLL_PUBLIC SessionClearTask : public Task { public: SessionClearTask(ScriptNodePtr p); virtual ~SessionClearTask(); diff --git a/project2/basics/tasks/session/sessionSetTask.cpp b/project2/basics/tasks/session/sessionSetTask.cpp index 120dd06..f009e46 100644 --- a/project2/basics/tasks/session/sessionSetTask.cpp +++ b/project2/basics/tasks/session/sessionSetTask.cpp @@ -4,7 +4,7 @@ #include "session.h" #include "execContext.h" -DECLARE_LOADER("sessionset", SessionSetTask); +NAMEDFACTORY("sessionset", SessionSetTask, TaskFactory); SessionSetTask::SessionSetTask(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/tasks/session/sessionSetTask.h b/project2/basics/tasks/session/sessionSetTask.h index d38c216..51222c0 100644 --- a/project2/basics/tasks/session/sessionSetTask.h +++ b/project2/basics/tasks/session/sessionSetTask.h @@ -11,7 +11,7 @@ class CommonObjects; /// Project2 component to add/update a variable in the session -class SessionSetTask : public Task { +class DLL_PUBLIC SessionSetTask : public Task { public: SessionSetTask(ScriptNodePtr p); virtual ~SessionSetTask(); diff --git a/project2/basics/tasks/structExceptHandling.cpp b/project2/basics/tasks/structExceptHandling.cpp index b79dae6..b77a4a8 100644 --- a/project2/basics/tasks/structExceptHandling.cpp +++ b/project2/basics/tasks/structExceptHandling.cpp @@ -3,16 +3,17 @@ #include "scriptLoader.h" #include "scriptStorage.h" #include "scripts.h" +#include <task.h> -DECLARE_LOADER("handler", StructuredExceptionHandler); +NAMEDFACTORY("handler", StructuredExceptionHandler, TaskFactory); StructuredExceptionHandler::StructuredExceptionHandler(ScriptNodePtr e) : SourceObject(e), IHaveSubTasks(e) { - e->script->loader.addLoadTargetSub(e, "try", true, Storer::into<ElementLoader>(&normal)); - e->script->loader.addLoadTargetSub(e, "catch", false, Storer::into<ElementLoader>(&catches)); - e->script->loader.addLoadTargetSub(e, "finally", false, Storer::into<ElementLoader>(&finallies)); + e->script.lock()->loader.addLoadTargetSub(e, "try", true, Storer::into<TaskFactory>(&normal)); + e->script.lock()->loader.addLoadTargetSub(e, "catch", false, Storer::into<TaskFactory>(&catches)); + e->script.lock()->loader.addLoadTargetSub(e, "finally", false, Storer::into<TaskFactory>(&finallies)); } void diff --git a/project2/basics/tasks/structExceptHandling.h b/project2/basics/tasks/structExceptHandling.h index b6702f1..e6f0398 100644 --- a/project2/basics/tasks/structExceptHandling.h +++ b/project2/basics/tasks/structExceptHandling.h @@ -3,7 +3,7 @@ #include "iHaveSubTasks.h" -class StructuredExceptionHandler : public IHaveSubTasks { +class DLL_PUBLIC StructuredExceptionHandler : public IHaveSubTasks { public: StructuredExceptionHandler(ScriptNodePtr); diff --git a/project2/basics/tests/compoundTest.cpp b/project2/basics/tests/compoundTest.cpp index 3799d06..2b9d1d7 100644 --- a/project2/basics/tests/compoundTest.cpp +++ b/project2/basics/tests/compoundTest.cpp @@ -10,7 +10,7 @@ CompoundTest::CompoundTest(ScriptNodePtr s) : SourceObject(s), Test(s) { - s->script->loader.addLoadTarget(s, Storer::into<ElementLoader>(&tests)); + s->script.lock()->loader.addLoadTarget(s, Storer::into<TestFactory>(&tests)); } class All : public CompoundTest { @@ -26,7 +26,7 @@ class All : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), !boost::bind(&Test::passes, _1, ec)) == tests.end()); } }; -DECLARE_LOADER("all", All); +NAMEDFACTORY("all", All, TestFactory); class Any : public CompoundTest { public: @@ -41,7 +41,7 @@ class Any : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1, ec)) != tests.end()); } }; -DECLARE_LOADER("any", Any); +NAMEDFACTORY("any", Any, TestFactory); class None : public CompoundTest { public: @@ -56,7 +56,7 @@ class None : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1, ec)) == tests.end()); } }; -DECLARE_LOADER("none", None); +NAMEDFACTORY("none", None, TestFactory); class Not : public Test { public: @@ -64,7 +64,7 @@ class Not : public Test { SourceObject(s), Test(s) { - s->script->loader.addLoadTarget(s, Storer::into<ElementLoader>(&test)); + s->script.lock()->loader.addLoadTarget(s, Storer::into<TestFactory>(&test)); } bool passes(ExecContext * ec) const { if (!test) { @@ -75,4 +75,4 @@ class Not : public Test { private: TestPtr test; }; -DECLARE_LOADER("not", Not); +NAMEDFACTORY("not", Not, TestFactory); diff --git a/project2/basics/tests/compoundTest.h b/project2/basics/tests/compoundTest.h index cc213c3..182ed0e 100644 --- a/project2/basics/tests/compoundTest.h +++ b/project2/basics/tests/compoundTest.h @@ -4,7 +4,7 @@ #include <test.h> #include "scriptStorage.h" -class CompoundTest : public Test { +class DLL_PUBLIC CompoundTest : public Test { public: CompoundTest(ScriptNodePtr); diff --git a/project2/basics/tests/equals.cpp b/project2/basics/tests/equals.cpp index 425d317..3f32053 100644 --- a/project2/basics/tests/equals.cpp +++ b/project2/basics/tests/equals.cpp @@ -16,9 +16,9 @@ class Equals : public Test { bool passes(ExecContext * ec) const { return (a(ec) == b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("equals", Equals); +NAMEDFACTORY("equals", Equals, TestFactory); diff --git a/project2/basics/tests/greaterthan.cpp b/project2/basics/tests/greaterthan.cpp index b43cef1..01e5812 100644 --- a/project2/basics/tests/greaterthan.cpp +++ b/project2/basics/tests/greaterthan.cpp @@ -16,9 +16,9 @@ class GreaterThan : public Test { bool passes(ExecContext * ec) const { return (a(ec) > b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("greaterthan", GreaterThan); +NAMEDFACTORY("greaterthan", GreaterThan, TestFactory); diff --git a/project2/basics/tests/greaterthanorequal.cpp b/project2/basics/tests/greaterthanorequal.cpp index 67328b2..f5f0124 100644 --- a/project2/basics/tests/greaterthanorequal.cpp +++ b/project2/basics/tests/greaterthanorequal.cpp @@ -16,9 +16,9 @@ class GreaterThanOrEqual : public Test { bool passes(ExecContext * ec) const { return (a(ec) >= b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("greaterthanorequal", GreaterThanOrEqual); +NAMEDFACTORY("greaterthanorequal", GreaterThanOrEqual, TestFactory); diff --git a/project2/basics/tests/isdistinct.cpp b/project2/basics/tests/isdistinct.cpp index 47ed647..2c95535 100644 --- a/project2/basics/tests/isdistinct.cpp +++ b/project2/basics/tests/isdistinct.cpp @@ -37,4 +37,5 @@ class IsDistinct : public Test, IHaveParameters { typedef std::set<Vars> Rows; mutable Rows previous; }; -DECLARE_LOADER("isdistinct", IsDistinct); +NAMEDFACTORY("isdistinct", IsDistinct, TestFactory); + diff --git a/project2/basics/tests/isuniq.cpp b/project2/basics/tests/isuniq.cpp index dc71ac5..295be40 100644 --- a/project2/basics/tests/isuniq.cpp +++ b/project2/basics/tests/isuniq.cpp @@ -45,4 +45,5 @@ class IsUniq : public Test, IHaveParameters { typedef std::vector<VariableType> Vars; mutable Vars previous; }; -DECLARE_LOADER("isuniq", IsUniq); +NAMEDFACTORY("isuniq", IsUniq, TestFactory); + diff --git a/project2/basics/tests/lessthan.cpp b/project2/basics/tests/lessthan.cpp index f040532..3f172ef 100644 --- a/project2/basics/tests/lessthan.cpp +++ b/project2/basics/tests/lessthan.cpp @@ -16,9 +16,9 @@ class LessThan : public Test { bool passes(ExecContext * ec) const { return (a(ec) < b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("lessthan", LessThan); +NAMEDFACTORY("lessthan", LessThan, TestFactory); diff --git a/project2/basics/tests/lessthanorequal.cpp b/project2/basics/tests/lessthanorequal.cpp index 1cb0e9e..8a64e01 100644 --- a/project2/basics/tests/lessthanorequal.cpp +++ b/project2/basics/tests/lessthanorequal.cpp @@ -16,9 +16,9 @@ class LessThanOrEqual : public Test { bool passes(ExecContext * ec) const { return (a(ec) <= b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("lessthanorequal", LessThanOrEqual); +NAMEDFACTORY("lessthanorequal", LessThanOrEqual, TestFactory); diff --git a/project2/basics/tests/notequals.cpp b/project2/basics/tests/notequals.cpp index aeb784e..bbf3186 100644 --- a/project2/basics/tests/notequals.cpp +++ b/project2/basics/tests/notequals.cpp @@ -16,9 +16,9 @@ class NotEquals : public Test { bool passes(ExecContext * ec) const { return (a(ec) != b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("notequals", NotEquals); +NAMEDFACTORY("notequals", NotEquals, TestFactory); diff --git a/project2/basics/tests/validDateCheck.cpp b/project2/basics/tests/validDateCheck.cpp index b1ab5a3..a17933f 100644 --- a/project2/basics/tests/validDateCheck.cpp +++ b/project2/basics/tests/validDateCheck.cpp @@ -27,17 +27,17 @@ class ValidDateTest : public Test { struct tm tm, ftm; memset(&tm, 0, sizeof(struct tm)); mktime(&tm); - const char * at = applyTo(ec); - const char * f = format(ec); - const char * s = strptime(at, f, &tm); + const std::string at = applyTo(ec); + const std::string f = format(ec); + const char * s = strptime(at.c_str(), f.c_str(), &tm); if (!s || *s) { - Logger()->messagef(warnLev, "%s: check failed (parse) for '%s' against '%s'", + Logger()->messagebf(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'", + Logger()->messagebf(warnLev, "%s: check failed (normalise) for '%s' against '%s'", __PRETTY_FUNCTION__, at, f); return false; } @@ -51,7 +51,7 @@ class ValidDateTest : public Test { 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'", + Logger()->messagebf(warnLev, "%s: check failed (verify) for '%s' against '%s'", __PRETTY_FUNCTION__, at, f); return false; } @@ -62,5 +62,5 @@ class ValidDateTest : public Test { int warnLev; }; -DECLARE_LOADER("validdatetest", ValidDateTest); +NAMEDFACTORY("validdatetest", ValidDateTest, TestFactory); diff --git a/project2/basics/unittests/Jamfile.jam b/project2/basics/unittests/Jamfile.jam index 167c7c6..5892cd9 100644 --- a/project2/basics/unittests/Jamfile.jam +++ b/project2/basics/unittests/Jamfile.jam @@ -6,26 +6,30 @@ lib dummylib : <library>../../common//p2common ; -unit-test testLibraries : +path-constant me : . ; + +run testLibraries.cpp - : - <dependency>dummylib + : : dummylib : <library>../../common//p2common <library>..//p2basics <library>../../ut//p2ut - <library>..//boost_filesystem + <library>..//stdc++fs + : + testLibraries : ; -path-constant me : . ; - -unit-test standardTests : +run [ glob *.cpp : testLibraries.cpp dummylib.cpp ] - : + : : : <define>ROOT=\"$(me)\" <library>../../common//p2common <library>..//p2basics <library>../../ut//p2ut <library>../../xml//p2xml - <library>..//boost_filesystem + <library>../../url//p2url + <library>..//stdc++fs + : + standardTests : ; diff --git a/project2/basics/unittests/dummylib.cpp b/project2/basics/unittests/dummylib.cpp index 2e919a0..a493f3c 100644 --- a/project2/basics/unittests/dummylib.cpp +++ b/project2/basics/unittests/dummylib.cpp @@ -13,5 +13,5 @@ class DummyTask : public Task { } }; -DECLARE_LOADER("DummyTask", DummyTask); +NAMEDFACTORY("DummyTask", DummyTask, TaskFactory); diff --git a/project2/basics/unittests/testLibraries.cpp b/project2/basics/unittests/testLibraries.cpp index e48d77e..c43d382 100644 --- a/project2/basics/unittests/testLibraries.cpp +++ b/project2/basics/unittests/testLibraries.cpp @@ -1,12 +1,16 @@ #define BOOST_TEST_MODULE Client #include <boost/test/unit_test.hpp> -#include <boost/filesystem/convenience.hpp> +#include <filesystem> #include <testOptionsSource.h> #include <exceptions.h> #include <library.h> +#include <task.h> #include <testAppInstance.h> -const auto self = boost::filesystem::canonical("/proc/self/exe"); +#define XSTR(s) STR(s) +#define STR(s) #s +const std::filesystem::path root(XSTR(ROOT)); +const auto self = std::filesystem::canonical("/proc/self/exe"); BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); @@ -21,18 +25,23 @@ BOOST_AUTO_TEST_CASE( load_missing_library ) BOOST_AUTO_TEST_CASE( load_and_unload_library ) { - BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported); + // Path to test lib needs passing in + BOOST_REQUIRE_EQUAL(2, args.size()); + auto libraryPath = args[1]; + BOOST_REQUIRE(std::filesystem::exists(libraryPath)); + + BOOST_REQUIRE_THROW(TaskFactory::get("DummyTask"), AdHoc::NoSuchPluginException); BOOST_TEST_CHECKPOINT("Configure (load)"); TestOptionsSource::LoadTestOptions({ - { "library", (self.parent_path() / "libdummylib.so").string() } + { "library", libraryPath } }); BOOST_TEST_CHECKPOINT("Verify"); - BOOST_REQUIRE(ElementLoader::getFor("DummyTask")); + BOOST_REQUIRE(TaskFactory::get("DummyTask")); BOOST_TEST_CHECKPOINT("Configure (empty)"); TestOptionsSource::LoadTestOptions({ }); - BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported); + BOOST_REQUIRE_THROW(TaskFactory::get("DummyTask"), AdHoc::NoSuchPluginException); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/project2/basics/unittests/testViews.cpp b/project2/basics/unittests/testViews.cpp index a2ea224..1dbb30e 100644 --- a/project2/basics/unittests/testViews.cpp +++ b/project2/basics/unittests/testViews.cpp @@ -1,22 +1,22 @@ #define BOOST_TEST_MODULE Views #include <boost/test/unit_test.hpp> -#include <boost/filesystem/operations.hpp> +#include <filesystem> #include <xmlScriptParser.h> #include <testOptionsSource.h> #include <testScriptHost.h> #include <definedDirs.h> #include <testAppInstance.h> -boost::intrusive_ptr<TestScriptHost> -executeRowViewTest(ExecContext * ec, const boost::filesystem::path & script, const boost::filesystem::path & expected) +std::shared_ptr<TestScriptHost> +executeRowViewTest(ExecContext * ec, const std::filesystem::path & script, const std::filesystem::path & expected) { TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", RootDir.string() }, - { "application.dataroot", ("file://" / RootDir / "data").string() }, + { "common.datasourceRoot", rootDir.string() }, + { "application.dataroot", "file://" + (rootDir / "data").string() }, }); BOOST_TEST_CHECKPOINT("Load"); - ScriptReaderPtr r = new XmlScriptParser(script); - boost::intrusive_ptr<TestScriptHost> sr = new TestScriptHost(r); + ScriptReaderPtr r = std::make_shared<XmlScriptParser>(script); + std::shared_ptr<TestScriptHost> sr = std::make_shared<TestScriptHost>(r); BOOST_TEST_CHECKPOINT("Execute"); sr->process(ec); BOOST_TEST_CHECKPOINT("Compare"); @@ -28,17 +28,17 @@ BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); BOOST_AUTO_TEST_CASE( test_rowview_unsetcolumns ) { - executeRowViewTest(this, RootDir / "test_rowview_unsetcolumns.xml", RootDir / "expected" / "test_rowview_unsetcolumns.log"); + executeRowViewTest(this, rootDir / "test_rowview_unsetcolumns.xml", rootDir / "expected" / "test_rowview_unsetcolumns.log"); } BOOST_AUTO_TEST_CASE( test_rowview_nocolumns ) { - executeRowViewTest(this, RootDir / "test_rowview_nocolumns.xml", RootDir / "expected" / "test_rowview_nocolumns.log"); + executeRowViewTest(this, rootDir / "test_rowview_nocolumns.xml", rootDir / "expected" / "test_rowview_nocolumns.log"); } BOOST_AUTO_TEST_CASE( test_rowview_columns ) { - executeRowViewTest(this, RootDir / "test_rowview_columns.xml", RootDir / "expected" / "test_rowview_columns.log"); + executeRowViewTest(this, rootDir / "test_rowview_columns.xml", rootDir / "expected" / "test_rowview_columns.log"); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/project2/basics/views/autotree.cpp b/project2/basics/views/autotree.cpp index 2f5bb68..f96888e 100644 --- a/project2/basics/views/autotree.cpp +++ b/project2/basics/views/autotree.cpp @@ -1,12 +1,10 @@ #include <pch.hpp> #include "autotree.h" #include "presenter.h" -#include "scopeObject.h" #include "scriptLoader.h" -#include "scopeObject.h" #include <boost/bind.hpp> -DECLARE_LOADER("autotree", AutoTree); +NAMEDFACTORY("autotree", AutoTree, ViewFactory); AutoTree::AutoTree(ScriptNodePtr p) : SourceObject(p), @@ -57,7 +55,7 @@ AutoTreeNode::AutoTreeNode(ScriptNodePtr sn, unsigned int p, unsigned int d) : includes.insert({n->value("name", NULL).as<Glib::ustring>(), Variable::fromScriptNode(n)} ); } if (sn->valueExists("tree")) { - tree = new AutoTreeNode(sn->child("tree"), pos + keys.size(), depth + 1); + tree = std::make_shared<AutoTreeNode>(sn->child("tree"), pos + keys.size(), depth + 1); } } diff --git a/project2/basics/views/autotree.h b/project2/basics/views/autotree.h index 48f46be..9276bab 100644 --- a/project2/basics/views/autotree.h +++ b/project2/basics/views/autotree.h @@ -1,15 +1,14 @@ #ifndef AUTOTREE_H #define AUTOTREE_H -#include <boost/intrusive_ptr.hpp> #include "rowProcessor.h" #include "view.h" #include "aggregate.h" class AutoTreeNode; -typedef boost::intrusive_ptr<const AutoTreeNode> AutoTreeNodePtr; +typedef std::shared_ptr<const AutoTreeNode> AutoTreeNodePtr; -class AutoTreeState { +class DLL_PUBLIC AutoTreeState { public: typedef boost::tuple<bool, bool> Opened; @@ -17,7 +16,7 @@ class AutoTreeState { std::vector<VariableType> values; }; -class AutoTreeNode : public IntrusivePtrBase { +class DLL_PUBLIC AutoTreeNode { public: typedef std::map<Glib::ustring, Variable> Values; @@ -29,7 +28,7 @@ class AutoTreeNode : public IntrusivePtrBase { void closeArray(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const; void closeObject(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const; AutoTreeNodePtr child() const; - + protected: private: @@ -44,7 +43,7 @@ class AutoTreeNode : public IntrusivePtrBase { }; /// Project2 component to create tree output based on a records in a row set -class AutoTree : public View, public RowProcessor { +class DLL_PUBLIC AutoTree : public View, public RowProcessor { public: AutoTree(ScriptNodePtr); virtual ~AutoTree(); diff --git a/project2/basics/views/flatView.cpp b/project2/basics/views/flatView.cpp index af49d0d..36c0427 100644 --- a/project2/basics/views/flatView.cpp +++ b/project2/basics/views/flatView.cpp @@ -1,12 +1,12 @@ #include "pch.hpp" #include "flatView.h" #include "presenter.h" -#include "scopeObject.h" #include "scriptLoader.h" -#include "scopeObject.h" #include <boost/bind.hpp> +#include <factory.impl.h> -DECLARE_LOADER("flatview", FlatView); +NAMEDFACTORY("flatview", FlatView, FlatViewFactory); +INSTANTIATEFACTORY(FlatView, std::shared_ptr<const ScriptNode>); FlatView::FlatView(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/views/flatView.h b/project2/basics/views/flatView.h index 5dc24dc..72acabc 100644 --- a/project2/basics/views/flatView.h +++ b/project2/basics/views/flatView.h @@ -5,9 +5,10 @@ #include "rowProcessor.h" #include "view.h" #include "aggregate.h" +#include <visibility.h> /// Project2 component to create output based on a records in a flat row set -class FlatView : public SourceObject, public RowProcessor { +class DLL_PUBLIC FlatView : public SourceObject, public RowProcessor { public: FlatView(ScriptNodePtr); virtual ~FlatView(); @@ -23,6 +24,7 @@ class FlatView : public SourceObject, public RowProcessor { typedef std::map<Glib::ustring, Variable> Columns; Columns viewColumns; }; +typedef AdHoc::Factory<FlatView, std::shared_ptr<const ScriptNode>> FlatViewFactory; #endif diff --git a/project2/basics/views/rowView.cpp b/project2/basics/views/rowView.cpp index 9727480..f5e108b 100644 --- a/project2/basics/views/rowView.cpp +++ b/project2/basics/views/rowView.cpp @@ -1,12 +1,11 @@ #include <pch.hpp> #include "rowView.h" #include "presenter.h" -#include "scopeObject.h" #include "scriptLoader.h" -#include "scopeObject.h" +#include <scopeExit.h> #include <boost/bind.hpp> -DECLARE_LOADER("view", RowView); +NAMEDFACTORY("view", RowView, ViewFactory); RowView::RowView(ScriptNodePtr p) : SourceObject(p), @@ -24,9 +23,9 @@ RowView::RowView(ScriptNodePtr p) : viewColumns->insert(Columns::value_type(node->get_name(), Variable(node))); } } - p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&subViews)); - p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&valueAggregates)); - p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&setAggregates)); + p->script.lock()->loader.addLoadTarget(p, Storer::into<ViewFactory>(&subViews)); + p->script.lock()->loader.addLoadTarget(p, Storer::into<ValueAggregateFactory>(&valueAggregates)); + p->script.lock()->loader.addLoadTarget(p, Storer::into<SetAggregateFactory>(&setAggregates)); } RowView::~RowView() @@ -73,10 +72,10 @@ RowView::execute(const MultiRowSetPresenter * p, ExecContext * ec) const p->addNewRowSet(rootName(ec)); } bool rowsFound = false; - ScopeObject pres(rootName(ec).isNull() ? ScopeObject::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p)); + AdHoc::ScopeExit pres(rootName(ec).isNull() ? AdHoc::ScopeExit::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p)); { p->addNewArray(recordName(ec), true); - ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, true)); + AdHoc::ScopeExit pres(boost::bind(&MultiRowSetPresenter::finishArray, p, true)); RowProcessor::execute(ec, boost::bind(&RowView::rowReady, this, _1, p, ec, boost::ref(rowsFound))); } if (required(ec) && !rowsFound) { @@ -85,7 +84,7 @@ RowView::execute(const MultiRowSetPresenter * p, ExecContext * ec) const for (SetAggregateCPtr s : setAggregates) { p->addNewArray(s->name, false); - ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, false)); + AdHoc::ScopeExit pres(boost::bind(&MultiRowSetPresenter::finishArray, p, false)); s->onResultValues(boost::bind(&MultiRowSetPresenter::addNamedValue, p, "value", _1)); s->reset(); } diff --git a/project2/basics/views/rowView.h b/project2/basics/views/rowView.h index a65ea69..1ace513 100644 --- a/project2/basics/views/rowView.h +++ b/project2/basics/views/rowView.h @@ -8,7 +8,7 @@ #include "aggregate.h" /// Project2 component to create output based on a records in a row set -class RowView : public View, public RowProcessor { +class DLL_PUBLIC RowView : public View, public RowProcessor { public: RowView(ScriptNodePtr); virtual ~RowView(); diff --git a/project2/basics/views/singleton.cpp b/project2/basics/views/singleton.cpp index c67fb12..913776a 100644 --- a/project2/basics/views/singleton.cpp +++ b/project2/basics/views/singleton.cpp @@ -2,7 +2,7 @@ #include "view.h" #include "iHaveParameters.h" #include "presenter.h" -#include "scopeObject.h" +#include <scopeExit.h> class Singleton : public View { public: @@ -14,12 +14,12 @@ class Singleton : public View { for (ScriptNodePtr node : p->childrenIn("columns")) { viewColumns.insert(Columns::value_type(node->get_name(), Variable(node))); } - p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&subViews)); + p->script.lock()->loader.addLoadTarget(p, Storer::into<ViewFactory>(&subViews)); } void execute(const MultiRowSetPresenter * p, ExecContext * ec) const { p->addNewRowSet(rootName(ec)); - ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishRowSet, p)); + AdHoc::ScopeExit pres(boost::bind(&MultiRowSetPresenter::finishRowSet, p)); for (const Columns::value_type & col : viewColumns) { p->addNamedValue(col.first, col.second(ec)); } @@ -40,5 +40,5 @@ class Singleton : public View { typedef ANONSTORAGEOF(View) SubViews; SubViews subViews; }; -DECLARE_LOADER("singleton", Singleton); +NAMEDFACTORY("singleton", Singleton, ViewFactory); diff --git a/project2/basics/views/viewGroup.cpp b/project2/basics/views/viewGroup.cpp index 0049e9d..591babd 100644 --- a/project2/basics/views/viewGroup.cpp +++ b/project2/basics/views/viewGroup.cpp @@ -7,7 +7,7 @@ class ViewGroup : public View { SourceObject(s), View(s) { - s->script->loader.addLoadTarget(s, Storer::into<ElementLoader>(&subViews)); + s->script.lock()->loader.addLoadTarget(s, Storer::into<ViewFactory>(&subViews)); } void execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const @@ -23,4 +23,4 @@ class ViewGroup : public View { SubViews subViews; }; -DECLARE_LOADER("viewgroup", ViewGroup); +NAMEDFACTORY("viewgroup", ViewGroup, ViewFactory); |
