Alida-C++ 0.5
|
00001 /* 00002 * This file is part of Alida-C++ library for 00003 * 00004 * Automatic Logging of Process Information in Data Analysis. 00005 * 00006 * Copyright (C) 2012 - @YEAR@ 00007 * 00008 * This program is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * Fore more information on Alida, visit 00022 * 00023 * http://www.informatik.uni-halle.de/alida/ 00024 * 00025 */ 00026 00027 /* 00028 * Most recent change(s): 00029 * 00030 * $Rev: 69 $ 00031 * $Date: 2012-03-07 11:28:04 +0100 (Mi, 07 Mrz 2012) $ 00032 * $Author: moeller $ 00033 * 00034 */ 00035 00036 #include <math.h> 00037 #include <stdio.h> 00038 #include <stdlib.h> 00039 00040 #include <fstream> 00041 #include <iostream> 00042 #include <sstream> 00043 #include <string> 00044 00045 #include "dataio/ioManagerCmdline.h" 00046 #include "dataio/provider/cmdline/nativeDatatypesProvider.h" 00047 00048 using namespace std; 00049 00050 using namespace Alida; 00051 00056 REGISTER_PROVIDER(NativeDatatypesProvider,double,Cmdline); 00057 00058 // 00059 /* === do not remove this line - help for doxygen === */ 00060 00065 REGISTER_PROVIDER(NativeDatatypesProvider,int,Cmdline); 00066 00067 // 00068 /* === do not remove this line - help for doxygen === */ 00069 00074 REGISTER_PROVIDER(NativeDatatypesProvider,float,Cmdline); 00075 00084 void* 00085 NativeDatatypesProvider::parseInput(string input, string type) const 00086 { 00087 if (typeid(new float()).name() == type) { 00088 cout << "Reading a float..." << endl; 00089 float* retFloat = new float(); 00090 sscanf(input.c_str(),"%f",retFloat); 00091 return retFloat; 00092 } 00093 else if (typeid(new double()).name() == type) { 00094 cout << "Reading a double..." << endl; 00095 double *retDouble = new double(); 00096 (*retDouble) = atof(input.c_str()); 00097 return retDouble; 00098 } 00099 else if (typeid(new int()).name() == type) { 00100 cout << "Reading an int..." << endl; 00101 int *retInt = new int(); 00102 (*retInt) = atoi(input.c_str()); 00103 return retInt; 00104 00105 } 00106 else { 00107 cerr << "NativeDatatypesProvider: unknown type requested! Error!" << endl; 00108 return NULL; 00109 } 00110 } 00111 00120 string NativeDatatypesProvider::writeOutput( 00121 string format, string type, void *data) const 00122 { 00123 ostringstream outString; 00124 if (typeid(new float()).name() == type) { 00125 outString.setf(ios_base::scientific,ios_base::floatfield); 00126 outString.precision(10); 00127 outString << *((float*)data); 00128 } 00129 else if (typeid(new double()).name() == type) { 00130 outString.setf(ios_base::scientific,ios_base::floatfield); 00131 outString.precision(10); 00132 outString << *((double*)data); 00133 } 00134 else if (typeid(new int()).name() == type) { 00135 outString.precision(10); 00136 outString << *((int*)data); 00137 } 00138 else { 00139 outString << "NativeDatatypesProvider: unknown type in writing data!"; 00140 } 00141 return outString.str(); 00142 } 00143