From 77954b11521564c41a8587be87cff51fe22cde0c Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 5 Aug 2010 23:48:05 +0000 Subject: Cache the result of default column compose Use this cache now lots of things are const refs --- project2/fileRows.cpp | 8 ++++---- project2/fileRows.h | 6 +++--- project2/iterate.h | 7 +++++-- project2/perRowValues.h | 2 +- project2/rawView.cpp | 6 +++--- project2/rawView.h | 2 +- project2/rowBase.h | 6 +++--- project2/sqlRows.cpp | 6 +++--- project2/sqlRows.h | 6 +++--- project2/view.h | 7 +++++-- 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index 239ad6b..855136f 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -26,7 +26,7 @@ _FileRows::columnCount() const return columns.size(); } -Glib::ustring +const Glib::ustring & _FileRows::getColumnName(unsigned int col) const { return columns[col]; @@ -93,13 +93,13 @@ _FileRows::execute() const } } -Glib::ustring +const Glib::ustring & _FileRows::getCurrentValue(unsigned int col) const { return *values[col]; } -Glib::ustring +const Glib::ustring & _FileRows::getCurrentValue(const Glib::ustring & id) const { Values::const_iterator v = values.begin(); @@ -108,7 +108,7 @@ _FileRows::getCurrentValue(const Glib::ustring & id) const return **v; } } - return ""; + throw PerRowValues::FieldDoesNotExist(); } void diff --git a/project2/fileRows.h b/project2/fileRows.h index 3e8d3c6..335e723 100644 --- a/project2/fileRows.h +++ b/project2/fileRows.h @@ -16,9 +16,9 @@ class _FileRows : public RowBase { void execute() const; unsigned int columnCount() const; - Glib::ustring getColumnName(unsigned int col) const; - Glib::ustring getCurrentValue(const Glib::ustring & id) const; - Glib::ustring getCurrentValue(unsigned int col) const; + const Glib::ustring & getColumnName(unsigned int col) const; + const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; + const Glib::ustring & getCurrentValue(unsigned int col) const; typedef std::set CharSet; const Glib::ustring path; diff --git a/project2/iterate.h b/project2/iterate.h index 1f6dfda..53f7050 100644 --- a/project2/iterate.h +++ b/project2/iterate.h @@ -20,7 +20,7 @@ class _Iterate : public virtual _SourceObject, public PerRowValues, public _NoOu virtual ~_Iterate(); virtual void execute() const = 0; - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const = 0; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; static void AddLoaders(Loaders & l, NoOutputExecutes & vs); protected: @@ -33,7 +33,10 @@ class _GenericIterate : public _Iterate, public Driver { public: _GenericIterate(const xmlpp::Element * p); - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const { return Driver::getCurrentValue(id); } + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const + { + return Driver::getCurrentValue(id); + } virtual void executeChildren() const; virtual void execute() const; virtual void rowReady() const; diff --git a/project2/perRowValues.h b/project2/perRowValues.h index cee7e07..5b5b9ab 100644 --- a/project2/perRowValues.h +++ b/project2/perRowValues.h @@ -21,7 +21,7 @@ class PerRowValues { PerRowValues(); virtual ~PerRowValues() = 0; - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const = 0; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; void use(const RowUser * r) const { rowUsers.insert(r); } static const RowValuesStack & Stack() { return stack; } diff --git a/project2/rawView.cpp b/project2/rawView.cpp index 920a900..3fe925a 100644 --- a/project2/rawView.cpp +++ b/project2/rawView.cpp @@ -1,4 +1,4 @@ -#include +#include #include "rawView.h" #include "xml.h" #include "xmlObjectLoader.h" @@ -12,10 +12,10 @@ _RawView::_RawView(const xmlpp::Element * p) : { } -Glib::ustring +const Glib::ustring & _RawView::getCurrentValue(const Glib::ustring & id) const { - return ""; + throw std::runtime_error("_RawView::getCurrentValue not implemented"); } void _RawView::execute(xmlpp::Element * par) const diff --git a/project2/rawView.h b/project2/rawView.h index 9d7dd44..8909927 100644 --- a/project2/rawView.h +++ b/project2/rawView.h @@ -12,7 +12,7 @@ class _RawView : public _View { public: _RawView(const xmlpp::Element * p); void execute(xmlpp::Element *) const; - Glib::ustring getCurrentValue(const Glib::ustring & id) const; + const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; private: const xmlpp::Element * copyRoot; }; diff --git a/project2/rowBase.h b/project2/rowBase.h index 337a72e..c9397ef 100644 --- a/project2/rowBase.h +++ b/project2/rowBase.h @@ -4,9 +4,9 @@ class RowBase { public: virtual unsigned int columnCount() const = 0; - virtual Glib::ustring getColumnName(unsigned int col) const = 0; - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const = 0; - virtual Glib::ustring getCurrentValue(unsigned int col) 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 void rowReady() const = 0; }; diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index fc4c91c..ca814f7 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -21,13 +21,13 @@ _SqlRows::~_SqlRows() delete query; } -Glib::ustring +const Glib::ustring & _SqlRows::getCurrentValue(const Glib::ustring & id) const { return (*query)[id].compose(); } -Glib::ustring +const Glib::ustring & _SqlRows::getCurrentValue(unsigned int col) const { return (*query)[col].compose(); @@ -39,7 +39,7 @@ _SqlRows::columnCount() const return query->columnCount(); } -Glib::ustring +const Glib::ustring & _SqlRows::getColumnName(unsigned int col) const { return (*query)[col].name; diff --git a/project2/sqlRows.h b/project2/sqlRows.h index fb64caf..98a20f3 100644 --- a/project2/sqlRows.h +++ b/project2/sqlRows.h @@ -19,9 +19,9 @@ class _SqlRows : public IHaveParameters, public RowBase { void execute() const; unsigned int columnCount() const; - Glib::ustring getColumnName(unsigned int col) const; - Glib::ustring getCurrentValue(const Glib::ustring & id) const; - Glib::ustring getCurrentValue(unsigned int col) const; + const Glib::ustring & getColumnName(unsigned int col) const; + const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; + const Glib::ustring & getCurrentValue(unsigned int col) const; const std::string dataSource; const Glib::ustring sql; diff --git a/project2/view.h b/project2/view.h index a5f9453..165ed12 100644 --- a/project2/view.h +++ b/project2/view.h @@ -19,7 +19,7 @@ class _View : public virtual _SourceObject, public PerRowValues { _View(const xmlpp::Element * p); virtual ~_View(); virtual void execute(xmlpp::Element *) const = 0; - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const = 0; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; const Glib::ustring recordName; static void AddLoaders(Loaders & l, Views & vs); @@ -33,7 +33,10 @@ class _GenericView : public _View, public Driver { public: _GenericView(const xmlpp::Element * p); - virtual Glib::ustring getCurrentValue(const Glib::ustring & id) const { return Driver::getCurrentValue(id); } + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const + { + return Driver::getCurrentValue(id); + } virtual void execute(xmlpp::Element * e) const; virtual void rowReady() const; private: -- cgit v1.2.3