cgenerator.cpp

Go to the documentation of this file.
00001 /* cgenerator.cpp -- cgenerator class */
00002 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00022 
00023 
00024       
00025 #include "cgenerator.h" 
00026 
00027 
00028 namespace faudes {
00029 
00030 
00031 /***********************************************************************************
00032  *
00033  * implementation of AttributeCFlags 
00034  *
00035  */
00036 
00037 //Write(rTw)
00038 // Note: you should write attributes in a section, so that
00039 // the AttributeVoid read method can detect and skip them.
00040 // Here, we make an execption of the rule ...
00041 void AttributeCFlags::Write(TokenWriter& rTw) const {
00042   if(!IsDefault()) {
00043     Token token;
00044     // if no other flags used, write option string
00045     if( (mFlags & ~mAllCFlags) == 0 ) {
00046       std::string option;
00047       if((mDefCFlags & mControllableFlag) != (mFlags & mControllableFlag)) {
00048         if(Controllable()) option = option+"C";
00049         else option = option+"c";
00050       }
00051       if((mDefCFlags & mObservableFlag) != (mFlags & mObservableFlag)) {
00052         if(Observable()) option = option+"O";
00053         else option = option+"o";
00054       }
00055       if((mDefCFlags & mForcibleFlag) != (mFlags & mForcibleFlag)) {
00056         if(Forcible()) option = option+"F";
00057         else option = option+"f";
00058       }
00059       token.SetOption(option);
00060     } 
00061     // if other flags used, write hex
00062     else { 
00063       token.SetInteger16(mFlags);
00064     }
00065     rTw << token;
00066   }
00067 }
00068 
00069 //Write()
00070 void AttributeCFlags::Write(void) const {
00071   TokenWriter rTw(TokenWriter::Stdout);
00072   Write(rTw);
00073 }
00074 
00075 
00076 
00077 //ToString()
00078 std::string AttributeCFlags::ToString(void) const {
00079   return ToStringInteger16(mFlags);
00080 }
00081 
00085 //Read(rTr)
00086 void AttributeCFlags::Read(TokenReader& rTr) {
00087   mFlags=mDefCFlags;
00088   Token token;
00089   rTr.Peek(token);
00090   if(token.Type()==Token::Integer16) { 
00091     rTr.Get(token);
00092     mFlags=token.IntegerValue();
00093     return;
00094   } 
00095   if(token.Type()==Token::Option) { 
00096     rTr.Get(token);
00097     std::string option=token.StringValue();
00098     if(option.find( 'C', 0) != std::string::npos) SetControllable();
00099     if(option.find( 'c', 0) != std::string::npos) ClrControllable();
00100     if(option.find( 'O', 0) != std::string::npos) SetObservable();
00101     if(option.find( 'o', 0) != std::string::npos) ClrObservable();
00102     if(option.find( 'F', 0) != std::string::npos) SetForcible();
00103     if(option.find( 'f', 0) != std::string::npos) ClrForcible();
00104     return;
00105   }
00106 }
00107 
00108 
00109 
00110 
00111 } // end namespace

Generated on Fri May 9 11:26:47 2008 for libFAUDES 2.09b by  doxygen 1.4.4