1 /****************************************************************************
2 ** libebml : parse EBML files, see http://embl.sourceforge.net/
4 ** <file/class description>
6 ** Copyright (C) 2002-2005 Steve Lhomme. All rights reserved.
8 ** This file is part of libebml.
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.
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.
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
24 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
26 ** Contact license@matroska.org if any conditions of this licensing are
29 **********************************************************************/
33 \version \$Id: EbmlUInteger.cpp 1079 2005-03-03 13:18:14Z robux4 $
34 \author Steve Lhomme <robux4 @ users.sf.net>
35 \author Moritz Bunkus <moritz @ bunkus.org>
39 #include "ebml/EbmlUInteger.h"
41 START_LIBEBML_NAMESPACE
43 EbmlUInteger::EbmlUInteger()
44 :EbmlElement(DEFAULT_UINT_SIZE
, false)
47 EbmlUInteger::EbmlUInteger(const uint64 aDefaultValue
)
48 :EbmlElement(DEFAULT_UINT_SIZE
, true), Value(aDefaultValue
), DefaultValue(aDefaultValue
)
53 EbmlUInteger::EbmlUInteger(const EbmlUInteger
& ElementToClone
)
54 :EbmlElement(ElementToClone
)
55 ,Value(ElementToClone
.Value
)
56 ,DefaultValue(ElementToClone
.DefaultValue
)
61 \todo handle exception on errors
63 uint32
EbmlUInteger::RenderData(IOCallback
& output
, bool bForceRender
, bool bKeepIntact
)
65 binary FinalData
[8]; // we don't handle more than 64 bits integers
68 return 0; // integer bigger coded on more than 64 bits are not supported
70 uint64 TempValue
= Value
;
71 for (unsigned int i
=0; i
<Size
;i
++) {
72 FinalData
[Size
-i
-1] = TempValue
& 0xFF;
76 output
.writeFully(FinalData
,Size
);
81 uint64
EbmlUInteger::UpdateSize(bool bKeepIntact
, bool bForceRender
)
83 if (!bKeepIntact
&& IsDefaultValue())
88 } else if (Value
<= 0xFFFF) {
90 } else if (Value
<= 0xFFFFFF) {
92 } else if (Value
<= 0xFFFFFFFF) {
94 } else if (Value
<= EBML_PRETTYLONGINT(0xFFFFFFFFFF)) {
96 } else if (Value
<= EBML_PRETTYLONGINT(0xFFFFFFFFFFFF)) {
98 } else if (Value
<= EBML_PRETTYLONGINT(0xFFFFFFFFFFFFFF)) {
104 if (DefaultSize
> Size
) {
111 uint64
EbmlUInteger::ReadData(IOCallback
& input
, ScopeMode ReadFully
)
113 if (ReadFully
!= SCOPE_NO_DATA
)
116 input
.readFully(Buffer
, Size
);
119 for (unsigned int i
=0; i
<Size
; i
++)
130 END_LIBEBML_NAMESPACE