cfl_elementary.cppGo to the documentation of this file.00001 /** @file cfl_elementary.cpp Runtime interface, elementary types */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2009 Ruediger Berndt 00006 Copyright (C) 2010 Thomas Moor 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 #include "cfl_elementary.h" 00024 00025 namespace faudes{ 00026 00027 00028 00029 /* 00030 ******************************************************************** 00031 ******************************************************************** 00032 ******************************************************************** 00033 00034 Implementation of class Integer 00035 00036 ******************************************************************** 00037 ******************************************************************** 00038 ******************************************************************** 00039 */ 00040 00041 00042 // public: 00043 Integer::Integer() { 00044 CValue(0); 00045 } 00046 00047 Integer::Integer(Int val) { 00048 CValue(val); 00049 } 00050 00051 Integer* Integer::New() const{ 00052 return(new Integer()); 00053 } 00054 00055 Integer* Integer::Copy() const{ 00056 return(new Integer(mCInteger)); 00057 } 00058 00059 const Integer* Integer::Cast(const Type* pOther) const{ 00060 return dynamic_cast<const Integer*>(pOther); 00061 } 00062 00063 void Integer::CValue(Int val){ 00064 mCInteger = val; 00065 } 00066 00067 Int Integer::CValue() const{ 00068 return(mCInteger); 00069 } 00070 00071 Int* Integer::CReference() { 00072 return &mCInteger; 00073 } 00074 00075 void Integer::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{ 00076 (void) pContext; 00077 std::string label=rLabel; 00078 std::string ftype="Integer"; 00079 if(label=="") label=ftype; 00080 Token btag; 00081 btag.SetBegin(label); 00082 if(ftype!=label) btag.InsAttributeString("ftype",ftype); 00083 FD_DRTI("Integer::DoWrite(): file " << rTw.FileName() << " section " << label); 00084 rTw.Write(btag); 00085 rTw.WriteFloat(mCInteger); 00086 rTw.WriteEnd(label); 00087 } 00088 00089 void Integer::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00090 (void) pContext; 00091 std::string label = rLabel; 00092 if(label == "") label = "Integer"; 00093 FD_DRTI("Integer()::DoRead(): file " << rTr.FileName() << " section " << label); 00094 rTr.ReadBegin(label); 00095 mCInteger = (Int)rTr.ReadFloat(); 00096 rTr.ReadEnd(label); 00097 FD_DRTI("Integer::DoRead(): done"); 00098 } 00099 00100 00101 // integer sum, uniform rti api 00102 long int IntegerSum(const Integer& arg1, const Integer& arg2) { 00103 return arg1+arg2; 00104 } 00105 00106 // integer sum, uniform rti api 00107 long int IntegerSum(const IntegerVector& intvect) { 00108 long int res=0; 00109 for(unsigned int i=0; i< intvect.Size(); i++) 00110 res+=intvect.At(i); 00111 return res; 00112 } 00113 00114 00115 /* 00116 ******************************************************************** 00117 ******************************************************************** 00118 ******************************************************************** 00119 00120 Implementation of class String 00121 00122 ******************************************************************** 00123 ******************************************************************** 00124 ******************************************************************** 00125 */ 00126 00127 00128 // constructor 00129 String::String() { 00130 CValue(""); 00131 } 00132 00133 // constructor 00134 String::String(std::string val) { 00135 CValue(val); 00136 } 00137 00138 // factory constructor 00139 String* String::New() const{ 00140 return new String(); 00141 } 00142 00143 // factory constructor 00144 String* String::Copy() const{ 00145 return new String(mCString); 00146 } 00147 00148 // cast 00149 const String* String::Cast(const Type* pOther) const{ 00150 return dynamic_cast<const String*>(pOther); 00151 } 00152 00153 // c value 00154 std::string String::CValue() const{ 00155 return mCString; 00156 } 00157 00158 // c value 00159 void String::CValue(std::string s){ 00160 mCString = s; 00161 } 00162 00163 // c ref 00164 std::string* String::CReference() { 00165 return &mCString; 00166 } 00167 00168 // token io 00169 void String::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{ 00170 (void) pContext; 00171 std::string label=rLabel; 00172 std::string ftype="String"; 00173 if(label=="") label=ftype; 00174 Token btag; 00175 btag.SetBegin(label); 00176 if(ftype!=label) btag.InsAttributeString("ftype",ftype); 00177 FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label); 00178 rTw.Write(btag); 00179 rTw.WriteString(mCString); 00180 rTw.WriteEnd(label); 00181 } 00182 00183 // token io 00184 void String::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00185 (void) pContext; 00186 std::string label = rLabel; 00187 if(label == "") label = "String"; 00188 FD_DRTI("String::DoRead(): file " << rTr.FileName() << " section " << label); 00189 rTr.ReadBegin(label); 00190 mCString = rTr.ReadString(); 00191 rTr.ReadEnd(label); 00192 FD_DRTI("String::DoRead(): done"); 00193 } 00194 00195 00196 /* 00197 ******************************************************************** 00198 ******************************************************************** 00199 ******************************************************************** 00200 00201 Implementation of class Boolean 00202 00203 ******************************************************************** 00204 ******************************************************************** 00205 ******************************************************************** 00206 */ 00207 00208 00209 // constructor 00210 Boolean::Boolean() { 00211 CValue(true); 00212 } 00213 00214 // constructor 00215 Boolean::Boolean(bool val) { 00216 CValue(val); 00217 } 00218 00219 // factory constructor 00220 Boolean* Boolean::New() const{ 00221 return new Boolean(); 00222 } 00223 00224 // factory constructor 00225 Boolean* Boolean::Copy() const{ 00226 return new Boolean(mCBool); 00227 } 00228 00229 // cast 00230 const Boolean* Boolean::Cast(const Type* pOther) const{ 00231 return dynamic_cast<const Boolean*>(pOther); 00232 } 00233 00234 // cvaliu 00235 void Boolean::CValue(bool val){ 00236 mCBool = val; 00237 } 00238 00239 // cvalue 00240 bool Boolean::CValue() const{ 00241 return(mCBool); 00242 } 00243 00244 // c ref 00245 bool* Boolean::CReference() { 00246 return &mCBool; 00247 } 00248 00249 // token io 00250 void Boolean::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{ 00251 (void) pContext; 00252 std::string label=rLabel; 00253 std::string ftype="Boolean"; 00254 if(label=="") label=ftype; 00255 Token btag; 00256 btag.SetBegin(label); 00257 if(ftype!=label) btag.InsAttributeString("ftype",ftype); 00258 FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label); 00259 rTw.Write(btag); 00260 if(mCBool) rTw.WriteString("true"); 00261 else rTw.WriteString("false"); 00262 rTw.WriteEnd(label); 00263 } 00264 00265 00266 // token io 00267 void Boolean::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00268 (void) pContext; 00269 std::string label = rLabel; 00270 if(label == "") label = "Boolean"; 00271 FD_DRTI("Boolean::DoRead(): file " << rTr.FileName() << " section " << label); 00272 rTr.ReadBegin(label); 00273 std::string value = rTr.ReadString(); 00274 std::transform(value.begin(), value.end(), value.begin(), tolower); 00275 if(value=="true") mCBool=true; 00276 else if(value=="false") mCBool=false; 00277 else { 00278 std::stringstream err; 00279 err << "Expected true or false: " << rTr.FileLine(); 00280 throw Exception("Boolean::DoRead()", err.str(), 52); 00281 } 00282 rTr.ReadEnd(label); 00283 FD_DRTI("Boolean::DoRead(): done"); 00284 } 00285 00286 00287 00288 } //namspace 00289 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |