]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkData.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkData.h
index f473a027fac93f1e7fbf8594d92b0cdf70c3083b..9b93b57bbc5b9b94f9b6330f864c62e3eaadb110 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkData.h,v $
   Language:  C++
-  Date:      $Date: 2008/01/22 15:02:00 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/04/08 06:59:30 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
 =========================================================================*/
 /**
  *\file
- *\brief  Defines Data and TypeInfo 
+ *\brief  Defines Data and DataInfo 
  * 
  * Data is bbtk general type exchanged between black boxes (adapted from boost::any).
- * TypeInfo is the bbtk type of object storing informations on a data type (typedef on std::type_info). 
+ * DataInfo is the bbtk type of object storing informations on a data type : includes C++ type info (std::type_info) and a string describing the "nature" of the data (what is the content of the structure). 
  */
 
 #ifndef __bbtkData_h__
 #define __bbtkData_h__
 
-//#include "bbtkSystem.h"
-//#include "bbtkMessageManager.h"
-//#include <string>
-//#include <typeinfo>
-
-//#include "bbtkany.h"
-
-//#include "bbtkReferenceCountedObject.h"
 
 #include "bbtkAny.h"
+#include "bbtkRTTI.h"
 
 namespace bbtk
 {
   
+  /// The generic type of "data" exchanged between black boxes
   typedef any<thing> Data;
 
-  /*
-
-  /// Can transport any kind of data (adaptation of boost::any)
-    class Data
-    {
-    public: // structors
-
-        Data()
-          : content(0)
-        {
-        }
-
-        template<typename ValueType>
-        Data(const ValueType & value)
-          : content(new holder<ValueType>(value))
-        {
-        }
-
-        Data(const Data & other)
-          : content(other.content ? other.content->clone() : 0)
-        {
-        }
-
-        ~Data()
-        {
-            delete content;
-        }
-
-    public: // modifiers
-
-        Data & swap(Data & rhs)
-        {
-            std::swap(content, rhs.content);
-            return *this;
-        }
-
-        template<typename ValueType>
-        Data & operator=(const ValueType & rhs)
-        {
-            Data(rhs).swap(*this);
-            return *this;
-        }
-
-        Data & operator=(const Data & rhs)
-        {
-            Data(rhs).swap(*this);
-            return *this;
-        }
-
-    public: // queries
-
-        bool empty() const
-        {
-            return !content;
-        }
-
-        const std::type_info & type() const
-        {
-            return content ? content->type() : typeid(void);
-        }
-
-#ifndef BBTK_NO_MEMBER_TEMPLATE_FRIENDS
-    private: // types
-#else
-    public: // types (public so Data_cast can be non-friend)
-#endif
-
-        class placeholder
-        {
-        public: // structors
-
-            virtual ~placeholder()
-            {
-            }
-
-        public: // queries
-
-            virtual const std::type_info & type() const = 0;
-
-            virtual placeholder * clone() const = 0;
-
-        };
-
-        template<typename ValueType>
-        class holder : public placeholder
-        {
-        public: // structors
-
-            holder(const ValueType & value)
-              : held(value)
-            {
-            }
-
-        public: // queries
+  /// Object storing informations on a data type : includes C++ type info (std::type_info) and a string describing the "nature" of the data (what is the content of the structure)
+  class DataInfo
+  {
+  public:
+    DataInfo( TypeInfo type, const std::string& nature="") 
+      : mType(type), mNature(nature)
+    {}
 
-            virtual const std::type_info & type() const
-            {
-                return typeid(ValueType);
-            }
+    ~DataInfo() {}
 
-            virtual placeholder * clone() const
-            {
-                return new holder(held);
-            }
+    TypeInfo GetType() const { return mType; }
+    const std::string& GetNature() const { return mNature; }
 
-        public: // representation
-
-            ValueType held;
-
-        };
-
-#ifndef BBTK_NO_MEMBER_TEMPLATE_FRIENDS
-
-    private: // representation
-
-      //       template<typename ValueType>
-      //       friend ValueType * Data_cast(Data *);
-
-        template<typename ValueType>
-        friend ValueType * unsafe_Data_cast(Data *);
  
-        template<typename ValueType>
-        friend ValueType  unsafe_Data_cast(Data &);
-
-#else
-
-    public: // representation (public so Data_cast can be non-friend)
-
-#endif
-
-        placeholder * content;
-
-    };
+    /// Equality
+    bool operator== ( const DataInfo& k ) const
+      {
+       return ( (mType == k.mType)  &&
+                (mNature == k.mNature) );
+      }
+    /// Comparison
+    bool operator< ( const DataInfo& k ) const
+      {
+       return ( ( mType.before(k.mType) ) ||
+                ( ( mType == k.mType ) &&
+                  ( mNature.compare(k.mNature) < 0 ) ) );
+      }
+
+
+  private:
+    DataInfo() : mType(typeid(void)), mNature("") {}
+    TypeInfo mType;
+    std::string mNature;
+
+  };
 
-    class bad_Data_cast : public std::bad_cast
-    {
-    public:
-        virtual const char * what() const throw()
-        {
-            return "bbtk::bad_Data_cast: "
-                   "failed conversion using bbtk::Data_cast";
-        }
-    };
-  */
-  /*
-    template<typename ValueType>
-    ValueType * Data_cast(Data * operand)
-    {
-        return operand && operand->type() == typeid(ValueType)
-                    ? &static_cast<Data::holder<ValueType> *>(operand->content)->held
-                    : 0;
-    }
-
-    template<typename ValueType>
-    const ValueType * Data_cast(const Data * operand)
-    {
-        return Data_cast<ValueType>(const_cast<Data *>(operand));
-    }
-
-// Removed Data_cast
-    template<typename ValueType>
-    ValueType Data_cast(const Data & operand)
-    {
-        typedef BBTK_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-
-#ifdef BBTK_NO_TEMPLATE_PARTIAL_SPECIALIZATION
-        // If 'nonref' is still reference type, it means the user has not
-        // specialized 'remove_reference'.
-
-        // Please use BBTK_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro
-        // to generate specialization of remove_reference for your class
-        // See type traits library documentation for details
-        BBTK_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
-
-        const nonref * result = Data_cast<nonref>(&operand);
-        if(!result)
-            bbtk::throw_exception(bad_Data_cast());
-        return *result;
-    }
-
-    template<typename ValueType>
-    ValueType Data_cast(Data & operand)
-    {
-        typedef BBTK_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-
-#ifdef BBTK_NO_TEMPLATE_PARTIAL_SPECIALIZATION
-        // The comment in the above version of 'Data_cast' explains when this
-        // assert is fired and what to do.
-        BBTK_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
-
-        nonref * result = Data_cast<nonref>(&operand);
-        if(!result)
-            bbtk::throw_exception(bad_Data_cast());
-        return *result;
-    }
-  */
-    // Note: The "unsafe" versions of Data_cast are not part of the
-    // public interface and may be removed at Data time. They are
-    // required where we know what type is stored in the Data and can't
-    // use typeid() comparison, e.g., when our types may travel across
-    // different shared libraries.
-    // LG : This is precisely our case !
-  /*
-    template<typename ValueType>
-    inline ValueType * unsafe_Data_cast(Data * operand)
-    {
-        return &static_cast<Data::holder<ValueType> *>(operand->content)->held;
-    }
-
-    template<typename ValueType>
-    inline const ValueType * unsafe_Data_cast(const Data * operand)
-    {
-        return unsafe_Data_cast<ValueType>(const_cast<Data *>(operand));
-    }
+  
+  /// dump in a stream
+  inline std::ostream& operator<<(std::ostream& s, const DataInfo& d) 
+  {
+    s << "<" << TypeName(d.GetType()) << "("<< d.GetNature()<<")>";
+    return s;
+  }
 
-    template<typename ValueType>
-    inline ValueType  unsafe_Data_cast(Data & operand)
-    {
-        return static_cast<Data::holder<ValueType> *>(operand.content)->held;
-    }
 
-    template<typename ValueType>
-    inline ValueType unsafe_Data_cast(const Data & operand)
-    {
-        return *unsafe_Data_cast<ValueType>(const_cast<Data *>(&operand));
-    }
-  */
 
 }// namespace bbtk