]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkAny.h
3480 Bug typeid in Macos
[bbtk.git] / kernel / src / bbtkAny.h
index 71edc872f423209239dde51d298720b0329c72b0..9f161c97f08842ef35765a38323c2988d455fc06 100644 (file)
@@ -311,7 +311,13 @@ namespace bbtk
     template<typename Type>
     inline bool contains()
     {
-      return ( type() == typeid(Type) );
+//EED 2021-12-15 typeid comparation is not working in MacOs for objects declared  in different libraries
+// ex: itk <-> vtk templates convertion
+#if defined(MACOSX)
+             if ( strcmp( type().name()  , typeid(Type).name() ) ==0 ) return true; else return false;
+#else
+             return ( type() == typeid(Type) );
+#endif
     }
 
     /// Returns true iff the contained type is a pointer
@@ -323,7 +329,14 @@ namespace bbtk
     /// Returns true iff the contained type is t
     inline bool contains(TypeInfo t)
     {
-      return ( (bool)((type() == t)!=0) );
+//EED 2021-12-15 typeid comparation is not working in MacOs for objects declared  in different libraries
+// ex: itk <-> vtk templates convertion
+#if defined(MACOSX)
+        bool compTmp = (strcmp( type().name()  , t.name() ) == 0);
+        return ( compTmp!=0 );
+#else
+        return ( (bool)((type() == t)!=0) );
+#endif
      }
 
     /// Returns true iff any of type ValueType can be held 
@@ -344,14 +357,13 @@ namespace bbtk
                         <<"> with content : "
                         <<HumanTypeName(type())<<std::endl);
 
-        printf("EED bbtkAny get()   self=%s \n" , HumanTypeName<self >().c_str() );
-        printf("EED bbtkAny get()   ValueType=%s \n" , bbtk::HumanTypeName<ValueType>().c_str() );
-        printf("EED bbtkAny get()   Type=%s \n" , bbtk::HumanTypeName<>(type()).c_str()  );
-        printf("EED bbtkAny get()   type name=(-%s-) \n" , type().name()  );
-        printf("EED bbtkAny get()   ValueType name=(-%s-) \n" , typeid(ValueType).name()  );
-// 2021-12-15
-        if ( strcmp( type().name()  , typeid(ValueType).name() ) ==0 )
-//        if ( type() == typeid(ValueType) )
+//EED 2021-12-15 typeid comparation is not working in MacOs for objects declared  in different libraries
+// ex: itk <-> vtk templates convertion
+#if defined(MACOSX)
+    if ( strcmp( type().name()  , typeid(ValueType).name() ) ==0 )
+#else
+    if ( type() == typeid(ValueType) )
+#endif
         {
             return static_cast< anyholder<ValueType> *>(content)->held;
         }
@@ -366,7 +378,13 @@ namespace bbtk
     template<typename ValueType>
     inline const ValueType* getP() const
     {
+//EED 2021-12-15 typeid comparation is not working in MacOs for objects declared  in different libraries
+// ex: itk <-> vtk templates convertion
+#if defined(MACOSX)
+      if ( strcmp( type().name()  , typeid(ValueType).name() ) ==0 )
+#else
       if ( type() == typeid(ValueType) )
+#endif
        return &static_cast< anyholder<ValueType> *>(content)->held;
  
       bbtkError(HumanTypeName<self >()