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 #define FAUDES_SYMBOLSET_H
28 
29 
30 #include "cfl_definitions.h"
31 #include "cfl_attributes.h"
32 #include "cfl_symboltable.h"
33 #include "cfl_baseset.h"
34 #include <set>
35 #include <map>
36 #include <algorithm>
37 
38 namespace faudes {
39 
40 /** @addtogroup ContainerClasses */
41 /** @{ */
42 
43 /**
44  * Set of symbols.
45  *
46  * The class is built on top of the faudes version
47  * TBaseSet of STL sets. It provides the essentials of the STL interface and
48  * plus token based file IO.
49  * Invalid iterators throw an exception (id 62) when used as an argument to a SymbolSet function.
50  * If the macro FAUDES_CHECKED is defined, the attempt to insert an invalid symbol
51  * an exception (id 61).
52  *
53  * Note that a symbol set holds a plain set of valid faudes symbols with no indices
54  * or symboltable associated. If you are looking for a set of items with
55  * mandatory symbolic names you most likely are better of with a NameSet or a
56  * TaNameSet. Currently, there is no attributed version of a SymbolSet.
57  *
58  * The token IO format is demonstrated by the following example
59  * of a set with name "MySymbols"
60  * \code
61  * <MySymbols>
62  * "ASymbol"
63  * "AnotherSymbol"
64  * </MySymbols>
65  * \endcode
66  * Note that you can read SymbolSet files to NameSets and vice versa.
67  *
68  */
69 
70 class FAUDES_API SymbolSet : public TBaseSet<std::string> {
71 
73 
74 public:
75 
76  /**
77  * Constructor.
78  */
79  SymbolSet(void);
80 
81  /**
82  * Copy-constructor.
83  */
84  SymbolSet(const TBaseSet<std::string>& rOtherSet);
85 
86  /**
87  * Construct from file. Uses the Read(TokenReader&, const std::string&) function to read.
88  * a SymbolSet from section rLabel in file rFilename.
89  *
90  * @param rFilename
91  * Name of file to read
92  * @param rLabel
93  * Section to read
94  *
95  * @exception Exception
96  * - IO Errors (id 1)
97  * - token musmatch (id 50, 51, 52)
98  */
99  SymbolSet(const std::string& rFilename, const std::string& rLabel = "SymbolSet");
100 
101  /**
102  * Virtual destructor
103  */
104  virtual ~SymbolSet(void) {};
105 
106  /**
107  * Test whether the given string is a valid faudes symbol
108  * @param symbol
109  * Symbol to test
110  * @return
111  * True if valid
112  */
113  bool Valid(const std::string& symbol) const;
114 
115  /**
116  * Iterators on indexset.
117  */
119 
120  /**
121  * Insert specified symbol
122  *
123  * @param symbol
124  * Symbol to insert
125  * @return
126  * True if symbol was new to set
127  */
128  bool Insert(const std::string& symbol);
129 
130  /**
131  * Compute an Idx type signature for a Set. This method
132  * is currently not implemented.
133  *
134  * @return
135  * Idx type set signature
136  */
137  Idx Signature(void) const {return 0;};
138 
139  /**
140  * Return pretty printable symbol.
141  *
142  * @param symbol
143  * Symbol to print
144  *
145  * @return
146  * String
147  */
148  std::string Str(const std::string& symbol) const {return symbol; };
149 
150  protected:
151 
152 
153 
154  /**
155  * Assign my members. This method calls the base class to assign its members.
156  *
157  * @param rSource
158  * Source to copy from
159  * @return
160  * Ref to this set
161  */
162  void DoAssign(const SymbolSet& rSource);
163 
164  /**
165  * Write to TokenWriter, see TBaseSet for public wrappers.
166  *
167  * @param tw
168  * Reference to TokenWriter
169  * @param rLabel
170  * Label of section to write, defaults to name of set
171  * @param pContext
172  * Write context for contextual information
173  *
174  * @exception Exception
175  * - IO errors (id 2)
176  */
177  void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
178 
179  /**
180  * Read from TokenReader, see TBaseSet for public wrappers.
181  *
182  * @param rTr
183  * Reference to tokenreader
184  * @param rLabel
185  * Section to read
186  * @param pContext
187  * Read context for contextual information
188  *
189  * @exception Exception
190  * - IO errors (id 1)
191  * - token mismatch (id 50, 51, 52)
192  */
193  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
194 
195 
196 };
197 
198 
199 /** @} doxygen group */
200 
201 
202 } // namespace faudes
203 
204 #endif
Classes AttributeVoid and AttributeFlags
Class TBaseSet.
Compiletime options.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
Class SymbolTable.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
Set of symbols.
Definition: cfl_symbolset.h:70
TBaseSet< std::string >::Iterator Iterator
Iterators on indexset.
virtual ~SymbolSet(void)
Virtual destructor.
Idx Signature(void) const
Compute an Idx type signature for a Set.
std::string Str(const std::string &symbol) const
Return pretty printable symbol.
STL style set template.
Definition: cfl_baseset.h:93
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)

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