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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Abhinav Gangwar <abhgang@gmail.com>
0004 //
0005 
0006 #include "GeoDataSchema.h"
0007 
0008 // Qt
0009 #include <QDataStream>
0010 
0011 // Marble
0012 #include "GeoDataTypes.h"
0013 #include "GeoDataSimpleField.h"
0014 
0015 namespace Marble
0016 {
0017 
0018 class GeoDataSchemaPrivate
0019 {
0020   public:
0021     QHash<QString, GeoDataSimpleField> m_simpleField;
0022     QString m_name;
0023 };
0024 
0025 GeoDataSchema::GeoDataSchema()
0026     : d( new GeoDataSchemaPrivate )
0027 {
0028 }
0029 
0030 GeoDataSchema::GeoDataSchema( const QHash<QString, GeoDataSimpleField>& simplefields )
0031     : d( new GeoDataSchemaPrivate )
0032 {
0033     d->m_simpleField = simplefields;
0034 }
0035 
0036 GeoDataSchema::GeoDataSchema( const GeoDataSchema& other )
0037     : GeoDataObject( other ),
0038       d( new GeoDataSchemaPrivate( *other.d ) )
0039 {
0040 }
0041 
0042 GeoDataSchema &GeoDataSchema::operator=(const GeoDataSchema &other)
0043 {
0044     GeoDataObject::operator=( other );
0045     *d = *other.d;
0046     return *this;
0047 }
0048 
0049 bool GeoDataSchema::operator==(const GeoDataSchema& other) const
0050 {
0051     return equals(other) &&
0052            d->m_name == other.d->m_name &&
0053            d->m_simpleField == other.d->m_simpleField;
0054 }
0055 
0056 bool GeoDataSchema::operator!=(const GeoDataSchema& other) const
0057 {
0058     return !this->operator==( other );
0059 }
0060 
0061 GeoDataSchema::~GeoDataSchema()
0062 {
0063     delete d;
0064 }
0065 
0066 QString GeoDataSchema::schemaName() const
0067 {
0068     return d->m_name;
0069 }
0070 
0071 void GeoDataSchema::setSchemaName( const QString& name )
0072 {
0073     d->m_name = name;
0074 }
0075 
0076 GeoDataSimpleField& GeoDataSchema::simpleField( const QString& name ) const
0077 {
0078     return d->m_simpleField[ name ];
0079 }
0080 
0081 void GeoDataSchema::addSimpleField( const GeoDataSimpleField &value )
0082 {
0083     d->m_simpleField.insert( value.name(), value );
0084 }
0085 
0086 QList<GeoDataSimpleField> GeoDataSchema::simpleFields() const
0087 {
0088     return d->m_simpleField.values();
0089 }
0090 
0091 const char* GeoDataSchema::nodeType() const
0092 {
0093     return GeoDataTypes::GeoDataSchemaType;
0094 }
0095 
0096 void GeoDataSchema::pack( QDataStream& stream ) const
0097 {
0098     stream << d->m_simpleField.size();
0099 
0100     QHash<QString, GeoDataSimpleField>::const_iterator begin = d->m_simpleField.constBegin();
0101     QHash<QString, GeoDataSimpleField>::const_iterator end = d->m_simpleField.constEnd();
0102 
0103     for( ; begin != end; ++begin ) {
0104         begin.value().pack( stream );
0105     }
0106 }
0107 
0108 void GeoDataSchema::unpack( QDataStream& stream )
0109 {
0110     int size = 0;
0111     stream >> size;
0112     for( int i = 0; i < size; ++i ) {
0113         GeoDataSimpleField simpleField;
0114         simpleField.unpack( stream );
0115         d->m_simpleField.insert( simpleField.name(), simpleField );
0116     }
0117 }
0118 
0119 }