1 #include "bbstdStringTo.h"
2 #include "bbstdPackage.h"
8 //====================================================================
9 BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringTo,
10 bbtk::AtomicBlackBox);
11 //====================================================================
13 //====================================================================
14 // Template specialization of DoIt
15 template <> void StringTo<bool> ::DoIt()
17 if ( (bbGetInputIn()=="true") ||
18 (bbGetInputIn()=="TRUE") ||
19 (bbGetInputIn()=="True") ||
20 (bbGetInputIn()=="1") )
24 else if ( (bbGetInputIn()=="false") ||
25 (bbGetInputIn()=="FALSE") ||
26 (bbGetInputIn()=="False") ||
27 (bbGetInputIn()=="0") )
29 bbSetOutputOut(false);
33 bbtkError("cannot convert '"<<bbGetInputIn()<<"' to a bool");
37 // Template specialization of DoIt
38 template <> void StringTo<bbtk::Void> ::DoIt()
42 template <> void StringTo<int8_t> ::DoIt()
44 bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) );
47 template <> void StringTo<uint8_t> ::DoIt()
49 bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) );
52 template <> void StringTo<int16_t> ::DoIt()
54 bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) );
57 template <> void StringTo<uint16_t> ::DoIt()
59 bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) );
62 template <> void StringTo<int32_t> ::DoIt()
64 bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) );
67 template <> void StringTo<uint32_t> ::DoIt()
69 bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) );
72 template <> void StringTo<float> ::DoIt()
74 bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) );
77 template <> void StringTo<double> ::DoIt()
79 bbSetOutputOut( atof ( bbGetInputIn().c_str() ) );
82 //====================================================================
84 //====================================================================
85 // Add the specialized adaptors to the package
86 typedef bbtk::Void Void;
87 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,bool);
88 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int8_t);
89 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint8_t);
90 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int16_t);
91 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint16_t);
92 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int32_t);
93 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint32_t);
94 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,float);
95 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,double);
96 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,Void);
97 //====================================================================