About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

cfl_functions.cpp

Go to the documentation of this file.
00001 /** @file cfl_functions.cpp Runtime interface, operations on faudes types */
00002 
00003     /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005     Copyright (C) 2009 Ruediger Berndt
00006     Copyright (C) 2009 Thomas Moor
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2.1 of the License, or (at your option) any later version.
00012 
00013     This library 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 GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00021 
00022 
00023 #include "cfl_functions.h"
00024 #include "cfl_registry.h"
00025 
00026 
00027 namespace faudes{
00028 
00029 /*
00030 ********************************************************************
00031 ********************************************************************
00032 ********************************************************************
00033 
00034 Implementation of class Parameter
00035 
00036 ********************************************************************
00037 ********************************************************************
00038 ********************************************************************
00039 */
00040 
00041 // constructor, default 
00042 Parameter::Parameter(void) : 
00043   mName(""), mTDName(""), mAttr(Parameter::UnDef), mCReturn(false) 
00044 {}
00045 
00046 // constructor, by member values 
00047   Parameter::Parameter(const std::string& rName, const std::string& rTypeName, ParamAttr attr, bool cret) : 
00048     mName(rName), mTDName(rTypeName), mAttr(attr), mCReturn(cret) 
00049 {}
00050 
00051 // Desctructor 
00052 Parameter::~Parameter(void){}
00053 
00054 // get name
00055 const std::string& Parameter::Name(void) const 
00056   { return mName;}
00057 
00058 // set name
00059 void Parameter::Name(const std::string& rName) 
00060   { mName=rName;}
00061 
00062 // get type
00063 const std::string& Parameter::Type(void) const 
00064   { return mTDName;}
00065 
00066 // set type
00067 void Parameter::Type(const std::string& rTypeName) 
00068   { mTDName=rTypeName;}
00069 
00070 // get attribute
00071 const Parameter::ParamAttr& Parameter::Attribute(void) const 
00072   { return mAttr; }
00073 
00074 // set attribute
00075 void Parameter::Attribute(const ParamAttr& rAttr) 
00076   { mAttr=rAttr;}
00077 
00078 // get c ret flag
00079 bool  Parameter::CReturn(void) const 
00080   { return mCReturn; }
00081 
00082 // set c ret flag
00083 void Parameter::CReturn(bool cret) 
00084 { mCReturn=cret;}
00085 
00086 // set attribute
00087 void Parameter::Attribute(const std::string& rAttrStr) { 
00088   mAttr=Parameter::UnDef;    
00089   if(rAttrStr=="In") mAttr=Parameter::In;
00090   if(rAttrStr=="Out") mAttr=Parameter::Out;
00091   if(rAttrStr=="InOut") mAttr=Parameter::InOut;
00092 }
00093 
00094 // textual attribute
00095 std::string Parameter::AStr(Parameter::ParamAttr attr){
00096   switch(attr){
00097   case Parameter::In: return "In";
00098   case Parameter::Out: return "Out";
00099   case Parameter::InOut: return "InOut";
00100   default: break;
00101   }
00102   return "UnDef";
00103 }
00104 
00105 // textual parameter
00106 std::string Parameter::Str(void) const {
00107   std::string res = "+" + AStr(mAttr)+ "+ " + mTDName + " " + mName;
00108   return res;
00109 }
00110 
00111 // set to "undefined"
00112 void Parameter::Clear(void){
00113   mName = "";
00114   mTDName = "";
00115   mAttr = Parameter::UnDef;
00116   mCReturn=false;
00117 }
00118 
00119 // test equality
00120 bool Parameter::operator==(const Parameter& rOther) const {
00121   if(mName!=rOther.mName) return false;
00122   if(mTDName!=rOther.mTDName) return false;
00123   if(mAttr!=rOther.mAttr) return false;
00124   if(mCReturn!=rOther.mCReturn) return false;
00125   return true;
00126 }
00127 
00128 
00129 
00130 /*
00131 ********************************************************************
00132 ********************************************************************
00133 ********************************************************************
00134 
00135 Implementation of class Signature
00136 
00137 ********************************************************************
00138 ********************************************************************
00139 ********************************************************************
00140 */
00141 
00142 
00143 // faudes type (cannot do autoregister)
00144 FAUDES_TYPE_IMPLEMENTATION_NEW(Void,Signature,Type)
00145 FAUDES_TYPE_IMPLEMENTATION_COPY(Void,Signature,Type)
00146 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,Signature,Type)
00147 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,Signature,Type)
00148 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,Signature,Type)
00149 
00150 // constructor
00151 Signature::Signature(void) : Type() {}
00152 
00153 // copy constructor
00154 Signature::Signature(const Signature& rSrc) : Type()
00155 {
00156   DoAssign(rSrc);
00157 }
00158 
00159 // std faudes type
00160 void Signature::DoAssign(const Signature& rSrc) {
00161   // assign my members
00162   mName=rSrc.mName;
00163   mParameters=rSrc.mParameters;
00164 }
00165 
00166 // std faudes type
00167 bool Signature::DoEqual(const Signature& rOther) const {
00168   // test my members
00169   if(mName!=rOther.mName) return false;
00170   if(mParameters!=rOther.mParameters) return false;
00171   return true;
00172 }
00173 
00174 
00175 // clear signature
00176 void Signature::Clear(void){
00177   FD_DRTI("Signature::Clear()");
00178   mName="";
00179   mParameters.clear();
00180 }
00181 
00182 // get name
00183 const std::string& Signature::Name(void) const{
00184   return mName;
00185 }
00186 
00187 // set name
00188 void Signature::Name(const std::string& rName){
00189   mName = rName;
00190 }
00191 
00192 // get size
00193 int Signature::Size() const{
00194   return mParameters.size();
00195 }
00196 
00197 // get parameter
00198 const Parameter& Signature::At(int n) const{
00199   // check range
00200   if((n < 0) || (n >= Size())){
00201     std::stringstream err;
00202     err << "Index out of range: " << n << std::endl;
00203     throw Exception("Signature::At()", err.str(), 47);
00204   }
00205   // return const ref
00206   return mParameters.at(n);
00207 }
00208 
00209 // set parameter
00210 void Signature::At(int n, const Parameter& rParam) {
00211   // check range
00212   if((n < 0) || (n >= Size())){
00213     std::stringstream err;
00214     err << "Index out of range: " << n << std::endl;
00215     throw Exception("Signature::At()", err.str(), 47);
00216   }
00217   // set ref
00218   mParameters[n]=rParam;
00219 }
00220 
00221 // append parameter
00222 void Signature::Append(const Parameter& rParam){
00223   mParameters.push_back(rParam);
00224 }
00225 
00226 
00227 
00228 // token io
00229 void Signature::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00230   // ignore
00231   (void) rLabel;
00232   (void) pContext;
00233   // write my tag
00234   Token btag;
00235   btag.SetBegin("Signature");
00236   btag.InsAttribute("name",mName);
00237   rTw << btag;
00238   // parameter specs
00239   for(int i=0; i<Size(); i++){
00240     Token par;
00241     par.SetEmpty("Parameter");
00242     par.InsAttribute("name",mParameters.at(i).Name());
00243     par.InsAttribute("ftype",mParameters.at(i).Type());
00244     switch(mParameters.at(i).Attribute()){
00245     case Parameter::In: par.InsAttribute("access","In"); break;
00246     case Parameter::Out: par.InsAttribute("access","Out"); break;
00247     case Parameter::InOut: par.InsAttribute("access","InOut"); break;
00248     default: break;
00249     }
00250     if(mParameters.at(i).CReturn()) par.InsAttribute("creturn","true");
00251     rTw << par ;
00252   }
00253   // end section
00254   rTw.WriteEnd("Signature");
00255 }
00256 
00257 // token io
00258 void Signature::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext){
00259   // ignore
00260   (void) rLabel;
00261   (void) pContext;
00262   // read my section
00263   FD_DRTI("Signature::DoRead(): file " << rTr.FileName());
00264   Token token;
00265   rTr.ReadBegin("Signature",token);
00266 
00267   // detect and digest old pre 2.16b file format
00268   // note: this section will eventually be removed
00269   if(!token.ExistsAttributeString("name")) {
00270     mName=rTr.ReadString();
00271     FD_DRTI("Signature::DoRead(): found (pre 2.16b file)" << mName);
00272     while(!rTr.Eos("Signature")) {
00273       std::string pname=rTr.ReadString();
00274       std::string ptype=rTr.ReadString();
00275       Parameter::ParamAttr pattr= Parameter::UnDef;
00276       bool cret=false;
00277       Token token;
00278       rTr.Peek(token);
00279       while(token.Type()==Token::Option) {
00280         rTr.Get(token);
00281         if(token.StringValue()=="In") pattr= Parameter::In;
00282         if(token.StringValue()=="Out") pattr= Parameter::Out;
00283         if(token.StringValue()=="InOut") pattr= Parameter::InOut;
00284         if(token.StringValue()=="OutIn") pattr= Parameter::InOut;
00285         if(token.StringValue()=="CReturn") cret=true;
00286         rTr.Peek(token);
00287       }
00288       Append(Parameter(pname,ptype,pattr,cret));
00289     }
00290     rTr.ReadEnd("Signature");
00291     return;
00292   } // end pre 2.16b file format
00293    
00294   // extract name
00295   mName=token.AttributeStringValue("name");
00296   FD_DRTI("Signature::DoRead(): found " << mName);  
00297   // loop parameters
00298   while(!rTr.Eos("Signature")) {
00299     Token par;
00300     rTr.ReadBegin("Parameter",par);
00301     // parameter name
00302     std::string pname=par.AttributeStringValue("name");
00303     // parameter type
00304     std::string ptype=par.AttributeStringValue("ftype");
00305     // parameter access
00306     Parameter::ParamAttr pattr= Parameter::UnDef;
00307     if(par.ExistsAttributeString("access")){
00308       std::string paccess = par.AttributeStringValue("access");
00309       if(paccess=="In")    pattr= Parameter::In;
00310       if(paccess=="Out")   pattr= Parameter::Out;
00311       if(paccess=="InOut") pattr= Parameter::InOut;
00312       if(paccess=="OutIn") pattr= Parameter::InOut;
00313     }
00314     // parameter cret  
00315     bool cret=false;
00316     if(par.ExistsAttributeString("creturn")){
00317       std::string pcret = par.AttributeStringValue("creturn");
00318       if(pcret=="true")   cret=true;
00319       if(pcret=="True")   cret=true;
00320       if(pcret=="Yes")    cret=true;
00321       if(pcret=="yes")    cret=true;
00322     }
00323     // insert
00324     Append(Parameter(pname,ptype,pattr,cret));
00325     rTr.ReadEnd("Parameter");
00326   }
00327   // done
00328   rTr.ReadEnd("Signature");
00329   FD_DRTI("Signature::DoRead(): done");
00330 }
00331 
00332 
00333 
00334 
00335 /*
00336 ********************************************************************
00337 ********************************************************************
00338 ********************************************************************
00339 
00340 Implementation of class FunctionDefinition
00341 
00342 ********************************************************************
00343 ********************************************************************
00344 ********************************************************************
00345 */
00346 
00347 // faudes type (cannot do autoregister)
00348 FAUDES_TYPE_IMPLEMENTATION_NEW(Void,FunctionDefinition,Documentation)
00349 FAUDES_TYPE_IMPLEMENTATION_COPY(Void,FunctionDefinition,Documentation)
00350 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,FunctionDefinition,Documentation)
00351 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,FunctionDefinition,Documentation)
00352 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,FunctionDefinition,Documentation)
00353 
00354 
00355 // constructor
00356 FunctionDefinition::FunctionDefinition(const std::string& name) : 
00357   Documentation(), 
00358   mpFunction(NULL) 
00359 {
00360   Name(name);
00361 }
00362 
00363 // copy constructor
00364 FunctionDefinition::FunctionDefinition(const FunctionDefinition& rSrc) :
00365   Documentation(), 
00366   mpFunction(NULL) 
00367 {
00368   DoAssign(rSrc);
00369 }
00370 
00371 // std faudes type
00372 void FunctionDefinition::DoAssign(const FunctionDefinition& rSrc) {
00373   // assign base members
00374   Documentation::DoAssign(rSrc);
00375   // assign my members
00376   mVariants=rSrc.mVariants;
00377   mVariantIndexMap=rSrc.mVariantIndexMap;
00378   // special member
00379   if(mpFunction) delete mpFunction;
00380   mpFunction=0;
00381   if(rSrc.mpFunction) {
00382     mpFunction=rSrc.mpFunction->New();
00383     mpFunction->Definition(this);
00384   }
00385 }
00386 
00387 // std faudes type
00388 bool FunctionDefinition::DoEqual(const FunctionDefinition& rOther) const {
00389   // test base members
00390   if(!Documentation::DoEqual(rOther)) return false;
00391   // test my members
00392   if(mVariants!=rOther.mVariants) return false;
00393   return true;
00394 }
00395 
00396 // clear (all but prototype)
00397 void FunctionDefinition::Clear(){
00398   FD_DRTI("FunctionDefinition::Clear(): " << Name());
00399   // call base
00400   Documentation::Clear();
00401   // clear my variants
00402   mVariants.clear();
00403   mVariantIndexMap.clear();
00404 }
00405 
00406 // clear (variants only)
00407 void FunctionDefinition::ClearVariants(){
00408   FD_DRTI("FunctionDefinition::ClearVariants(): " << Name());
00409   // clear my variants
00410   mVariants.clear();
00411   mVariantIndexMap.clear();
00412 }
00413 
00414 
00415 // get prototype object
00416 const Function* FunctionDefinition::Prototype(void) const{
00417   return(mpFunction);
00418 }
00419 
00420 // set prototype object
00421 void FunctionDefinition::Prototype(Function* pFunc){
00422   // delte any existing prototype
00423   if(mpFunction) delete mpFunction;
00424   // record new prototype
00425   mpFunction = pFunc;
00426   // bail out
00427   if(!mpFunction) return;
00428   // ensure that our prototype uses us as function definition
00429   mpFunction->Definition(this);
00430 }
00431 
00432 // construct function on head
00433 Function* FunctionDefinition::NewFunction() const{
00434   FD_DRTI("FunctionDefinition::NewFunction(): name " << Name());
00435   if(!mpFunction) return NULL;
00436   return(mpFunction->New());
00437 }
00438 
00439 
00440 // # of variants
00441 int FunctionDefinition::VariantsSize() const{
00442   return(mVariants.size());
00443 }
00444 
00445 // existence of variant by name
00446 bool FunctionDefinition::ExistsVariant(const std::string& varname) const {
00447   return mVariantIndexMap.find(varname)!= mVariantIndexMap.end();
00448 }
00449 
00450 // get index by variant name
00451 int FunctionDefinition::VariantIndex(const std::string& rName) const {
00452   std::map<std::string,int>::const_iterator vit= mVariantIndexMap.find(rName);
00453   if(vit==mVariantIndexMap.end()) return -1;
00454   return vit->second;
00455 }
00456 
00457 // extend variants
00458 void FunctionDefinition::AppendVariant(const Signature& rVariant){
00459   FD_DRTI("FunctionDefinition::AppendVariant()");
00460   // assure that no variant with the same name is yet contained in the list
00461   if(ExistsVariant(rVariant.Name())) {
00462     std::stringstream err;
00463     err << "Attempt to append variant with existing name: " << rVariant.Name() << " in " << Name() << std::endl;
00464     throw Exception("FunctionDefinition::AppendVariant()", err.str(), 47);
00465   }
00466   // do append
00467   mVariantIndexMap[rVariant.Name()]=mVariants.size();
00468   mVariants.push_back(rVariant);
00469 }
00470 
00471 
00472 // get signature by variant name
00473 const Signature& FunctionDefinition::Variant(const std::string& rName) const{
00474   std::map<std::string,int>::const_iterator vit= mVariantIndexMap.find(rName);
00475   if(vit==mVariantIndexMap.end()) {
00476     std::stringstream err;
00477     err << "Access to non existing variant " << rName << " in fnct " << Name() << std::endl;
00478     throw Exception("FunctionDefinition::Variant()", err.str(), 47);
00479   }
00480   return mVariants.at(vit->second);
00481 }
00482 
00483 
00484 // get signature by variant index
00485 const Signature& FunctionDefinition::Variant(int n) const{
00486   // check range
00487   if((n < 0) || (n >= VariantsSize())){
00488     std::stringstream err;
00489     err << "Index out of range: " << n << std::endl;
00490     throw Exception("FunctionDefinition::Variant()", err.str(), 47);
00491   }
00492   return mVariants.at(n);
00493 }
00494 
00495 
00496 // token io
00497 void FunctionDefinition::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00498   FD_DRTI("FunctionDefinition::DoRead()");
00499   // ignore
00500   (void) pContext;
00501   // label
00502   std::string label=rLabel;
00503   if(label=="") label="FunctionDefinition";
00504   // base can handle this
00505   Documentation::DoRead(rTr,label,pContext);
00506 }
00507 
00508 
00509 // token io
00510 void FunctionDefinition::DoReadCore(TokenReader& rTr) {
00511   FD_DRTI("FunctionDefinition::DoReadCore()");
00512   // call base
00513   Documentation::DoReadCore(rTr);  
00514   // do variants
00515   rTr.ReadBegin("VariantSignatures");
00516   while(!rTr.Eos("VariantSignatures")) {
00517     Signature sig;
00518     sig.Read(rTr);
00519     // no doublets
00520     if(ExistsVariant(sig.Name())) continue;
00521     // append variant signature
00522     AppendVariant(sig);
00523   } // end: !EOS
00524   rTr.ReadEnd("VariantSignatures");
00525 }
00526 
00527 
00528 // token io
00529 void FunctionDefinition::DoWrite(TokenWriter& rTw,  const std::string& rLabel, const Type* pContext) const {
00530   // label
00531   std::string label=rLabel;
00532   if(label=="") label="FunctionDefinition";
00533   // base can handle
00534   Documentation::DoWrite(rTw,label,pContext); 
00535 }
00536 
00537 // token io
00538 void FunctionDefinition::DoWriteCore(TokenWriter& rTw) const {
00539   FD_DRTI("FunctionDefinition::DoWriteCore(): file " << rTw.FileName());
00540   // call base core
00541   Documentation::DoWriteCore(rTw);  
00542   // write signatures
00543   rTw.WriteBegin("VariantSignatures");
00544   if(mVariants.size()>1) rTw << "\n";
00545   for(unsigned int i=0; i<mVariants.size(); i++) {
00546     mVariants.at(i).Write(rTw);
00547      if(mVariants.size()>1) rTw << "\n";
00548   }
00549   rTw.WriteEnd("VariantSignatures");
00550   rTw << "\n";
00551 }
00552 
00553 
00554 /*
00555 ********************************************************************
00556 ********************************************************************
00557 ********************************************************************
00558 
00559 Implementation of class Function
00560 
00561 ********************************************************************
00562 ********************************************************************
00563 ********************************************************************
00564 */
00565 
00566 // Constructor 
00567 Function::Function(const FunctionDefinition* fdef) : 
00568   pFuncDef(fdef), 
00569   mVariantIndex(-1) 
00570 {
00571 #ifdef FAUDES_DEBUG_RUNTIMEINTERFACE
00572   if(!pFuncDef)
00573     {FD_DRTI("Function::Function(): prototype object");}
00574   else
00575     {FD_DRTI("Function::Function(): " << pFuncDef->Name());}
00576 #endif
00577   // have default variant
00578   if(pFuncDef)
00579   if(pFuncDef->VariantsSize()>0)
00580      Variant(0);
00581 }
00582 
00583 // set function definition
00584 void Function::Definition(const FunctionDefinition* fdef) {
00585   // invalidate variant
00586   mVariantIndex = -1;
00587   mParameterValues.clear();
00588   // set
00589   pFuncDef=fdef;
00590   // report
00591 #ifdef FAUDES_DEBUG_RUNTIMEINTERFACE
00592   if(!pFuncDef)
00593     {FD_DRTI("Function::Definition(): prototype object");}
00594   else
00595     {FD_DRTI("Function::Definition(): " << pFuncDef->Name());}
00596 #endif
00597 }
00598 
00599 // get function definition
00600 const FunctionDefinition* Function::Definition(void) const {
00601   return pFuncDef;
00602 }
00603 
00604 
00605 // get signature size
00606 int Function::VariantsSize(void) const {
00607   if(!pFuncDef) return 0;
00608   return pFuncDef->VariantsSize();
00609 }
00610 
00611 // set variant signature
00612 void Function::Variant(int n) {
00613   // clear recent variant
00614   mVariantIndex=-1;
00615   mParameterValues.clear(); 
00616   // prototype object can not have a variant
00617   if(!pFuncDef) {
00618     std::stringstream err;
00619     err << "No valid function definition available" << std::endl;
00620     throw Exception("Function::Variant(n)", err.str(), 47);
00621   }
00622   // index out of ragne
00623   if(n<0 || n >= VariantsSize()) {
00624     std::stringstream err;
00625     err << "Variant index out of range" << std::endl;
00626     throw Exception("Function::Variant(n)", err.str(), 48);
00627   }
00628   // set variant 
00629   mVariantIndex=n;
00630   int nparam = pFuncDef->Variant(mVariantIndex).Size();
00631   while((int) mParameterValues.size()<nparam)
00632     mParameterValues.push_back(0);
00633 }
00634 
00635 // set variant signature
00636 void Function::Variant(const std::string& rVariantName) {
00637   // prototype object can not have a variant
00638   if(!pFuncDef) {
00639     std::stringstream err;
00640     err << "No valid function definition available" << std::endl;
00641     throw Exception("Function::Variant(name)", err.str(), 47);
00642   }
00643   // get index
00644   int varid = pFuncDef->VariantIndex(rVariantName);
00645   // detect invalid name
00646   if(varid<0) {
00647     std::stringstream err;
00648     err << "Unknown varaiant name " << rVariantName << std::endl;
00649     throw Exception("Function::Variant(name)", err.str(), 47);
00650   }
00651   // set by index
00652   Variant(varid);
00653 }
00654 
00655 // get signature
00656 const Signature* Function::Variant(void) const {
00657   if(!pFuncDef) return 0;
00658   if(mVariantIndex<0) return 0;
00659   return &pFuncDef->Variant(mVariantIndex);
00660 }
00661 
00662 // get signature size
00663 int Function::ParamsSize(void) const {
00664   return mParameterValues.size();
00665 }
00666 
00667 // set parameter value
00668 void Function::ParamValue(int n, Type* pVal){
00669   if((n < 0) || (n >= ParamsSize())){
00670     std::stringstream err;
00671     err << "Parameter index out of range: " << n << std::endl;
00672     throw Exception("Function::ParamValue()", err.str(), 47);
00673   }
00674   mParameterValues.at(n) = pVal;
00675 }
00676 
00677 // get parameter
00678 Type* Function::ParamValue(int n) const{
00679   if((n < 0) || (n >= ParamsSize())){
00680     std::stringstream err;
00681     err << "Parameter index out of range: " << n << std::endl;
00682     throw Exception("Function::ParamValue()", err.str(), 47);
00683   }
00684   return(mParameterValues.at(n));
00685 }
00686 
00687 
00688 // allocate parameter value
00689 void Function::AllocateValue(int n) {
00690   FD_DRTI("Function::AllocateValue()");
00691   if(!Variant()) {
00692     std::stringstream err;
00693     err << "No variant specified";
00694     throw Exception("Function::AllocateValue()", err.str(), 47);
00695   }
00696   if((n < 0) || (n >= ParamsSize())){
00697     std::stringstream err;
00698     err << "Parameter index out of range: " << n << std::endl;
00699     throw Exception("Function::AllocateValue()", err.str(), 47);
00700   }
00701   ParamValue(n,TypeRegistry::G()->NewObject(Variant()->At(n).Type()));
00702 }
00703 
00704 // allocate parameter value
00705 void Function::AllocateValues(void) {
00706   FD_DRTI("Function::AllocateValues()");
00707   for(int i = 0; i < ParamsSize(); i++) 
00708     AllocateValue(i);
00709 }
00710 
00711 // allocate parameter value
00712 void Function::FreeValues(void) {
00713   FD_DRTI("Function::FreeValues()");
00714   for(int i = 0; i < ParamsSize(); i++) { 
00715     delete mParameterValues.at(i);
00716     mParameterValues.at(i) =0;
00717   }
00718 }
00719 
00720 
00721 // type check wrapper
00722 bool Function::TypeCheck(int n) {
00723   FD_DRTI("Function::TypeCheck()");
00724   if(mVariantIndex<0) {
00725     std::stringstream err;
00726     err << "Variant not set" << std::endl;
00727     throw Exception("Function::TypeCheck(n)", err.str(), 48);
00728   }
00729   if(n<0 || n>= ParamsSize()) {
00730     std::stringstream err;
00731     err << "Parameter out of range" << std::endl;
00732     throw Exception("Function::Typechek(n)", err.str(), 48);
00733   }
00734   bool res=DoTypeCheck(n);
00735   FD_DRTI("Function::TypeCheck() done, ok=" << res);
00736   return res;
00737 }
00738 
00739 // type check wrapper
00740 bool Function::TypeCheck(void) {
00741   FD_DRTI("Function::TypeCheck()");
00742   if(mVariantIndex<0) {
00743     std::stringstream err;
00744     err << "Variant not set" << std::endl;
00745     throw Exception("Function::TypeCheck()", err.str(), 48);
00746   }
00747   for(int i=0; i<ParamsSize(); i++) 
00748     if(!DoTypeCheck(i)) return false;
00749   FD_DRTI("Function::TypeCheck() done, ok");
00750   return true;
00751 }
00752 
00753 // exec wrapper
00754 void Function::Execute(void){
00755   FD_DRTI("Function::Execute()");
00756   if(!Variant()) {
00757     std::stringstream err;
00758     err << "Variant not set" << std::endl;
00759     throw Exception("Function::Execute()", err.str(), 48);
00760   }
00761   for(int n=0; n<ParamsSize(); n++) {
00762     if(!DoTypeCheck(n)) {
00763       std::stringstream err;
00764       err << "Cannot cast parameter \"" << Variant()->At(n).Name() << 
00765         "\" to type \"" << Variant()->At(n).Type() << "\"";
00766       throw Exception("Function::Execute()", err.str(), 48);
00767     }
00768   }
00769   DoExecute();
00770   FD_DRTI("Function::Execute() done");
00771 }
00772 
00773 
00774 // token io (informative/debug)
00775 void Function::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00776   (void) pContext;
00777   std::string label = rLabel;
00778   if(label == "") label = "Function";
00779   FD_DRTI("Function::DoWrite(): file " << rTw.FileName() << " section " << label);
00780   rTw.Columns(1);
00781   rTw.WriteBegin(label);
00782   rTw << "\n";
00783   rTw.WriteBegin("Parameters");
00784   for(int i = 0; i < ParamsSize(); i++){
00785     rTw << typeid(ParamValue(i)).name();
00786     rTw << "\n";
00787   }
00788   rTw.WriteEnd("Parameters");
00789   rTw << "\n";
00790   rTw.WriteEnd(label);
00791   FD_DRTI("Function::DoWrite(): done");
00792 }
00793 
00794 
00795 } // namespace
00796 

libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen