00001 /*************************************************************************** 00002 * 00003 * Copyright (C) 2009 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 #ifdef COMMAND 00048 public Command 00049 #else 00050 public Processor 00051 #endif 00052 00053 { 00054 00055 public: 00056 00057 const char* 00058 getName() const; 00059 00060 #ifdef COMMAND 00061 const char* 00062 getCommandName() const; 00063 #endif 00064 00065 value::Result 00066 getResult(const DataSet& data) const; 00067 00068 value::Value 00069 getValue(const DataSet& data) const; 00070 00071 private: 00072 00073 friend class ProcessorInstantiator<tag::TAG>; 00074 Calculator(); 00075 00076 }; // class Calculator 00077 00078 /*-------------------------------------------------------------------------- 00079 * ProcessorInstantiator::getInstance() 00080 *------------------------------------------------------------------------*/ 00081 00082 template <> 00083 Processor& 00084 ProcessorInstantiator<tag::TAG>::getInstance() { 00085 static Calculator<tag::TAG> singleton; 00086 return singleton; 00087 } 00088 00089 /*-------------------------------------------------------------------------- 00090 * Calculator::getResult() 00091 *------------------------------------------------------------------------*/ 00092 00093 value::Result 00094 Calculator<tag::TAG>::getResult(const DataSet& data) const { 00095 return getValue(data); 00096 } 00097 00098 /*-------------------------------------------------------------------------- 00099 * Calculator::Calculator() 00100 *------------------------------------------------------------------------*/ 00101 00102 Calculator<tag::TAG>::Calculator() { 00103 util::Global<ProcessorMngr>::get()->add(this); 00104 } 00105 00106 /*-------------------------------------------------------------------------- 00107 * Macro clean-up 00108 *------------------------------------------------------------------------*/ 00109 00110 #undef TAG 00111 00112 #ifdef COMMAND 00113 #undef COMMAND 00114 #endif