+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ # pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ # This software is governed by the CeCILL-B license under French law and
+ # abiding by the rules of distribution of free software. You can use,
+ # modify and/ or redistribute the software under the terms of the CeCILL-B
+ # license as circulated by CEA, CNRS and INRIA at the following URL
+ # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ # or in the file LICENSE.txt.
+ #
+ # As a counterpart to the access to the source code and rights to copy,
+ # modify and redistribute granted by the license, users are provided only
+ # with a limited warranty and the software's author, the holder of the
+ # economic rights, and the successive licensors have only limited
+ # liability.
+ #
+ # The fact that you are presently reading this means that you have had
+ # knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
/*=========================================================================
-
Program: bbtk
Module: $RCSfile: bbtkData.h,v $
Language: C++
- Date: $Date: 2008/01/22 15:02:00 $
- Version: $Revision: 1.1 $
-
- Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
- l'Image). All rights reserved. See doc/license.txt or
- http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notices for more information.
-
+ Date: $Date: 2012/11/16 08:49:01 $
+ Version: $Revision: 1.5 $
=========================================================================*/
+
+
+
+
/**
*\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)
- {
- }
+ /// 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)
+ {}
+
+ ~DataInfo() {}
+
+ TypeInfo GetType() const { return mType; }
+ const std::string& GetNature() const { return mNature; }
+
+ /// 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;
+
+ };
- public: // queries
-
- virtual const std::type_info & type() const
- {
- return typeid(ValueType);
- }
-
- virtual placeholder * clone() const
- {
- return new holder(held);
- }
-
- 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;
-
- };
-
- 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