]> Creatis software - bbtk.git/blob - packages/std/src/bbstdStringTo.cxx
1f154d4dde76cdc3c1552cd215e93760c5a58de7
[bbtk.git] / packages / std / src / bbstdStringTo.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbstdStringTo.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:27 $
6   Version:   $Revision: 1.4 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31
32 #include "bbstdStringTo.h"
33 #include "bbstdPackage.h"
34
35
36 namespace bbstd 
37 {
38
39   //====================================================================
40   BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringTo,
41                                          bbtk::AtomicBlackBox);
42   //====================================================================
43
44   //====================================================================
45   // Template specialization of DoIt
46   template <> void StringTo<bool> ::DoIt()
47   {
48     if ( (bbGetInputIn()=="true") || 
49          (bbGetInputIn()=="TRUE") || 
50          (bbGetInputIn()=="True") || 
51          (bbGetInputIn()=="1")     )  
52     {
53        bbSetOutputOut(true);
54     }
55     else if ( (bbGetInputIn()=="false") || 
56               (bbGetInputIn()=="FALSE") ||
57               (bbGetInputIn()=="False") ||
58               (bbGetInputIn()=="0") )  
59     {   
60        bbSetOutputOut(false); 
61     }
62     else 
63     {
64        bbtkError("cannot convert '"<<bbGetInputIn()<<"' to a bool");
65     }
66   }
67   
68   // Template specialization of DoIt
69   template <> void StringTo<bbtk::Void> ::DoIt()
70   {
71   }
72   
73   template <> void StringTo<int8_t> ::DoIt()
74   {
75     bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) );
76   }
77   
78   template <> void StringTo<uint8_t> ::DoIt()
79   {
80     bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) );
81   }
82   
83   template <> void StringTo<int16_t> ::DoIt()
84   {
85     bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) );
86   }
87   
88   template <> void StringTo<uint16_t> ::DoIt()
89   {
90     bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) );
91   }
92   
93   template <> void StringTo<int32_t> ::DoIt()
94   {
95     bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) );
96   }
97   
98   template <> void StringTo<uint32_t> ::DoIt()
99   {
100     bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) );
101   }
102   
103   template <> void StringTo<float> ::DoIt()
104   {
105     bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) );
106   }
107   
108   template <> void StringTo<double> ::DoIt()
109   {
110     bbSetOutputOut( atof ( bbGetInputIn().c_str() ) );
111   }
112   
113   //====================================================================
114   
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   //====================================================================
129   
130 } // namespace bbstd