2009-05-09 03:08:38 +02:00
|
|
|
/*
|
|
|
|
|
PLACEMENT-INDEX.hpp - tracking individual Placements and their relations
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-11-13 04:52:48 +01:00
|
|
|
/** @file placement-index.hpp
|
|
|
|
|
** Key interface of the session implementation datastructure.
|
|
|
|
|
** The PlacementIndex is attached to and controlled by the SessionImpl.
|
|
|
|
|
** Client code is not intended to interface directly to this API. Even
|
|
|
|
|
** Proc-Layer internal facilities use the session datastructure through
|
|
|
|
|
** SessionServices. Embedded within the implementation of PlacementIndex
|
|
|
|
|
** is a flat table structure holding all the Placement instances \em contained
|
|
|
|
|
** in the session. Any further structuring exists on the logical level only.
|
|
|
|
|
**
|
|
|
|
|
** \par PlacementIndex, PlacementRef and MObjectRef
|
|
|
|
|
** TODO
|
|
|
|
|
**
|
|
|
|
|
** \par Querying and contents discovery
|
|
|
|
|
** TODO
|
2009-05-09 03:08:38 +02:00
|
|
|
**
|
2009-05-09 17:32:29 +02:00
|
|
|
** @see PlacementRef
|
|
|
|
|
** @see PlacementIndex_test
|
2009-05-09 03:08:38 +02:00
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-09 17:32:29 +02:00
|
|
|
#ifndef MOBJECT_PLACEMENT_INDEX_H
|
|
|
|
|
#define MOBJECT_PLACEMENT_INDEX_H
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
//#include "pre.hpp"
|
|
|
|
|
//#include "proc/mobject/session/locatingpin.hpp"
|
|
|
|
|
//#include "proc/asset/pipe.hpp"
|
2009-06-09 09:05:19 +02:00
|
|
|
#include "lib/util.hpp"
|
2009-06-06 07:12:09 +02:00
|
|
|
#include "lib/factory.hpp"
|
2009-11-13 04:52:48 +01:00
|
|
|
#include "lib/itertools.hpp"
|
2009-05-20 03:36:12 +02:00
|
|
|
#include "proc/mobject/placement.hpp"
|
2009-05-13 03:46:08 +02:00
|
|
|
#include "proc/mobject/placement-ref.hpp"
|
2009-05-09 03:08:38 +02:00
|
|
|
|
2009-05-20 03:36:12 +02:00
|
|
|
#include <tr1/memory>
|
2009-11-12 20:15:52 +01:00
|
|
|
#include <tr1/unordered_map>
|
2009-06-06 07:12:09 +02:00
|
|
|
#include <boost/noncopyable.hpp>
|
2009-05-20 03:36:12 +02:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2009-05-13 03:46:08 +02:00
|
|
|
#include <vector>
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
|
2009-11-06 19:27:53 +01:00
|
|
|
namespace mobject {
|
|
|
|
|
|
|
|
|
|
class MObject;
|
|
|
|
|
|
|
|
|
|
namespace session {
|
2009-06-09 09:05:19 +02:00
|
|
|
|
2009-11-27 02:43:09 +01:00
|
|
|
LUMIERA_ERROR_DECLARE (NOT_IN_SESSION); ///< referring to a Placement not known to the current session
|
|
|
|
|
|
|
|
|
|
|
2009-09-30 00:27:14 +02:00
|
|
|
using lib::factory::RefcountFac;
|
2009-05-20 03:36:12 +02:00
|
|
|
using std::tr1::shared_ptr;
|
|
|
|
|
using boost::scoped_ptr;
|
2009-06-09 09:05:19 +02:00
|
|
|
|
2009-11-13 04:52:48 +01:00
|
|
|
|
|
|
|
|
class PlacementIndex;
|
|
|
|
|
typedef shared_ptr<PlacementIndex> PPIdx;
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
/**
|
2009-11-13 04:52:48 +01:00
|
|
|
* Structured compound of Placement instances
|
|
|
|
|
* with lookup capabilities. Core of the session datastructure.
|
|
|
|
|
* Adding a Placement creates a separate instance within this network,
|
|
|
|
|
* owned and managed by the backing implementation. All placements are
|
|
|
|
|
* related in a tree-like hierarchy of scopes, where each Placement is
|
|
|
|
|
* within the scope of a parent Placement. There is an additional
|
|
|
|
|
* reverse index, allowing to find the immediate children of any
|
|
|
|
|
* given Placement efficiently. All lookup is based on the
|
|
|
|
|
* Placement's hash-IDs.
|
2009-05-09 03:08:38 +02:00
|
|
|
*/
|
2009-05-09 17:32:29 +02:00
|
|
|
class PlacementIndex
|
2009-11-13 04:52:48 +01:00
|
|
|
: boost::noncopyable
|
2009-05-09 03:08:38 +02:00
|
|
|
{
|
2009-05-20 03:36:12 +02:00
|
|
|
class Table;
|
|
|
|
|
|
|
|
|
|
scoped_ptr<Table> pTab_;
|
|
|
|
|
|
2009-11-12 20:15:52 +01:00
|
|
|
|
2009-11-13 04:52:48 +01:00
|
|
|
typedef PlacementMO::ID _PID;
|
|
|
|
|
typedef std::tr1::unordered_multimap<_PID,_PID>::iterator ScopeIter;
|
|
|
|
|
|
2009-11-12 20:15:52 +01:00
|
|
|
|
|
|
|
|
|
2009-05-20 03:36:12 +02:00
|
|
|
public:
|
|
|
|
|
typedef Placement<MObject> PlacementMO;
|
2009-06-02 03:31:52 +02:00
|
|
|
typedef PlacementRef<MObject> PRef;
|
2009-06-09 09:05:19 +02:00
|
|
|
typedef PlacementMO::ID const& ID;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
2009-11-13 04:52:48 +01:00
|
|
|
typedef lib::TransformIter<lib::RangeIter<ScopeIter>, PlacementMO> iterator;
|
2009-11-01 03:47:35 +01:00
|
|
|
|
2009-06-06 07:12:09 +02:00
|
|
|
|
2009-05-20 03:36:12 +02:00
|
|
|
PlacementMO& find (ID) const;
|
|
|
|
|
|
|
|
|
|
template<class MO>
|
2009-06-02 03:31:52 +02:00
|
|
|
Placement<MO>& find (PlacementMO::Id<MO>) const;
|
|
|
|
|
template<class MO>
|
2009-11-01 03:47:35 +01:00
|
|
|
Placement<MO>& find (PlacementRef<MO> const&) const;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
PlacementMO& getScope (PlacementMO const&) const;
|
|
|
|
|
PlacementMO& getScope (ID) const;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
2009-11-12 20:15:52 +01:00
|
|
|
iterator getReferrers (ID) const;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** retrieve the logical root scope */
|
2009-06-09 09:05:19 +02:00
|
|
|
PlacementMO& getRoot() const;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
size_t size() const;
|
|
|
|
|
bool contains (PlacementMO const&) const;
|
|
|
|
|
bool contains (ID) const;
|
2009-05-20 03:36:12 +02:00
|
|
|
|
2009-11-12 02:15:02 +01:00
|
|
|
|
2009-10-29 04:32:00 +01:00
|
|
|
|
|
|
|
|
|
2009-05-20 03:36:12 +02:00
|
|
|
/* == mutating operations == */
|
|
|
|
|
|
2009-11-27 02:03:20 +01:00
|
|
|
ID insert (PlacementMO const& newObj, PlacementMO const& targetScope);
|
2009-05-20 03:36:12 +02:00
|
|
|
bool remove (PlacementMO&);
|
|
|
|
|
bool remove (ID);
|
2009-06-06 07:12:09 +02:00
|
|
|
|
|
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
typedef RefcountFac<PlacementIndex> Factory;
|
2009-06-06 07:12:09 +02:00
|
|
|
|
|
|
|
|
static Factory create;
|
|
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
~PlacementIndex();
|
|
|
|
|
|
2009-10-16 03:13:57 +02:00
|
|
|
void clear();
|
|
|
|
|
|
2009-06-06 07:12:09 +02:00
|
|
|
protected:
|
|
|
|
|
PlacementIndex() ;
|
2009-06-09 09:05:19 +02:00
|
|
|
|
2009-09-30 00:27:14 +02:00
|
|
|
friend class lib::factory::Factory<PlacementIndex, lib::factory::Wrapper<PlacementIndex, shared_ptr<PlacementIndex> > >;
|
2009-05-09 03:08:38 +02:00
|
|
|
};
|
|
|
|
|
|
2009-11-13 04:52:48 +01:00
|
|
|
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* === forwarding implementations of the templated API === */
|
|
|
|
|
|
|
|
|
|
template<class MO>
|
|
|
|
|
inline Placement<MO>&
|
|
|
|
|
PlacementIndex::find (PlacementMO::Id<MO> id) const
|
|
|
|
|
{
|
|
|
|
|
PlacementMO& result (find (id));
|
|
|
|
|
REQUIRE (INSTANCEOF (MO, &result) );
|
|
|
|
|
return static_cast<Placement<MO>&> (result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class MO>
|
|
|
|
|
inline Placement<MO>&
|
|
|
|
|
PlacementIndex::find (PlacementRef<MO> const& pRef) const
|
|
|
|
|
{
|
|
|
|
|
PlacementMO::Id<MO> id (pRef);
|
|
|
|
|
return find (id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Placement<MObject>&
|
|
|
|
|
PlacementIndex::getScope (PlacementMO const& p) const
|
|
|
|
|
{
|
|
|
|
|
return getScope(p.getID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
|
PlacementIndex::contains (PlacementMO const& p) const
|
|
|
|
|
{
|
|
|
|
|
return contains (p.getID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
|
PlacementIndex::remove (PlacementMO& p)
|
|
|
|
|
{
|
|
|
|
|
return remove (p.getID());
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-06 07:12:09 +02:00
|
|
|
|
|
|
|
|
|
2009-11-06 19:27:53 +01:00
|
|
|
}} // namespace mobject::session
|
2009-05-09 03:08:38 +02:00
|
|
|
#endif
|