File: groupfile.h

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (303 lines) | stat: -rw-r--r-- 8,266 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/***************************************************************************
                          groupfile.h  -  description
                             -------------------
    begin                : Tue Jan 23 2001
    copyright            : (C) 2001 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef groupfileH
#define groupfileH


#include <list>
#include <fstream>
#include <iostream>
#include "../errors.h"

#include "../ascstring.h"



//using namespace std;


/**
*@brief Abstract representation of an entry in a group-file. Composite-Pattern
*@author Kevin Hirschmann
*/
class AbstractEntry {
  friend class Category;
public:
  /**
  *@brief Destructor
  */
  virtual ~AbstractEntry();
  /**
  *@brief Generates the string-representation of this entry (including all its subentries)
  */
  virtual ASCString toString() const = 0;
  /**
  *@brief Sorts the subentries of this entry in alphabetic order
  */
  virtual void sort()=0;
  /**
  *@brief Adds a new subpoint (with all its entries)
  *@param entry The new entry is appended behind all previous added entries
  *@attention Add only pointer to heap objects. Memory management is delgated to
  *superCategory
  *@code
  * {
  * Category set(s->name, cssFile);
  * Category* hqCat = new Category(HQ, cssFile);
  * Category* facCat = new Category(FACTORY, cssFile);
  * set.addEntry(hqCat);
  * set.addEntry(facCat);   
  * CategoryMember* dataEntry = new CategoryMember(bt->name.toUpper(), cssFile, fileLink, TARGET);
  * //At block end  set is deleted and automatically all added entries
  * //which are here hqCat, facCat, dataEntry
  * }
  *@endcode
  */
  virtual void addEntry(AbstractEntry* entry) throw (ASCmsgException) = 0;  
  /**
  *@brief Removes the AbstractEntry (if it is a sub-entry)
  */
  virtual void removeEntry(AbstractEntry* e) = 0;
  /**
  *@brief Updates the depth of all subentries 
  */
  virtual void updateDepth() = 0;
  /**
  *@brief Defines an order upon AbstractEntry. The order is equivalent to the alphabetic order of member lineData
  */
  bool operator<(const AbstractEntry& e) const;
  /**
  *@brief Retrieves the depth of this entry. The topmost entry has a depth of 0.
  *@return An int representing the depth of on which this entry resides.
  */
  int getDepth() const {
    return depth;
  }

protected:
  /**
  *@brief Full name of the cssFile
  */
  ASCString cssFile;
  /**
  *@brief The text line of this entry
  */
  ASCString lineData;

  /**
  *@brief A reference to the parent
  */
  AbstractEntry* parent;
  /**
  *@brief The depth of this entry
  */
  int depth;

  /**
  *@brief Returns a copy of this element with copies of all its subelements.
  *       The caller is responsible for deletion
  */
  virtual AbstractEntry* clone() = 0;

  /**
  *@brief Standard-Constructor
  */
  AbstractEntry(): parent(0), depth(0) {}
  AbstractEntry(ASCString data, ASCString css): cssFile(css), lineData(data), parent(0), depth(0) {};


};


typedef std::list<AbstractEntry*> AbstractEntryList;


/**
*@brief Represents a category entry in a GroupFile
*@author Kevin Hirschmann
*/
class Category: public AbstractEntry {
public:

  /**
  *@brief Constructor for creating a new Category in a GroupFile
  *@param label The label of the category
  *@param css The full path to the cssFile
  */
  Category(ASCString label, ASCString css);
  /**
  *@brief Copy-Constructor
  */
  Category(const Category& cat);
  /**
  *@brief Destructor
  */
  virtual ~Category();

