libFAUDES

Sections

Index

cfl_elementary.cpp

Go 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(SignedIdx 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(SignedIdx val){
00064   mCInteger = val;
00065 }
00066 
00067 SignedIdx Integer::CValue() const{
00068   return(mCInteger);
00069 }
00070 
00071 SignedIdx* 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   if(label=="") label="Integer";
00079   FD_DRTI("Integer::DoWrite(): file " << rTw.FileName() << " section " << label);
00080   rTw.WriteBegin(label);
00081   rTw.WriteFloat(mCInteger);
00082   rTw.WriteEnd(label);
00083 }
00084 
00085 void Integer::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00086   (void) pContext;
00087   std::string label = rLabel;
00088   if(label == "") label = "Integer";
00089   FD_DRTI("Integer()::DoRead(): file " << rTr.FileName() << "  section " << label);
00090   rTr.SeekBegin(label);
00091   mCInteger = (SignedIdx)rTr.ReadFloat();
00092   rTr.SeekEnd(label);
00093   FD_DRTI("Integer::DoRead(): done");
00094 }
00095 
00096 
00097 // integer sum, uniform rti api
00098 long int IntegerSum(const Integer& arg1, const Integer& arg2) {
00099   return arg1+arg2;
00100 }
00101 
00102 // integer sum, uniform rti api
00103 long int IntegerSum(const IntegerVector& intvect) {
00104   long int res=0;
00105   for(unsigned int i=0; i< intvect.Size(); i++) 
00106     res+=intvect.At(i);
00107   return res;
00108 }
00109 
00110 
00111 /*
00112 ********************************************************************
00113 ********************************************************************
00114 ********************************************************************
00115 
00116 Implementation of class String
00117 
00118 ********************************************************************
00119 ********************************************************************
00120 ********************************************************************
00121 */
00122 
00123 
00124 // constructor
00125 String::String() {
00126   CValue("");
00127 }
00128 
00129 // constructor
00130 String::String(std::string val) {
00131   CValue(val);
00132 }
00133 
00134 // factory constructor
00135 String* String::New() const{
00136   return new String();
00137 }
00138 
00139 // factory constructor
00140 String* String::Copy() const{
00141   return new String(mCString);
00142 }
00143 
00144 // cast
00145 const String* String::Cast(const Type* pOther) const{
00146   return dynamic_cast<const String*>(pOther);
00147 }
00148 
00149 // c value
00150 std::string String::CValue() const{
00151   return mCString;
00152 }
00153 
00154 // c value
00155 void String::CValue(std::string s){
00156   mCString = s;
00157 }
00158 
00159 // c ref
00160 std::string* String::CReference() {
00161   return &mCString;
00162 }
00163 
00164 // token io
00165 void String::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00166   (void)pContext;
00167   std::string label = rLabel;
00168   if(label == "") label = "String";
00169   FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label);
00170   rTw.WriteBegin(label);
00171   rTw.WriteString(mCString);
00172   rTw.WriteEnd(label);
00173 }
00174 
00175 // token io
00176 void String::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00177   (void) pContext;
00178   std::string label = rLabel;
00179   if(label == "") label = "String";
00180   FD_DRTI("String::DoRead(): file " << rTr.FileName() << "  section " << label);
00181   rTr.SeekBegin(label);
00182   mCString = rTr.ReadString();
00183   rTr.SeekEnd(label);
00184   FD_DRTI("String::DoRead(): done");
00185 }
00186 
00187 
00188 /*
00189 ********************************************************************
00190 ********************************************************************
00191 ********************************************************************
00192 
00193 Implementation of class Boolean
00194 
00195 ********************************************************************
00196 ********************************************************************
00197 ********************************************************************
00198 */
00199 
00200 
00201 // constructor
00202 Boolean::Boolean() {
00203   CValue(true);
00204 }
00205 
00206 // constructor
00207 Boolean::Boolean(bool val) {
00208   CValue(val);
00209 }
00210 
00211 // factory constructor
00212 Boolean* Boolean::New() const{
00213   return new Boolean();
00214 }
00215 
00216 // factory constructor
00217 Boolean* Boolean::Copy() const{
00218   return new Boolean(mCBool);
00219 }
00220 
00221 // cast
00222 const Boolean* Boolean::Cast(const Type* pOther) const{
00223   return dynamic_cast<const Boolean*>(pOther);
00224 }
00225 
00226 // cvaliu
00227 void Boolean::CValue(bool val){
00228   mCBool = val;
00229 }
00230 
00231 // cvalue 
00232 bool Boolean::CValue() const{
00233   return(mCBool);
00234 }
00235 
00236 // c ref
00237 bool* Boolean::CReference() {
00238   return &mCBool;
00239 }
00240 
00241 // token io
00242 void Boolean::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00243   (void)pContext;
00244   std::string label = rLabel;
00245   if(label == "") label = "Boolean";
00246   FD_DRTI("Boolean::DoWrite(): file " << rTw.FileName() << " section " << label);
00247   rTw.WriteBegin(label);
00248   if(mCBool) rTw.WriteString("true");
00249   else rTw.WriteString("false");
00250   rTw.WriteEnd(label);
00251 }
00252 
00253 
00254 // token io
00255 void Boolean::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00256   (void) pContext;
00257   std::string label = rLabel;
00258   if(label == "") label = "Boolean";
00259   FD_DRTI("Boolean::DoRead(): file " << rTr.FileName() << "  section " << label);
00260   rTr.SeekBegin(label);
00261   std::string value = rTr.ReadString();
00262   std::transform(value.begin(), value.end(), value.begin(), tolower);
00263   if(value=="true") mCBool=true;
00264   else if(value=="false") mCBool=false;
00265   else {
00266     std::stringstream err;
00267     err << "Expected true or false: " << rTr.FileLine();
00268     throw Exception("Boolean::DoRead()", err.str(), 52);
00269   }
00270   rTr.SeekEnd(label);
00271   FD_DRTI("Boolean::DoRead(): done");
00272 }
00273 
00274 
00275 
00276 } //namspace
00277 

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3