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 template class FAUDES_TAPI TcGenerator<AttributeVoid, AttributeVoid, AttributeCFlags,AttributeVoid>;
35 */
36 
37 
38 /***********************************************************************************
39  *
40  * implementation of AttributeCFlags
41  *
42  */
43 
44 
45 // faudes type std
46 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeCFlags,AttributeFlags)
47 
48 // Assign my members
49 void AttributeCFlags::DoAssign(const AttributeCFlags& rSrcAttr) {
50  // call base
51  AttributeFlags::DoAssign(rSrcAttr);
52 }
53 
54 // Test my members
55 bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const {
56  // call base
57  if(!AttributeFlags::DoEqual(rOther)) return false;
58  // no additional members
59  return true;
60 }
61 
62 //Write(rTw)
63 // Note: you should write attributes in a section, so that
64 // the AttributeVoid read method can detect and skip them.
65 // Here, we make an execption of the rule ...
66 void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
67  (void) rLabel; (void) pContext;
68  if(IsDefault()) return;
69  FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
70  Token token;
71  // if no other flags used, write option string
72  if( (mFlags & ~mAllCFlags) == 0 ) {
73  std::string option;
75  if(Controllable()) option = option+"C";
76  else option = option+"c";
77  }
79  if(Observable()) option = option+"O";
80  else option = option+"o";
81  }
83  if(Forcible()) option = option+"F";
84  else option = option+"f";
85  }
87  if(Highlevel()) option = option+"A";
88  else option = option+"a";
89  }
90  if(option!="") {
91  token.SetOption(option);
92  rTw << token;
93  }
94  }
95  // if other flags used, write hex
96  else {
97  token.SetInteger16(mFlags);
98  rTw << token;
99  }
100 }
101 
102 //XWrite(rTw)
103 void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
104  (void) rLabel; (void) pContext;
105  if(IsDefault()) return;
106  FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
107  Token token;
108  // if further flags are used, let base class write with base 16
109  if( (mFlags & ~mAllCFlags) != 0 ) {
110  AttributeFlags::DoXWrite(rTw,rLabel,pContext);
111  }
112  // write friendly tags anyway
113  std::string option;
115  token.SetEmpty("Controllable");
116  if(!Controllable()) token.InsAttributeBoolean("value",0);
117  rTw.Write(token);
118  }
120  token.SetEmpty("Observable");
121  if(!Observable()) token.InsAttributeBoolean("value",0);
122  rTw.Write(token);
123  }
125  token.SetEmpty("Forcible");
126  if(!Forcible()) token.InsAttributeBoolean("value",0);
127  rTw.Write(token);
128  }
130  token.SetEmpty("HighLevel");
131  if(!Highlevel()) token.SetEmpty("LowLevel");
132  rTw.Write(token);
133  }
134 }
135 
136 //DoRead(rTr)
137 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
138  (void) rLabel; (void) pContext;
140  Token token;
141  rTr.Peek(token);
142  // faudes format, flags as integer
143  if(token.IsInteger16()) {
144  AttributeFlags::DoRead(rTr,rLabel,pContext);
145  return;
146  }
147  // faudes format, flags as option string
148  if(token.IsOption()) {
149  rTr.Get(token);
150  std::string option=token.OptionValue();
151  if(option.find( 'C', 0) != std::string::npos) SetControllable();
152  if(option.find( 'c', 0) != std::string::npos) ClrControllable();
153  if(option.find( 'O', 0) != std::string::npos) SetObservable();
154  if(option.find( 'o', 0) != std::string::npos) ClrObservable();
155  if(option.find( 'F', 0) != std::string::npos) SetForcible();
156  if(option.find( 'f', 0) != std::string::npos) ClrForcible();
157  if(option.find( 'A', 0) != std::string::npos) SetHighlevel();
158  if(option.find( 'a', 0) != std::string::npos) SetLowlevel();
159  return;
160  }
161  // xml format
162  while(true) {
163  rTr.Peek(token);
164  // explicit integer
165  if(token.IsBegin("Flags")) {
166  AttributeFlags::DoRead(rTr,rLabel,pContext);
167  continue;
168  }
169  // known bits
170  if(token.IsBegin("Controllable")) {
171  rTr.ReadBegin("Controllable",token);
172  SetControllable();
173  if(token.ExistsAttributeInteger("value"))
174  if(token.AttributeIntegerValue("value")==false)
175  ClrControllable();
176  rTr.ReadEnd("Controllable");
177  continue;
178  }
179  if(token.IsBegin("Observable")) {
180  rTr.ReadBegin("Observable",token);
181  SetObservable();
182  if(token.ExistsAttributeInteger("value"))
183  if(token.AttributeIntegerValue("value")==false)
184  ClrObservable();
185  rTr.ReadEnd("Observable");
186  continue;
187  }
188  if(token.IsBegin("Forcible")) {
189  rTr.ReadBegin("Forcible",token);
190  SetForcible();
191  if(token.ExistsAttributeInteger("value"))
192  if(token.AttributeIntegerValue("value")==false)
193  ClrForcible();
194  rTr.ReadEnd("Forcible");
195  continue;
196  }
197  if(token.IsBegin("HighLevel")) {
198  rTr.ReadBegin("HighLevel",token);
199  SetHighlevel();
200  if(token.ExistsAttributeInteger("value"))
201  if(token.AttributeIntegerValue("value")==false)
202  SetLowlevel();
203  continue;
204  }
205  if(token.IsBegin("LowLevel")) {
206  rTr.ReadBegin("LowLevel",token);
207  SetLowlevel();
208  if(token.ExistsAttributeInteger("value"))
209  if(token.AttributeIntegerValue("value")==false)
210  SetHighlevel();
211  continue;
212  }
213  // stop at unknown tag
214  break;
215  }
216 }
217 
218 
219 } // end namespace
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition: cfl_types.h:951
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
static const fType mAllCFlags
bool Forcible(void) const
static const fType mDefCFlags
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
bool DoEqual(const AttributeCFlags &rOther) const
bool Controllable(void) const
static const fType mAbstractionFlag
static const fType mForcibleFlag
static const fType mObservableFlag
bool Highlevel(void) const
static const fType mControllableFlag
virtual bool IsDefault(void) const
bool Observable(void) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool DoEqual(const AttributeFlags &rOther) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void DoAssign(const AttributeFlags &rSrcAttr)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
void Write(Token &rToken)
bool IsInteger16(void) const
Definition: cfl_token.cpp:224
void SetInteger16(const Int number)
Definition: cfl_token.cpp:129
Int AttributeIntegerValue(const std::string &name)
Definition: cfl_token.cpp:397
void InsAttributeBoolean(const std::string &name, Int value)
Definition: cfl_token.cpp:337
void SetOption(const std::string &rName)
Definition: cfl_token.cpp:113
bool IsBegin(void) const
Definition: cfl_token.cpp:259
void SetEmpty(const std::string &rName)
Definition: cfl_token.cpp:106
const std::string & OptionValue(void) const
Definition: cfl_token.cpp:184
bool ExistsAttributeInteger(const std::string &name)
Definition: cfl_token.cpp:366
bool IsOption(void) const
Definition: cfl_token.cpp:239

libFAUDES 2.33c --- 2025.05.15 --- c++ api documentaion by doxygen