cfl_functions.cpp
Go to the documentation of this file.
1 /** @file cfl_functions.cpp Runtime interface, operations on faudes types */
2 
3  /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2009 Ruediger Berndt
6  Copyright (C) 2009 Thomas Moor
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #include "cfl_functions.h"
24 #include "cfl_registry.h"
25 
26 
27 namespace faudes{
28 
29 /*
30 ********************************************************************
31 ********************************************************************
32 ********************************************************************
33 
34 Implementation of class Parameter
35 
36 ********************************************************************
37 ********************************************************************
38 ********************************************************************
39 */
40 
41 // constructor, default
43  mName(""), mTDName(""), mAttr(Parameter::UnDef), mCReturn(false)
44 {}
45 
46 // constructor, by member values
47  Parameter::Parameter(const std::string& rName, const std::string& rTypeName, ParamAttr attr, bool cret) :
48  mName(rName), mTDName(rTypeName), mAttr(attr), mCReturn(cret)
49 {}
50 
51 // Desctructor
53 
54 // get name
55 const std::string& Parameter::Name(void) const
56  { return mName;}
57 
58 // set name
59 void Parameter::Name(const std::string& rName)
60  { mName=rName;}
61 
62 // get type
63 const std::string& Parameter::Type(void) const
64  { return mTDName;}
65 
66 // set type
67 void Parameter::Type(const std::string& rTypeName)
68  { mTDName=rTypeName;}
69 
70 // get attribute
72  { return mAttr; }
73 
74 // set attribute
75 void Parameter::Attribute(const ParamAttr& rAttr)
76  { mAttr=rAttr;}
77 
78 // get c ret flag
79 bool Parameter::CReturn(void) const
80  { return mCReturn; }
81 
82 // set c ret flag
83 void Parameter::CReturn(bool cret)
84 { mCReturn=cret;}
85 
86 // set attribute
87 void Parameter::Attribute(const std::string& rAttrStr) {
89  if(rAttrStr=="In") mAttr=Parameter::In;
90  if(rAttrStr=="Out") mAttr=Parameter::Out;
91  if(rAttrStr=="InOut") mAttr=Parameter::InOut;
92 }
93 
94 // textual attribute
96  switch(attr){
97  case Parameter::In: return "In";
98  case Parameter::Out: return "Out";
99  case Parameter::InOut: return "InOut";
100  default: break;
101  }
102  return "UnDef";
103 }
104 
105 // textual parameter
106 std::string Parameter::Str(void) const {
107  std::string res = "+" + AStr(mAttr)+ "+ " + mTDName + " " + mName;
108  return res;
109 }
110 
111 // set to "undefined"
112 void Parameter::Clear(void){
113  mName = "";
114  mTDName = "";
116  mCReturn=false;
117 }
118 
119 // test equality
120 bool Parameter::operator==(const Parameter& rOther) const {
121  if(mName!=rOther.mName) return false;
122  if(mTDName!=rOther.mTDName) return false;
123  if(mAttr!=rOther.mAttr) return false;
124  if(mCReturn!=rOther.mCReturn) return false;
125  return true;
126 }
127 
128 
129 
130 /*
131 ********************************************************************
132 ********************************************************************
133 ********************************************************************
134 
135 Implementation of class Signature
136 
137 ********************************************************************
138 ********************************************************************
139 ********************************************************************
140 */
141 
142 
143 // faudes type (cannot do autoregister)
149 
150 // constructor
151 Signature::Signature(void) : Type() {}
152 
153 // copy constructor
155 {
156  DoAssign(rSrc);
157 }
158 
159 // std faudes type
160 void Signature::DoAssign(const Signature& rSrc) {
161  // assign my members
162  mName=rSrc.mName;
164 }
165 
166 // std faudes type
167 bool Signature::DoEqual(const Signature& rOther) const {
168  // test my members
169  if(mName!=rOther.mName) return false;
170  if(mParameters!=rOther.mParameters) return false;
171  return true;
172 }
173 
174 
175 // clear signature
176 void Signature::Clear(void){
177  FD_DRTI("Signature::Clear()");
178  mName="";
179  mParameters.clear();
180 }
181 
182 // get name
183 const std::string& Signature::Name(void) const{
184  return mName;
185 }
186 
187 // set name
188 void Signature::Name(const std::string& rName){
189  mName = rName;
190 }
191 
192 // get size
193 int Signature::Size() const{
194  return mParameters.size();
195 }
196 
197 // get parameter
198 const Parameter& Signature::At(int n) const{
199  // check range
200  if((n < 0) || (n >= Size())){
201  std::stringstream err;
202  err << "Index out of range: " << n << std::endl;
203  throw Exception("Signature::At()", err.str(), 47);
204  }
205  // return const ref
206  return mParameters.at(n);
207 }
208 
209 // set parameter
210 void Signature::At(int n, const Parameter& rParam) {
211  // check range
212  if((n < 0) || (n >= Size())){
213  std::stringstream err;
214  err << "Index out of range: " << n << std::endl;
215  throw Exception("Signature::At()", err.str(), 47);
216  }
217  // set ref
218  mParameters[n]=rParam;
219 }
220 
221 // append parameter
222 void Signature::Append(const Parameter& rParam){
223  mParameters.push_back(rParam);
224 }
225 
226 
227 
228 // token io
229 void Signature::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
230  // ignore
231  (void) rLabel;
232  (void) pContext;
233  // write my tag
234  Token btag;
235  btag.SetBegin("Signature");
236  btag.InsAttribute("name",mName);
237  rTw << btag;
238  // parameter specs
239  for(int i=0; i<Size(); i++){
240  Token par;
241  par.SetEmpty("Parameter");
242  par.InsAttribute("name",mParameters.at(i).Name());
243  par.InsAttribute("ftype",mParameters.at(i).Type());
244  switch(mParameters.at(i).Attribute()){
245  case Parameter::In: par.InsAttribute("access","In"); break;
246  case Parameter::Out: par.InsAttribute("access","Out"); break;
247  case Parameter::InOut: par.InsAttribute("access","InOut"); break;
248  default: break;
249  }
250  if(mParameters.at(i).CReturn()) par.InsAttribute("creturn","true");
251  rTw << par ;
252  }
253  // end section
254  rTw.WriteEnd("Signature");
255 }
256 
257 // token io
258 void Signature::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext){
259  // ignore
260  (void) rLabel;
261  (void) pContext;
262  // read my section
263  FD_DRTI("Signature::DoRead(): file " << rTr.FileName());
264  Token token;
265  rTr.ReadBegin("Signature",token);
266 
267  // detect and digest old pre 2.16b file format
268  // note: this section will eventually be removed
269  if(!token.ExistsAttributeString("name")) {
270  mName=rTr.ReadString();
271  FD_DRTI("Signature::DoRead(): found (pre 2.16b file)" << mName);
272  while(!rTr.Eos("Signature")) {
273  std::string pname=rTr.ReadString();
274  std::string ptype=rTr.ReadString();
276  bool cret=false;
277  Token token;
278  rTr.Peek(token);
279  while(token.Type()==Token::Option) {
280  rTr.Get(token);
281  if(token.StringValue()=="In") pattr= Parameter::In;
282  if(token.StringValue()=="Out") pattr= Parameter::Out;
283  if(token.StringValue()=="InOut") pattr= Parameter::InOut;
284  if(token.StringValue()=="OutIn") pattr= Parameter::InOut;
285  if(token.StringValue()=="CReturn") cret=true;
286  rTr.Peek(token);
287  }
288  Append(Parameter(pname,ptype,pattr,cret));
289  }
290  rTr.ReadEnd("Signature");
291  return;
292  } // end pre 2.16b file format
293 
294  // extract name
295  mName=token.AttributeStringValue("name");
296  FD_DRTI("Signature::DoRead(): found " << mName);
297  // loop parameters
298  while(!rTr.Eos("Signature")) {
299  Token par;
300  rTr.ReadBegin("Parameter",par);
301  // parameter name
302  std::string pname=par.AttributeStringValue("name");
303  // parameter type
304  std::string ptype=par.AttributeStringValue("ftype");
305  // parameter access
307  if(par.ExistsAttributeString("access")){
308  std::string paccess = par.AttributeStringValue("access");
309  if(paccess=="In") pattr= Parameter::In;
310  if(paccess=="Out") pattr= Parameter::Out;
311  if(paccess=="InOut") pattr= Parameter::InOut;
312  if(paccess=="OutIn") pattr= Parameter::InOut;
313  }
314  // parameter cret
315  bool cret=false;
316  if(par.ExistsAttributeString("creturn")){
317  std::string pcret = par.AttributeStringValue("creturn");
318  if(pcret=="true") cret=true;
319  if(pcret=="True") cret=true;
320  if(pcret=="Yes") cret=true;
321  if(pcret=="yes") cret=true;
322  }
323  // insert
324  Append(Parameter(pname,ptype,pattr,cret));
325  rTr.ReadEnd("Parameter");
326  }
327  // done
328  rTr.ReadEnd("Signature");
329  FD_DRTI("Signature::DoRead(): done");
330 }
331 
332 
333 
334 
335 /*
336 ********************************************************************
337 ********************************************************************
338 ********************************************************************
339 
340 Implementation of class FunctionDefinition
341 
342 ********************************************************************
343 ********************************************************************
344 ********************************************************************
345 */
346 
347 // faudes type (cannot do autoregister)
353 
354 
355 // constructor
356 FunctionDefinition::FunctionDefinition(const std::string& name) :
357  Documentation(),
358  mpFunction(NULL)
359 {
360  Name(name);
361 }
362 
363 // copy constructor
365  Documentation(),
366  mpFunction(NULL)
367 {
368  DoAssign(rSrc);
369 }
370 
371 // std faudes type
373  // assign base members
375  // assign my members
376  mVariants=rSrc.mVariants;
378  // special member
379  if(mpFunction) delete mpFunction;
380  mpFunction=0;
381  if(rSrc.mpFunction) {
382  mpFunction=rSrc.mpFunction->New();
383  mpFunction->Definition(this);
384  }
385 }
386 
387 // std faudes type
389  // test base members
390  if(!Documentation::DoEqual(rOther)) return false;
391  // test my members
392  if(mVariants!=rOther.mVariants) return false;
393  return true;
394 }
395 
396 // clear (all but prototype)
398  FD_DRTI("FunctionDefinition::Clear(): " << Name());
399  // call base
401  // clear my variants
402  mVariants.clear();
403  mVariantIndexMap.clear();
404 }
405 
406 // clear (variants only)
408  FD_DRTI("FunctionDefinition::ClearVariants(): " << Name());
409  // clear my variants
410  mVariants.clear();
411  mVariantIndexMap.clear();
412 }
413 
414 
415 // get prototype object
417  return(mpFunction);
418 }
419 
420 // set prototype object
422  // delte any existing prototype
423  if(mpFunction) delete mpFunction;
424  // record new prototype
425  mpFunction = pFunc;
426  // bail out
427  if(!mpFunction) return;
428  // ensure that our prototype uses us as function definition
429  mpFunction->Definition(this);
430 }
431 
432 // construct function on head
434  FD_DRTI("FunctionDefinition::NewFunction(): name " << Name());
435  if(!mpFunction) return NULL;
436  return(mpFunction->New());
437 }
438 
439 
440 // # of variants
442  return(mVariants.size());
443 }
444 
445 // existence of variant by name
446 bool FunctionDefinition::ExistsVariant(const std::string& varname) const {
447  return mVariantIndexMap.find(varname)!= mVariantIndexMap.end();
448 }
449 
450 // get index by variant name
451 int FunctionDefinition::VariantIndex(const std::string& rName) const {
452  std::map<std::string,int>::const_iterator vit= mVariantIndexMap.find(rName);
453  if(vit==mVariantIndexMap.end()) return -1;
454  return vit->second;
455 }
456 
457 // extend variants
459  FD_DRTI("FunctionDefinition::AppendVariant()");
460  // assure that no variant with the same name is yet contained in the list
461  if(ExistsVariant(rVariant.Name())) {
462  std::stringstream err;
463  err << "Attempt to append variant with existing name: " << rVariant.Name() << " in " << Name() << std::endl;
464  throw Exception("FunctionDefinition::AppendVariant()", err.str(), 47);
465  }
466  // do append
467  mVariantIndexMap[rVariant.Name()]=mVariants.size();
468  mVariants.push_back(rVariant);
469 }
470 
471 
472 // get signature by variant name
473 const Signature& FunctionDefinition::Variant(const std::string& rName) const{
474  std::map<std::string,int>::const_iterator vit= mVariantIndexMap.find(rName);
475  if(vit==mVariantIndexMap.end()) {
476  std::stringstream err;
477  err << "Access to non existing variant " << rName << " in fnct " << Name() << std::endl;
478  throw Exception("FunctionDefinition::Variant()", err.str(), 47);
479  }
480  return mVariants.at(vit->second);
481 }
482 
483 
484 // get signature by variant index
486  // check range
487  if((n < 0) || (n >= VariantsSize())){
488  std::stringstream err;
489  err << "Index out of range: " << n << std::endl;
490  throw Exception("FunctionDefinition::Variant()", err.str(), 47);
491  }
492  return mVariants.at(n);
493 }
494 
495 
496 // token io
497 void FunctionDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
498  FD_DRTI("FunctionDefinition::DoRead()");
499  // ignore
500  (void) pContext;
501  // label
502  std::string label=rLabel;
503  if(label=="") label="FunctionDefinition";
504  // base can handle this
505  Documentation::DoRead(rTr,label,pContext);
506 }
507 
508 
509 // token io
511  FD_DRTI("FunctionDefinition::DoReadCore()");
512  // call base
514  // do variants
515  rTr.ReadBegin("VariantSignatures");
516  while(!rTr.Eos("VariantSignatures")) {
517  Signature sig;
518  sig.Read(rTr);
519  // no doublets
520  if(ExistsVariant(sig.Name())) continue;
521  // append variant signature
522  AppendVariant(sig);
523  } // end: !EOS
524  rTr.ReadEnd("VariantSignatures");
525 }
526 
527 
528 // token io
529 void FunctionDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
530  // label
531  std::string label=rLabel;
532  if(label=="") label="FunctionDefinition";
533  // base can handle
534  Documentation::DoWrite(rTw,label,pContext);
535 }
536 
537 // token io
539  FD_DRTI("FunctionDefinition::DoWriteCore(): file " << rTw.FileName());
540  // call base core
542  // write signatures
543  rTw.WriteBegin("VariantSignatures");
544  if(mVariants.size()>1) rTw << "\n";
545  for(unsigned int i=0; i<mVariants.size(); i++) {
546  mVariants.at(i).Write(rTw);
547  if(mVariants.size()>1) rTw << "\n";
548  }
549  rTw.WriteEnd("VariantSignatures");
550  rTw << "\n";
551 }
552 
553 
554 /*
555 ********************************************************************
556 ********************************************************************
557 ********************************************************************
558 
559 Implementation of class Function
560 
561 ********************************************************************
562 ********************************************************************
563 ********************************************************************
564 */
565 
566 // Constructor
568  pFuncDef(fdef),
569  mVariantIndex(-1)
570 {
571 #ifdef FAUDES_DEBUG_RUNTIMEINTERFACE
572  if(!pFuncDef)
573  {FD_DRTI("Function::Function(): prototype object");}
574  else
575  {FD_DRTI("Function::Function(): " << pFuncDef->Name());}
576 #endif
577  // have default variant
578  if(pFuncDef)
579  if(pFuncDef->VariantsSize()>0)
580  Variant(0);
581 }
582 
583 // set function definition
585  // invalidate variant
586  mVariantIndex = -1;
587  mParameterValues.clear();
588  // set
589  pFuncDef=fdef;
590  // report
591 #ifdef FAUDES_DEBUG_RUNTIMEINTERFACE
592  if(!pFuncDef)
593  {FD_DRTI("Function::Definition(): prototype object");}
594  else
595  {FD_DRTI("Function::Definition(): " << pFuncDef->Name());}
596 #endif
597 }
598 
599 // get function definition
601  return pFuncDef;
602 }
603 
604 
605 // get signature size
606 int Function::VariantsSize(void) const {
607  if(!pFuncDef) return 0;
608  return pFuncDef->VariantsSize();
609 }
610 
611 // set variant signature
612 void Function::Variant(int n) {
613  // pass on t o virtual interface
614  DoVariant(n);
615 }
616 
617 // set variant signature
618 void Function::DoVariant(int n) {
619  // clear recent variant
620  mVariantIndex=-1;
621  mParameterValues.clear();
622  // prototype object can not have a variant
623  if(!pFuncDef) {
624  std::stringstream err;
625  err << "No valid function definition available" << std::endl;
626  throw Exception("Function::Variant(n)", err.str(), 47);
627  }
628  // index out of range
629  if(n<0 || n >= VariantsSize()) {
630  std::stringstream err;
631  err << "Variant index out of range" << std::endl;
632  throw Exception("Function::Variant(n)", err.str(), 48);
633  }
634  // set variant
635  mVariantIndex=n;
636  int nparam = pFuncDef->Variant(mVariantIndex).Size();
637  while((int) mParameterValues.size()<nparam)
638  mParameterValues.push_back(0);
639 }
640 
641 // set variant signature
642 void Function::Variant(const std::string& rVariantName) {
643  // prototype object can not have a variant
644  if(!pFuncDef) {
645  std::stringstream err;
646  err << "No valid function definition available" << std::endl;
647  throw Exception("Function::Variant(name)", err.str(), 47);
648  }
649  // get index
650  int varid = pFuncDef->VariantIndex(rVariantName);
651  // detect invalid name
652  if(varid<0) {
653  std::stringstream err;
654  err << "Unknown variant name " << rVariantName << std::endl;
655  throw Exception("Function::Variant(name)", err.str(), 48);
656  }
657  // set by index
658  DoVariant(varid);
659 }
660 
661 // get signature
662 const Signature* Function::Variant(void) const {
663  if(!pFuncDef) return 0;
664  if(mVariantIndex<0) return 0;
665  return &pFuncDef->Variant(mVariantIndex);
666 }
667 
668 // get signature size
669 int Function::ParamsSize(void) const {
670  return mParameterValues.size();
671 }
672 
673 // set parameter value
674 void Function::ParamValue(int n, Type* pVal){
675  if((n < 0) || (n >= ParamsSize())){
676  std::stringstream err;
677  err << "Parameter index out of range: " << n << std::endl;
678  throw Exception("Function::ParamValue()", err.str(), 47);
679  }
680  mParameterValues.at(n) = pVal;
681 }
682 
683 // get parameter
685  if((n < 0) || (n >= ParamsSize())){
686  std::stringstream err;
687  err << "Parameter index out of range: " << n << std::endl;
688  throw Exception("Function::ParamValue()", err.str(), 47);
689  }
690  return(mParameterValues.at(n));
691 }
692 
693 
694 // allocate parameter value
696  FD_DRTI("Function::AllocateValue()");
697  if(!Variant()) {
698  std::stringstream err;
699  err << "No variant specified";
700  throw Exception("Function::AllocateValue()", err.str(), 47);
701  }
702  if((n < 0) || (n >= ParamsSize())){
703  std::stringstream err;
704  err << "Parameter index out of range: " << n << std::endl;
705  throw Exception("Function::AllocateValue()", err.str(), 47);
706  }
707  ParamValue(n,TypeRegistry::G()->NewObject(Variant()->At(n).Type()));
708 }
709 
710 // allocate parameter value
712  FD_DRTI("Function::AllocateValues()");
713  for(int i = 0; i < ParamsSize(); i++)
714  AllocateValue(i);
715 }
716 
717 // allocate parameter value
719  FD_DRTI("Function::FreeValues()");
720  for(int i = 0; i < ParamsSize(); i++) {
721  delete mParameterValues.at(i);
722  mParameterValues.at(i) =0;
723  }
724 }
725 
726 
727 // type check wrapper
728 bool Function::TypeCheck(int n) {
729  FD_DRTI("Function::TypeCheck()");
730  if(mVariantIndex<0) {
731  std::stringstream err;
732  err << "Variant not set" << std::endl;
733  throw Exception("Function::TypeCheck(n)", err.str(), 48);
734  }
735  if(n<0 || n>= ParamsSize()) {
736  std::stringstream err;
737  err << "Parameter out of range" << std::endl;
738  throw Exception("Function::Typechek(n)", err.str(), 48);
739  }
740  bool res=DoTypeCheck(n);
741  FD_DRTI("Function::TypeCheck() done, ok=" << res);
742  return res;
743 }
744 
745 // type check wrapper
747  FD_DRTI("Function::TypeCheck()");
748  if(mVariantIndex<0) {
749  std::stringstream err;
750  err << "Variant not set" << std::endl;
751  throw Exception("Function::TypeCheck()", err.str(), 48);
752  }
753  for(int i=0; i<ParamsSize(); i++)
754  if(!DoTypeCheck(i)) return false;
755  FD_DRTI("Function::TypeCheck() done, ok");
756  return true;
757 }
758 
759 // exec wrapper
760 void Function::Execute(void){
761  FD_DRTI("Function::Execute()");
762  if(!Variant()) {
763  std::stringstream err;
764  err << "Variant not set" << std::endl;
765  throw Exception("Function::Execute()", err.str(), 48);
766  }
767  for(int n=0; n<ParamsSize(); n++) {
768  if(!DoTypeCheck(n)) {
769  std::stringstream err;
770  err << "Cannot cast parameter \"" << Variant()->At(n).Name() <<
771  "\" to type \"" << Variant()->At(n).Type() << "\"";
772  throw Exception("Function::Execute()", err.str(), 48);
773  }
774  }
775  DoExecute();
776  FD_DRTI("Function::Execute() done");
777 }
778 
779 
780 // token io (informative/debug)
781 void Function::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
782  (void) pContext;
783  std::string label = rLabel;
784  if(label == "") label = "Function";
785  FD_DRTI("Function::DoWrite(): file " << rTw.FileName() << " section " << label);
786  rTw.Columns(1);
787  rTw.WriteBegin(label);
788  rTw << "\n";
789  rTw.WriteBegin("Parameters");
790  for(int i = 0; i < ParamsSize(); i++){
791  rTw << typeid(ParamValue(i)).name();
792  rTw << "\n";
793  }
794  rTw.WriteEnd("Parameters");
795  rTw << "\n";
796  rTw.WriteEnd(label);
797  FD_DRTI("Function::DoWrite(): done");
798 }
799 
800 
801 } // namespace
802 
#define FD_DRTI(message)
Debug: optional on function and type definition.
Runtime interface, operations on faudes types.
Runtime interface, registry for faudes-types and functions.
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition: cfl_types.h:904
#define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype, ctype, cbase)
Definition: cfl_types.h:891
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition: cfl_types.h:893
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition: cfl_types.h:896
#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype, ctype, cbase)
faudes type implementation macros
Definition: cfl_types.h:889
faudes type implementation macros, overall
Definition: cfl_types.h:1128
void Clear(void)
Clear.
Definition: cfl_types.cpp:384
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:667
bool DoEqual(const Documentation &rOther) const
Std faudes type interface: test equality.
Definition: cfl_types.cpp:373
const std::string & Name(void) const
Get name of the entety to document (aka faudes-type or faudes-function).
Definition: cfl_types.cpp:396
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:642
void DoAssign(const Documentation &rSrc)
Std faudes type interface: assignment.
Definition: cfl_types.cpp:363
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:564
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:513
Faudes exception class.
A FunctionDefinition defines the interface to a faudes-function.
const Signature & Variant(const std::string &rName) const
Return reference to Signature by name.
void DoAssign(const FunctionDefinition &rSrc)
Std faudes type interface: assignment.
int VariantsSize(void) const
Return number of supported Signature instances.
virtual void ClearVariants(void)
Clear variants (keep docu and prototype)
Function * NewFunction() const
Construct function on heap.
const Function * Prototype(void) const
Return pointer to function object prototype.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
bool DoEqual(const FunctionDefinition &rOther) const
Std faudes type interface: test equality.
int VariantIndex(const std::string &rName) const
Return index of Signature by name.
virtual void AppendVariant(const Signature &pVar)
Add Signature to function definition.
std::map< std::string, int > mVariantIndexMap
Variant name to index map.
FunctionDefinition(const std::string &name="")
Constructor.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
std::vector< faudes::Signature > mVariants
Vector containing all supported Signatures.
Function * mpFunction
Prototype instance.
bool ExistsVariant(const std::string &varname) const
Test existence of variant by its name.
virtual void Clear(void)
Clear documentation-data and signature (keep prototype)
A faudes-function hosts parameter values of some faudes type and provides a method to perform an oper...
virtual bool DoTypeCheck(int n)=0
Method to test the type of an assigned parameter with the specified faudes::Signature (i....
virtual void Definition(const FunctionDefinition *fdef)
Set function definition.
void Execute(void)
Perform operation.
void AllocateValue(int i)
const FunctionDefinition * pFuncDef
corresponding function definition
const Signature * Variant(void) const
Return pointer to assigned faudes::Signature.
const FunctionDefinition * Definition(void) const
Get function definition.
Function(const FunctionDefinition *fdef)
Constructor For the function to be operational, a valid reference to the corresponding FunctionDefini...
void FreeValues(void)
Destruct parameter values.
bool TypeCheck(void)
Perform a type check on the list of current parameter values.
void AllocateValues(void)
Construct parameter values.
virtual void DoVariant(int n)
std::vector< Type * > mParameterValues
Vector of arguments.
void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write function-data (typeid-name of arguments) to TokenWriter.
void ParamValue(int n, Type *param)
Set parameter at certain position.
int mVariantIndex
current variant aka signature as index w.r.t.
virtual void DoExecute()=0
Executes code of reimplemented method of child class(es).
int ParamsSize(void) const
Return number of parameters with current signature.
int VariantsSize(void) const
Return number of variants.
virtual Function * New() const =0
Construct on heap.
Structure to model a parameter type within the Signature of a Function.
Definition: cfl_functions.h:45
std::string Str(void) const
Convenience method to produce a textual representation of a parameter.
std::string mTDName
Faudes type.
bool mCReturn
C-Return flag.
std::string mName
Name.
void Clear()
Set to "undefined".
bool operator==(const Parameter &rOther) const
Test equality.
bool CReturn(void) const
Get C-Return flag.
Parameter(void)
Constructor, default.
ParamAttr
A function parameter has has one out of four so called io-attrributes;.
Definition: cfl_functions.h:52
const std::string & Type(void) const
Get type.
const ParamAttr & Attribute(void) const
Get Attribute.
static std::string AStr(Parameter::ParamAttr attr)
Convenience method to produce a textual representation of an io attribute.
~Parameter(void)
Desctructor.
const std::string & Name(void) const
Get name.
ParamAttr mAttr
IO-Attribute.
Signature of a Function.
std::string mName
Variable to store name.
int Size(void) const
Return number of parameters.
Signature(void)
Constructor.
bool DoEqual(const Signature &rOther) const
Std faudes type interface: test equality.
void Clear(void)
Clear signature.
const std::string & Name(void) const
Return signature name.
const Parameter & At(int n) const
Get parameter type by position.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read signature from from TokenReader.
void Append(const Parameter &rParam)
Append positional parameter.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
std::vector< Parameter > mParameters
Vector of Parameter-objects.
void DoAssign(const Signature &rSrc)
Std faudes type interface: assignment.
A TokenReader reads sequential tokens from a file or string.
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
std::string ReadString(void)
Read string token.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
std::string FileName(void) const
Access the filename.
A TokenWriter writes sequential tokens to a file, a string or stdout.
std::string FileName(void) const
Get the filename.
void WriteEnd(const std::string &rLabel)
Write end label.
int Columns(void) const
Get number of columns in a line.
void WriteBegin(const std::string &rLabel)
Write begin label.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
@ Option
+xyZ+ (option string, may not contain a "+")
Definition: cfl_token.h:86
bool ExistsAttributeString(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:355
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:105
void InsAttribute(const std::string &name, const std::string &value)
Insert named attribute, no type.
Definition: cfl_token.cpp:299
void SetBegin(const std::string &rName)
Initialize as Begin token.
Definition: cfl_token.cpp:91
const std::string & AttributeStringValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:385
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
static TypeRegistry * G()
Method to access the single global instance of the registry.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
Type(void)
Constructor.
Definition: cfl_types.cpp:45
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen