1/****************************************************************************
2** libebml : parse EBML files, see http://embl.sourceforge.net/
3**
4** <file/class description>
5**
6** Copyright (C) 2002-2005 Steve Lhomme.  All rights reserved.
7**
8** This file is part of libebml.
9**
10** This library is free software; you can redistribute it and/or
11** modify it under the terms of the GNU Lesser General Public
12** License as published by the Free Software Foundation; either
13** version 2.1 of the License, or (at your option) any later version.
14**
15** This library is distributed in the hope that it will be useful,
16** but WITHOUT ANY WARRANTY; without even the implied warranty of
17** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18** Lesser General Public License for more details.
19**
20** You should have received a copy of the GNU Lesser General Public
21** License along with this library; if not, write to the Free Software
22** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23**
24** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
25**
26** Contact license@matroska.org if any conditions of this licensing are
27** not clear to you.
28**
29**********************************************************************/
30
31/*!
32	\file
33	\version \$Id: EbmlUInteger.h 1079 2005-03-03 13:18:14Z robux4 $
34	\author Steve Lhomme     <robux4 @ users.sf.net>
35	\author Julien Coloos    <suiryc @ users.sf.net>
36	\author Moritz Bunkus    <moritz @ bunkus.org>
37*/
38#ifndef LIBEBML_UINTEGER_H
39#define LIBEBML_UINTEGER_H
40
41#include "EbmlTypes.h"
42#include "EbmlElement.h"
43
44START_LIBEBML_NAMESPACE
45
46const int DEFAULT_UINT_SIZE = 0; ///< optimal size stored
47
48/*!
49    \class EbmlUInteger
50    \brief Handle all operations on an unsigned integer EBML element
51*/
52class EBML_DLL_API EbmlUInteger : public EbmlElement {
53	public:
54		EbmlUInteger();
55		EbmlUInteger(const uint64 DefaultValue);
56		EbmlUInteger(const EbmlUInteger & ElementToClone);
57
58		EbmlUInteger & operator=(const uint64 NewValue) {Value = NewValue; bValueIsSet = true; return *this;}
59
60		/*!
61			Set the default size of the integer (usually 1,2,4 or 8)
62		*/
63		void SetDefaultSize(const int nDefaultSize = DEFAULT_UINT_SIZE) {Size = nDefaultSize;}
64
65		bool ValidateSize() const {return (Size <= 8);}
66		uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
67		uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
68		uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
69
70		bool operator<(const EbmlUInteger & EltCmp) const {return Value < EltCmp.Value;}
71
72		operator uint8()  const {return uint8(Value); }
73		operator uint16() const {return uint16(Value);}
74		operator uint32() const {return uint32(Value);}
75		operator uint64() const {return Value;}
76
77		void SetDefaultValue(uint64 aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
78
79		const uint64 DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
80
81		bool IsDefaultValue() const {
82			return (DefaultISset() && Value == DefaultValue);
83		}
84
85	protected:
86		uint64 Value; /// The actual value of the element
87		uint64 DefaultValue;
88};
89
90END_LIBEBML_NAMESPACE
91
92#endif // LIBEBML_UINTEGER_H
93