File indexing completed on 2024-05-12 03:50:18

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Harshit Jain <hjain.itbhu@gmail.com>
0004 //
0005 
0006 // Own
0007 #include "GeoDataTimeSpan.h"
0008 
0009 // Private
0010 #include "GeoDataTimeSpan_p.h"
0011 
0012 // Qt
0013 #include <QDataStream>
0014 #include <QDateTime>
0015 
0016 // GeoData
0017 #include "GeoDataTypes.h"
0018 #include "MarbleDebug.h"
0019 
0020 namespace Marble
0021 {
0022 
0023 GeoDataTimeSpan::GeoDataTimeSpan()
0024     : GeoDataTimePrimitive(), d( new GeoDataTimeSpanPrivate )
0025 {
0026 }
0027 
0028 GeoDataTimeSpan::GeoDataTimeSpan( const GeoDataTimeSpan& other )
0029     : GeoDataTimePrimitive( other ), d( new GeoDataTimeSpanPrivate( *other.d ) )
0030 {
0031 }
0032 
0033 GeoDataTimeSpan::~GeoDataTimeSpan()
0034 {
0035     delete d;
0036 }
0037 
0038 const char* GeoDataTimeSpan::nodeType() const
0039 {
0040     return GeoDataTypes::GeoDataTimePrimitiveType;
0041 }
0042 
0043 const GeoDataTimeStamp & GeoDataTimeSpan::end() const
0044 {
0045   return d->m_end;
0046 }
0047 
0048 GeoDataTimeStamp &GeoDataTimeSpan::end()
0049 {
0050   return d->m_end;
0051 }
0052 
0053 void GeoDataTimeSpan::setEnd( const GeoDataTimeStamp& end )
0054 {
0055   d->m_end = end;
0056 }
0057 
0058 bool GeoDataTimeSpan::isValid() const
0059 {
0060   if (d->m_begin.when().isValid() != d->m_end.when().isValid()) {
0061     return true;
0062   }
0063 
0064   return d->m_begin.when().isValid() && d->m_end.when().isValid() && d->m_begin.when() <= d->m_end.when();
0065 }
0066 
0067 const GeoDataTimeStamp & GeoDataTimeSpan::begin() const
0068 {
0069   return d->m_begin;
0070 }
0071 
0072 GeoDataTimeStamp &GeoDataTimeSpan::begin()
0073 {
0074   return d->m_begin;
0075 }
0076 
0077 void GeoDataTimeSpan::setBegin( const GeoDataTimeStamp& begin )
0078 {
0079     d->m_begin = begin;
0080 }
0081 
0082 GeoDataTimeSpan& GeoDataTimeSpan::operator=( const GeoDataTimeSpan& other )
0083 {
0084     GeoDataTimePrimitive::operator=( other );
0085     *d = *other.d;
0086     return *this;
0087 }
0088 
0089 bool GeoDataTimeSpan::operator==( const GeoDataTimeSpan& other ) const
0090 {
0091     return equals(other) &&
0092            d->m_begin == other.d->m_begin &&
0093            d->m_end == other.d->m_end;
0094 }
0095 
0096 bool GeoDataTimeSpan::operator!=( const GeoDataTimeSpan& other ) const
0097 {
0098     return !this->operator==( other );
0099 }
0100 
0101 void GeoDataTimeSpan::pack( QDataStream& stream ) const
0102 {
0103     GeoDataTimePrimitive::pack( stream );
0104     d->m_begin.pack( stream );
0105     d->m_end.pack( stream );
0106 }
0107 
0108 void GeoDataTimeSpan::unpack( QDataStream& stream )
0109 {
0110     GeoDataTimePrimitive::unpack( stream );
0111     d->m_begin.unpack( stream );
0112     d->m_end.unpack( stream );
0113 }
0114 
0115 }