WIP implement scope content enumeration
unresolved problem with TransformIter yielding a reference
This commit is contained in:
parent
9f09a8aa49
commit
4afa1ada5b
2 changed files with 61 additions and 9 deletions
|
|
@ -53,6 +53,7 @@
|
||||||
#include <boost/functional/hash.hpp>
|
#include <boost/functional/hash.hpp>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <tr1/unordered_map>
|
#include <tr1/unordered_map>
|
||||||
|
#include <tr1/functional>
|
||||||
#include <tr1/memory>
|
#include <tr1/memory>
|
||||||
//#include <algorithm>
|
//#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -68,6 +69,9 @@ namespace session {
|
||||||
using std::tr1::unordered_map;
|
using std::tr1::unordered_map;
|
||||||
using std::tr1::unordered_multimap;
|
using std::tr1::unordered_multimap;
|
||||||
using lib::TypedAllocationManager;
|
using lib::TypedAllocationManager;
|
||||||
|
// using std::tr1::placeholders::_1;
|
||||||
|
using std::tr1::function;
|
||||||
|
using std::tr1::bind;
|
||||||
//using util::contains;
|
//using util::contains;
|
||||||
//using std::string;
|
//using std::string;
|
||||||
//using std::map;
|
//using std::map;
|
||||||
|
|
@ -106,8 +110,11 @@ namespace session {
|
||||||
};
|
};
|
||||||
|
|
||||||
// using a hashtables to implement the index
|
// using a hashtables to implement the index
|
||||||
typedef unordered_map<ID, PlacementEntry, hash<ID> > IDTable;
|
typedef PlacementMO::ID PID;
|
||||||
typedef std::tr1::unordered_multimap<ID,ID, hash<ID> > ScopeTable;
|
typedef unordered_map<PID, PlacementEntry, hash<PID> > IDTable;
|
||||||
|
typedef std::tr1::unordered_multimap<PID,PID, hash<PID> > ScopeTable;
|
||||||
|
|
||||||
|
typedef pair<ScopeIter, ScopeIter> ScopeContents;
|
||||||
|
|
||||||
|
|
||||||
TypedAllocationManager allocator_;
|
TypedAllocationManager allocator_;
|
||||||
|
|
@ -168,6 +175,15 @@ namespace session {
|
||||||
return *scope;
|
return *scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlacementIndex::iterator
|
||||||
|
queryScopeContents (ID id) const
|
||||||
|
{
|
||||||
|
REQUIRE (contains (id));
|
||||||
|
ScopeContents contents = scopeTab_.equal_range (id);
|
||||||
|
return iterator (ScopeRangeIter(contents.first, contents.second)
|
||||||
|
,rangeIndexElementsResolver() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -229,6 +245,7 @@ namespace session {
|
||||||
PPlacement newEntry = allocator_.create<PlacementMO> (newObj);
|
PPlacement newEntry = allocator_.create<PlacementMO> (newObj);
|
||||||
ID newID = newEntry->getID();
|
ID newID = newEntry->getID();
|
||||||
|
|
||||||
|
ASSERT (newID, "invalid");
|
||||||
ASSERT (!contains (newID));
|
ASSERT (!contains (newID));
|
||||||
placementTab_[newID].element = newEntry;
|
placementTab_[newID].element = newEntry;
|
||||||
placementTab_[newID].scope = placementTab_[scopeID].element;
|
placementTab_[newID].scope = placementTab_[scopeID].element;
|
||||||
|
|
@ -301,6 +318,34 @@ namespace session {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Helper for building a scope exploring iterator
|
||||||
|
* for PlacementIndex: our "reverse index" (scopeTab_)
|
||||||
|
* tracks the contents of each scope as pairs (scopeID,elementID).
|
||||||
|
* After fetching the range of matching entries, whenever the client
|
||||||
|
* dereferences the iterator, we have to pick up the second ID and
|
||||||
|
* resolve it through the main index table (placementTab_).
|
||||||
|
*/
|
||||||
|
PlacementMO&
|
||||||
|
resolveScopeIndexElement(pair<PID,PID> const& entry)
|
||||||
|
{
|
||||||
|
ID elemID (entry.second);
|
||||||
|
ASSERT (contains (elemID));
|
||||||
|
return fetch (elemID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef function<PlacementMO& (pair<PID,PID> const&)> ElementResolver;
|
||||||
|
mutable ElementResolver elementResolver_;
|
||||||
|
|
||||||
|
ElementResolver
|
||||||
|
scopeIndexElementsResolver() const ///< @return functor for iterator element access
|
||||||
|
{
|
||||||
|
if (!elementResolver_)
|
||||||
|
elementResolver_ = bind (&Table::resolveScopeIndexElement, this, _1 );
|
||||||
|
return elementResolver_;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -370,13 +415,19 @@ namespace session {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Retrieve all the elements attached to the given entry (scope)
|
||||||
|
* Each element (Placement) can act as a scope, containing other
|
||||||
|
* Placements, which will be discovered by this query one level
|
||||||
|
* deep (not recursive).
|
||||||
|
* @return an Lumiera Forward Iterator, yielding the children,
|
||||||
|
* possibly empty if the denoted element is a leaf.
|
||||||
|
* @note results are returned in arbitrary order (hashtable)
|
||||||
|
*/
|
||||||
PlacementIndex::iterator
|
PlacementIndex::iterator
|
||||||
PlacementIndex::getReferrers (ID) const
|
PlacementIndex::getReferrers (ID id) const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED ("query the Placement relation index and retrieve all other placements bound to this one by a placement-relation");
|
__check_knownID(*this, id);
|
||||||
// do a query using equal_range of the hashtable (unordered_multimap)
|
return pTab_->queryScopeContents(id);
|
||||||
// build a RangeIter from them
|
|
||||||
// use this to build an auto-fetching IterAdapter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ namespace session {
|
||||||
|
|
||||||
|
|
||||||
typedef PlacementMO::ID _PID;
|
typedef PlacementMO::ID _PID;
|
||||||
typedef std::tr1::unordered_multimap<_PID,_PID>::iterator ScopeIter;
|
typedef std::tr1::unordered_multimap<_PID,_PID>::const_iterator ScopeIter;
|
||||||
|
typedef lib::RangeIter<ScopeIter> ScopeRangeIter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -107,7 +108,7 @@ namespace session {
|
||||||
typedef PlacementRef<MObject> PRef;
|
typedef PlacementRef<MObject> PRef;
|
||||||
typedef PlacementMO::ID const& ID;
|
typedef PlacementMO::ID const& ID;
|
||||||
|
|
||||||
typedef lib::TransformIter<lib::RangeIter<ScopeIter>, PlacementMO> iterator;
|
typedef lib::TransformIter<ScopeRangeIter, PlacementMO&> iterator;
|
||||||
|
|
||||||
|
|
||||||
PlacementMO& find (ID) const;
|
PlacementMO& find (ID) const;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue