base/FuncSignature.hpp
Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID 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   OpenFLUID 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 OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00048 
00055 #ifndef __FUNCSIGNATURE_H__
00056 #define __FUNCSIGNATURE_H__
00057 
00058 #include <boost/regex.hpp>
00059 
00060 #include <openfluid/config.hpp>
00061 #include <openfluid/core/TypeDefs.hpp>
00062 
00063 
00064 // =====================================================================
00065 // =====================================================================
00066 
00070 #define BEGIN_SIGNATURE_HOOK \
00071   openfluid::base::FunctionSignature* GetPlugSignature() \
00072   { \
00073     openfluid::base::FunctionSignature* Signature = new openfluid::base::FunctionSignature(); \
00074     Signature->setSDKVersion(openfluid::config::FULL_VERSION);
00075 
00076 
00080 #define END_SIGNATURE_HOOK \
00081     return Signature; \
00082   }
00083 
00084 
00085 // =====================================================================
00086 // =====================================================================
00087 
00088 
00092 #define DECLARE_SIGNATURE_ID(id) Signature->ID = id;
00093 
00097 #define DECLARE_SIGNATURE_NAME(name) Signature->Name = name;
00098 
00102 #define DECLARE_SIGNATURE_DESCRIPTION(desc) Signature->Description = desc;
00103 
00107 #define DECLARE_SIGNATURE_DOMAIN(domain) Signature->Domain = domain;
00108 
00112 #define DECLARE_SIGNATURE_PROCESS(process) Signature->Process = process;
00113 
00117 #define DECLARE_SIGNATURE_METHOD(method) Signature->Method = method;
00118 
00122 #define DECLARE_SIGNATURE_AUTHORNAME(name) Signature->Author = name;
00123 
00127 #define DECLARE_SIGNATURE_AUTHOREMAIL(email) Signature->AuthorEmail = email;
00128 
00132 #define DECLARE_SIGNATURE_VERSION(version) Signature->Version = version;
00133 
00137 #define DECLARE_SIGNATURE_STATUS(status) Signature->Status = status;
00138 
00142 #define DECLARE_SIGNATURE_SDKVERSION Signature->setSDKVersion(openfluid::config::FULL_VERSION);
00143 
00144 // =====================================================================
00145 // =====================================================================
00146 
00147 
00154 #define DECLARE_FUNCTION_PARAM(name,description,unit) \
00155   Signature->HandledData.FunctionParams.push_back(openfluid::base::SignatureHandledDataItem((name),(""),description,unit));
00156 
00157 
00158 
00159 // =====================================================================
00160 // =====================================================================
00161 
00162 
00170 #define DECLARE_PRODUCED_VAR(name,uclass,description,unit) \
00171   Signature->HandledData.ProducedVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00172 
00180 #define DECLARE_UPDATED_VAR(name,uclass,description,unit) \
00181   Signature->HandledData.UpdatedVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00182 
00190 #define DECLARE_REQUIRED_VAR(name,uclass,description,unit) \
00191   Signature->HandledData.RequiredVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00192 
00193 
00194 
00202 #define DECLARE_REQUIRED_PREVVAR(name,uclass,description,unit) \
00203   Signature->HandledData.RequiredPrevVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00204 
00212 #define DECLARE_USED_VAR(name,uclass,description,unit) \
00213   Signature->HandledData.UsedVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00214 
00215 
00223 #define DECLARE_USED_PREVVAR(name,uclass,description,unit) \
00224   Signature->HandledData.UsedPrevVars.push_back(openfluid::base::SignatureHandledTypedDataItem((name),uclass,description,unit));
00225 
00233 #define DECLARE_REQUIRED_INPUTDATA(name,uclass,description,unit) \
00234   Signature->HandledData.RequiredInput.push_back(openfluid::base::SignatureHandledDataItem((name),uclass,description,unit));
00235 
00243 #define DECLARE_USED_INPUTDATA(name,uclass,description,unit) \
00244   Signature->HandledData.UsedInput.push_back(openfluid::base::SignatureHandledDataItem((name),uclass,description,unit));
00245 
00250 #define DECLARE_USED_EVENTS(uclass) Signature->HandledData.UsedEventsOnUnits.push_back(uclass);
00251 
00252 
00253 
00259 #define DECLARE_UPDATED_UNITSGRAPH(description) Signature->HandledUnitsGraph.UpdatedUnitsGraph = (description);
00260 
00261 
00268 #define DECLARE_UPDATED_UNITSCLASS(uclass,description) Signature->HandledUnitsGraph.UpdatedUnitsClass.push_back(openfluid::base::SignatureHandledUnitsClassItem(uclass,description));
00269 
00270 
00275 #define DECLARE_REQUIRED_EXTRAFILE(name) \
00276   Signature->HandledData.RequiredExtraFiles.push_back(name);
00277 
00282 #define DECLARE_USED_EXTRAFILE(name) \
00283   Signature->HandledData.UsedExtraFiles.push_back(name);
00284 
00285 
00286 // =====================================================================
00287 // =====================================================================
00288 
00289 
00290 
00291 namespace openfluid { namespace base {
00292 
00293 
00294 typedef std::string FuncID_t;
00295 typedef std::string FuncName_t;
00296 typedef std::string FuncVersion_t;
00297 typedef std::string FuncMethod_t;
00298 typedef std::string FuncProcess_t;
00299 typedef std::string FuncDomain_t;
00300 
00301 
00305 enum FuncStatus_t
00306 {
00310   EXPERIMENTAL,
00311 
00315   BETA,
00316 
00320   STABLE
00321 };
00322 
00323 
00324 // =====================================================================
00325 // =====================================================================
00329 class SignatureHandledDataItem
00330 {
00331   public:
00332 
00333     std::string DataName;
00334     openfluid::core::UnitClass_t UnitClass;
00335     std::string Description;
00336     std::string DataUnit;
00337 
00338     SignatureHandledDataItem() :
00339       DataName(""),UnitClass(""),Description(""),DataUnit("") {}
00340 
00341     SignatureHandledDataItem(std::string DName, openfluid::core::UnitClass_t UClass,
00342         std::string DDescription, std::string DUnit) :
00343           DataName(DName),UnitClass(UClass),Description(DDescription),DataUnit(DUnit) {}
00344 
00345 };
00346 
00350 class SignatureHandledTypedDataItem : public SignatureHandledDataItem
00351 {
00352 
00353   public:
00354 
00355     static bool getVariableNameAndType(const std::string SourceStr, std::string& VarName, openfluid::core::Value::Type& VarType)
00356     {
00357       const boost::basic_regex<char> eVect("^([-.\\w]+)\\[\\]$"); //match "abc[]"
00358       const boost::basic_regex<char> eNone("[^[\\]][-.\\w]+"); //match "abc"
00359       const boost::basic_regex<char> eType("^([-.\\w]+)\\[(\\w+)\\]$");  //match "abc[type]"
00360       boost::smatch Type;
00361 
00362       if(boost::regex_match(SourceStr,Type,eVect) && Type.size() == 2)
00363       {
00364         VarName = Type[1];
00365         VarType = openfluid::core::Value::VECTOR;
00366         return true;
00367       }
00368 
00369       if(boost::regex_match(SourceStr,eNone))
00370       {
00371         VarName = SourceStr;
00372         VarType = openfluid::core::Value::NONE;
00373         return true;
00374       }
00375 
00376       if(boost::regex_match(SourceStr,Type,eType) && Type.size() == 3)
00377       {
00378         VarName = Type[1];
00379         return openfluid::core::Value::getValueTypeFromString(Type[2],VarType);
00380       }
00381 
00382       return false;
00383     }
00384 
00385     openfluid::core::Value::Type DataType;
00386 
00387     SignatureHandledTypedDataItem() :
00388       DataType(openfluid::core::Value::NONE) {}
00389 
00390     SignatureHandledTypedDataItem(std::string DName, openfluid::core::UnitClass_t UClass,
00391         std::string DDescription, std::string DUnit)
00392     {
00393       UnitClass = UClass;
00394       Description = DDescription;
00395       DataUnit = DUnit;
00396 
00397       if(!getVariableNameAndType(DName,DataName,DataType))
00398         throw openfluid::base::OFException("OpenFLUID framework","SignatureHandledTypedDataItem::SignatureHandledTypedDataItem","Variable " + DName + " is not well formated.");
00399     }
00400 
00401 };
00402 
00403 
00407 class SignatureHandledUnitsClassItem
00408 {
00409   public:
00410 
00411     openfluid::core::UnitClass_t UnitsClass;
00412     std::string Description;
00413 
00414     SignatureHandledUnitsClassItem() :
00415       UnitsClass(""),Description("") {}
00416 
00417     SignatureHandledUnitsClassItem(openfluid::core::UnitClass_t UClass,
00418         std::string DDescription) :
00419           UnitsClass(UClass),Description(DDescription) {}
00420 };
00421 
00422 
00426 class SignatureHandledData
00427 {
00428   public:
00429 
00430     std::vector<SignatureHandledTypedDataItem> ProducedVars;
00431 
00432     std::vector<SignatureHandledTypedDataItem> UpdatedVars;
00433 
00434     std::vector<SignatureHandledTypedDataItem> RequiredVars;
00435 
00436     std::vector<SignatureHandledTypedDataItem> UsedVars;
00437 
00438     std::vector<SignatureHandledTypedDataItem> RequiredPrevVars;
00439 
00440     std::vector<SignatureHandledTypedDataItem> UsedPrevVars;
00441 
00442     std::vector<SignatureHandledDataItem> FunctionParams;
00443 
00444     std::vector<SignatureHandledDataItem> RequiredInput;
00445 
00446     std::vector<SignatureHandledDataItem> UsedInput;
00447 
00448     std::vector<std::string> RequiredExtraFiles;
00449 
00450     std::vector<std::string> UsedExtraFiles;
00451 
00452     std::vector<openfluid::core::UnitClass_t> UsedEventsOnUnits;
00453 
00454 
00455     SignatureHandledData()
00456     {
00457 
00458     }
00459 
00460 };
00461 
00462 
00463 class SignatureHandledUnitsGraph
00464 {
00465   public:
00466 
00467     std::string UpdatedUnitsGraph;
00468 
00469     std::vector<SignatureHandledUnitsClassItem> UpdatedUnitsClass;
00470 
00471     SignatureHandledUnitsGraph()
00472     {
00473       UpdatedUnitsGraph.clear();
00474     }
00475 };
00476 
00477 
00478 
00483 class FunctionSignature
00484 {
00485 
00486   public:
00487 
00491     FuncID_t ID;
00492 
00496     FuncName_t Name;
00497 
00501     std::string Description;
00502 
00506     FuncDomain_t Domain;
00507 
00511     FuncProcess_t Process;
00512 
00516     FuncMethod_t Method;
00517 
00521     FuncVersion_t Version;
00522 
00526     FuncStatus_t Status;
00527 
00531     std::string SDKVersion;
00532 
00536     std::string Author;
00537 
00541     std::string AuthorEmail;
00542 
00546     SignatureHandledData HandledData;
00547 
00551     SignatureHandledUnitsGraph HandledUnitsGraph;
00552 
00553 
00554     FunctionSignature() :
00555       ID(""),Name(""),Description(""),Domain(""),Process(""),Method(""),Version(""),
00556       Status(EXPERIMENTAL),SDKVersion(""),Author(""),AuthorEmail("") {}
00557 
00558     void setSDKVersion(FuncVersion_t Version)
00559     {
00560       SDKVersion = Version;
00561     }
00562 
00563 };
00564 
00565 
00566 
00567 } } // namespaces
00568 
00569 
00570 
00571 #endif

Generated using Doxygen 1.7.6.1
Creative Commons License Creative Commons By-NC-ND license