]> Creatis software - bbtk.git/blob - packages/std/src/bbstdStringToVector.cxx
372d1d49fbc9360bd8398c233ff03c295b262d82
[bbtk.git] / packages / std / src / bbstdStringToVector.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbstdStringToVector.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:27 $
6   Version:   $Revision: 1.5 $
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 #include "bbstdStringToVector.h"
33 #include "bbstdPackage.h"
34
35
36 namespace bbstd
37 {
38   //====================================================================
39   BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringToVector,
40                                          bbtk::AtomicBlackBox);
41   //====================================================================
42   
43   //====================================================================
44   // Template specialization of decode_item
45   template <> int8_t StringToVector<int8_t> ::decode_item(const std::string& s)
46   {
47     return (int8_t)atoi ( s.c_str() );
48   }
49   
50   template <> uint8_t StringToVector<uint8_t> ::decode_item(const std::string& s)
51   {
52     return (uint8_t)atoi ( s.c_str() );
53 }
54
55 template <> int16_t StringToVector<int16_t> ::decode_item(const std::string& s)
56 {
57   return (int16_t)atoi ( s.c_str() );
58 }
59
60 template <> uint16_t StringToVector<uint16_t> ::decode_item(const std::string& s)
61 {
62   return (uint16_t)atoi ( s.c_str() );
63 }
64
65 template <> int32_t StringToVector<int32_t> ::decode_item(const std::string& s)
66 {
67   return (int32_t)atoi ( s.c_str() );
68 }
69
70 template <> uint32_t StringToVector<uint32_t> ::decode_item(const std::string& s) 
71 {
72   return (uint32_t)atoi ( s.c_str() );
73 }
74
75 template <> long StringToVector<long> ::decode_item(const std::string& s)
76 {
77   // std::cout << bbGetFullName() << " v="<<s<<std::endl;
78   return (long)atoi ( s.c_str() );
79 }
80
81 template <> float StringToVector<float> ::decode_item(const std::string& s)
82 {
83   return (float)atof ( s.c_str() );
84 }
85
86 template <> double StringToVector<double> ::decode_item(const std::string& s)
87 {
88   return atof ( s.c_str() );
89 }
90
91 template <> std::string StringToVector<std::string> ::decode_item(const std::string& s)
92 {
93   return s;
94 }
95
96 //====================================================================
97
98 //====================================================================
99 // Add the specialized adaptors to the package
100
101 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int8_t);
102 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint8_t);
103 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int16_t);
104 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint16_t);
105 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int32_t);
106 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint32_t);
107 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,long);
108 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,float);
109 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,double);
110 typedef std::string string;
111 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,string);
112 //====================================================================
113
114 } // namespace bbstd