00001 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 #include "symbolset.h" 00024 00025 namespace faudes { 00026 00027 // SymbolSet() 00028 SymbolSet::SymbolSet(void) : 00029 TBaseSet<std::string>() 00030 { 00031 FD_DC("SymbolSet(" << this << ")::SymbolSet()"); 00032 Name("SymbolSet"); 00033 } 00034 00035 // SymbolSet(rOtherSet) 00036 SymbolSet::SymbolSet(const TBaseSet<std::string>& rOtherSet) : 00037 TBaseSet<std::string>(rOtherSet) 00038 { 00039 FD_DC("SymbolSet(" << this << ")::SymbolSet(rOtherSet " << &rOtherSet << ")"); 00040 } 00041 00042 // File constructor 00043 SymbolSet::SymbolSet(const std::string& rFilename, const std::string& rLabel) : 00044 TBaseSet<std::string>() 00045 { 00046 FD_DC("SymbolSet(" << this << ")::SymbolSet(" << rFilename << ")"); 00047 Read(rFilename, rLabel); 00048 } 00049 00050 // DoWrite(rTw&) 00051 void SymbolSet::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00052 (void) pContext; 00053 std::string label=rLabel; 00054 if(label=="") label=Name(); 00055 if(label=="") label="SymbolSet"; 00056 rTw.WriteBegin(label); 00057 Iterator it; 00058 // iterate symbols to write 00059 for (it = Begin(); it != End(); ++it) { 00060 rTw << *it; 00061 } 00062 rTw.WriteEnd(label); 00063 } 00064 00065 // DoRead(rTr, rLabel, context) 00066 void SymbolSet::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00067 std::string label=rLabel; 00068 if(label=="") label="SymbolSet"; 00069 Name(label); 00070 Clear(); 00071 rTr.SeekBegin(label); 00072 Token token; 00073 while(!rTr.Eos(label)) { 00074 rTr.Get(token); 00075 // read individual symbol 00076 if (token.Type() == Token::String) { 00077 FD_DC("SymbolSet(" << this << ")::DoRead(..): inserting symbol \"" 00078 << token.StringValue() << "\""); 00079 // insert element 00080 Insert(token.StringValue()); 00081 continue; 00082 } 00083 // ignore unknown attributes 00084 AttributeVoid attr; 00085 attr.Read(rTr); 00086 } 00087 rTr.SeekEnd(label); 00088 } 00089 00090 //Insert(symbol) 00091 bool SymbolSet::Insert(const std::string& symbol) { 00092 return TBaseSet<std::string>::Insert(symbol); 00093 } 00094 00095 00096 //Valid(idx) 00097 bool SymbolSet::Valid(const std::string& symbol) const { 00098 return SymbolTable::ValidSymbol(symbol); 00099 } 00100 00101 00102 00103 00104 } // end name space