  /**
  *@brief Adds a new subpoint (with all its entries)
  *@param entry The new entry is appended behind all previous added entries
  *@attention Add only pointer to heap objects. Memory management is delgated to
  *superCategory
  *@code
  * {
  * Category set(s->name, cssFile);
  * Category* hqCat = new Category(HQ, cssFile);
  * Category* facCat = new Category(FACTORY, cssFile);
  * set.addEntry(hqCat);
  * set.addEntry(facCat);   
  * CategoryMember* dataEntry = new CategoryMember(bt->name.toUpper(), cssFile, fileLink, TARGET);
  * //At block end  set is deleted and automatically all added entries
  * //which are here hqCat, facCat, dataEntry
  * }
  *@endcode
  */
  virtual void addEntry(AbstractEntry* entry) throw (ASCmsgException);

  virtual void removeEntry(AbstractEntry* entry);
  /**
  *@brief Generates the string-representation of this entry (including all its subentries)
  */
  virtual ASCString toString() const;
  /**
  *@brief Updates the depth of all subentries 
  */
  virtual void updateDepth();
  /**
  *@brief Sorts the subentries of this entry in alphabetic order
  */
  virtual void sort();

  /**
  *@brief Assignment operator. Creates a deep copy
  */
  Category& operator=(const Category&);
  /**
  *@brief Returns a copy of this element with copies of all its subelements.
  *       The caller is responsible for deletion
  */
  virtual AbstractEntry* clone();


private:
  /**
  *@brief A vector containing pointers to all subentries
  */
  AbstractEntryList subEntries;

};

/**
  *@brief A leaf in the category entries
  */
class CategoryMember: public AbstractEntry {
public:
  /**
  *@brief Constructor for creating a link in the menu to a HTML-page 
  *@param label The label for the menu entry
  *@param css Full path to a css file
  *@param file the full name to the HTML page
  *@param target The target 
  */
  CategoryMember(ASCString label, ASCString css, ASCString file, ASCString target);
  /**
  *@brief Generates the string-representation of this entry
  */
  virtual ASCString toString() const;
  /**
  *@brief Adds a new subpoint (with all its entries)
  *@param entry The new entry is appended behind all previous added entries
  *@attention Add only pointer to heap objects. Memory management is delgated to
  *superCategory
  *@code
  * {
  * Category set(s->name, cssFile);
  * Category* hqCat = new Category(HQ, cssFile);
  * Category* facCat = new Category(FACTORY, cssFile);
  * set.addEntry(hqCat);
  * set.addEntry(facCat);   
  * CategoryMember* dataEntry = new CategoryMember(bt->name.toUpper(), cssFile, fileLink, TARGET);
  * //At block end  set is deleted and automatically all added entries
  * //which are here hqCat, facCat, dataEntry
  * }
  *@endcode
  */
  virtual void addEntry(AbstractEntry* entry) throw (ASCmsgException) {
    throw ASCmsgException("Exception: Trying to add an entry to a CategoryMember");
  } //Exception
  
  virtual void removeEntry(AbstractEntry* entry){} //Exception
  /**
  *@brief Updates the depth of all subentries 
  */
  virtual void updateDepth();
  /**
  *@brief Does nothing
  */
  virtual void sort();

protected:
  /**
  *@brief Returns a copy of this element with copies of all its subelements.
  *       The caller is responsible for deletion
  */
  virtual AbstractEntry* clone();
private:
  ASCString target;
  /**
  *@brief The full name to the HTML file
  */
  ASCString file;

};

/**
*@brief Represents a group-file for menu generation by menugen.
*@author Kevin Hirschmann
*/
class GroupFile {
private:
  const Category& topCategory;
  ASCString fileName;
  static int count;
public:

  /**
  *@brief Constructor
  *@param fileName Defines the name (including path) to write to
  *@param topCat The top-category (topmost menu point)
  */
  GroupFile(ASCString fileName, const Category& topCat);
  /**
  *@brief Copy-Constructor
  */
  GroupFile(const GroupFile& gf);

  /**
  *@brief Destructor
  */
  ~GroupFile();

  /**
  *@brief Writes the output to the destination defined in the constructor parameter fileName  
  */
  void write();
};


#endif