1 /*=========================================================================
3 Module: $RCSfile: bbstdStringTo.cxx,v $
5 Date: $Date: 2008/10/17 08:18:27 $
6 Version: $Revision: 1.4 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
32 #include "bbstdStringTo.h"
33 #include "bbstdPackage.h"
39 //====================================================================
40 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringTo,
41 bbtk::AtomicBlackBox);
42 //====================================================================
44 //====================================================================
45 // Template specialization of DoIt
46 template <> void StringTo<bool> ::DoIt()
48 if ( (bbGetInputIn()=="true") ||
49 (bbGetInputIn()=="TRUE") ||
50 (bbGetInputIn()=="True") ||
51 (bbGetInputIn()=="1") )
55 else if ( (bbGetInputIn()=="false") ||
56 (bbGetInputIn()=="FALSE") ||
57 (bbGetInputIn()=="False") ||
58 (bbGetInputIn()=="0") )
60 bbSetOutputOut(false);
64 bbtkError("cannot convert '"<<bbGetInputIn()<<"' to a bool");
68 // Template specialization of DoIt
69 template <> void StringTo<bbtk::Void> ::DoIt()
73 template <> void StringTo<int8_t> ::DoIt()
75 bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) );
78 template <> void StringTo<uint8_t> ::DoIt()
80 bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) );
83 template <> void StringTo<int16_t> ::DoIt()
85 bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) );
88 template <> void StringTo<uint16_t> ::DoIt()
90 bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) );
93 template <> void StringTo<int32_t> ::DoIt()
95 bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) );
98 template <> void StringTo<uint32_t> ::DoIt()
100 bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) );
103 template <> void StringTo<float> ::DoIt()
105 bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) );
108 template <> void StringTo<double> ::DoIt()
110 bbSetOutputOut( atof ( bbGetInputIn().c_str() ) );
113 //====================================================================
115 //====================================================================
116 // Add the specialized adaptors to the package
117 typedef bbtk::Void Void;
118 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,bool);
119 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int8_t);
120 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint8_t);
121 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int16_t);
122 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint16_t);
123 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int32_t);
124 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint32_t);
125 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,float);
126 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,double);
127 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,Void);
128 //====================================================================