]> Creatis software - bbtk.git/blob - kernel/src/bbtkData.h
=== MAJOR RELEASE ====
[bbtk.git] / kernel / src / bbtkData.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkData.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:15 $
7   Version:   $Revision: 1.3 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See doc/license.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *\file
20  *\brief  Defines Data and DataInfo 
21  * 
22  * Data is bbtk general type exchanged between black boxes (adapted from boost::any).
23  * 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). 
24  */
25
26 #ifndef __bbtkData_h__
27 #define __bbtkData_h__
28
29
30 #include "bbtkAny.h"
31 #include "bbtkRTTI.h"
32
33 namespace bbtk
34 {
35   
36   /// The generic type of "data" exchanged between black boxes
37   typedef any<thing> Data;
38
39   /// 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)
40   class DataInfo
41   {
42   public:
43     DataInfo( TypeInfo type, const std::string& nature="") 
44       : mType(type), mNature(nature)
45     {}
46
47     ~DataInfo() {}
48
49     TypeInfo GetType() const { return mType; }
50     const std::string& GetNature() const { return mNature; }
51
52     /// Equality
53     bool operator== ( const DataInfo& k ) const
54       {
55         return ( (mType == k.mType)  &&
56                  (mNature == k.mNature) );
57       }
58     /// Comparison
59     bool operator< ( const DataInfo& k ) const
60       {
61         return ( ( mType.before(k.mType) ) ||
62                  ( ( mType == k.mType ) &&
63                    ( mNature.compare(k.mNature) < 0 ) ) );
64       }
65
66
67   private:
68     DataInfo() : mType(typeid(void)), mNature("") {}
69     TypeInfo mType;
70     std::string mNature;
71
72   };
73
74   
75   /// dump in a stream
76   inline std::ostream& operator<<(std::ostream& s, const DataInfo& d) 
77   {
78     s << "<" << TypeName(d.GetType()) << "("<< d.GetNature()<<")>";
79     return s;
80   }
81
82
83
84 }// namespace bbtk
85
86 #endif
87