]> Creatis software - bbtk.git/blob - kernel/src/bbtkTypeMapping.h
450bfcc796c4ccd1ff721e98a2a299a618f5244b
[bbtk.git] / kernel / src / bbtkTypeMapping.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkTypeMapping.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:14 $
6   Version:   $Revision: 1.2 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 #ifndef __bbtkTypeMapping_h_INCLUDED__
33 #define __bbtkTypeMapping_h_INCLUDED__
34
35
36 namespace bbtk 
37 {
38
39 /// 
40 template <typename ValueType>
41 class TypeMapping 
42 {
43 public:
44   TypeMapping() {}
45
46   template <typename T>
47   ValueType& value() 
48   {
49     return m_map[ (void*)typeid(T).name() ];
50   }
51   template <typename T>
52   ValueType& operator[]( const T& ) 
53   {
54     return m_map[ (void*)typeid(T).name() ];
55   }
56
57   ValueType& operator[]( const std::type_info& t) 
58   {
59     return m_map[ (void*)t.name() ];
60   }
61   
62   unsigned int size() const { return m_map.size(); }
63
64   typedef typename std::map<void*, ValueType>::const_iterator const_iterator;
65
66   const_iterator begin() const { return m_map.begin(); }
67   const_iterator end() const { return m_map.end(); }
68
69 protected:
70   std::map<void*, ValueType> m_map;
71 };
72
73
74
75 }
76 #endif