IterSource implementation draft
This commit is contained in:
parent
ea5668c5e3
commit
16962ae714
4 changed files with 158 additions and 5 deletions
|
|
@ -43,11 +43,14 @@
|
|||
#include "lib/iter-adapter.hpp"
|
||||
//#include "lib/bool-checkable.hpp"
|
||||
|
||||
#include <tr1/memory>
|
||||
|
||||
|
||||
|
||||
|
||||
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<class TY>
|
||||
template<typename TY>
|
||||
class IterSource
|
||||
: public lib::BoolCheckable<IterSource<TY> >
|
||||
// : public lib::BoolCheckable<IterSource<TY> >
|
||||
{
|
||||
|
||||
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<IterSource> 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<Pos, DataHandle> 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 TY>
|
||||
typename IterSource<TY>::iterator IterSource<TY>::EMPTY_SOURCE = iterator();
|
||||
|
||||
|
||||
|
||||
|
||||
/* === pre-defined Adapters for frequently used Containers === */
|
||||
|
||||
namespace iter_impl {
|
||||
|
||||
template<class CON>
|
||||
struct _SeqType
|
||||
{
|
||||
typedef typename CON::iterator::value_type Val;
|
||||
typedef typename IterSource<Val>::iterator Iter;
|
||||
};
|
||||
|
||||
template<class MAP>
|
||||
struct _MapType
|
||||
{
|
||||
typedef typename MAP::key_type Key;
|
||||
typedef typename IterSource<Key>::iterator Iter;
|
||||
};
|
||||
}
|
||||
|
||||
template<class MAP>
|
||||
typename iter_impl::_MapType<MAP>::Iter
|
||||
eachMapKey (MAP& map)
|
||||
{
|
||||
UNIMPLEMENTED ("standard iter wrapper yielding all map keys");
|
||||
}
|
||||
|
||||
|
||||
template<class MAP>
|
||||
typename iter_impl::_MapType<MAP>::Iter
|
||||
eachDistinctKey (MAP& map)
|
||||
{
|
||||
UNIMPLEMENTED ("standard iter wrapper yielding all distinct keys of a multimap");
|
||||
}
|
||||
|
||||
|
||||
template<class CON>
|
||||
typename iter_impl::_SeqType<CON>::Iter
|
||||
eachEntry (CON& container)
|
||||
{
|
||||
UNIMPLEMENTED ("standard iter wrapper yielding all distinct keys of a multimap");
|
||||
}
|
||||
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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 <boost/format.hpp>
|
||||
|
|
@ -304,6 +305,8 @@ namespace session {
|
|||
|
||||
/* == access for self-test == */
|
||||
|
||||
typedef lib::IterSource<PID>::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)
|
||||
|
|
|
|||
|
|
@ -356,6 +356,10 @@ out: ::12::11::10::9::8::7::6::5::4::3
|
|||
END
|
||||
|
||||
|
||||
PLANNED "Iterable data source" IterSource_test 20 <<END
|
||||
END
|
||||
|
||||
|
||||
TEST "Iterable type detection" IterableClassification_test <<END
|
||||
out: can_STL_ForEach<LongVector> : Yes
|
||||
out: can_STL_ForEach<TimeSet> : Yes
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "lib/iter-source.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
|
|
@ -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<char*>
|
||||
, noncopyable
|
||||
{
|
||||
|
||||
virtual Pos
|
||||
firstResult ()
|
||||
{
|
||||
UNIMPLEMENTED ("start iteration");
|
||||
}
|
||||
|
||||
virtual void
|
||||
nextResult (Pos& pos)
|
||||
{
|
||||
UNIMPLEMENTED ("iteration step");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public:
|
||||
TestSource (uint num)
|
||||
{
|
||||
UNIMPLEMENTED ("dedicated IterSource implementation");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue