cfl_symbolset.cpp
Go to the documentation of this file.
1 /** @file cfl_symbolset.cpp @brief Class SymbolSet */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Copyright (C) 2007 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #include "cfl_symbolset.h"
24 
25 namespace faudes {
26 
27 // std faudes type
28 FAUDES_TYPE_IMPLEMENTATION(SymbolSet,SymbolSet,TBaseSet<std::string>)
29 
30 
31 // SymbolSet()
33  TBaseSet<std::string>()
34 {
35  FD_DC("SymbolSet(" << this << ")::SymbolSet()");
36  Name("SymbolSet");
37 }
38 
39 // SymbolSet(rOtherSet)
41  TBaseSet<std::string>(rOtherSet)
42 {
43  FD_DC("SymbolSet(" << this << ")::SymbolSet(rOtherSet " << &rOtherSet << ")");
44 }
45 
46 // File constructor
47 SymbolSet::SymbolSet(const std::string& rFilename, const std::string& rLabel) :
48  TBaseSet<std::string>()
49 {
50  FD_DC("SymbolSet(" << this << ")::SymbolSet(" << rFilename << ")");
51  Read(rFilename, rLabel);
52 }
53 
54 // DoAssign
55 void SymbolSet::DoAssign(const SymbolSet& rSourceSet) {
57 }
58 
59 
60 // DoWrite(rTw&)
61 void SymbolSet::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
62  (void) pContext;
63  std::string label=rLabel;
64  if(label=="") label=Name();
65  if(label=="") label="SymbolSet";
66  rTw.WriteBegin(label);
67  Iterator it;
68  // iterate symbols to write
69  for (it = Begin(); it != End(); ++it) {
70  rTw << *it;
71  }
72  rTw.WriteEnd(label);
73 }
74 
75 // DoRead(rTr, rLabel, context)
76 void SymbolSet::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
77  std::string label=rLabel;
78  if(label=="") label="SymbolSet";
79  Name(label);
80  Clear();
81  rTr.ReadBegin(label);
82  Token token;
83  while(!rTr.Eos(label)) {
84  rTr.Get(token);
85  // read individual symbol
86  if (token.Type() == Token::String) {
87  FD_DC("SymbolSet(" << this << ")::DoRead(..): inserting symbol \""
88  << token.StringValue() << "\"");
89  // insert element
90  Insert(token.StringValue());
91  continue;
92  }
93  // ignore unknown attributes
94  AttributeVoid attr;
95  attr.Read(rTr);
96  }
97  rTr.ReadEnd(label);
98 }
99 
100 //Insert(symbol)
101 bool SymbolSet::Insert(const std::string& symbol) {
102  return TBaseSet<std::string>::Insert(symbol);
103 }
104 
105 
106 //Valid(idx)
107 bool SymbolSet::Valid(const std::string& symbol) const {
108  return SymbolTable::ValidSymbol(symbol);
109 }
110 
111 
112 
113 
114 } // end name space
#define FD_DC(message)
Debug: optional report on container operations.
Class SymbolSet, TaSymbolSet.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Minimal Attribute.
Set of symbols.
Definition: cfl_symbolset.h:70
void DoAssign(const SymbolSet &rSource)
Assign my members.
TBaseSet< std::string >::Iterator Iterator
Iterators on indexset.
void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read from TokenReader, see TBaseSet for public wrappers.
bool Insert(const std::string &symbol)
Insert specified symbol.
void DoWrite(TokenWriter &tw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see TBaseSet for public wrappers.
bool Valid(const std::string &symbol) const
Test whether the given string is a valid faudes symbol.
SymbolSet(void)
Constructor.
static bool ValidSymbol(const std::string &rName)
Test validiy of candidate symbol.
STL style set template.
Definition: cfl_baseset.h:93
A TokenReader reads sequential tokens from a file or string.
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteBegin(const std::string &rLabel)
Write begin label.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
@ String
any string, space separated or quoted, must start with a letter
Definition: cfl_token.h:85
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
virtual bool Insert(const T &rElem)
Insert specified element.
Definition: cfl_baseset.h:1960
virtual void Clear(void)
Clear all set.
Definition: cfl_baseset.h:1902
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
const std::string & Name(void) const
Return name of TBaseSet.
Definition: cfl_baseset.h:1755
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen