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