00001 /*************************************************************************** 00002 * 00003 * Copyright (C) 2009-2011 Cassio Neri Moreira 00004 * 00005 * This file is part of the KeyValue library. 00006 * 00007 * The KeyValue library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as published 00009 * by the Free Software Foundation, either version 3 of the License, or (at 00010 * your option) any later version. 00011 * 00012 * The KeyValue library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 00015 * Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with KeyValue. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * If you modify this library, or any covered work, by linking or combining 00021 * it with Excel (or a modified version of that program), containing parts 00022 * covered by the terms of End-User License Agreement for Microsoft 00023 * Software, the licensors of KeyValue grant you additional permission to 00024 * convey the resulting work. 00025 * 00026 **************************************************************************/ 00027 00036 #ifndef TAG 00037 #error "Please, #define TAG before including DeclareCalculator.h." 00038 #endif 00039 00040 namespace tag { 00041 class TAG; 00042 } 00043 00044 template <> 00045 class Calculator<tag::TAG> : 00046 00047 public Processor 00048 00049 #ifdef COMMAND 00050 , public Command 00051 #endif 00052 00053 { 00054 00055 public: 00056 00057 // Inherited from processor / User defined 00058 const char* 00059 getName() const; 00060 00061 // Inherited from processor / Defined below 00062 value::Result 00063 getResult(const DataSet& data) const; 00064 00065 #ifdef COMMAND 00066 // Inherited from Command // User defined 00067 const char* 00068 getCommandName() const; 00069 #endif 00070 00071 // Local / User defined 00072 value::Value 00073 getValue(const DataSet& data) const; 00074 00075 private: 00076 00077 friend class ProcessorInstantiator<tag::TAG>; 00078 00079 // Local / Defined below 00080 Calculator(); 00081 00082 }; // class Calculator 00083 00084 /*-------------------------------------------------------------------------- 00085 * Calculator::getResult() 00086 *------------------------------------------------------------------------*/ 00087 00088 value::Result 00089 Calculator<tag::TAG>::getResult(const DataSet& data) const { 00090 return getValue(data); 00091 } 00092 00093 /*-------------------------------------------------------------------------- 00094 * ProcessorInstantiator::getInstance() 00095 *------------------------------------------------------------------------*/ 00096 00097 template <> 00098 const Processor& 00099 ProcessorInstantiator<tag::TAG>::getInstance() { 00100 static const Calculator<tag::TAG> singleton; 00101 return singleton; 00102 } 00103 00104 /*-------------------------------------------------------------------------- 00105 * Calculator::Calculator() 00106 *------------------------------------------------------------------------*/ 00107 00108 Calculator<tag::TAG>::Calculator() { 00109 util::Global<ProcessorMngr>::get()->add(*this); 00110 } 00111 00112 /*-------------------------------------------------------------------------- 00113 * Macro clean-up 00114 *------------------------------------------------------------------------*/ 00115 00116 #undef TAG 00117 00118 #ifdef COMMAND 00119 #undef COMMAND 00120 #endif