diff options
Diffstat (limited to 'project2/common/commonObjects.h')
-rw-r--r-- | project2/common/commonObjects.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/project2/common/commonObjects.h b/project2/common/commonObjects.h new file mode 100644 index 0000000..dae563a --- /dev/null +++ b/project2/common/commonObjects.h @@ -0,0 +1,40 @@ +#ifndef COMMONOBJECTS_H +#define COMMONOBJECTS_H + +#include "dataSource.h" +#include "rowSet.h" +#include "xmlStorage.h" + +class CommonObjects : public virtual IntrusivePtrBase { + public: + typedef STORAGEOF(RowSet) RowSets; + typedef STORAGEOF(DataSource) DataSources; + + SimpleMessageException(DataSourceNotFound); + SimpleMessageException(DataSourceNotCompatible); + + virtual ~CommonObjects(); + + RowSetPtr getSource(const std::string &) const; + template <class DataSourceType> + const DataSourceType * dataSource(const std::string & name) const + { + DataSources::const_iterator i = datasources.find(name); + if (i == datasources.end()) { + i = loadDataSource(name); + } + const DataSourceType * s = boost::dynamic_pointer_cast<const DataSourceType>(i->second).get(); + if (!s) { + throw DataSourceNotCompatible(name); + } + return s; + } + protected: + RowSets rowSets; + mutable DataSources datasources; + private: + DataSources::const_iterator loadDataSource(const std::string & name) const; +}; + +#endif + |