diff --git a/src/lib/iter-source.hpp b/src/lib/iter-source.hpp index 9ef4b93d9..549907e89 100644 --- a/src/lib/iter-source.hpp +++ b/src/lib/iter-source.hpp @@ -43,11 +43,14 @@ #include "lib/iter-adapter.hpp" //#include "lib/bool-checkable.hpp" +#include + namespace lib { - + + using std::tr1::shared_ptr; namespace { } @@ -58,16 +61,136 @@ namespace lib { * which then can be accessed through IterAdapter as a frontend, * allowing to pull individual elements until exhaustion. * + * This base class is empty and makes now assumptions regarding + * identity, instantiation and copying. + * * @see PlacementIndex::Table#_eachEntry_4check usage example * @see iter-source-test.cpp */ - template + template class IterSource - : public lib::BoolCheckable > +// : public lib::BoolCheckable > { + + static void + detach_without_destroy (IterSource * source) + { + WARN_IF (!source, library, "IterSource deleter called with NULL source pointer"); + if (source) + source->disconnect(); + } + + + protected: /* == data source API for implementation == */ + + typedef TY* Pos; + typedef shared_ptr DataHandle; + + + /** iteration start: prepare the first element. + * may return NULL in case of empty data source + */ + virtual Pos firstResult () =0; + + /** iteration step: switch on to the next element. + * The pos pointer may be set to NULL to report + * iteration end + */ + virtual void nextResult(Pos& pos) =0; + + /** disconnect the data source / iteration frontend. + * Depending on the way the IterSource got created + * this \em might (or might not) be followed by + * destroying the data source. + * @note must not throw + */ + virtual void disconnect () { } + + + public: + + virtual ~IterSource() { }; ///< is ABC + + /* == Iteration control API for IterAdapter frontend == */ + + friend bool + hasNext (DataHandle const&, Pos const& pos) ////TICKET #410 + { + return bool(pos); + } + + friend void + iterNext (DataHandle& source, Pos& pos) + { + source->nextResult(pos); + } + + + /* == public builder API to create instances == */ + + typedef IterAdapter iterator; + + static iterator + build (IterSource& sourceImpl) + { + DataHandle sourceHandle (&sourceImpl, &detach_without_destroy); + Pos first = sourceImpl.firstResult(); + return iterator (sourceHandle, first); + } + + static iterator EMPTY_SOURCE; }; + /** storage for the empty data-source constant */ + template + typename IterSource::iterator IterSource::EMPTY_SOURCE = iterator(); + + + + + /* === pre-defined Adapters for frequently used Containers === */ + + namespace iter_impl { + + template + struct _SeqType + { + typedef typename CON::iterator::value_type Val; + typedef typename IterSource::iterator Iter; + }; + + template + struct _MapType + { + typedef typename MAP::key_type Key; + typedef typename IterSource::iterator Iter; + }; + } + + template + typename iter_impl::_MapType::Iter + eachMapKey (MAP& map) + { + UNIMPLEMENTED ("standard iter wrapper yielding all map keys"); + } + + + template + typename iter_impl::_MapType::Iter + eachDistinctKey (MAP& map) + { + UNIMPLEMENTED ("standard iter wrapper yielding all distinct keys of a multimap"); + } + + + template + typename iter_impl::_SeqType::Iter + eachEntry (CON& container) + { + UNIMPLEMENTED ("standard iter wrapper yielding all distinct keys of a multimap"); + } + } // namespace lib #endif diff --git a/src/proc/mobject/session/placement-index.cpp b/src/proc/mobject/session/placement-index.cpp index 5334432fa..701da196b 100644 --- a/src/proc/mobject/session/placement-index.cpp +++ b/src/proc/mobject/session/placement-index.cpp @@ -56,6 +56,7 @@ #include "lib/typed-allocation-manager.hpp" //#include "proc/mobject/mobject.hpp" ///////////////////////TODO necessary? #include "lib/util-foreach.hpp" +#include "lib/iter-source.hpp" //#include @@ -304,6 +305,8 @@ namespace session { /* == access for self-test == */ + typedef lib::IterSource::iterator IDIter; + PlacementMO* _root_4check () { return root_.get(); } PlacementMO* _element_4check (ID id){ return base_entry(id).element.get();} PlacementMO* _scope_4check (ID id) { return base_entry(id).scope.get(); } @@ -511,8 +514,6 @@ namespace session { /* ====== PlacementIndex validity self-check ====== */ -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #479 !!!!!!!!! -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! namespace { // Implementation details of self-check LUMIERA_ERROR_DEFINE(INDEX_CORRUPTED, "PlacementIndex corrupted"); @@ -611,8 +612,10 @@ namespace session { { checkRoot (tab._root_4check()); +#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #479 !!!!!!!!! for_each ( tab._eachEntry_4check(), &Validator::checkEntry, this, _1 ); for_each ( tab._eachScope_4check(), &Validator::checkScope, this, _1 ); +#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! } };//(End) Validator (PlacementIndex self-check implementation) diff --git a/tests/40components.tests b/tests/40components.tests index 243037a3a..b8f3a930c 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -356,6 +356,10 @@ out: ::12::11::10::9::8::7::6::5::4::3 END +PLANNED "Iterable data source" IterSource_test 20 < : Yes out: can_STL_ForEach : Yes diff --git a/tests/lib/iter-source-test.cpp b/tests/lib/iter-source-test.cpp index 8ba128603..6d368df6e 100644 --- a/tests/lib/iter-source-test.cpp +++ b/tests/lib/iter-source-test.cpp @@ -28,6 +28,7 @@ #include "lib/iter-source.hpp" #include +#include #include #include @@ -38,6 +39,7 @@ namespace test{ using ::Test; using boost::lexical_cast; + using boost::noncopyable; using util::isnil; using std::list; using std::cout; @@ -55,7 +57,28 @@ namespace test{ */ class TestSource : public IterSource + , noncopyable { + + virtual Pos + firstResult () + { + UNIMPLEMENTED ("start iteration"); + } + + virtual void + nextResult (Pos& pos) + { + UNIMPLEMENTED ("iteration step"); + } + + + + public: + TestSource (uint num) + { + UNIMPLEMENTED ("dedicated IterSource implementation"); + } };