2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbstdStringTo.cxx,v $
32 Date: $Date: 2012/11/16 08:51:32 $
33 Version: $Revision: 1.5 $
34 =========================================================================*/
36 #include "bbstdStringTo.h"
37 #include "bbstdPackage.h"
43 //====================================================================
44 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringTo,
45 bbtk::AtomicBlackBox);
46 //====================================================================
48 //====================================================================
49 // Template specialization of DoIt
50 template <> void StringTo<bool> ::DoIt()
52 if ( (bbGetInputIn()=="true") ||
53 (bbGetInputIn()=="TRUE") ||
54 (bbGetInputIn()=="True") ||
55 (bbGetInputIn()=="1") )
59 else if ( (bbGetInputIn()=="false") ||
60 (bbGetInputIn()=="FALSE") ||
61 (bbGetInputIn()=="False") ||
62 (bbGetInputIn()=="0") )
64 bbSetOutputOut(false);
68 bbtkError("cannot convert '"<<bbGetInputIn()<<"' to a bool");
72 // Template specialization of DoIt
73 template <> void StringTo<bbtk::Void> ::DoIt()
77 template <> void StringTo<int8_t> ::DoIt()
79 bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) );
82 template <> void StringTo<uint8_t> ::DoIt()
84 bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) );
87 template <> void StringTo<int16_t> ::DoIt()
89 bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) );
92 template <> void StringTo<uint16_t> ::DoIt()
94 bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) );
97 template <> void StringTo<int32_t> ::DoIt()
99 bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) );
102 template <> void StringTo<uint32_t> ::DoIt()
104 bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) );
107 template <> void StringTo<float> ::DoIt()
109 bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) );
112 template <> void StringTo<double> ::DoIt()
114 bbSetOutputOut( atof ( bbGetInputIn().c_str() ) );
117 //====================================================================
119 //====================================================================
120 // Add the specialized adaptors to the package
121 typedef bbtk::Void Void;
122 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,bool);
123 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int8_t);
124 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint8_t);
125 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int16_t);
126 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint16_t);
127 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int32_t);
128 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint32_t);
129 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,float);
130 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,double);
131 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,Void);
132 //====================================================================