<commit_before>/*
    Copyright (C) 2007 <NAME> <<EMAIL>>
    Copyright (C) 2007 <NAME> <<EMAIL>>

    This file is part of the KDE project

    This library is free software you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    aint with this library see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "GeoDataDocument.h"

#include "GeoDataFolder.h"
#include "GeoDataPlacemark.h"
#include "GeoDataStyle.h"
#include "GeoDataStyleMap.h"

#include <QtCore/QDebug>

#include "GeoDataDocument_p.h"

namespace Marble
{

GeoDataDocument::GeoDataDocument()
    : GeoDataContainer( new GeoDataDocumentPrivate )
{
}

GeoDataDocument::GeoDataDocument( GeoDataFeature& other )
    : GeoDataContainer( other )
{
}

GeoDataDocument::GeoDataDocument( const GeoDataDocument& other )
: GeoDataContainer( other )
{
}

GeoDataDocument::~GeoDataDocument()
{
    p()->m_styleHash.clear();
    p()->m_styleMapHash.clear();
}

GeoDataDocumentPrivate* GeoDataDocument::p() const
{
    return static_cast<GeoDataDocumentPrivate*>(d);
}

QString GeoDataDocument::fileName() const
{
    return p()->m_filename;
}

void GeoDataDocument::setFileName( const QString &value )
{
    detach();
    p()->m_filename = value;
}

void GeoDataDocument::addStyle( const GeoDataStyle& style )
{
    detach();
    p()->m_styleHash.insert( style.styleId(), style );
}

void GeoDataDocument::removeStyle( const QString& styleId )
{
    detach();
    p()->m_styleHash.remove( styleId );
}

GeoDataStyle& GeoDataDocument::style( const QString& styleId ) const
{
    /*
     * FIXME: m_styleHash always should contain at least default
     *        GeoDataStyle element
     */
    return p()->m_styleHash[ styleId ];
}

QList<GeoDataStyle> GeoDataDocument::styles() const
{
    return p()->m_styleHash.values();
}

void GeoDataDocument::addStyleMap( const GeoDataStyleMap& map )
{
    detach();
    qDebug( "GeoDataDocument: Add new styleMap" );
    p()->m_styleMapHash.insert( map.styleId(), map );
}

void GeoDataDocument::removeStyleMap( const QString& mapId )
{
    detach();
    p()->m_styleMapHash.remove( mapId );
}

GeoDataStyleMap& GeoDataDocument::styleMap( const QString& styleId ) const
{
    return p()->m_styleMapHash[ styleId ];
}

QList<GeoDataStyleMap> GeoDataDocument::styleMaps() const
{
    return p()->m_styleMapHash.values();
}

void GeoDataDocument::pack( QDataStream& stream ) const
{
    GeoDataContainer::pack( stream );

    stream << p()->m_styleHash.size();
    
    
    for( QMap<QString, GeoDataStyle>::const_iterator iterator 
          = p()->m_styleHash.constBegin(); 
        iterator != p()->m_styleHash.constEnd(); 
        ++iterator ) {
        iterator.value().pack( stream );
    }
}


void GeoDataDocument::unpack( QDataStream& stream )
{
    detach();
    GeoDataContainer::unpack( stream );

    int size = 0;

    stream >> size;
    for( int i = 0; i < size; i++ ) {
        GeoDataStyle style;
        style.unpack( stream );
        p()->m_styleHash.insert( style.styleId(), style );
    }
}

}
<commit_msg>do not call that - the private d pointer might already be deleted and the QMaps get cleared at exit anyway<commit_after>/*
    Copyright (C) 2007 <NAME> <<EMAIL>>
    Copyright (C) 2007 <NAME> <<EMAIL>>

    This file is part of the KDE project

    This library is free software you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    aint with this library see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "GeoDataDocument.h"

#include "GeoDataFolder.h"
#include "GeoDataPlacemark.h"
#include "GeoDataStyle.h"
#include "GeoDataStyleMap.h"

#include <QtCore/QDebug>

#include "GeoDataDocument_p.h"

namespace Marble
{

GeoDataDocument::GeoDataDocument()
    : GeoDataContainer( new GeoDataDocumentPrivate )
{
}

GeoDataDocument::GeoDataDocument( GeoDataFeature& other )
    : GeoDataContainer( other )
{
}

GeoDataDocument::GeoDataDocument( const GeoDataDocument& other )
: GeoDataContainer( other )
{
}

GeoDataDocument::~GeoDataDocument()
{
}

GeoDataDocumentPrivate* GeoDataDocument::p() const
{
    return static_cast<GeoDataDocumentPrivate*>(d);
}

QString GeoDataDocument::fileName() const
{
    return p()->m_filename;
}

void GeoDataDocument::setFileName( const QString &value )
{
    detach();
    p()->m_filename = value;
}

void GeoDataDocument::addStyle( const GeoDataStyle& style )
{
    detach();
    p()->m_styleHash.insert( style.styleId(), style );
}

void GeoDataDocument::removeStyle( const QString& styleId )
{
    detach();
    p()->m_styleHash.remove( styleId );
}

GeoDataStyle& GeoDataDocument::style( const QString& styleId ) const
{
    /*
     * FIXME: m_styleHash always should contain at least default
     *        GeoDataStyle element
     */
    return p()->m_styleHash[ styleId ];
}

QList<GeoDataStyle> GeoDataDocument::styles() const
{
    return p()->m_styleHash.values();
}

void GeoDataDocument::addStyleMap( const GeoDataStyleMap& map )
{
    detach();
    qDebug( "GeoDataDocument: Add new styleMap" );
    p()->m_styleMapHash.insert( map.styleId(), map );
}

void GeoDataDocument::removeStyleMap( const QString& mapId )
{
    detach();
    p()->m_styleMapHash.remove( mapId );
}

GeoDataStyleMap& GeoDataDocument::styleMap( const QString& styleId ) const
{
    return p()->m_styleMapHash[ styleId ];
}

QList<GeoDataStyleMap> GeoDataDocument::styleMaps() const
{
    return p()->m_styleMapHash.values();
}

void GeoDataDocument::pack( QDataStream& stream ) const
{
    GeoDataContainer::pack( stream );

    stream << p()->m_styleHash.size();
    
    
    for( QMap<QString, GeoDataStyle>::const_iterator iterator 
          = p()->m_styleHash.constBegin(); 
        iterator != p()->m_styleHash.constEnd(); 
        ++iterator ) {
        iterator.value().pack( stream );
    }
}


void GeoDataDocument::unpack( QDataStream& stream )
{
    detach();
    GeoDataContainer::unpack( stream );

    int size = 0;

    stream >> size;
    for( int i = 0; i < size; i++ ) {
        GeoDataStyle style;
        style.unpack( stream );
        p()->m_styleHash.insert( style.styleId(), style );
    }
}

}

{'fraction_non_alphanumeric': 0.11456337257049001, 'fraction_numerical': 0.006022447303586094, 'mean_word_length': 3.750975292587776, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4139819', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2249, 'n_words': 643}