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

libFAUDES 2.28a --- 2016.09.13 --- c++ api documentaion by doxygen