]> Creatis software - bbtk.git/blob - packages/std/src/bbstdStringToVector.cxx
b3ceb3ee3c7c2e0cb2c101e244bcf87c957867dc
[bbtk.git] / packages / std / src / bbstdStringToVector.cxx
1 #include "bbstdStringToVector.h"
2 #include "bbstdPackage.h"
3
4
5 namespace bbstd
6 {
7   //====================================================================
8   BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringToVector,
9                                          bbtk::AtomicBlackBox);
10   //====================================================================
11   
12   //====================================================================
13   // Template specialization of decode_item
14   template <> int8_t StringToVector<int8_t> ::decode_item(const std::string& s)
15   {
16     return (int8_t)atoi ( s.c_str() );
17   }
18   
19   template <> uint8_t StringToVector<uint8_t> ::decode_item(const std::string& s)
20   {
21     return (uint8_t)atoi ( s.c_str() );
22 }
23
24 template <> int16_t StringToVector<int16_t> ::decode_item(const std::string& s)
25 {
26   return (int16_t)atoi ( s.c_str() );
27 }
28
29 template <> uint16_t StringToVector<uint16_t> ::decode_item(const std::string& s)
30 {
31   return (uint16_t)atoi ( s.c_str() );
32 }
33
34 template <> int32_t StringToVector<int32_t> ::decode_item(const std::string& s)
35 {
36   return (int32_t)atoi ( s.c_str() );
37 }
38
39 template <> uint32_t StringToVector<uint32_t> ::decode_item(const std::string& s) 
40 {
41   return (uint32_t)atoi ( s.c_str() );
42 }
43
44 template <> long StringToVector<long> ::decode_item(const std::string& s)
45 {
46   // std::cout << bbGetFullName() << " v="<<s<<std::endl;
47   return (long)atoi ( s.c_str() );
48 }
49
50 template <> float StringToVector<float> ::decode_item(const std::string& s)
51 {
52   return (float)atof ( s.c_str() );
53 }
54
55 template <> double StringToVector<double> ::decode_item(const std::string& s)
56 {
57   return atof ( s.c_str() );
58 }
59
60 template <> std::string StringToVector<std::string> ::decode_item(const std::string& s)
61 {
62   return s;
63 }
64
65 //====================================================================
66
67 //====================================================================
68 // Add the specialized adaptors to the package
69
70 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int8_t);
71 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint8_t);
72 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int16_t);
73 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint16_t);
74 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int32_t);
75 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint32_t);
76 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,long);
77 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,float);
78 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,double);
79 typedef std::string string;
80 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,string);
81 //====================================================================
82
83 } // namespace bbstd