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: EbmlFloat.h 1079 2005-03-03 13:18:14Z robux4 $ 34 \author Steve Lhomme <robux4 @ users.sf.net> 35*/ 36#ifndef LIBEBML_FLOAT_H 37#define LIBEBML_FLOAT_H 38 39#include "EbmlTypes.h" 40#include "EbmlElement.h" 41 42START_LIBEBML_NAMESPACE 43 44/*! 45 \class EbmlFloat 46 \brief Handle all operations on a float EBML element 47*/ 48class EBML_DLL_API EbmlFloat : public EbmlElement { 49 public: 50 enum Precision { 51 FLOAT_32 52 ,FLOAT_64 53 }; 54 55 EbmlFloat(const Precision prec = FLOAT_32); 56 EbmlFloat(const double DefaultValue, const Precision prec = FLOAT_32); 57 EbmlFloat(const EbmlFloat & ElementToClone); 58 59 bool ValidateSize() const 60 { 61 return (Size == 4 || Size == 8); 62 } 63 64 uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); 65 uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); 66 uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); 67 68 void SetPrecision(const EbmlFloat::Precision prec = FLOAT_32) 69 { 70 if (prec == FLOAT_64) 71 Size = 8; 72 else 73 Size = 4; // default size 74 } 75 76 77// EbmlFloat & operator=(const float NewValue) { Value = NewValue; return *this;} 78 EbmlFloat & operator=(const double NewValue) { Value = NewValue; bValueIsSet = true; return *this;} 79 80 bool operator<(const EbmlFloat & EltCmp) const {return Value < EltCmp.Value;} 81 82 operator const float() const {return float(Value);} 83 operator const double() const {return double(Value);} 84 85 void SetDefaultValue(double aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;} 86 87 const double DefaultVal() const {assert(DefaultIsSet); return DefaultValue;} 88 89 bool IsDefaultValue() const { 90 return (DefaultISset() && Value == DefaultValue); 91 } 92 93 protected: 94 double Value; /// The actual value of the element 95 double DefaultValue; 96}; 97 98END_LIBEBML_NAMESPACE 99 100#endif // LIBEBML_FLOAT_H 101