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
cDomainNaturalNumber.h
Go to the documentation of this file.
1 /**
2  * @class cDomainNaturalNumber
3  * file name: cDomainNaturalNumber.h
4  * @author Betti Oesterholz
5  * @date 21.12.2009
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents a domain for natural numbers.
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 file contains the class for natural number Fib -domains.
28  * The representet domain is defined by the maximal number in the domain.
29  * If N is the maximal number, the domain {0, ..., N} is the
30  * unscaled domain and if dScalingFactor is the scaling factor
31  * { 0*dScalingFactor, ..., N * dScalingFactor} is the scaled
32  * domain.
33  *
34  */
35 /*
36 History:
37 21.12.2009 Oesterholz created
38 01.12.2011 Oesterholz method isInBoundaries() added
39 */
40 
41 #ifndef ___C_DOMAIN_NATURAL_NUMBER_H__
42 #define ___C_DOMAIN_NATURAL_NUMBER_H__
43 
44 
45 #include "version.h"
46 
47 #include "cDomainIntegerBasis.h"
49 
50 
51 namespace fib{
52 
53 
55 protected:
56 
57  /**
58  * The maximal number of the natural numbers in this domain.
59  */
61 
62  /**
63  * The cDomainNaturalNumber uses a cDomainNaturalNumberBit domain for
64  * storing values.
65  */
67 
68 public:
69 
70  /**
71  * The constructor for unscaled natural numer domains.
72  * If ulMaxNumber is the maximal number for the domain
73  * {0, ..., ulMaxNumber} is the domain.
74  *
75  * @param ulMaxNumber the maximal number of the domain
76  */
78 
79 
80  /**
81  * The constructor for scaled natural numer domains.
82  * If ulMaxNumber is the maximal number for the domain
83  * { 0*dScalingFactor, ..., ulMaxNumber * dScalingFactor} the scaled
84  * domain.
85  *
86  * @param ulMaxNumber the maximal number of the domain
87  * @param dScalingFactor the scaling factor of the domain
88  * the scaling factor has to be greater 0.0
89  */
91 
92  /**
93  * The copyconstructor for natural numer domains.
94  *
95  * @param domain the natural number domain to copy
96  */
98 
99  /**
100  * @return the type of the domain as an string
101  */
102  virtual string getType() const;
103 
104  /**
105  * This method checks if the given value is an element of the
106  * domain. If the value dValue is an element of the
107  * domain true is returned, else false.
108  *
109  * @param dValue the value for which to check, if it is an element of
110  * the domain
111  * @return if the value dValue is an element of the domain true
112  * true is returned, else false
113  */
114  virtual bool isElement( const doubleFib dValue ) const;
115 
116  /**
117  * This method checks if the given value is inside the domain
118  * boundaries. If the value dValue is inside of the domain boundaries
119  * true is returned, else false.
120  * A value is inside of the vector domain boudaries, if it is greater
121  * than the minimum value minus the scaling factor and lower than the
122  * maximum value plus the scaling factor.
123  *
124  * @param dValue the value for which to check, if it is inside of
125  * the domain boundaries
126  * @return if the vector dValue is inside of the domain boundaries
127  * true is returned, else false
128  */
129  virtual bool isInBoundaries( const doubleFib dValue ) const;
130 
131 
132  /**
133  * This method round the given value dValue to an value in the
134  * domain of this object.
135  * The rounded vale will be the value with the minimal distance to the
136  * given value dValue. If more of these exists the smales will be
137  * returned.
138  *
139  * @param dValue the value which should be rounded
140  * @return the rounded value of dValue
141  */
142  virtual doubleFib round( const doubleFib dValue ) const;
143 
144 
145  /**
146  * This method returns the biggest value in the domain.
147  *
148  * @return the biggest value in the domain
149  */
150  doubleFib getMaximum() const ;
151 
152 
153  /**
154  * This method returns the smalest value in the domain.
155  *
156  * @return the smalest value in the domain
157  */
158  virtual doubleFib getMinimum() const;
159 
160 
161  /**
162  * This method returns the nullvalue of the domain.
163  * The nullvalue is the value 0 rounded to an value in the
164  * domain.
165  *
166  * @return the nullvalue of the domain
167  */
168  virtual doubleFib getNull() const;
169 
170 
171  /**
172  * This method checks if the given value is an element of the
173  * unscaled domain. If the value lValue is an element of the
174  * unscaled domain true is returned, else false.
175  *
176  * @param lValue the value for which to check, if it is an element of
177  * the unscaled domain
178  * @return if the value dValue is an element of the unscaled
179  * domain true true is returned, else false
180  */
181  virtual bool isUnscaledElement( const longFib lValue ) const;
182 
183 
184  /**
185  * This method round the given value dValue to an value in the
186  * unscaled domain of this object.
187  * The rounded vale will be the unscaled value with the minimal
188  * distance to the given value lValue. If more of these exists the
189  * smales will be returned.
190  *
191  * @param lValue the value which should be rounded
192  * @return the rounded unscaled value of lValue
193  */
194  virtual longFib roundUnscaled( const longFib lValue ) const;
195 
196 
197  /**
198  * This method returns the biggest value in the unscaled domain.
199  *
200  * @return the biggest value in the unscaled domain
201  */
202  virtual longFib getMaximumUnscaled() const;
203 
204 
205  /**
206  * This method returns the smalest value in the unscaled domain.
207  *
208  * @return the smalest value in the unscaled domain
209  */
210  virtual longFib getMinimumUnscaled() const;
211 
212 
213  /**
214  * This method returns the nullvalue of the unscaled domain.
215  * The nullvalue is the value 0 rounded to an value in the unscaled
216  * domain.
217  *
218  * @return the nullvalue of the domain
219  */
220  virtual longFib getNullUnscaled() const;
221 
222  /**
223  * This Method clones this object.
224  *
225  * @return a clone of this object
226  */
227  virtual cDomainNaturalNumber *clone() const;
228 
229 
230  /**
231  * This Method checks if the given domain is equal to this domain.
232  *
233  * @param domain the domain which should be equal to this domain
234  * @return true if the given domain is equal to this domain, else false
235  */
236  virtual bool operator==( const cDomain &domain ) const;
237 
238 
239  /**
240  * This method evaluades the size of the domain in bits in the
241  * compressed file form.
242  *
243  * @see store()
244  * @return the size of the domain in bits in the compressed form
245  */
246  virtual unsignedIntFib getCompressedSize() const;
247 
248  /**
249  * This method evaluades the size of values in the domain in bits in
250  * the compressed file form.
251  *
252  * @see store()
253  * @return the size of the domain in bits in the compressed form
254  */
256 
257  /**
258  * This method stores this domain in the XML -format into the
259  * given stream.
260  *
261  * @param ostream the stream where domains should be stored to
262  * @return true if this domain are stored, else false
263  */
264  virtual bool storeXml( ostream & ostream ) const;
265 
266  /**
267  * This method restores a domain in the XML -format from an TinyXml element.
268  *
269  * @param pXmlNode a pointer to the TinyXml node wher the domain is stored in
270  * @return an integervalue with the errorvalue
271  * possible errorvalues are:
272  * - 0 loading successful
273  * - -1 loading error, invalid pXmlElement
274  * - -2 loading error, invalid data in pXmlElement
275  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
276  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
277  * object is wrong
278  */
279  virtual intFib restoreXml( const TiXmlElement * pXmlElement ) ;
280 
281  /**
282  * This method stores this domain in the compressed fib -format
283  * into the given stream.
284  * It is needed because the stream can yust store byts but the size of
285  * fib -elements can be any number of bits. Because of that ther have to
286  * be a possibility to exchange the missing bits betwean the fib -elements.
287  *
288  * @see cFibElement::store
289  * @param stream the stream where this domain should be stored to
290  * @param cRestBits the not yet writen bits which should be stored
291  * @param uiRestBitPosition the number of bits in the cRestBits which
292  * should be writen respectively containing valid information
293  * @return true if the domain is stored, else false
294  */
295  virtual bool store( ostream & stream, char & cRestBits,
296  unsigned char & uiRestBitPosition ) const;
297 
298  /**
299  * This method restores a domain from a bitstream, wher it is
300  * stored in the compressed fib -format.
301  *
302  * @see store
303  * @param iBitStream the stream where the domain is stored in,
304  * because the stream is an cReadBits, any number of bits can be
305  * readed from it
306  * @return an integervalue with the errorvalue
307  * possible errorvalues are:
308  * - 0 loading successful
309  * - -1 loading error, invalid pXmlElement
310  * - -2 loading error, invalid data in pXmlElement
311  * - 1 loading warning, invalid data in pXmlElement, error could be corrected
312  * - 2 loading warning, invalid data in pXmlElement, maybe the loaded
313  * object is wrong
314  */
315  virtual intFib restore( cReadBits & iBitStream );
316 
317  /**
318  * This method stores the given value dValue in the compressed
319  * fib -format for the domain into the given stream.
320  * It is needed because the stream can yust store byts but the size of
321  * fib -elements can be any number of bits. Because of that ther have to
322  * be a possibility to exchange the missing bits betwean the fib -elements.
323  *
324  * @see cFibElement::store
325  * @param dValue the value to store
326  * @param stream the stream where this domain should be stored to
327  * @param cRestBits the not yet writen bits which should be stored
328  * @param uiRestBitPosition the number of bits in the cRestBits which
329  * should be writen respectively containing valid information
330  * @return true if the domain is stored, else false
331  */
332  virtual bool storeValue( doubleFib dValue, ostream & stream,
333  char & cRestBits, unsigned char & uiRestBitPosition ) const;
334 
335  /**
336  * This method stores the given unscaled value lValue in the compressed
337  * fib -format for the domain into the given stream.
338  * It is needed because the stream can yust store byts but the size of
339  * fib -elements can be any number of bits. Because of that ther have to
340  * be a possibility to exchange the missing bits betwean the fib -elements.
341  *
342  * @see cFibElement::store
343  * @param lValue the value to store
344  * @param stream the stream where this domain should be stored to
345  * @param cRestBits the not yet writen bits which should be stored
346  * @param uiRestBitPosition the number of bits in the cRestBits which
347  * should be writen respectively containing valid information
348  * @return true if the domain is stored, else false
349  */
350  virtual bool storeUnscaledValue( longFib lValue, ostream & stream,
351  char & cRestBits, unsigned char & uiRestBitPosition ) const;
352 
353  /**
354  * This method restores the a unscaled integer value of the domain from
355  * the stream iBitStream, wher it is stored in the compressed fib -format.
356  *
357  * @see storeValue
358  * @see restoreValue
359  * @see storeUnscaledValue
360  * @see cFibElement::restore
361  * @param iBitStream the stream where this value is stored to in,
362  * because this stream is an cReadBits, any number of bits can be
363  * readed from it
364  * @param outStatus An reference to an integervalue where the errorvalue
365  * can be stored to. If the pointer is NULL no errorvalue will be
366  * given back.
367  * possible errorvalues are:
368  * - 0 loading successful
369  * - -1 loading error, invalid stream
370  * - -2 loading error, invalid data in stream
371  * - 1 loading warning, invalid data in stream, error could be corrected
372  * - 2 loading warning, invalid data in stream, maybe the loaded
373  * object is wrong
374  * @return the unscaled restored value
375  */
376  virtual longFib restoreIntegerValue( cReadBits & iBitStream, intFib & outStatus ) const;
377 
378 };//end class cDomainNaturalNumber
379 
380 
381 }//end namespace fib
382 
383 #endif