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 OBJECT_TYPE 00037 #error "Please, #define OBJECT_TYPE before including DeclareBuilder.h." 00038 #endif 00039 00040 #ifndef TAG 00041 #error "Please, #define TAG before including DeclareBuilder.h." 00042 #endif 00043 00044 namespace tag { 00045 class TAG; 00046 } 00047 00048 template <> 00049 class Builder<tag::TAG> : 00050 00051 #ifdef BUILDS_FROM 00052 public BuilderFrom<OBJECT_TYPE, BUILDS_FROM> 00053 #else 00054 public AbstractBuilder 00055 #endif 00056 00057 #ifdef COMMAND 00058 , public Command 00059 #endif 00060 00061 { 00062 00063 public: 00064 00065 // Inherited from processor / User defined 00066 const char* 00067 getName() const; 00068 00069 // Inherited from processor / Defined below 00070 value::Result 00071 getResult(const DataSet& data) const; 00072 00073 // Inherited from AbstractBuilder / Defined below 00074 const ::std::type_info& 00075 getObjectType() const; 00076 00077 #ifdef BUILDS_FROM 00078 // Inherited from BuilderFromVariant / User defined 00079 value::PtrTraits<ObjectType>::Type_ 00080 getObject(const BUILDS_FROM& data) const; 00081 #endif 00082 00083 #ifdef KV_COMMAND 00084 // Inherited from Command / User defined 00085 const char* 00086 getCommandName() const; 00087 #endif 00088 00089 // Local / User defined 00090 value::PtrTraits<OBJECT_TYPE>::Type_ 00091 getObject(const DataSet& data) const; 00092 00093 private: 00094 00095 // Inherited from AbstractBuilder / Defined below 00096 void 00097 thrower() const; 00098 00099 friend class ProcessorInstantiator<tag::TAG>; 00100 00101 // Local / Defined below 00102 Builder(); 00103 00104 }; // class Builder 00105 00106 /*-------------------------------------------------------------------------- 00107 * Builder::getResult() 00108 *------------------------------------------------------------------------*/ 00109 00110 value::Result 00111 Builder<tag::TAG>::getResult(const DataSet& data) const { 00112 return getObject(data); 00113 } 00114 00115 /*-------------------------------------------------------------------------- 00116 * Builder::getObjectType() 00117 *------------------------------------------------------------------------*/ 00118 00119 const ::std::type_info& 00120 Builder<tag::TAG>::getObjectType() const { 00121 return typeid(OBJECT_TYPE); 00122 } 00123 00124 /*-------------------------------------------------------------------------- 00125 * Builder::thrower() 00126 *------------------------------------------------------------------------*/ 00127 00128 void 00129 Builder<tag::TAG>::thrower() const { 00130 throw static_cast<OBJECT_TYPE*>(0); 00131 } 00132 00133 /*-------------------------------------------------------------------------- 00134 * ProcessorInstantiator::getInstance() 00135 *------------------------------------------------------------------------*/ 00136 00137 template <> 00138 const Processor& 00139 ProcessorInstantiator<tag::TAG>::getInstance() { 00140 static const Builder<tag::TAG> singleton; 00141 return singleton; 00142 } 00143 00144 /*-------------------------------------------------------------------------- 00145 * Builder::Builder() 00146 *------------------------------------------------------------------------*/ 00147 00148 Builder<tag::TAG>::Builder() { 00149 util::Global<ProcessorMngr>::get()->add(*this); 00150 } 00151 00152 /*-------------------------------------------------------------------------- 00153 * Macro clean-up 00154 *------------------------------------------------------------------------*/ 00155 00156 #undef OBJECT_TYPE 00157 #undef TAG 00158 00159 #ifdef COMMAND 00160 #undef COMMAND 00161 #endif 00162 00163 #ifdef BUILDS_FROM 00164 #undef BUILDS_FROM 00165 #endif