cfl_symbolset.h
Go to the documentation of this file.
1 /** @file cfl_symbolset.h @brief Class SymbolSet, TaSymbolSet */
2 
3 
4 /* FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2006 Bernd Opitz
7  Copyright (C) 2007 Thomas Moor
8  Exclusive copyright is granted to Klaus Schmidt
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 
25 
26 #ifndef FAUDES_SYMBOLSET_H
27 
28 #include "cfl_definitions.h"
29 #include "cfl_attributes.h"
30 #include "cfl_symboltable.h"
31 #include "cfl_baseset.h"
32 #include <set>
33 #include <map>
34 #include <algorithm>
35 
36 namespace faudes {
37 
38 /** @addtogroup ContainerClasses */
39 /** @{ */
40 
41 /**
42  * Set of symbols.
43  *
44  * The class is built on top of the faudes version
45  * TBaseSet of STL sets. It provides the essentials of the STL interface and
46  * plus token based file IO.
47  * Invalid iterators throw an exception (id 62) when used as an argument to a SymbolSet function.
48  * If the macro FAUDES_CHECKED is defined, the attempt to insert an invalid symbol
49  * an exception (id 61).
50  *
51  * Note that a symbol set holds a plain set of valid faudes symbols with no indices
52  * or symboltable associated. If you are looking for a set of items with
53  * mandatory symbolic names you most likely are better of with a NameSet or a
54  * TaNameSet. Currently, there is no attributed version of a SymbolSet.
55  *
56  * The token IO format is demonstrated by the following example
57  * of a set with name "MySymbols"
58  * \code
59  * <MySymbols>
60  * "ASymbol"
61  * "AnotherSymbol"
62  * </MySymbols>
63  * \endcode
64  * Note that you can read SymbolSet files to NameSets and vice versa.
65  *
66  */
67 
68 class SymbolSet : public TBaseSet<std::string> {
69 
71 
72 public:
73 
74  /**
75  * Constructor.
76  */
77  SymbolSet(void);
78 
79  /**
80  * Copy-constructor.
81  */
82  SymbolSet(const TBaseSet<std::string>& rOtherSet);
83 
84  /**
85  * Construct from file. Uses the Read(TokenReader&, const std::string&) function to read.
86  * a SymbolSet from section rLabel in file rFilename.
87  *
88  * @param rFilename
89  * Name of file to read
90  * @param rLabel
91  * Section to read
92  *
93  * @exception Exception
94  * - IO Errors (id 1)
95  * - token musmatch (id 50, 51, 52)
96  */
97  SymbolSet(const std::string& rFilename, const std::string& rLabel = "SymbolSet");
98 
99  /**
100  * Virtual destructor
101  */
102  virtual ~SymbolSet(void) {};
103 
104  /**
105  * Test whether the given string is a valid faudes symbol
106  * @param symbol
107  * Symbol to test
108  * @return
109  * True if valid
110  */
111  bool Valid(const std::string& symbol) const;
112 
113  /**
114  * Iterators on indexset.
115  */
117 
118  /**
119  * Insert specified symbol
120  *
121  * @param symbol
122  * Symbol to insert
123  * @return
124  * True if symbol was new to set
125  */
126  bool Insert(const std::string& symbol);
127 
128  /**
129  * Compute an Idx type signature for a Set. This method
130  * is currently not implemented.
131  *
132  * @return
133  * Idx type set signature
134  */
135  Idx Signature(void) const {return 0;};
136 
137  /**
138  * Return pretty printable symbol.
139  *
140  * @param symbol
141  * Symbol to print
142  *
143  * @return
144  * String
145  */
146  std::string Str(const std::string& symbol) const {return symbol; };
147 
148  protected:
149 
150 
151 
152  /**
153  * Assign my members. This method calls the base class to assign its members.
154  *
155  * @param rSource
156  * Source to copy from
157  * @return
158  * Ref to this set
159  */
160  virtual void DoAssign(const SymbolSet& rSource);
161 
162  /**
163  * Write to TokenWriter, see TBaseSet for public wrappers.
164  *
165  * @param tw
166  * Reference to TokenWriter
167  * @param rLabel
168  * Label of section to write, defaults to name of set
169  * @param pContext
170  * Write context for contextual information
171  *
172  * @exception Exception
173  * - IO errors (id 2)
174  */
175  void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
176 
177  /**
178  * Read from TokenReader, see TBaseSet for public wrappers.
179  *
180  * @param rTr
181  * Reference to tokenreader
182  * @param rLabel
183  * Section to read
184  * @param pContext
185  * Read context for contextual information
186  *
187  * @exception Exception
188  * - IO errors (id 1)
189  * - token mismatch (id 50, 51, 52)
190  */
191  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
192 
193 
194 };
195 
196 
197 /** @} doxygen group */
198 
199 
200 } // namespace faudes
201 
202 #define FAUDES_SYMBOLSET_H
203 #endif

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen