[Marble-commits] KDE/kdeedu/marble/src/lib/geodata/scene
Jens-Michael Hoffmann
jensmh at gmx.de
Sat Apr 10 16:12:12 CEST 2010
SVN commit 1113332 by jmhoffmann:
GeoSceneLayer: Avoid code duplication for const/non-const method pairs.
The non-const method is now implemented by means of the const method,
for details, see "Effective C++" (third edition).
M +8 -15 GeoSceneLayer.cpp
--- trunk/KDE/kdeedu/marble/src/lib/geodata/scene/GeoSceneLayer.cpp #1113331:1113332
@@ -111,19 +111,12 @@
return dataset;
}
+// implement non-const method by means of const method,
+// for details, see "Effective C++" (third edition)
GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name )
{
- GeoSceneAbstractDataset* dataset = 0;
-
- QVector<GeoSceneAbstractDataset*>::const_iterator it = m_datasets.constBegin();
- QVector<GeoSceneAbstractDataset*>::const_iterator end = m_datasets.constEnd();
- for (; it != end; ++it) {
- if ( (*it)->name() == name ) {
- dataset = *it;
- break;
- }
- }
- return dataset;
+ return const_cast<GeoSceneAbstractDataset*>
+ ( static_cast<GeoSceneLayer const *>( this )->dataset( name ));
}
const GeoSceneAbstractDataset * GeoSceneLayer::groundDataset() const
@@ -134,12 +127,12 @@
return m_datasets.first();
}
+// implement non-const method by means of const method,
+// for details, see "Effective C++" (third edition)
GeoSceneAbstractDataset * GeoSceneLayer::groundDataset()
{
- if ( m_datasets.isEmpty() )
- return 0;
-
- return m_datasets.first();
+ return const_cast<GeoSceneAbstractDataset*>
+ ( static_cast<GeoSceneLayer const *>( this )->groundDataset() );
}
QVector<GeoSceneAbstractDataset *> GeoSceneLayer::datasets() const
More information about the Marble-commits
mailing list