cfl_elementary.hGo to the documentation of this file.00001 /** @file cfl_elementary.h 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 #ifndef FAUDES_ELEMENTARY_H 00024 #define FAUDES_ELEMENTARY_H 00025 00026 #include "cfl_types.h" 00027 #include "cfl_functions.h" 00028 #include "cfl_basevector.h" 00029 00030 00031 00032 namespace faudes { 00033 00034 00035 00036 /* 00037 ******************************************************************** 00038 ******************************************************************** 00039 ******************************************************************** 00040 00041 Elementary type, representing an integer value. 00042 00043 ******************************************************************** 00044 ******************************************************************** 00045 ******************************************************************** 00046 */ 00047 00048 /** Elementary type */ 00049 class Integer : public Type { 00050 00051 public: 00052 /** Constructor */ 00053 Integer(void); 00054 00055 /** 00056 * Constructor provided with initial value. 00057 * 00058 * @param val 00059 * Initial value. 00060 */ 00061 Integer(Int val); 00062 00063 /** Destructor */ 00064 ~Integer(void){} 00065 00066 /** 00067 * Construct on heap. 00068 * Create new Integer instance and return pointer. 00069 * 00070 * @return 00071 * Pointer to Integer instance. 00072 * 00073 */ 00074 virtual Integer* New(void) const; 00075 00076 /** 00077 * Construct copy on heap. 00078 * Create new Integer instance and return pointer. 00079 * 00080 * @return 00081 * Pointer to Integer instance. 00082 * 00083 */ 00084 virtual Integer* Copy(void) const; 00085 00086 /** 00087 * Cast the other object to Integer. 00088 * Returns NULL if the cast is not possible. 00089 * 00090 * @param pOther 00091 * Pointer to object to cast. 00092 * @return 00093 * Pointer to Integer instance, or NULL 00094 * 00095 */ 00096 virtual const Integer* Cast(const Type* pOther) const; 00097 00098 /** 00099 * Set value. 00100 * 00101 * @param val 00102 * Value to be set. 00103 */ 00104 void CValue(Int val); 00105 00106 /** 00107 * Get value. 00108 * 00109 * @return 00110 * Value of object. (Int) 00111 */ 00112 Int CValue(void) const; 00113 00114 /** 00115 * Get reference. 00116 * 00117 * @return 00118 * Reference to c value. 00119 */ 00120 Int* CReference(void); 00121 00122 /** 00123 * Sum operator. 00124 */ 00125 Integer operator+ (const Int& clint){ 00126 CValue(mCInteger + clint); 00127 return(*this); 00128 } 00129 00130 /** 00131 * Sum operator. 00132 */ 00133 Integer operator+ (const Integer& coint){ 00134 CValue(mCInteger + coint.CValue()); 00135 return(*this); 00136 } 00137 00138 /** 00139 * Assignment operator. 00140 */ 00141 Integer operator= (const Int& clint){ 00142 CValue(clint); 00143 return(*this); 00144 } 00145 00146 /** 00147 * Assignment operator. 00148 */ 00149 Integer operator= (const Integer& coint){ 00150 CValue(coint.CValue()); 00151 return(*this); 00152 } 00153 00154 /** 00155 * Assignment/Sum operator 00156 */ 00157 Integer operator+= (const Int& clint){ 00158 Int litmp = CValue(); 00159 CValue(litmp + clint); 00160 return(*this); 00161 } 00162 00163 /** 00164 * Assignment/Sum operator 00165 */ 00166 Integer operator+= (const Integer& coint){ 00167 Int litmp = CValue() + coint.CValue(); 00168 CValue(litmp); 00169 return(*this); 00170 } 00171 00172 /** 00173 * Conversion to C++ type 00174 */ 00175 operator Int() const { return CValue();}; 00176 00177 00178 /** 00179 * Reimplementation of faudes::Type::DoWrite() 00180 * Write data to Tokenwriter. 00181 * 00182 * @param rTw 00183 * Reference to TokenWriter. 00184 * @param rLabel 00185 * Label of section to write. 00186 * @param pContext 00187 * Context information 00188 * 00189 * @exception Exception 00190 * - IO Error (id 2) 00191 */ 00192 void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const; 00193 00194 /** 00195 * Read data from TokenReader. 00196 * 00197 * @param rTr 00198 * Reference to TokenReader. 00199 * @param rLabel 00200 * Section to read. 00201 * @param pContext 00202 * Context information 00203 * 00204 * @exception Exception 00205 * - Token mismatch 00206 * - IO Error 00207 */ 00208 void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00209 00210 protected: 00211 00212 /** Variable to store current value. */ 00213 Int mCInteger; 00214 00215 }; // Integer 00216 00217 // convenience typedef 00218 typedef TBaseVector<Integer> IntegerVector; 00219 00220 // Sum of two integers, uniform rti api 00221 long int IntegerSum(const Integer& arg1, const Integer& arg2); 00222 00223 // Sum of multiple integers, uniform rti api 00224 long int IntegerSum(const IntegerVector& intvect); 00225 00226 /* 00227 ******************************************************************** 00228 ******************************************************************** 00229 ******************************************************************** 00230 00231 Elementary type, representing a string value. 00232 00233 ******************************************************************** 00234 ******************************************************************** 00235 ******************************************************************** 00236 */ 00237 00238 /** Elementary type */ 00239 class String : public Type{ 00240 00241 public: 00242 /** Constructor */ 00243 String(void); 00244 00245 /** 00246 * Constructor provided with initial value. 00247 * 00248 * @param val 00249 * Initial value. 00250 */ 00251 String(std::string val); 00252 00253 /** Destructor */ 00254 ~String(void){} 00255 00256 /** 00257 * Construct on heap. 00258 * Create new String instance and return pointer. 00259 * 00260 * NOTE: 00261 * Calling function takes control. 00262 * 00263 * @return 00264 * Pointer to String instance. 00265 */ 00266 virtual String* New(void) const; 00267 00268 /** 00269 * Construct copy on heap. 00270 * Create new String instance and return pointer. 00271 * 00272 * @return 00273 * Pointer to Integer instance. 00274 * 00275 */ 00276 virtual String* Copy(void) const; 00277 00278 /** 00279 * Cast the other object to String. 00280 * Returns NULL if the cast is not possible. 00281 * 00282 * @param pOther 00283 * Pointer to object to cast. 00284 * @return 00285 * Pointer to String instance, or NULL 00286 * 00287 */ 00288 virtual const String* Cast(const Type* pOther) const; 00289 00290 /** 00291 * Set value. 00292 * 00293 * @param val 00294 * Value to be set. (std::string) 00295 */ 00296 void CValue(std::string val); 00297 00298 /** 00299 * Get value 00300 * 00301 * @return 00302 * Value of object. (std::string) 00303 */ 00304 std::string CValue(void) const; 00305 00306 /** 00307 * Get reference. 00308 * 00309 * @return 00310 * Reference to c value. 00311 */ 00312 std::string* CReference(void); 00313 00314 /** 00315 * Assignment operator. 00316 */ 00317 String& operator= (const String& costr){ 00318 CValue(costr.CValue()); 00319 return(*this); 00320 } 00321 00322 /* 00323 * Assignment operator, std::string source 00324 */ 00325 String& operator= (const std::string& cstr){ 00326 CValue(cstr); 00327 return(*this); 00328 } 00329 00330 /** 00331 * Conversion to std::string 00332 */ 00333 operator std::string() const { return CValue();}; 00334 00335 00336 /** 00337 * Write data to Tokenwriter. 00338 * 00339 * @param rTw 00340 * Reference to TokenWriter. 00341 * @param rLabel 00342 * Label of section to write. 00343 * @param pContext 00344 * Write context to provide contextual information (ignored) 00345 * 00346 * @exception Exception 00347 * - IO Error 00348 */ 00349 void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const; 00350 00351 00352 /** 00353 * Read data from TokenReader. 00354 * 00355 * @param rTr 00356 * Reference to TokenReader. 00357 * @param rLabel 00358 * Section to read. 00359 * @param pContext 00360 * Read context to provide contextual information (ignored) 00361 * 00362 * @exception Exception 00363 * - Token mismatch 00364 * - IO Error 00365 */ 00366 void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00367 00368 protected: 00369 /** Variable to store current value. */ 00370 std::string mCString; 00371 00372 }; // String 00373 00374 00375 00376 00377 /* 00378 ******************************************************************** 00379 ******************************************************************** 00380 ******************************************************************** 00381 00382 Elementary type, representing a boolean value. 00383 00384 ******************************************************************** 00385 ******************************************************************** 00386 ******************************************************************** 00387 */ 00388 00389 /** Elementary type */ 00390 class Boolean : public Type{ 00391 00392 public: 00393 /** Constructor */ 00394 Boolean(void); 00395 00396 /** 00397 * Constructor provided with initial value. 00398 * 00399 * @param val 00400 * Initial value. (bool) 00401 */ 00402 Boolean(bool val); 00403 00404 /** Destructor */ 00405 ~Boolean(void){} 00406 00407 /** 00408 * Construct on heap. 00409 * Create new Boolean instance and return pointer. 00410 * 00411 * NOTE: 00412 * Calling function takes control. 00413 * 00414 * @return 00415 * Pointer to Boolean instance. 00416 */ 00417 virtual Boolean* New(void) const; 00418 00419 /** 00420 * Construct copy on heap. 00421 * Create new Boolean instance and return pointer. 00422 * 00423 * @return 00424 * Pointer to Boolean instance. 00425 * 00426 */ 00427 virtual Boolean* Copy(void) const; 00428 00429 /** 00430 * Cast the other object to Boolean. 00431 * Returns NULL if the cast is not possible. 00432 * 00433 * @param pOther 00434 * Pointer to object to cast. 00435 * @return 00436 * Pointer to Boolean instance, or NULL 00437 * 00438 */ 00439 virtual const Boolean* Cast(const Type* pOther) const; 00440 00441 /** 00442 * Set value. 00443 * 00444 * @param val 00445 * Value to be set. 00446 */ 00447 void CValue(bool val); 00448 00449 /** 00450 * Get value. 00451 * 00452 * @return 00453 * Value of object. (bool) 00454 */ 00455 bool CValue(void) const; 00456 00457 /** 00458 * Get reference. 00459 * 00460 * @return 00461 * Reference to c value. 00462 */ 00463 bool* CReference(void); 00464 00465 /** 00466 * Assignment operator. 00467 */ 00468 Boolean operator= (const bool& bbool){ 00469 CValue(bbool); 00470 return(*this); 00471 } 00472 00473 /** 00474 * Assignment operator. 00475 */ 00476 Boolean operator= (const Boolean& cobool){ 00477 CValue(cobool.CValue()); 00478 return(*this); 00479 } 00480 00481 00482 /** 00483 * Conversion to C++ type bool 00484 */ 00485 operator bool() const { return CValue();}; 00486 00487 /** 00488 * Write data to Tokenwriter. 00489 * 00490 * NOTE: 00491 * 0 = false 00492 * 1 = true 00493 * 00494 * @param rTw 00495 * Reference to TokenWriter. 00496 * @param rLabel 00497 * Label of section to write. 00498 * @param pContext 00499 * Write context to provide contextual information (ignored) 00500 * 00501 * @exception Exception 00502 * - IO Error 00503 */ 00504 void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const; 00505 00506 /** 00507 * Read data from TokenReader. 00508 * 00509 * NOTE: 00510 * 0 = false 00511 * 1 = true 00512 * 00513 * @param rTr 00514 * Reference to TokenReader. 00515 * @param rLabel 00516 * Section to read. 00517 * @param pContext 00518 * Read context to provide contextual information (ignored) 00519 * 00520 * @exception Exception 00521 * - Token mismatch 00522 * - IO Error 00523 */ 00524 void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00525 00526 protected: 00527 00528 /** Variable to store current value. */ 00529 bool mCBool; 00530 00531 }; // Boolean 00532 00533 00534 00535 } // namespace 00536 00537 #endif libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |