3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / plugins / matroska / libebml / EbmlUInteger.cpp
blobf153c5ba3684350296969c2c4d46ac254de83159
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
24 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
26 ** Contact license@matroska.org if any conditions of this licensing are
27 ** not clear to you.
29 **********************************************************************/
31 /*!
32 \file
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>
37 #include <cassert>
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)
50 DefaultIsSet = true;
53 EbmlUInteger::EbmlUInteger(const EbmlUInteger & ElementToClone)
54 :EbmlElement(ElementToClone)
55 ,Value(ElementToClone.Value)
56 ,DefaultValue(ElementToClone.DefaultValue)
60 /*!
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
67 if (SizeLength > 8)
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;
73 TempValue >>= 8;
76 output.writeFully(FinalData,Size);
78 return Size;
81 uint64 EbmlUInteger::UpdateSize(bool bKeepIntact, bool bForceRender)
83 if (!bKeepIntact && IsDefaultValue())
84 return 0;
86 if (Value <= 0xFF) {
87 Size = 1;
88 } else if (Value <= 0xFFFF) {
89 Size = 2;
90 } else if (Value <= 0xFFFFFF) {
91 Size = 3;
92 } else if (Value <= 0xFFFFFFFF) {
93 Size = 4;
94 } else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFF)) {
95 Size = 5;
96 } else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFF)) {
97 Size = 6;
98 } else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFFFF)) {
99 Size = 7;
100 } else {
101 Size = 8;
104 if (DefaultSize > Size) {
105 Size = DefaultSize;
108 return Size;
111 uint64 EbmlUInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
113 if (ReadFully != SCOPE_NO_DATA)
115 binary Buffer[8];
116 input.readFully(Buffer, Size);
117 Value = 0;
119 for (unsigned int i=0; i<Size; i++)
121 Value <<= 8;
122 Value |= Buffer[i];
124 bValueIsSet = true;
127 return Size;
130 END_LIBEBML_NAMESPACE