The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cDomains.h
Go to the documentation of this file.
1 /**
2  * @class cDomains
3  * file name: cDomains.h
4  * @author Betti Oesterholz
5  * @date 09.06.2009
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a list of domains.
11  * Copyright (C) @c LGPL3 2009 Betti Oesterholz
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License (LGPL) as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  *
26  *
27  * This class represents a list of domains for an root -element.
28  * The domain list consists of a number of domains with a type for which
29  * they apply. No two domains can be for the same type.
30  *
31  */
32 /*
33 History:
34 09.06.2009 Oesterholz created
35 12.02.2012 Oesterholz methods for changed cDomainReference
36 11.03.2012 Oesterholz getDirectDomainForElement() added
37 23.09.2012 Oesterholz Warning removed: virtual destructor added
38 */
39 
40 #ifndef ___C_DOMAINS_H__
41 #define ___C_DOMAINS_H__
42 
43 #include "version.h"
44 
45 #include "fibDatatyps.h"
46 #include "cReadBits.h"
47 
48 #include "cDomain.h"
49 #include "cTypeElement.h"
50 #include "cDomainElement.h"
51 #include "cDomainReference.h"
52 #include "cDomainIntegerBit.h"
53 
54 #include <list>
55 #include <map>
56 #include <string>
57 #include <ostream>
58 #include <istream>
59 
60 
61 
62 using std::list;
63 using std::string;
64 
65 namespace fib{
66 
67 
68 class cDomains{
69 protected:
70 
71  /**
72  * the list with the domains for this domain list
73  */
74  list<cDomainElement> domainElements;
75 
76 
77 //next part is needed for the cDomainReference
78  /**
79  * The standard domain when no other domain is aviable.
80  * (not mutable: cDomainIntegerBit can't be changed ;) )
81  */
83 
84  /**
85  * A map with the standard domains which wher created for returning
86  * a domain reference.
87  */
88  mutable list<cDomainElement> standardDomains;
89 
90 public:
91 
92  /**
93  * The constructor for the domain list.
94  */
95  cDomains();
96 
97  /**
98  * The desstructor for the domain list.
99  */
100  virtual ~cDomains();
101 
102  /**
103  * @return the number of domains in the domain list
104  */
106 
107 
108  /**
109  * This method returns the domain on the given position iDomainNumber
110  * in the domain list.
111  * If the domain on the position is a reference domain @see cDomainReference
112  * the domain to which it is refered to will be returned.
113  *
114  * @param iDomainNumber the position on which the domain to
115  * return stands in the domain list (the counting begins with 1)
116  * @return a reference to the iDomainNumber'th domain (so you can adopt
117  * the domain) of this domain list or the Nullpointer NULL if non
118  * such exists;
119  */
120  cDomain * getDomain( unsignedIntFib iDomainNumber ) const;
121 
122 
123  /**
124  * This method returns the type on the given position iTypeNumber
125  * in the domain list.
126  *
127  * @param iTypeNumber the position on which the type to
128  * return stands in the domain list (the counting begins with 1)
129  * @return a reference to the iTypeNumber'th type of this domain list or
130  * the Nullpointer NULL if non such exists;
131  */
132  cTypeElement * getType( unsignedIntFib iTypeNumber ) const;
133 
134 
135  /**
136  * This method returns the domain for the given type from the
137  * domain list.
138  * If the domain for the type is a reference domain @see cDomainReference
139  * the domain to which it is refered to will be returned.
140  *
141  * @param type the type for which the domain is to return
142  * @return a reference to the domain (so you can adopt the domain) of
143  * this domain list for elements of the given type or the Nullpointer
144  * NULL if non such exists;
145  */
146  cDomain * getDomainForElement( const cTypeElement &type ) const;
147 
148 
149  /**
150  * This method returns the direct domain on the given position
151  * iDomainNumber in the domain list, without evaluating it.
152  * Since some domains (ie cDomainReference) are evalued by methods like
153  * getDomain(), this method will return the domain directly without
154  * evaluing it.
155  *
156  * @see getDomain()
157  * @see getDomainForElement()
158  * @param iDomainNumber the position on which the direct domain to
159  * return stands in the domain list (the counting begins with 1)
160  * @return a reference to the iDomainNumber'th direct domain (so you
161  * can adopt the domain) of this domain list or the Nullpointer
162  * NULL if non such exists;
163  */
164  cDomain * getDirectDomain( const unsignedIntFib iDomainNumber ) const;
165 
166  /**
167  * This method returns the direct domain for the given type
168  * in the domain list, without evaluating it.
169  * Since some domains (ie cDomainReference) are evalued by methods like
170  * getDomainForElement(), this method will return the domain directly
171  * without evaluing it.
172  *
173  * @see getDomain()
174  * @see getDomainForElement()
175  * @param type the type for which the domain is to return
176  * @return a reference to the direct domain (so you can adopt the domain)
177  * of the gifen type of this domain list or the Nullpointer
178  * NULL if non such exists;
179  */
180  cDomain * getDirectDomainForElement( const cTypeElement &type ) const;
181 
182  /**
183  * This method returns the domain to which the given reference domain
184  * refers to.
185  * If no domain to which it is refered can be found the standard domain
186  * for the pDomainReference type will be returned.
187  *
188  * @param pDomainReference reference domain for which the domain is to
189  * be returned
190  * @param pTypeElementForWhich a pointer to the type element for which the
191  * domain should be
192  * @return a pointer to the domain (so you can adopt the domain) for
193  * the reference domain or the Nullpointer NULL if non such exists
194  */
196  cTypeElement * pTypeElementForWhich = NULL ) const;
197 
198 
199  /**
200  * This method adds a given domain for the given type to the domain list.
201  * If an domain for the element allready exists, it is replaced.
202  *
203  * @param type the type for which the domain is to add
204  * @param domain the domain for the given type
205  * @return the number of the position on which the new domain stands in
206  * the domain list or 0 if the domain wasn't inserted
207  */
208  unsignedIntFib addDomain( const cTypeElement &type, const cDomain &domain );
209 
210  /**
211  * This method adds a given domain for the given type to the domain list.
212  * If an domain for the element allready exists, it is replaced.
213  * This add method dosn't copy the domain, befor adding it.
214  *
215  * @param type the type for which the domain is to add
216  * @param domain a pointer to the domain for the given type
217  * @return the number of the position on which the new domain stands in
218  * the domain list or 0 if the domain wasn't inserted
219  */
220  unsignedIntFib addDomain( const cTypeElement &type, cDomain * domain );
221 
222 
223  /**
224  * This method sets the domain for the given type to the standarddomain
225  * of the type. If no entry for the type exists, an entry is added.
226  *
227  * @param type the type for which the domain is to set to the
228  * standarddomain
229  * @return the number of the position on which the type stands in
230  * the domain list
231  */
233 
234 
235  /**
236  * This method deletes the domain on the given position iDomainNumber
237  * in the domain list.
238  *
239  * @param iDomainNumber the position on which the domain to
240  * delete stands in the domain list (the counting begins with 1)
241  * @return true if the domain on the position is deleted, else false
242  */
243  bool deleteDomain( unsignedIntFib iDomainNumber );
244 
245 
246  /**
247  * This method deletes the domain for the given type from the
248  * domain list.
249  *
250  * @param type the type for which the domain is to delete
251  * @return true if the domain for the given type is deleted, else false
252  */
253  bool deleteDomain( const cTypeElement &type );
254 
255 
256  /**
257  * This Method clones this object.
258  *
259  * @return a clone of this object
260  */
261  virtual cDomains *clone() const;
262 
263 
264  /**
265  * This method evaluades the size of the domains in bits in the
266  * compressed file form.
267  *
268  * @see store()
269  * @return the size of the domains in bits in the compressed form
270  */
271  virtual unsignedLongFib getCompressedSize() const;
272 
273  /**
274  * This method stores this domains in the XML -format into the
275  * given stream.
276  *
277  * @param ostream the stream where domains should be stored to
278  * @param szName the name the writen XML -element should have
279  * @return true if this domains are stored, else false
280  */
281  virtual bool storeXml( ostream & ostream, string szName=string("domains") ) const;
282 
283  /**
284  * This method restores this optionalpart in the XML -format from an
285  * an TinyXml element.
286  *
287  * @param pXmlNode a pointer to the TinyXml node wher the domains are stored in
288  * @return an integervalue with the errorvalue
289  * possible errorvalues are:
290  * - 0 loading successful
291  * - -1 loading error, invalid pXmlElement
292  * - -2 loading error, invalid data in pXmlElement
293  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
294  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
295  * object is wrong
296  */
297  virtual intFib restoreXml( const TiXmlElement * pXmlElement );
298 
299  /**
300  * This method stores this domains in the compressed Fib -format
301  * into the given stream.
302  * It is needed because the stream can yust store byts but the size of
303  * fib -elements can be any number of bits. Because of that ther have to
304  * be a possibility to exchange the missing bits betwean the fib -elements.
305  *
306  * @see cFibElement::store
307  * @param stream the stream where this domains should be stored to
308  * @param cRestBits the not yet writen bits which should be stored
309  * @param uiRestBitPosition the number of bits in the cRestBits which
310  * should be writen respectively containing valid information
311  * @return true if the domains are stored, else false
312  */
313  virtual bool store( ostream & stream, char & cRestBits,
314  unsigned char & uiRestBitPosition ) const;
315 
316  /**
317  * This method restores the domains from a bitstream, wher it is
318  * stored in the compressed fib -format.
319  *
320  * @see store
321  * @see cFibElement::store
322  * @param iBitStream the stream where this domains is stored in,
323  * because this stream is an cReadBits, any number of bits can be
324  * readed from it
325  * @return the errorvalue
326  * possible errorvalues are:
327  * - 0 loading successful
328  * - -1 loading error, invalid stream
329  * - -2 loading error, invalid data in stream
330  * - 1 loading warning, invalid data in stream, error could be corrected
331  * - 2 loading warning, invalid data in stream, maybe the loaded
332  * object is wrong
333  */
334  virtual intFib restore( cReadBits & iBitStream );
335 
336  /**
337  * This Method checks if the given domains is equal to this domains.
338  *
339  * @param domains the domains to compare with this
340  * @return true if the given domains is equal to this
341  * domains, else false
342  */
343  virtual bool equal( const cDomains &domains ) const;
344 
345  /**
346  * This method checks if the given domains is equal to this domains.
347  *
348  * @param domains the domains to compare with this
349  * @return true if the given domains is equal to this
350  * domains, else false
351  */
352  virtual bool operator==( const cDomains &domains ) const;
353 
354  /**
355  * This operator makes this domains equal to the given domains.
356  *
357  * @param domains the domains to which this should be equal
358  * @return a refernce to this domain
359  */
360  virtual cDomains & operator=( const cDomains &domains );
361 
362 
363 };//end class cDomains
364 
365 
366 }//end namespace fib
367 
368 #endif //___C_DOMAINS_H__