cfl_elementary.cpp
Go to the documentation of this file.
1 /** @file cfl_elementary.cpp Runtime interface, elementary types */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2010 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_elementary.h"
24 
25 namespace faudes{
26 
27 
28 
29 /*
30 ********************************************************************
31 ********************************************************************
32 ********************************************************************
33 
34 Implementation of class Integer
35 
36 ********************************************************************
37 ********************************************************************
38 ********************************************************************
39 */
40 
41 
42 // public:
44  CValue(0);
45 }
46 
48  CValue(val);
49 }
50 
52  return(new Integer());
53 }
54 
56  return(new Integer(mCInteger));
57 }
58 
59 const Integer* Integer::Cast(const Type* pOther) const{
60  return dynamic_cast<const Integer*>(pOther);
61 }
62 
63 void Integer::CValue(Int val){
64  mCInteger = val;
65 }
66 
68  return(mCInteger);
69 }
70 
72  return &mCInteger;
73 }
74 
75 void Integer::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
76  (void) pContext;
77  std::string label=rLabel;
78  std::string ftype="Integer";
79  if(label=="") label=ftype;
80  Token btag;
81  btag.SetBegin(label);
82  if(ftype!=label) btag.InsAttributeString("ftype",ftype);
83  FD_DRTI("Integer::DoWrite(): file " << rTw.FileName() << " section " << label);
84  rTw.Write(btag);
85  rTw.WriteFloat(mCInteger);
86  rTw.WriteEnd(label);
87 }
88 
89 void Integer::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
90  (void) pContext;
91  std::string label = rLabel;
92  if(label == "") label = "Integer";
93  FD_DRTI("Integer()::DoRead(): file " << rTr.FileName() << " section " << label);
94  rTr.ReadBegin(label);
95  mCInteger = (Int)rTr.ReadFloat();
96  rTr.ReadEnd(label);
97  FD_DRTI("Integer::DoRead(): done");
98 }
99 
100 
101 // integer sum, uniform rti api
102 long int IntegerSum(const Integer& arg1, const Integer& arg2) {
103  return arg1+arg2;
104 }
105 
106 // integer sum, uniform rti api
107 long int IntegerSum(const IntegerVector& intvect) {
108  long int res=0;
109  for(unsigned int i=0; i< intvect.Size(); i++)
110  res+=intvect.At(i);
111  return res;
112 }
113 
114 
115 /*
116 ********************************************************************
117 ********************************************************************
118 ********************************************************************
119 
120 Implementation of class String
121 
122 ********************************************************************
123 ********************************************************************
124 ********************************************************************
125 */
126 
127 
128 // constructor
130  CValue("");
131 }
132 
133 // constructor
134 String::String(std::string val) {
135  CValue(val);
136 }
137 
138 // factory constructor
140  return new String();
141 }
142 
143 // factory constructor
145  return new String(mCString);
146 }
147 
148 // cast
149 const String* String::Cast(const Type* pOther) const{
150  return dynamic_cast<const String*>(pOther);
151 }
152 
153 // c value
154 std::string String::CValue() const{
155  return mCString;
156 }
157 
158 // c value
159 void String::CValue(std::string s){
160  mCString = s;
161 }
162 
163 // c ref
164 std::string* String::CReference() {
165  return &mCString;
166 }
167 
168 // token io
169 void String::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
170  (void) pContext;
171  std::string label=rLabel;
172  std::string ftype="String";
173  if(label=="") label=ftype;
174  Token btag;
175  btag.SetBegin(label);
176  if(ftype!=label) btag.InsAttributeString("ftype",ftype);
177  FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label);
178  rTw.Write(btag);
179  rTw.WriteString(mCString);
180  rTw.WriteEnd(label);
181 }
182 
183 // token io
184 void String::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
185  (void) pContext;
186  std::string label = rLabel;
187  if(label == "") label = "String";
188  FD_DRTI("String::DoRead(): file " << rTr.FileName() << " section " << label);
189  rTr.ReadBegin(label);
190  mCString = rTr.ReadString();
191  rTr.ReadEnd(label);
192  FD_DRTI("String::DoRead(): done");
193 }
194 
195 
196 /*
197 ********************************************************************
198 ********************************************************************
199 ********************************************************************
200 
201 Implementation of class Boolean
202 
203 ********************************************************************
204 ********************************************************************
205 ********************************************************************
206 */
207 
208 
209 // constructor
211  CValue(true);
212 }
213 
214 // constructor
215 Boolean::Boolean(bool val) {
216  CValue(val);
217 }
218 
219 // factory constructor
221  return new Boolean();
222 }
223 
224 // factory constructor
226  return new Boolean(mCBool);
227 }
228 
229 // cast
230 const Boolean* Boolean::Cast(const Type* pOther) const{
231  return dynamic_cast<const Boolean*>(pOther);
232 }
233 
234 // cvaliu
235 void Boolean::CValue(bool val){
236  mCBool = val;
237 }
238 
239 // cvalue
240 bool Boolean::CValue() const{
241  return(mCBool);
242 }
243 
244 // c ref
246  return &mCBool;
247 }
248 
249 // token io
250 void Boolean::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
251  (void) pContext;
252  std::string label=rLabel;
253  std::string ftype="Boolean";
254  if(label=="") label=ftype;
255  Token btag;
256  btag.SetBegin(label);
257  if(ftype!=label) btag.InsAttributeString("ftype",ftype);
258  FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label);
259  rTw.Write(btag);
260  if(mCBool) rTw.WriteString("true");
261  else rTw.WriteString("false");
262  rTw.WriteEnd(label);
263 }
264 
265 
266 // token io
267 void Boolean::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
268  (void) pContext;
269  std::string label = rLabel;
270  if(label == "") label = "Boolean";
271  FD_DRTI("Boolean::DoRead(): file " << rTr.FileName() << " section " << label);
272  rTr.ReadBegin(label);
273  std::string value = rTr.ReadString();
274  std::transform(value.begin(), value.end(), value.begin(), tolower);
275  if(value=="true") mCBool=true;
276  else if(value=="false") mCBool=false;
277  else {
278  std::stringstream err;
279  err << "Expected true or false: " << rTr.FileLine();
280  throw Exception("Boolean::DoRead()", err.str(), 52);
281  }
282  rTr.ReadEnd(label);
283  FD_DRTI("Boolean::DoRead(): done");
284 }
285 
286 
287 
288 } //namspace
289 

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen