Commit in lcio/src/cpp/include on MAIN
LCRTRelations.h+51-81.1 -> 1.2
added LC1ToNRelations

lcio/src/cpp/include
LCRTRelations.h 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- LCRTRelations.h	27 Nov 2006 09:57:42 -0000	1.1
+++ LCRTRelations.h	28 Nov 2006 13:35:46 -0000	1.2
@@ -154,6 +154,13 @@
   public LCRelationTraits<LCLinkTraits<FromRelation<U>,From>,
 			  LCLinkTraits<ToRelation<U>,To> > {} ; 
 
+
+template <class U, class From, class To>
+struct LC1ToNRelation : 
+  public LCRelationTraits<LCLinkTraits<FromRelation<U>,From>,
+			  LCLinkListTraits<ToRelation<U>,To> > {
+} ; 
+
 template <class U, class From, class To>
 struct LCNToNRelation : 
   public LCRelationTraits<LCLinkListTraits<FromRelation<U>,From>,
@@ -226,7 +233,6 @@
   template <class R> 
   friend void unset_relation(typename R::from_traits::value_type f );
 
-
   template <class R> 
   friend void add_relation( typename R::from_traits::value_type f, 
 		     typename R::to_traits::value_type t) ;
@@ -349,21 +355,50 @@
 }
 
 
+template <bool is_container>
+struct helper{
+
+  template <class T, class S>
+  inline static void add( T t, S s) { t.push_back( s )  ; }
+
+  template <class T, class S>
+  inline static void remove( T t, S s) { t.remove( s )  ; }
+};
+
+template <>
+struct helper<false>{
+
+  template <class T, class S> 
+  inline static void add( T& t, S s) { 
+
+    t = s ; 
+//     std::cout << " assigning " << s << " to " << t << std::endl ;
+  }
+
+  template <class T, class S>
+  inline static void remove( T& t, S s) { t = 0 ; }
+};
+
 template <class R> 
 void add_relation(  typename R::from_traits::value_type f, 
 		    typename R::to_traits::value_type t){
 
   f->LCRTRelations::access_to<R>().push_back( t ) ;
-  t->LCRTRelations::access_from <R>().push_back( f ) ;
+
+//   std::cout << " ask to assign " << f << " to " << t << std::endl ;
+  helper<R::from_traits::is_container>::add( t->LCRTRelations::access_from<R>() , f ) ; 
 }
 
 
+
+
 template <class R> 
 void remove_relation( typename R::from_traits::value_type f, 
 		      typename R::to_traits::value_type t ) {
   
   f->LCRTRelations::access_to<R>().remove( t ) ;
-  t->LCRTRelations::access_from<R>().remove( f ) ;
+
+  helper<R::from_traits::is_container>::remove( t->LCRTRelations::access_from <R>() , f ) ; 
 }
 
 
@@ -374,7 +409,11 @@
   
   for( typename R::to_traits::iterator it = cl.begin(); it!=cl.end(); ++it){
     
-    (*it)->LCRTRelations::access_from<R>().remove( f ) ;
+
+//     (*it)->LCRTRelations::access_from<R>().remove( f ) ;
+
+    helper<R::from_traits::is_container>::remove((*it)->LCRTRelations::access_from <R>() , f ) ; 
+
   }
   cl.clear() ;
 }
@@ -387,14 +426,18 @@
   
   for( typename R::to_traits::iterator it = lt2.begin() ;it !=  lt2.end() ; it++ ){
     
-    typename R::from_traits::ref  lf2 = (*it)->LCRTRelations::access_from<R>() ;
+    typename R::from_traits::value_type  lf2 = (*it)->LCRTRelations::access_from<R>() ;
     
-    lf2.remove( f2 )  ;
+//     lf2.remove( f2 )  ;
+
+    helper<R::from_traits::is_container>::remove( lf2, f2 ) ; 
     
-    lf2.push_back( f1 ) ;
+//     lf2.push_back( f1 ) ;
+
+    helper<R::from_traits::is_container>::add( lf2, f1 ) ; 
   }
 
-  typename R::from_traits::ref  lt1 = f1->LCRTRelations::access_to<R>() ;
+  typename R::to_traits::ref  lt1 = f1->LCRTRelations::access_to<R>() ;
   
   lt1.merge( lt2 ) ;
 }
CVSspam 0.2.8