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