cfl_cgenerator.cpp
Go to the documentation of this file.
1 /** @file cfl_cgenerator.cpp Classes TcGenerator, System and AttributeCFlags */
2 
3 
4 /* FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2006 Bernd Opitz
7  Copyright (C) 2007 Thomas Moor
8  Exclusive copyright is granted to Klaus Schmidt
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 
25 
26 #include "cfl_cgenerator.h"
27 
28 
29 namespace faudes {
30 
31 // instantiate to export symbols for API type System (clang 8.0.0 issue, 2017/12 )
32 /*
33 template class FAUDES_API TaNameSet<AttributeCFlags>;
34 */
35 
37  // template class FAUDES_API TaGenerator<AttributeVoid, AttributeVoid, AttributeCFlags,AttributeVoid>;
38 
39 /***********************************************************************************
40  *
41  * implementation of AttributeCFlags
42  *
43  */
44 
45 
46 // faudes type std
48 
49 // Assign my members
50 void AttributeCFlags::DoAssign(const AttributeCFlags& rSrcAttr) {
51  // call base
52  AttributeFlags::DoAssign(rSrcAttr);
53 }
54 
55 // Test my members
56 bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const {
57  // call base
58  if(!AttributeFlags::DoEqual(rOther)) return false;
59  // no additional members
60  return true;
61 }
62 
63 //Write(rTw)
64 // Note: you should write attributes in a section, so that
65 // the AttributeVoid read method can detect and skip them.
66 // Here, we make an execption of the rule ...
67 void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
68  (void) rLabel; (void) pContext;
69  if(IsDefault()) return;
70  FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
71  Token token;
72  // if no other flags used, write option string
73  if( (mFlags & ~mAllCFlags) == 0 ) {
74  std::string option;
76  if(Controllable()) option = option+"C";
77  else option = option+"c";
78  }
80  if(Observable()) option = option+"O";
81  else option = option+"o";
82  }
84  if(Forcible()) option = option+"F";
85  else option = option+"f";
86  }
88  if(Highlevel()) option = option+"A";
89  else option = option+"a";
90  }
91  if(option!="") {
92  token.SetOption(option);
93  rTw << token;
94  }
95  }
96  // if other flags used, write hex
97  else {
98  token.SetInteger16(mFlags);
99  rTw << token;
100  }
101 }
102 
103 //XWrite(rTw)
104 void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
105  (void) rLabel; (void) pContext;
106  if(IsDefault()) return;
107  FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
108  Token token;
109  // if further flags are used, let base class write with base 16
110  if( (mFlags & ~mAllCFlags) != 0 ) {
111  AttributeFlags::DoXWrite(rTw,rLabel,pContext);
112  }
113  // write friendly tags anyway
114  std::string option;
116  token.SetEmpty("Controllable");
117  if(!Controllable()) token.InsAttributeBoolean("value",0);
118  rTw.Write(token);
119  }
121  token.SetEmpty("Observable");
122  if(!Observable()) token.InsAttributeBoolean("value",0);
123  rTw.Write(token);
124  }
126  token.SetEmpty("Forcible");
127  if(!Forcible()) token.InsAttributeBoolean("value",0);
128  rTw.Write(token);
129  }
131  token.SetEmpty("HighLevel");
132  if(!Highlevel()) token.SetEmpty("LowLevel");
133  rTw.Write(token);
134  }
135 }
136 
137 //DoRead(rTr)
138 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
139  (void) rLabel; (void) pContext;
141  Token token;
142  rTr.Peek(token);
143  // faudes format, flags as integer
144  if(token.IsInteger16()) {
145  AttributeFlags::DoRead(rTr,rLabel,pContext);
146  return;
147  }
148  // faudes format, flags as option string
149  if(token.IsOption()) {
150  rTr.Get(token);
151  std::string option=token.OptionValue();
152  if(option.find( 'C', 0) != std::string::npos) SetControllable();
153  if(option.find( 'c', 0) != std::string::npos) ClrControllable();
154  if(option.find( 'O', 0) != std::string::npos) SetObservable();
155  if(option.find( 'o', 0) != std::string::npos) ClrObservable();
156  if(option.find( 'F', 0) != std::string::npos) SetForcible();
157  if(option.find( 'f', 0) != std::string::npos) ClrForcible();
158  if(option.find( 'A', 0) != std::string::npos) SetHighlevel();
159  if(option.find( 'a', 0) != std::string::npos) SetLowlevel();
160  return;
161  }
162  // xml format
163  while(true) {
164  rTr.Peek(token);
165  // explicit integer
166  if(token.IsBegin("Flags")) {
167  AttributeFlags::DoRead(rTr,rLabel,pContext);
168  continue;
169  }
170  // known bits
171  if(token.IsBegin("Controllable")) {
172  rTr.ReadBegin("Controllable",token);
173  SetControllable();
174  if(token.ExistsAttributeInteger("value"))
175  if(token.AttributeIntegerValue("value")==false)
176  ClrControllable();
177  rTr.ReadEnd("Controllable");
178  continue;
179  }
180  if(token.IsBegin("Observable")) {
181  rTr.ReadBegin("Observable",token);
182  SetObservable();
183  if(token.ExistsAttributeInteger("value"))
184  if(token.AttributeIntegerValue("value")==false)
185  ClrObservable();
186  rTr.ReadEnd("Observable");
187  continue;
188  }
189  if(token.IsBegin("Forcible")) {
190  rTr.ReadBegin("Forcible",token);
191  SetForcible();
192  if(token.ExistsAttributeInteger("value"))
193  if(token.AttributeIntegerValue("value")==false)
194  ClrForcible();
195  rTr.ReadEnd("Forcible");
196  continue;
197  }
198  if(token.IsBegin("HighLevel")) {
199  rTr.ReadBegin("HighLevel",token);
200  SetHighlevel();
201  if(token.ExistsAttributeInteger("value"))
202  if(token.AttributeIntegerValue("value")==false)
203  SetLowlevel();
204  continue;
205  }
206  if(token.IsBegin("LowLevel")) {
207  rTr.ReadBegin("LowLevel",token);
208  SetLowlevel();
209  if(token.ExistsAttributeInteger("value"))
210  if(token.AttributeIntegerValue("value")==false)
211  SetHighlevel();
212  continue;
213  }
214  // stop at unknown tag
215  break;
216  }
217 }
218 
219 
220 } // end namespace
Classes TcGenerator, System and AttributeCFlags.
#define FD_DC(message)
Debug: optional report on container operations.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Attribute class to model event controllability properties.
void SetHighlevel(void)
Set abstraction flag.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
void SetForcible(void)
Set forcible flag.
static const fType mAllCFlags
All flags used by CFlags.
void ClrControllable(void)
Clear controllable flag.
bool Forcible(void) const
Query forcibility.
void ClrForcible(void)
Clear forcible flag.
static const fType mDefCFlags
Overall default value.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
bool DoEqual(const AttributeCFlags &rOther) const
Test equality of configuration data.
bool Controllable(void) const
Query controllablility.
static const fType mAbstractionFlag
static const fType mForcibleFlag
static const fType mObservableFlag
void ClrObservable(void)
Clear observable flag.
bool Highlevel(void) const
Query abstaction flag.
static const fType mControllableFlag
virtual bool IsDefault(void) const
Test for default value.
void SetControllable(void)
Set controllable flag.
bool Observable(void) const
Query observablility.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter (XML format), see AttributeVoid for public wrappers.
void SetLowlevel(void)
Clear abstraction flag.
void SetObservable(void)
Set observable flag.
Boolean flags Attribute.
bool DoEqual(const AttributeFlags &rOther) const
Test equality of configuration data.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see Type for public wrappers.
fType mFlags
Flags (public access for convenience)
Generator with controllability attributes.
A TokenReader reads sequential tokens from a file or string.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
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.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void Write(Token &rToken)
Write next token.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:54
bool IsInteger16(void) const
Test token Type.
Definition: cfl_token.cpp:224
void SetInteger16(const Int number)
Initialize as Integer16 token.
Definition: cfl_token.cpp:129
Int AttributeIntegerValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:397
void InsAttributeBoolean(const std::string &name, Int value)
Insert named attribute with boolean value.
Definition: cfl_token.cpp:337
void SetOption(const std::string &rName)
Initialize as Option token.
Definition: cfl_token.cpp:113
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:259
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:106
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:184
bool ExistsAttributeInteger(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:366
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:239
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
libFAUDES resides within the namespace faudes.

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen