1 #ifndef LCRTRelations_H
2 #define LCRTRelations_H 1
15 namespace lcrtrel_helper{
45 T* vec =
static_cast<T*
>(v) ;
46 for(
typename T::iterator it = vec->begin();it != vec->end(); ++it){
65 template <
class U,
class T ,
class I,
class D,
bool b>
97 template <
class U,
class T ,
class I=SimplePtrInit,
class D=NoDelete ,
bool b=1>
110 template <
class U,
class T ,
class I=CreationPtrInit<T>,
class D=DeletePtr<T> ,
bool b=1>
127 template <
class U,
class T>
133 template <
class U,
class T>
136 CreationPtrInit< std::list<T*> > ,
137 DeletePtr<std::list<T*> > ,false > {};
147 template <
class From,
class To>
155 template <
bool is_container>
158 template <
class T,
class S>
159 inline static void add( T t, S s) { t->push_back( s ) ; }
161 template <
class T,
class S>
162 inline static void remove( T t, S s) { t->remove( s ) ; }
170 template <
class T,
class S>
171 inline static void add( T& t, S s) { t = s ; }
173 template <
class T,
class S>
174 inline static void remove( T& t, S ) { t = 0 ; }
184 using namespace lcrtrel_helper ;
190 template <
class U,
typename T>
198 template <
class U,
typename T>
203 template <
class U,
class T>
206 CreationPtrInit< std::vector<T*> > ,
207 DeletePtr<std::vector<T*> > > {};
213 template <
class U,
class T>
216 CreationPtrInit< std::vector<T*> > ,
217 DeleteElements< std::vector<T*> > > {};
221 template <
class U,
class T>
224 CreationPtrInit< std::list<T*> > ,
225 DeletePtr<std::list<T*> > > {};
230 template <
class U,
class T>
233 CreationPtrInit< std::list<T*> > ,
234 DeleteElements< std::list<T*> > > {};
238 template <
class U,
class From,
class To>
241 RelationOneSide<ToRelation<U>,To> > {
246 template <
class U,
class From,
class To>
249 RelationManySide<ToRelation<U>,To> > {
253 template <
class U,
class From,
class To>
256 RelationManySide<ToRelation<U>,To> > {
267 static const int allowed_to_call_ext = 1 ;
295 #else // use double on 64bit systems
300 static const int allowed_to_call_ext = 1 ;
326 static const int allowed_to_call_ext = 1 ;
350 class LCRTRelations ;
359 typename R::to::obj_ptr t) ;
369 typename R::to::obj_ptr t) ;
375 typename R::to::obj_ptr t) ;
388 typename R::from::obj_ptr f2) ;
475 typename R::to::obj_ptr t);
481 typename R::to::obj_ptr t) ;
484 typename R::to::obj_ptr t) ;
490 typename R::from::obj_ptr f2) ;
504 inline typename V::ext_type
ext() {
514 inline const typename V::ext_type
ext()
const {
524 inline typename V::rel_type
rel() {
532 typename V::ptr &
ptr()
const {
538 if( iter != _extensionMap.end() ) {
543 userExtension = std::make_shared<V>();
544 ext_map::value_type element(
548 iter = _extensionMap.insert( element ).first;
550 if(
nullptr == userExtension ) {
553 return userExtension->pointer();
570 LCRTRelations* t = f->LCRTRelations::template rel<typename R::to>() ;
573 t->LCRTRelations::ptr<
typename R::from>() = 0 ;
575 f->LCRTRelations::template ptr<typename R::to>() = 0 ;
580 void set_relation(
typename R::from::obj_ptr f,
typename R::to::obj_ptr t){
583 unset_relation<R>( f ) ;
584 unset_relation<R>(t->LCRTRelations::template rel<typename R::from>() ) ;
586 f->LCRTRelations::template ptr<typename R::to>() = t ;
587 t->LCRTRelations::template ptr<typename R::from>() = f ;
595 typename R::to::obj_ptr t){
597 f->LCRTRelations::template ptr<typename R::to>()->push_back( t ) ;
608 typename R::to::obj_ptr t ) {
610 f->LCRTRelations::template ptr<typename R::to>()->
remove( t ) ;
619 typename R::to::ptr cl = f->LCRTRelations::template ptr<typename R::to>() ;
621 for(
typename R::to::iterator it = cl->begin(); it!=cl->end(); ++it){
631 typename R::from::obj_ptr f2 ) {
633 typename R::to::ptr lt2 = f2->LCRTRelations::template ptr<typename R::to>() ;
635 for(
typename R::to::iterator it = lt2->begin() ;it != lt2->end() ; it++ ){
641 f1->LCRTRelations::template ptr<typename R::to>()->merge( *lt2 ) ;
Factory for objects of type T.
Base exception class for LCIO - all other exceptions extend this.
ptr & pointer()
Extension data access.
void unset_relation(typename R::from::obj_ptr f)
Unset the 1-to-1 relation from f.
static void clean(void *)
void set_relation(typename R::from::obj_ptr f, typename R::to::obj_ptr t)
Set the 1-to-1 relation between two objects - prexisting inconsistent relations involving the two obj...
static void add(T &t, S s)
V::rel_type rel()
Provides read access to relations - the object types and their connectivity are defined by the class ...
Delete function for pointers w/ ownership.
Helper class for biderectional relations provides the to and from type.
ptr & pointer()
Extension data access.
LCBaseTraits< U, T, I, D, b > base
Delete function for containers of owned objects.
V::ptr & ptr() const
Returns the reference to the pointer to the extension/relation object.
static const int allowed_to_call_ext
void merge_relations(typename R::from::obj_ptr f1, typename R::from::obj_ptr f2)
Merge the relations from f2 to f1 - after this call f1 will hold all the relations and f2 will be emp...
Base class that provides run time (user) extensions and relation between objects. ...
static const bool is_container
LCBaseTraits< U, T, I, D, b > & operator=(const LCBaseTraits &)=delete
Helper class for relations.
Helper class for relations.
Function pointer for delete function.
void remove_relation(typename R::from::obj_ptr f, typename R::to::obj_ptr t)
Remove the link from from f to t from the N-to-N relation ship.
void remove_relations(typename R::from::obj_ptr f)
Removes all relations from the given object.
Base class for all extensions and relations of single objects.
T static_pointer_cast(T...args)
Helper class for relations.
Map of pointers to extension obbjects.
ptr & pointer()
Extension data access.
Simple Extension - pointer to an object of type T where the ownership is taken over by the object hol...
V::ext_type ext()
Provides access to an extension object - the type and ownership is defined by the class V which shoul...
Special Extension that allows to write int extensions directly (not through a pointer !)...
Empty delete function for pointers w/o ownership.
static void clean(void *v)
LCBaseTraits< U, T, I, D, b > base
static void remove(T t, S s)
Base class for all containers of extensions and relations, vectors, lists,...
void add_relation(typename R::from::obj_ptr f, typename R::to::obj_ptr t)
Add a link from f to t to an N-to-N relation ship.
std::type_index ext_index
static const bool is_container
static void clean(void *v)
ptr & pointer()
Extension data access.
Extension list holding pointers to objects of type T - ownership of the objects is taken...
Extension vector holding pointers to objects of type T - ownership of the objects is taken...
One to one relation between two objects of type From and To.
Extension vector holding pointers to objects of type T - no ownership of the objects is taken...
static void add(T t, S s)
const V::ext_type ext() const
Provides access to an extension object - the type and ownership is defined by the class V which shoul...
T::const_iterator const_iterator
One to many relation between one object of type From to many objects of type To.
Helper functions that treat single objects and containers.
std::shared_ptr< void > ext_type
Many to many relation between objects of type From to objects of type To.
Extension list holding pointers to objects of type T - no ownership of the objects is taken...
std::map< ext_index, ext_type > ext_map
Simple Extension - pointer to an object of type T.
Helper class for relations.