Alida-C++ 0.1

demo/operators/DemoOperator.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Alida-C++ library, an
00003  *
00004  * Advanced Library for Integrated Development of Data Analysis Applications.
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: 101 $
00031  * $Date: 2012-03-12 09:47:11 +0100 (Mo, 12 Mrz 2012) $
00032  * $Author: posch $
00033  *
00034  */
00035 
00036 #include <math.h>
00037 #include <stdio.h>
00038 
00039 #include <fstream>
00040 #include <iostream>
00041 #include <string>
00042 
00043 #include "demo/operators/DemoOperator.h"
00044 #include "operator/ALDOperatorManager.h"
00045 
00046 using namespace std;
00047 
00052 REGISTER_OPERATOR(DemoOperator);
00053 
00072 DemoOperator::DemoOperator()
00073 {
00074   DEFINE_PARAMETER( float, floatval, PARAMETER_IN,
00075         true, false, "a float val", "This is a float value", NULL);
00076 
00077   DEFINE_PARAMETER( double, doubleval, PARAMETER_IN,
00078         true, false, "a double val", "This is a double value", NULL);
00079 
00080   DEFINE_PARAMETER( int, intval, PARAMETER_IN,
00081         true, false, "an int val", "This is an int value", NULL);
00082 
00083   DEFINE_PARAMETER( std::string, stringval, PARAMETER_IN,
00084         true, false, "a string val", "This is a string value", NULL);
00085 
00086   DEFINE_PARAMETER( double, resultval, PARAMETER_OUT,
00087         true, false, "a double val",
00088                              "This is the result, sum of floatval and doubleval", NULL);
00089 }
00090 
00098 void DemoOperator::operate()
00099 {
00100   std::cout << "DemoOperator called..." << endl << endl;
00101 
00102   printf("Value of my parameter named floatval is %.8f\n",
00103     *((float*)(this->getParameter("floatval"))));
00104 
00105   printf("Value of my parameter named doubleval is %.20f\n",
00106     *((double*)(this->getParameter("doubleval"))));
00107   printf("Value of my parameter named intval is %d\n",
00108     *((int*)(this->getParameter("intval"))));
00109   std::cout << "Value of my parameter named stringval is " <<
00110     *((std::string*)(this->getParameter("stringval"))) << std::endl;
00111 
00112   double *result = new double();
00113   (*result) = (double)(*((float*)(this->getParameter("floatval")))) +
00114                 *((double*)(this->getParameter("doubleval")));
00115   this->setParameter("resultval",result);
00116   std::cout << endl << "... operate() finished!" << std::endl;
00117 }
00118 
00121 void DemoOperator::validateCustom() {
00122     if ( *((float*)(this->getParameter("floatval"))) < 0 ) {
00123         throw new ALDException( "DemoOperator", "validateCustom", "floatval is required to be non-negativ");
00124     }
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines