cfl_attributes.cpp

Go to the documentation of this file.
00001 /** @file cfl_attributes.cpp Classes AttributeVoid and AttributeFlags  */
00002 
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 "cfl_attributes.h"
00024 
00025 
00026 namespace faudes {
00027 
00028 /***********************************************************************************
00029  *
00030  * implementation of AttributeVoid 
00031  *
00032  */
00033 
00034 // faudes type
00035 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeVoid,Type)
00036 
00037 // constructor
00038 AttributeVoid::AttributeVoid(void) {
00039   FAUDES_OBJCOUNT_INC("Attribute");
00040 }
00041 
00042 // destructor
00043 AttributeVoid::~AttributeVoid(void) {
00044   FAUDES_OBJCOUNT_DEC("Attribute");
00045 }
00046 
00047 //DoWrite(rTr,rLabel,pContext)
00048 void AttributeVoid::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00049   (void) rTw; (void) rLabel; (void) pContext;
00050   FD_DC("AttributeVoid::DoWrite()");
00051 }
00052 
00053 //DoRead(rTr,rLabel,pContext)
00054 void AttributeVoid::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00055   (void) rLabel; (void) pContext; (void) rTr;
00056   FD_DC("AttributeVoid::DoRead()");
00057 }
00058 
00059 //Skip(rTr)
00060 void AttributeVoid::Skip(TokenReader& rTr) {
00061   FD_DC("AttributeVoid::Skip()");
00062   Token token;
00063   while(rTr.Peek(token)) {
00064     // break on index or name, since this is the next element
00065     if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
00066       break;
00067     }
00068     // break on end, since this is the end of the set
00069     if(token.Type()==Token::End) {
00070       break;
00071     }
00072     // break on Consecutive section, since this belongs to the set
00073     if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
00074       break;
00075     }
00076     // skip any attribute section from other file format
00077     if(token.Type()==Token::Begin){
00078       rTr.ReadBegin(token.StringValue());
00079       rTr.ReadEnd(token.StringValue());
00080       continue;
00081     }  
00082     // skip any other token from other file format
00083     rTr.Get(token);
00084   }
00085 }
00086 
00087 
00088 
00089 /***********************************************************************************
00090  *
00091  * implementation of AttributeFlags 
00092  *
00093  */
00094 
00095 // faudes type
00096 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeFlags,AttributeVoid)
00097 
00098 // Assign my members
00099 void AttributeFlags::DoAssign(const AttributeFlags& rSrcAttr) { 
00100   // call virtual clear: TODO: dont clear in virtual function
00101   Clear();
00102   // assign my members
00103   mFlags=rSrcAttr.mFlags; 
00104 }
00105 
00106 // Test my members for equality
00107 bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const { 
00108   return ( mFlags==rOther.mFlags ); 
00109 }
00110 
00111 //DoWrite(rTw)
00112 // Note: you should write attributes in a section, so that
00113 // the AttributeVoid read method can detect and skip them.
00114 // Here, we make an execption of the rule ...
00115 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
00116   (void) rLabel; (void) pContext;
00117   if(!AttributeFlags::IsDefault()) {
00118     FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
00119     Token token;
00120     token.SetInteger16(mFlags);
00121     rTw << token;
00122   }
00123 }
00124 
00125 
00126 //DoXWrite(rTw)
00127 void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
00128   (void) rLabel; (void) pContext;
00129   if(!AttributeFlags::IsDefault()) {
00130     FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
00131     Token token;
00132     token.SetEmpty("Flags");
00133     token.InsAttributeInteger16("value",mFlags);
00134     rTw << token;
00135   }
00136 }
00137 
00138 
00139 //DoRead(rTr)
00140 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00141   (void) rLabel; (void) pContext;
00142   FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
00143   Token token;
00144   rTr.Peek(token);
00145   // faudes format
00146   if(token.IsInteger16()) { 
00147     rTr.Get(token);
00148     mFlags=token.IntegerValue();
00149     return;
00150   } 
00151   // XML format
00152   if(token.IsBegin())
00153   if(token.StringValue()=="Flags") {
00154     rTr.ReadBegin("Flags",token);
00155     mFlags=token.AttributeIntegerValue("value");
00156     rTr.ReadEnd("Flags");
00157     return;
00158   }
00159   // default
00160   mFlags=mDefFlags;
00161 }
00162 
00163 
00164 } // namespace

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen