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: EbmlFloat.cpp 1243 2006-03-30 19:33:22Z mosu $
34 \author Steve Lhomme <robux4 @ users.sf.net>
39 #include "ebml/EbmlFloat.h"
41 START_LIBEBML_NAMESPACE
43 EbmlFloat::EbmlFloat(const EbmlFloat::Precision prec
)
44 :EbmlElement(0, false)
49 EbmlFloat::EbmlFloat(const double aDefaultValue
, const EbmlFloat::Precision prec
)
50 :EbmlElement(0, true), Value(aDefaultValue
), DefaultValue(aDefaultValue
)
56 EbmlFloat::EbmlFloat(const EbmlFloat
& ElementToClone
)
57 :EbmlElement(ElementToClone
)
58 ,Value(ElementToClone
.Value
)
59 ,DefaultValue(ElementToClone
.DefaultValue
)
64 \todo handle exception on errors
65 \todo handle 10 bits precision
67 uint32
EbmlFloat::RenderData(IOCallback
& output
, bool bForceRender
, bool bKeepIntact
)
69 assert(Size
== 4 || Size
== 8);
74 memcpy(&Tmp
, &val
, 4);
75 big_int32
TmpToWrite(Tmp
);
76 output
.writeFully(&TmpToWrite
.endian(), Size
);
77 } else if (Size
== 8) {
80 memcpy(&Tmp
, &val
, 8);
81 big_int64
TmpToWrite(Tmp
);
82 output
.writeFully(&TmpToWrite
.endian(), Size
);
88 uint64
EbmlFloat::UpdateSize(bool bKeepIntact
, bool bForceRender
)
90 if (!bKeepIntact
&& IsDefaultValue())
96 \todo remove the hack for possible endianess pb (test on little & big endian)
98 uint64
EbmlFloat::ReadData(IOCallback
& input
, ScopeMode ReadFully
)
100 if (ReadFully
!= SCOPE_NO_DATA
)
104 input
.readFully(Buffer
, Size
);
108 TmpRead
.Eval(Buffer
);
109 int32 tmpp
= int32(TmpRead
);
111 memcpy(&val
, &tmpp
, 4);
114 } else if (Size
== 8) {
116 TmpRead
.Eval(Buffer
);
117 int64 tmpp
= int64(TmpRead
);
119 memcpy(&val
, &tmpp
, 8);
128 END_LIBEBML_NAMESPACE