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 library is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU Lesser General Public
10 ** License as published by the Free Software Foundation; either
11 ** version 2.1 of the License, or (at your option) any later version.
13 ** This library is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** Lesser General Public License for more details.
18 ** You should have received a copy of the GNU Lesser General Public
19 ** License along with this library; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
24 ** Contact license@matroska.org if any conditions of this licensing are
27 **********************************************************************/
31 \version \$Id: EbmlSInteger.cpp 1079 2005-03-03 13:18:14Z robux4 $
32 \author Steve Lhomme <robux4 @ users.sf.net>
33 \author Moritz Bunkus <moritz @ bunkus.org>
37 #include "ebml/EbmlSInteger.h"
39 START_LIBEBML_NAMESPACE
41 EbmlSInteger::EbmlSInteger()
42 :EbmlElement(DEFAULT_INT_SIZE
, false)
45 EbmlSInteger::EbmlSInteger(const int64 aDefaultValue
)
46 :EbmlElement(DEFAULT_INT_SIZE
, true), Value(aDefaultValue
)
51 EbmlSInteger::EbmlSInteger(const EbmlSInteger
& ElementToClone
)
52 :EbmlElement(ElementToClone
)
53 ,Value(ElementToClone
.Value
)
54 ,DefaultValue(ElementToClone
.DefaultValue
)
59 \todo handle exception on errors
61 uint32
EbmlSInteger::RenderData(IOCallback
& output
, bool bForceRender
, bool bKeepIntact
)
63 binary FinalData
[8]; // we don't handle more than 64 bits integers
67 return 0; // integer bigger coded on more than 64 bits are not supported
69 int64 TempValue
= Value
;
70 for (i
=0; i
<Size
;i
++) {
71 FinalData
[Size
-i
-1] = binary(TempValue
& 0xFF);
75 output
.writeFully(FinalData
,Size
);
80 uint64
EbmlSInteger::UpdateSize(bool bKeepIntact
, bool bForceRender
)
82 if (!bKeepIntact
&& IsDefaultValue())
85 if (Value
<= 0x7F && Value
>= (-0x80)) {
87 } else if (Value
<= 0x7FFF && Value
>= (-0x8000)) {
89 } else if (Value
<= 0x7FFFFF && Value
>= (-0x800000)) {
91 } else if (Value
<= 0x7FFFFFFF && Value
>= (-0x80000000)) {
93 } else if (Value
<= EBML_PRETTYLONGINT(0x7FFFFFFFFF) &&
94 Value
>= EBML_PRETTYLONGINT(-0x8000000000)) {
96 } else if (Value
<= EBML_PRETTYLONGINT(0x7FFFFFFFFFFF) &&
97 Value
>= EBML_PRETTYLONGINT(-0x800000000000)) {
99 } else if (Value
<= EBML_PRETTYLONGINT(0x7FFFFFFFFFFFFF) &&
100 Value
>= EBML_PRETTYLONGINT(-0x80000000000000)) {
106 if (DefaultSize
> Size
) {
113 uint64
EbmlSInteger::ReadData(IOCallback
& input
, ScopeMode ReadFully
)
115 if (ReadFully
!= SCOPE_NO_DATA
)
118 input
.readFully(Buffer
, Size
);
120 if (Buffer
[0] & 0x80)
121 Value
= -1; // this is a negative value
123 Value
= 0; // this is a positive value
125 for (unsigned int i
=0; i
<Size
; i
++)
136 END_LIBEBML_NAMESPACE