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