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