From d043e9e80db2140bdea05b54bdd35ad7cddb13a0 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 18 Dec 2010 02:04:56 +0000 Subject: Do some renaming and reorganising at last --- project2/Jamfile.jam | 5 +-- project2/cgi/cgiAppEngine.h | 2 +- project2/commonObjects.cpp | 2 +- project2/commonObjects.h | 4 +-- project2/dumpTask.cpp | 6 ++-- project2/fileRows.cpp | 5 +-- project2/fileRows.h | 4 +-- project2/iterate.cpp | 12 +++---- project2/iterate.h | 2 +- project2/perRowValues.cpp | 85 --------------------------------------------- project2/perRowValues.h | 71 ------------------------------------- project2/presenter.cpp | 53 ---------------------------- project2/presenter.h | 24 ------------- project2/rowProcessor.cpp | 23 ++++++++++++ project2/rowProcessor.h | 23 ++++++++++++ project2/rowSet.cpp | 60 ++++++++++++++++++++++++++++++++ project2/rowSet.h | 51 +++++++++++++++++++++++++++ project2/rowUser.cpp | 10 ++++++ project2/rowUser.h | 13 +++++++ project2/rowView.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++ project2/rowView.h | 32 +++++++++++++++++ project2/sendmailTask.cpp | 3 +- project2/sqlMergeTask.cpp | 4 +-- project2/sqlMergeTask.h | 61 -------------------------------- project2/sqlRows.cpp | 3 +- project2/sqlRows.h | 4 +-- project2/urlRows.cpp | 5 +-- project2/urlRows.h | 4 +-- project2/variables.cpp | 24 ++++++------- project2/view.cpp | 83 ------------------------------------------- project2/view.h | 24 ------------- project2/xmlPresenter.cpp | 55 +++++++++++++++++++++++++++++ project2/xmlPresenter.h | 31 +++++++++++++++++ project2/xmlRows.cpp | 3 +- project2/xmlRows.h | 4 +-- 35 files changed, 432 insertions(+), 447 deletions(-) delete mode 100644 project2/perRowValues.cpp delete mode 100644 project2/perRowValues.h create mode 100644 project2/rowProcessor.cpp create mode 100644 project2/rowProcessor.h create mode 100644 project2/rowSet.cpp create mode 100644 project2/rowSet.h create mode 100644 project2/rowUser.cpp create mode 100644 project2/rowUser.h create mode 100644 project2/rowView.cpp create mode 100644 project2/rowView.h create mode 100644 project2/xmlPresenter.cpp create mode 100644 project2/xmlPresenter.h diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 7040562..011c5dd 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -18,9 +18,10 @@ lib curl : : curl ; lib p2common : appEngine.cpp dataSource.cpp environment.cpp fileStarGlibIoChannel.cpp iHaveParameters.cpp - iterate.cpp paramChecker.cpp perRowValues.cpp presenter.cpp rawView.cpp dumpTask.cpp + iterate.cpp paramChecker.cpp presenter.cpp rawView.cpp dumpTask.cpp sourceObject.cpp task.cpp variables.cpp view.cpp xmlObjectLoader.cpp exceptions.cpp - sessionClearTask.cpp session.cpp sessionSetTask.cpp commonObjects.cpp + sessionClearTask.cpp session.cpp sessionSetTask.cpp commonObjects.cpp xmlPresenter.cpp + rowView.cpp rowSet.cpp rowUser.cpp rowProcessor.cpp : ../libmisc//misc libxmlpp diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index db4d696..7998648 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -4,7 +4,7 @@ #include "../appEngine.h" #include "../task.h" #include "../paramChecker.h" -#include "../presenter.h" +#include "../xmlPresenter.h" #include "../commonObjects.h" #include #include diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp index f39eb60..90c8bdc 100644 --- a/project2/commonObjects.cpp +++ b/project2/commonObjects.cpp @@ -1,6 +1,6 @@ #include "commonObjects.h" -PerRowValuesPtr +RowSetPtr CommonObjects::getSource(const std::string & name) const { RowSets::const_iterator i = rowSets.find(name); diff --git a/project2/commonObjects.h b/project2/commonObjects.h index 32e201c..dc522ba 100644 --- a/project2/commonObjects.h +++ b/project2/commonObjects.h @@ -2,14 +2,14 @@ #define COMMONOBJECTS_H #include "dataSource.h" -#include "perRowValues.h" +#include "rowSet.h" class CommonObjects : public virtual IntrusivePtrBase { public: class DataSourceNotFound : public std::exception { }; class DataSourceNotCompatible : public std::exception { }; - PerRowValuesPtr getSource(const std::string &) const; + RowSetPtr getSource(const std::string &) const; template const DataSourceType * dataSource(const std::string & name) const { diff --git a/project2/dumpTask.cpp b/project2/dumpTask.cpp index cc13f0b..0d485f8 100644 --- a/project2/dumpTask.cpp +++ b/project2/dumpTask.cpp @@ -1,5 +1,5 @@ #include "dumpTask.h" -#include "perRowValues.h" +#include "rowSet.h" #include "xmlObjectLoader.h" #include #include @@ -24,7 +24,7 @@ DumpTask::loadComplete(const CommonObjects *) void DumpTask::execute() const { - const PerRowValues::RowValuesStack::value_type & r = PerRowValues::Stack().back(); + const RowSet::RowValuesStack::value_type & r = RowSet::Stack().back(); unsigned int cols = r->columnCount(); for (unsigned int c = 0; c < cols; c += 1) { if (c > 0) { @@ -33,7 +33,7 @@ DumpTask::execute() const try { fprintf(stderr, "%s = '%s'", r->getColumnName(c).c_str(), r->getCurrentValue(c).c_str()); } - catch (const PerRowValues::FieldDoesNotExist &) { + catch (const RowSet::FieldDoesNotExist &) { fprintf(stderr, "%s = null", r->getColumnName(c).c_str()); } } diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index f9bdebf..c42d6cf 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -1,4 +1,5 @@ #include "fileRows.h" +#include "rowProcessor.h" #include "xmlObjectLoader.h" #include "exceptions.h" @@ -6,7 +7,7 @@ ElementLoaderImpl filerowsLoader("filerows"); FileRows::FileRows(const xmlpp::Element * p) : SourceObject(p), - PerRowValues(p), + RowSet(p), path(p->get_attribute_value("path")), fieldSep(p->get_attribute_value("fieldSep")[0]), quoteChar(p->get_attribute_value("quoteChar")[0]), @@ -139,7 +140,7 @@ FileRows::getCurrentValue(const Glib::ustring & id) const return **v; } } - throw PerRowValues::FieldDoesNotExist(); + throw RowSet::FieldDoesNotExist(); } void diff --git a/project2/fileRows.h b/project2/fileRows.h index ec937ad..6f06d59 100644 --- a/project2/fileRows.h +++ b/project2/fileRows.h @@ -6,12 +6,12 @@ #include #include #include "variables.h" -#include "perRowValues.h" +#include "rowSet.h" #include "fileStarGlibIoChannel.h" class CommonObjects; -class FileRows : public PerRowValues { +class FileRows : public RowSet { public: FileRows(const xmlpp::Element * p); ~FileRows(); diff --git a/project2/iterate.cpp b/project2/iterate.cpp index 91d5c75..9e5c7f7 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -35,13 +35,13 @@ Iterate::rowReady() const void Iterate::execute() const { - PerRowValues::beginRow(source.get()); + RowSet::beginRow(source.get()); try { source->execute(this); - PerRowValues::endRow(source.get()); + RowSet::endRow(source.get()); } catch (...) { - PerRowValues::endRow(source.get()); + RowSet::endRow(source.get()); throw; } } @@ -54,13 +54,13 @@ Iterate::executeChildren() const sq.second->execute(); } else { - PerRowValues::beginRow(NULL); + RowSet::beginRow(NULL); try { sq.second->execute(); - PerRowValues::endRow(NULL); + RowSet::endRow(NULL); } catch (...) { - PerRowValues::endRow(NULL); + RowSet::endRow(NULL); throw; } } diff --git a/project2/iterate.h b/project2/iterate.h index a95aeaf..58b4944 100644 --- a/project2/iterate.h +++ b/project2/iterate.h @@ -6,7 +6,7 @@ #include #include "sourceObject.h" #include "xmlObjectLoader.h" -#include "perRowValues.h" +#include "rowProcessor.h" #include "noOutputExecute.h" class Iterate; diff --git a/project2/perRowValues.cpp b/project2/perRowValues.cpp deleted file mode 100644 index d4aa945..0000000 --- a/project2/perRowValues.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "perRowValues.h" -#include "commonObjects.h" -#include -#include -#include - -PerRowValues::RowValuesStack PerRowValues::stack; - -PerRowValues::PerRowValues(const xmlpp::Element * p) : - SourceObject(p), - rowNum(-1) -{ -} - -PerRowValues::~PerRowValues() -{ -} - -void -PerRowValues::use(const RowUser * r) const -{ - rowUsers.insert(r); -} - -void -PerRowValues::finish(const RowUser * r) const -{ - rowUsers.erase(r); -} - -void -PerRowValues::beginRow(const PerRowValues * r) -{ - stack.push_back(r); -} - -void -PerRowValues::endRow(const PerRowValues * r) -{ - if (stack.back() != r) { - syslog(LOG_ERR, "PerRowValues::endRow: stack is corrupted"); - std::abort(); - } - stack.pop_back(); -} - -void -PerRowValues::rowChanged() const -{ - BOOST_FOREACH(const RowUser * ru, rowUsers) { - ru->rowChanged(); - } -} - -unsigned int -PerRowValues::getRowNum() const -{ - return rowNum; -} - -RowUser::RowUser() -{ -} - -RowUser::~RowUser() -{ -} - -RowProcessor::RowProcessor(const xmlpp::Element * p) : - SourceObject(p), - IHaveParameters(p), - recordSource(p->get_attribute_value("source")), - filter(p->get_attribute_value("filter")) -{ -} - -void -RowProcessor::loadComplete(const CommonObjects * co) -{ - source = co->getSource(recordSource); - if (!filter.empty()) { - source->setFilter(filter); - } -} - diff --git a/project2/perRowValues.h b/project2/perRowValues.h deleted file mode 100644 index 5b8db9b..0000000 --- a/project2/perRowValues.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef PERROWVALUES_H -#define PERROWVALUES_H - -#include -#include -#include -#include -#include -#include "sourceObject.h" -#include "iHaveParameters.h" - -class RowUser { - public: - RowUser(); - virtual ~RowUser() = 0; - - virtual void rowChanged() const = 0; -}; - -class PerRowValues; -typedef boost::intrusive_ptr PerRowValuesPtr; -typedef std::map RowSets; - -class RowProcessor : public IHaveParameters, public virtual SourceObject { - public: - RowProcessor(const xmlpp::Element *); - virtual void rowReady() const = 0; - void loadComplete(const CommonObjects *); - - const std::string recordSource; - const Glib::ustring filter; - - protected: - PerRowValuesPtr source; -}; - -class PerRowValues : public virtual SourceObject { - public: - class ParentOutOfRange : public std::exception { }; - class FieldDoesNotExist : public std::exception { }; - typedef std::vector RowValuesStack; - PerRowValues(const xmlpp::Element *); - virtual ~PerRowValues() = 0; - - virtual void setFilter(const Glib::ustring &) = 0; - virtual unsigned int columnCount() const = 0; - virtual const Glib::ustring & getColumnName(unsigned int col) const = 0; - virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; - virtual const Glib::ustring & getCurrentValue(unsigned int col) const = 0; - virtual bool isNull(unsigned int col) const = 0; - virtual bool isNull(const Glib::ustring & id) const = 0; - unsigned int getRowNum() const; - virtual void execute(const RowProcessor *) const = 0; - void use(const RowUser * r) const; - void finish(const RowUser * r) const; - - static const RowValuesStack & Stack() { return stack; } - static void beginRow(const PerRowValues * r); - static void endRow(const PerRowValues * r); - void rowChanged() const; - - protected: - mutable unsigned int rowNum; - - private: - static RowValuesStack stack; - mutable std::set rowUsers; -}; - -#endif - diff --git a/project2/presenter.cpp b/project2/presenter.cpp index d7ddf5a..69300ec 100644 --- a/project2/presenter.cpp +++ b/project2/presenter.cpp @@ -65,56 +65,3 @@ Presenter::addField(const Glib::ustring & name, const Glib::ustring & ns, const popSub(); } -XmlPresenter::~XmlPresenter() -{ -} - -XmlPresenter::XmlPresenter(const std::string & group, const std::string & file) : - Presenter(group, file), - responseRootNodeName(present.get_document()->get_root_node()->get_attribute_value("root")), - responseStyle(present.get_document()->get_root_node()->get_attribute_value("style")), - contentType(present.get_document()->get_root_node()->get_attribute_value("contenttype")), - responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0"))) -{ - nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName)); - xmlNewNs(nodeStack.back()->cobj(), BAD_CAST "http://project2.randomdan.homeip.net", BAD_CAST "project2"); - // XSLT Style - char * buf; - if (responseStyle.length() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", - responseStyle.c_str()) > 0) { - xmlAddPrevSibling(nodeStack.back()->cobj(), - xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf)); - free(buf); - } -} - -XmlPresenter::XmlDocumentPtr -XmlPresenter::getDataDocument() const -{ - return responseDoc; -} - -void -XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const -{ - nodeStack.push_back(nodeStack.back()->add_child(name, ns)); -} - -void -XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, const Glib::ustring & value) const -{ - nodeStack.back()->set_attribute(name, value, ns); -} - -void -XmlPresenter::setText(const Glib::ustring & value) const -{ - nodeStack.back()->set_child_text(value); -} - -void -XmlPresenter::popSub() const -{ - nodeStack.pop_back(); -} - diff --git a/project2/presenter.h b/project2/presenter.h index 7968b88..b0f3262 100644 --- a/project2/presenter.h +++ b/project2/presenter.h @@ -33,29 +33,5 @@ class Presenter : public CommonObjects, public virtual IntrusivePtrBase { typedef boost::intrusive_ptr PresenterCPtr; typedef boost::intrusive_ptr PresenterPtr; -class XmlPresenter : public Presenter { - public: - typedef boost::shared_ptr XmlDocumentPtr; - XmlPresenter(const std::string & group, const std::string & file); - ~XmlPresenter(); - - void pushSub(const Glib::ustring & name, const Glib::ustring & ns) const; - void addAttr(const Glib::ustring & name, const Glib::ustring & ns, const Glib::ustring & value) const; - void setText(const Glib::ustring & value) const; - void popSub() const; - - virtual XmlDocumentPtr getDataDocument() const; - - const Glib::ustring responseRootNodeName; - const Glib::ustring responseStyle; - const Glib::ustring contentType; - - private: - XmlDocumentPtr responseDoc; - mutable std::vector nodeStack; -}; - -typedef boost::intrusive_ptr XmlPresenterPtr; - #endif diff --git a/project2/rowProcessor.cpp b/project2/rowProcessor.cpp new file mode 100644 index 0000000..26275a9 --- /dev/null +++ b/project2/rowProcessor.cpp @@ -0,0 +1,23 @@ +#include "rowProcessor.h" +#include "commonObjects.h" +#include +#include +#include + +RowProcessor::RowProcessor(const xmlpp::Element * p) : + SourceObject(p), + IHaveParameters(p), + recordSource(p->get_attribute_value("source")), + filter(p->get_attribute_value("filter")) +{ +} + +void +RowProcessor::loadComplete(const CommonObjects * co) +{ + source = co->getSource(recordSource); + if (!filter.empty()) { + source->setFilter(filter); + } +} + diff --git a/project2/rowProcessor.h b/project2/rowProcessor.h new file mode 100644 index 0000000..f47d04e --- /dev/null +++ b/project2/rowProcessor.h @@ -0,0 +1,23 @@ +#ifndef ROWPROCESSOR_H +#define ROWPROCESSOR_H + +#include +#include "sourceObject.h" +#include "iHaveParameters.h" +#include "rowSet.h" + +class RowProcessor : public IHaveParameters, public virtual SourceObject { + public: + RowProcessor(const xmlpp::Element *); + virtual void rowReady() const = 0; + void loadComplete(const CommonObjects *); + + const std::string recordSource; + const Glib::ustring filter; + + protected: + RowSetPtr source; +}; + +#endif + diff --git a/project2/rowSet.cpp b/project2/rowSet.cpp new file mode 100644 index 0000000..0869b58 --- /dev/null +++ b/project2/rowSet.cpp @@ -0,0 +1,60 @@ +#include "rowSet.h" +#include "rowUser.h" +#include "commonObjects.h" +#include +#include + +RowSet::RowValuesStack RowSet::stack; + +RowSet::RowSet(const xmlpp::Element * p) : + SourceObject(p), + rowNum(-1) +{ +} + +RowSet::~RowSet() +{ +} + +void +RowSet::use(const RowUser * r) const +{ + rowUsers.insert(r); +} + +void +RowSet::finish(const RowUser * r) const +{ + rowUsers.erase(r); +} + +void +RowSet::beginRow(const RowSet * r) +{ + stack.push_back(r); +} + +void +RowSet::endRow(const RowSet * r) +{ + if (stack.back() != r) { + syslog(LOG_ERR, "RowSet::endRow: stack is corrupted"); + std::abort(); + } + stack.pop_back(); +} + +void +RowSet::rowChanged() const +{ + BOOST_FOREACH(const RowUser * ru, rowUsers) { + ru->rowChanged(); + } +} + +unsigned int +RowSet::getRowNum() const +{ + return rowNum; +} + diff --git a/project2/rowSet.h b/project2/rowSet.h new file mode 100644 index 0000000..612a0b4 --- /dev/null +++ b/project2/rowSet.h @@ -0,0 +1,51 @@ +#ifndef ROWSET_H +#define ROWSET_H + +#include +#include +#include +#include +#include +#include "sourceObject.h" +#include "iHaveParameters.h" + +class RowProcessor; +class RowSet; +typedef boost::intrusive_ptr RowSetPtr; +typedef std::map RowSets; + +class RowSet : public virtual SourceObject { + public: + class ParentOutOfRange : public std::exception { }; + class FieldDoesNotExist : public std::exception { }; + typedef std::vector RowValuesStack; + RowSet(const xmlpp::Element *); + virtual ~RowSet() = 0; + + virtual void setFilter(const Glib::ustring &) = 0; + virtual unsigned int columnCount() const = 0; + virtual const Glib::ustring & getColumnName(unsigned int col) const = 0; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; + virtual const Glib::ustring & getCurrentValue(unsigned int col) const = 0; + virtual bool isNull(unsigned int col) const = 0; + virtual bool isNull(const Glib::ustring & id) const = 0; + unsigned int getRowNum() const; + virtual void execute(const RowProcessor *) const = 0; + void use(const RowUser * r) const; + void finish(const RowUser * r) const; + + static const RowValuesStack & Stack() { return stack; } + static void beginRow(const RowSet * r); + static void endRow(const RowSet * r); + void rowChanged() const; + + protected: + mutable unsigned int rowNum; + + private: + static RowValuesStack stack; + mutable std::set rowUsers; +}; + +#endif + diff --git a/project2/rowUser.cpp b/project2/rowUser.cpp new file mode 100644 index 0000000..2557af1 --- /dev/null +++ b/project2/rowUser.cpp @@ -0,0 +1,10 @@ +#include "rowUser.h" + +RowUser::RowUser() +{ +} + +RowUser::~RowUser() +{ +} + diff --git a/project2/rowUser.h b/project2/rowUser.h new file mode 100644 index 0000000..9597807 --- /dev/null +++ b/project2/rowUser.h @@ -0,0 +1,13 @@ +#ifndef ROWUSER_H +#define ROWUSER_H + +class RowUser { + public: + RowUser(); + virtual ~RowUser() = 0; + + virtual void rowChanged() const = 0; +}; + +#endif + diff --git a/project2/rowView.cpp b/project2/rowView.cpp new file mode 100644 index 0000000..e0cca9c --- /dev/null +++ b/project2/rowView.cpp @@ -0,0 +1,84 @@ +#include "rowView.h" +#include "presenter.h" +#include + +ElementLoaderImpl viewLoader("view"); + +RowView::RowView(const xmlpp::Element * p) : + SourceObject(p), + View(p), + RowProcessor(p), + rootName(p->get_attribute_value("rootname")), + recordName(p->get_attribute_value("recordname")) +{ + BOOST_FOREACH(xmlpp::Node * node, p->find("columns/column")) { + const xmlpp::Element * elem = dynamic_cast(node); + if (elem) { + viewColumns.insert(Columns::value_type(elem->get_attribute_value("name"), Variable::makeParent(elem->get_child_text()->get_content(), 0))); + } + } + LoaderBase loader("http://project2.randomdan.homeip.net", true); + loader.supportedStorers.insert(Storer::into(&subViews)); + loader.collectAll(p, true); +} + +RowView::~RowView() +{ +} + +void +RowView::loadComplete(const CommonObjects * co) +{ + RowProcessor::loadComplete(co); +} + +void +RowView::rowReady() const +{ + presenter->pushSub(recordName); + if (viewColumns.empty()) { + unsigned int cols = source->columnCount(); + for (unsigned int c = 0; c < cols; c += 1) { + if (!source->isNull(c)) { + presenter->addField(source->getColumnName(c), source->getCurrentValue(c)); + } + } + } + else { + BOOST_FOREACH(const Columns::value_type & col, viewColumns) { + if (!source->isNull(col.first)) { + presenter->addField(col.first, col.second); + } + } + } + executeChildren(); + source->rowChanged(); + presenter->popSub(); +} + +void +RowView::execute(const Presenter * p) const +{ + presenter = p; + presenter->pushSub(rootName); + RowSet::beginRow(source.get()); + try { + source->execute(this); + RowSet::endRow(source.get()); + presenter->popSub(); + } + catch (...) { + presenter->popSub(); + RowSet::endRow(source.get()); + throw; + } +} + +void +RowView::executeChildren() const +{ + BOOST_FOREACH(Views::value_type sq, subViews) { + sq.second->execute(presenter); + } +} + diff --git a/project2/rowView.h b/project2/rowView.h new file mode 100644 index 0000000..fb22b2b --- /dev/null +++ b/project2/rowView.h @@ -0,0 +1,32 @@ +#ifndef ROWVIEW_H +#define ROWVIEW_H + +#include +#include +#include "sourceObject.h" +#include "rowProcessor.h" +#include "view.h" + +class RowView : public View, public RowProcessor { + public: + RowView(const xmlpp::Element *); + virtual ~RowView(); + + void loadComplete(const CommonObjects *); + void execute(const Presenter *) const; + void rowReady() const; + + const Glib::ustring rootName; + const Glib::ustring recordName; + + protected: + typedef std::map Columns; + Columns viewColumns; + + void executeChildren() const; + Views subViews; + mutable const Presenter * presenter; +}; + +#endif + diff --git a/project2/sendmailTask.cpp b/project2/sendmailTask.cpp index a95945f..29d2c3b 100644 --- a/project2/sendmailTask.cpp +++ b/project2/sendmailTask.cpp @@ -1,8 +1,7 @@ #include "sendmailTask.h" #include #include "xmlObjectLoader.h" -#include "appEngine.h" -#include "presenter.h" +#include "xmlPresenter.h" #include #include #include diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index 09e18ca..93e91db 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -223,7 +223,7 @@ class Populate : public NoOutputExecute { } void execute() const { - const PerRowValues * iter = *++PerRowValues::Stack().rbegin(); + const RowSet * iter = *++RowSet::Stack().rbegin(); if (idxs.empty()) { idxs.resize(iter->columnCount()); // Sure this can be improved upon... but hey. @@ -243,7 +243,7 @@ class Populate : public NoOutputExecute { try { cmd->bindParamS(idxs[c], iter->getCurrentValue(c)); } - catch (const PerRowValues::FieldDoesNotExist &) { + catch (const RowSet::FieldDoesNotExist &) { cmd->bindNull(idxs[c]); } } diff --git a/project2/sqlMergeTask.h b/project2/sqlMergeTask.h index ede8424..08246d0 100644 --- a/project2/sqlMergeTask.h +++ b/project2/sqlMergeTask.h @@ -73,66 +73,5 @@ class SqlMergeTask : public Task { static bool defaultUseTempTable; }; -/* -class CopyBasedDbConversion : public DbConversion { - public: - CopyBasedDbConversion(const Connection & dest, const std::string dt); - virtual ~CopyBasedDbConversion(); - private: - void copyToTempTable() const; - virtual SelectCommand * selectCommand() const = 0; -}; -class SimpleDbConversion : public CopyBasedDbConversion { - public: - SimpleDbConversion(const Connection & src, const std::string st, const Connection & dest, - const std::string dt); - ~SimpleDbConversion(); - SelectCommand * selectCommand() const; - private: - const Connection & srcdb; - const Table stable; - mutable SelectCommand * srcCmd; -}; -class CustomDbConversion : public CopyBasedDbConversion { - public: - CustomDbConversion(SelectCommand * srcc, const Connection & dest, const std::string dt); - ~CustomDbConversion(); - private: - SelectCommand * selectCommand() const; - SelectCommand * srcCmd; -}; -class EasyFillDbConversion : public DbConversion { - public: - EasyFillDbConversion(const std::string src, const Connection & db, const std::string dt); - ~EasyFillDbConversion(); - - private: - void copyToTempTable() const; - const std::string srcSql; -}; -class FileFillDbConversion : public DbConversion { - public: - FileFillDbConversion(const std::string src, const Connection & db, const std::string dt); - ~FileFillDbConversion(); - - std::list post; - - private: - void copyToTempTable() const; - const std::string srcFile; -}; -class CustomFillDbConversion : public DbConversion { - public: - typedef void(*FillFunc)(const CustomFillDbConversion *); - - CustomFillDbConversion(FillFunc fill, const Connection & dest, const std::string dt); - ~CustomFillDbConversion(); - - private: - void copyToTempTable() const; - const FillFunc filler; -}; -*/ - #endif diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index 9d7950f..8d3e98c 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -1,4 +1,5 @@ #include "sqlRows.h" +#include "rowProcessor.h" #include "xml.h" #include "selectcommand.h" #include "rdbmsDataSource.h" @@ -12,7 +13,7 @@ ElementLoaderImpl sqlviewLoader("sqlrows"); SqlRows::SqlRows(const xmlpp::Element * p) : SourceObject(p), - PerRowValues(p), + RowSet(p), dataSource(p->get_attribute_value("datasource")), sqlCommand(dynamic_cast(p->get_children("sql").front())), query(NULL), diff --git a/project2/sqlRows.h b/project2/sqlRows.h index f3e5605..14ffb6f 100644 --- a/project2/sqlRows.h +++ b/project2/sqlRows.h @@ -6,11 +6,11 @@ #include #include "selectcommand.h" #include "iHaveParameters.h" -#include "perRowValues.h" +#include "rowSet.h" class RdbmsDataSource; -class SqlRows : public PerRowValues { +class SqlRows : public RowSet { public: SqlRows(const xmlpp::Element * p); ~SqlRows(); diff --git a/project2/urlRows.cpp b/project2/urlRows.cpp index 68d81e4..40c9f63 100644 --- a/project2/urlRows.cpp +++ b/project2/urlRows.cpp @@ -1,4 +1,5 @@ #include "urlRows.h" +#include "rowProcessor.h" #include "xmlObjectLoader.h" #include "exceptions.h" #include "../libmisc/curlsup.h" @@ -9,7 +10,7 @@ ElementLoaderImpl urlrowsLoader("urlrows"); UrlRows::UrlRows(const xmlpp::Element * p) : SourceObject(p), - PerRowValues(p), + RowSet(p), url(p->get_attribute_value("url")), fieldSep(p->get_attribute_value("fieldSep")[0]), quoteChar(p->get_attribute_value("quoteChar")[0]), @@ -82,7 +83,7 @@ UrlRows::getCurrentValue(const Glib::ustring & id) const return **v; } } - throw PerRowValues::FieldDoesNotExist(); + throw RowSet::FieldDoesNotExist(); } size_t diff --git a/project2/urlRows.h b/project2/urlRows.h index 3333fca..ea09fee 100644 --- a/project2/urlRows.h +++ b/project2/urlRows.h @@ -5,9 +5,9 @@ #include #include #include -#include "perRowValues.h" +#include "rowSet.h" -class UrlRows : public PerRowValues { +class UrlRows : public RowSet { public: UrlRows(const xmlpp::Element * p); ~UrlRows(); diff --git a/project2/variables.cpp b/project2/variables.cpp index c6a65f1..b0aecea 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -1,8 +1,8 @@ #include "variables.h" #include "exceptions.h" #include "appEngine.h" -#include "perRowValues.h" #include "session.h" +#include "rowUser.h" #include #include #include @@ -122,10 +122,10 @@ class VariableParent : public VariableImplDyn, public RowUser { if (!cacheValid) { try { if (!row) { - PerRowValues::RowValuesStack::const_reverse_iterator r = PerRowValues::Stack().rbegin(); + RowSet::RowValuesStack::const_reverse_iterator r = RowSet::Stack().rbegin(); for (size_t p = depth; p--; r++) ; - if (r == PerRowValues::Stack().rend()) { - throw PerRowValues::ParentOutOfRange(); + if (r == RowSet::Stack().rend()) { + throw RowSet::ParentOutOfRange(); } row = *r; row->use(this); @@ -135,13 +135,13 @@ class VariableParent : public VariableImplDyn, public RowUser { } getValue(cache, row); } - catch (PerRowValues::ParentOutOfRange) { + catch (RowSet::ParentOutOfRange) { if (!defaultValue) { throw; } cache = *defaultValue; } - catch (PerRowValues::FieldDoesNotExist) { + catch (RowSet::FieldDoesNotExist) { if (!defaultValue) { throw; } @@ -165,22 +165,22 @@ class VariableParent : public VariableImplDyn, public RowUser { if (name == "!rownum") { getValue = boost::bind(&assignHelper, _1, boost::bind(&boost::lexical_cast, - boost::bind(&PerRowValues::getRowNum, _2))); + boost::bind(&RowSet::getRowNum, _2))); } else { - throw PerRowValues::FieldDoesNotExist(); + throw RowSet::FieldDoesNotExist(); } } else { - typedef const Glib::ustring & (PerRowValues::*gCV)(const Glib::ustring &) const; + typedef const Glib::ustring & (RowSet::*gCV)(const Glib::ustring &) const; getValue = boost::bind(&assignHelper, _1, - boost::bind((gCV)&PerRowValues::getCurrentValue, _2, name)); + boost::bind((gCV)&RowSet::getCurrentValue, _2, name)); } } - mutable const PerRowValues * row; + mutable const RowSet * row; const size_t depth; const RowUser * dep; - boost::function2 getValue; + boost::function2 getValue; }; class VariableParse : public VariableImplDyn, public RowUser { diff --git a/project2/view.cpp b/project2/view.cpp index 53eff61..ad9ef1f 100644 --- a/project2/view.cpp +++ b/project2/view.cpp @@ -1,9 +1,4 @@ #include "view.h" -#include "presenter.h" -#include -#include - -ElementLoaderImpl viewLoader("view"); View::View(const xmlpp::Element * p) : SourceObject(p) @@ -14,81 +9,3 @@ View::~View() { } -RowView::RowView(const xmlpp::Element * p) : - SourceObject(p), - View(p), - RowProcessor(p), - rootName(p->get_attribute_value("rootname")), - recordName(p->get_attribute_value("recordname")) -{ - BOOST_FOREACH(xmlpp::Node * node, p->find("columns/column")) { - const xmlpp::Element * elem = dynamic_cast(node); - if (elem) { - viewColumns.insert(Columns::value_type(elem->get_attribute_value("name"), Variable::makeParent(elem->get_child_text()->get_content(), 0))); - } - } - LoaderBase loader("http://project2.randomdan.homeip.net", true); - loader.supportedStorers.insert(Storer::into(&subViews)); - loader.collectAll(p, true); -} - -RowView::~RowView() -{ -} - -void -RowView::loadComplete(const CommonObjects * co) -{ - RowProcessor::loadComplete(co); -} - -void -RowView::rowReady() const -{ - presenter->pushSub(recordName); - if (viewColumns.empty()) { - unsigned int cols = source->columnCount(); - for (unsigned int c = 0; c < cols; c += 1) { - if (!source->isNull(c)) { - presenter->addField(source->getColumnName(c), source->getCurrentValue(c)); - } - } - } - else { - BOOST_FOREACH(const Columns::value_type & col, viewColumns) { - if (!source->isNull(col.first)) { - presenter->addField(col.first, col.second); - } - } - } - executeChildren(); - source->rowChanged(); - presenter->popSub(); -} - -void -RowView::execute(const Presenter * p) const -{ - presenter = p; - presenter->pushSub(rootName); - PerRowValues::beginRow(source.get()); - try { - source->execute(this); - PerRowValues::endRow(source.get()); - presenter->popSub(); - } - catch (...) { - presenter->popSub(); - PerRowValues::endRow(source.get()); - throw; - } -} - -void -RowView::executeChildren() const -{ - BOOST_FOREACH(Views::value_type sq, subViews) { - sq.second->execute(presenter); - } -} - diff --git a/project2/view.h b/project2/view.h index 9f77cb6..8080824 100644 --- a/project2/view.h +++ b/project2/view.h @@ -5,9 +5,6 @@ #include #include #include "sourceObject.h" -#include "xmlObjectLoader.h" -#include "perRowValues.h" -#include "variables.h" class Presenter; class View; @@ -22,26 +19,5 @@ class View : public virtual SourceObject { virtual void execute(const Presenter *) const = 0; }; -class RowView : public View, public RowProcessor { - public: - RowView(const xmlpp::Element *); - virtual ~RowView(); - - void loadComplete(const CommonObjects *); - void execute(const Presenter *) const; - void rowReady() const; - - const Glib::ustring rootName; - const Glib::ustring recordName; - - protected: - typedef std::map Columns; - Columns viewColumns; - - void executeChildren() const; - Views subViews; - mutable const Presenter * presenter; -}; - #endif diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp new file mode 100644 index 0000000..af870eb --- /dev/null +++ b/project2/xmlPresenter.cpp @@ -0,0 +1,55 @@ +#include "xmlPresenter.h" + +XmlPresenter::~XmlPresenter() +{ +} + +XmlPresenter::XmlPresenter(const std::string & group, const std::string & file) : + Presenter(group, file), + responseRootNodeName(present.get_document()->get_root_node()->get_attribute_value("root")), + responseStyle(present.get_document()->get_root_node()->get_attribute_value("style")), + contentType(present.get_document()->get_root_node()->get_attribute_value("contenttype")), + responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0"))) +{ + nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName)); + xmlNewNs(nodeStack.back()->cobj(), BAD_CAST "http://project2.randomdan.homeip.net", BAD_CAST "project2"); + // XSLT Style + char * buf; + if (responseStyle.length() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", + responseStyle.c_str()) > 0) { + xmlAddPrevSibling(nodeStack.back()->cobj(), + xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf)); + free(buf); + } +} + +XmlPresenter::XmlDocumentPtr +XmlPresenter::getDataDocument() const +{ + return responseDoc; +} + +void +XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const +{ + nodeStack.push_back(nodeStack.back()->add_child(name, ns)); +} + +void +XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, const Glib::ustring & value) const +{ + nodeStack.back()->set_attribute(name, value, ns); +} + +void +XmlPresenter::setText(const Glib::ustring & value) const +{ + nodeStack.back()->set_child_text(value); +} + +void +XmlPresenter::popSub() const +{ + nodeStack.pop_back(); +} + diff --git a/project2/xmlPresenter.h b/project2/xmlPresenter.h new file mode 100644 index 0000000..c16cc2c --- /dev/null +++ b/project2/xmlPresenter.h @@ -0,0 +1,31 @@ +#ifndef XMLPRESENTER_H +#define XMLPRESENTER_H + +#include "presenter.h" + +class XmlPresenter : public Presenter { + public: + typedef boost::shared_ptr XmlDocumentPtr; + XmlPresenter(const std::string & group, const std::string & file); + ~XmlPresenter(); + + void pushSub(const Glib::ustring & name, const Glib::ustring & ns) const; + void addAttr(const Glib::ustring & name, const Glib::ustring & ns, const Glib::ustring & value) const; + void setText(const Glib::ustring & value) const; + void popSub() const; + + virtual XmlDocumentPtr getDataDocument() const; + + const Glib::ustring responseRootNodeName; + const Glib::ustring responseStyle; + const Glib::ustring contentType; + + private: + XmlDocumentPtr responseDoc; + mutable std::vector nodeStack; +}; + +typedef boost::intrusive_ptr XmlPresenterPtr; + +#endif + diff --git a/project2/xmlRows.cpp b/project2/xmlRows.cpp index ba5697a..377e3c9 100644 --- a/project2/xmlRows.cpp +++ b/project2/xmlRows.cpp @@ -1,4 +1,5 @@ #include "xmlRows.h" +#include "rowProcessor.h" #include "xml.h" #include "exceptions.h" #include @@ -13,7 +14,7 @@ ElementLoaderImpl xmlrowLoader("xmlrows"); XmlRows::XmlRows(const xmlpp::Element * p) : SourceObject(p), - PerRowValues(p), + RowSet(p), recordRoot(p->get_attribute_value("recordroot")), recordTrigger(p->get_attribute_value("recordtrigger")), filename(p->get_attribute_value("filename")), diff --git a/project2/xmlRows.h b/project2/xmlRows.h index 9d7bade..b7fe790 100644 --- a/project2/xmlRows.h +++ b/project2/xmlRows.h @@ -4,9 +4,9 @@ #include #include #include -#include "perRowValues.h" +#include "rowSet.h" -class XmlRows : public PerRowValues { +class XmlRows : public RowSet { public: typedef std::map Values; typedef std::vector Path; -- cgit v1.2.3