attributes.cpp

Go to the documentation of this file.
00001 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Exclusive copyright is granted to Klaus Schmidt
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 "attributes.h"
00024 
00025 
00026 namespace faudes {
00027 
00028 /***********************************************************************************
00029  *
00030  * implementation of AttributeVoid 
00031  *
00032  */
00033 
00034 // Write(label,context)
00035 void AttributeVoid::Write(const std::string& rLabel, const Type* pContext) const {
00036   TokenWriter tw(TokenWriter::Stdout);
00037   DoWrite(tw,rLabel,pContext);
00038 }
00039 
00040 // Write(rFileName, label, context, openmode)
00041 void AttributeVoid::Write(const std::string& rFileName, const std::string& rLabel, 
00042   const Type* pContext, std::ios::openmode openmode) const {
00043   try {
00044     TokenWriter tw(rFileName, openmode);
00045     DoWrite(tw, rLabel, pContext);
00046   }
00047   catch (std::ios::failure&) {
00048     std::stringstream errstr;
00049     errstr << "Exception opening/writing file \"" << rFileName << "\"";
00050     throw Exception("AttributeVoid::Write", errstr.str(), 2);
00051   }
00052 }
00053 
00054 // Write(tw,label,context)
00055 void AttributeVoid::Write(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00056   DoWrite(rTw,rLabel,pContext);
00057 }
00058 
00059 // ToString(label, context)
00060 std::string AttributeVoid::ToString(const std::string& rLabel, const Type* pContext) const {
00061   TokenWriter tw(TokenWriter::String);
00062   DoWrite(tw,rLabel,pContext);
00063   return tw.Str();
00064 }
00065 
00066 // Read(rFilename, rLabel,context)
00067 void AttributeVoid::Read(const std::string& rFilename, const std::string& rLabel, const Type* pContext) {
00068   TokenReader tr(rFilename);
00069   DoRead(tr,rLabel,pContext);
00070   Skip(tr);
00071 }
00072 
00073 // Read(rTr, rLabel, context)
00074 void AttributeVoid::Read(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00075   DoRead(rTr,rLabel,pContext);
00076   Skip(rTr);
00077 }
00078 
00079 
00080 //DoWrite(rTr,rLabel,pContext)
00081 void AttributeVoid::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00082   (void) rTw; (void) rLabel; (void) pContext;
00083   FD_DC("AttributeVoid::DoWrite()");
00084 }
00085 
00086 //DoRead(rTr,rLabel,pContext)
00087 void AttributeVoid::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00088   (void) rLabel; (void) pContext; (void) rTr;
00089   FD_DC("AttributeVoid::DoRead()");
00090 }
00091 
00092 //Skip(rTr)
00093 void AttributeVoid::Skip(TokenReader& rTr) {
00094   FD_DC("AttributeVoid::Skip()");
00095   Token token;
00096   while(rTr.Peek(token)) {
00097     // break on index or name, since this is the next element
00098     if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
00099       break;
00100     }
00101     // break on end, since this is the end of the set
00102     if(token.Type()==Token::End) {
00103       break;
00104     }
00105     // break on Consecutive section, since this belongs to the set
00106     if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
00107       break;
00108     }
00109     // skip any attribute section from other file format
00110     if(token.Type()==Token::Begin){
00111       rTr.ReadBegin(token.StringValue());
00112       rTr.ReadEnd(token.StringValue());
00113       continue;
00114     }  
00115     // skip any other token from other file format
00116     rTr.Get(token);
00117   }
00118 }
00119 
00120 
00121 
00122 /***********************************************************************************
00123  *
00124  * implementation of AttributeFlags 
00125  *
00126  */
00127 
00128 //DoWrite(rTw)
00129 // Note: you should write attributes in a section, so that
00130 // the AttributeVoid read method can detect and skip them.
00131 // Here, we make an execption of the rule ...
00132 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
00133   (void) rLabel; (void) pContext;
00134   if(!IsDefault()) {
00135     FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
00136     Token token;
00137     token.SetInteger16(mFlags);
00138     rTw << token;
00139   }
00140 }
00141 
00142 
00143 //DoRead(rTr)
00144 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00145   (void) rLabel; (void) pContext;
00146   FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
00147   Token token;
00148   rTr.Peek(token);
00149   if(token.Type()==Token::Integer16) { 
00150     rTr.Get(token);
00151     mFlags=token.IntegerValue();
00152   } else {
00153     mFlags=mDefFlags;
00154   }
00155 }
00156 
00157 
00158 } // namespace

Generated on Mon Nov 10 08:13:14 2008 for libFAUDES 2.11v by  doxygen 1.4.4