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 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.
12**
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.
17**
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
21**
22** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
23**
24** Contact license@matroska.org if any conditions of this licensing are
25** not clear to you.
26**
27**********************************************************************/
28
29/*!
30	\file
31	\version \$Id: EbmlDate.h 1079 2005-03-03 13:18:14Z robux4 $
32	\author Steve Lhomme     <robux4 @ users.sf.net>
33*/
34#ifndef LIBEBML_DATE_H
35#define LIBEBML_DATE_H
36
37#include "EbmlTypes.h"
38#include "EbmlElement.h"
39
40START_LIBEBML_NAMESPACE
41
42/*!
43    \class EbmlDate
44    \brief Handle all operations related to an EBML date
45*/
46class EBML_DLL_API EbmlDate : public EbmlElement {
47	public:
48		EbmlDate() :EbmlElement(8, false), myDate(0) {}
49		EbmlDate(const EbmlDate & ElementToClone);
50
51		/*!
52			\brief set the date with a UNIX/C/EPOCH form
53			\param NewDate UNIX/C date in UTC (no timezone)
54		*/
55		void SetEpochDate(int32 NewDate) {bValueIsSet = true; myDate = int64(NewDate - UnixEpochDelay) * 1000000000; bValueIsSet = true;}
56
57		/*!
58			\brief get the date with a UNIX/C/EPOCH form
59			\note the date is in UTC (no timezone)
60		*/
61		int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);}
62
63		bool ValidateSize() const {return ((Size == 8) || (Size == 0));}
64
65		/*!
66			\note no Default date handled
67		*/
68		uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) {
69			if(!bValueIsSet)
70				Size = 0;
71			else
72				Size = 8;
73			return Size;
74		}
75
76		bool operator<(const EbmlDate & EltCmp) const {return myDate < EltCmp.myDate;}
77
78		uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
79
80		bool IsDefaultValue() const {
81			return false;
82		}
83
84	protected:
85		uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
86
87		int64 myDate; ///< internal format of the date
88
89		static const uint64 UnixEpochDelay;
90};
91
92END_LIBEBML_NAMESPACE
93
94#endif // LIBEBML_DATE_H
95