|
From: <sv...@va...> - 2011-06-28 11:24:10
|
Author: cerion
Date: 2011-06-28 12:19:19 +0100 (Tue, 28 Jun 2011)
New Revision: 534
Log:
implemented a stack-based singleton for read-only suppression config
Modified:
trunk/src/options/suppressions.cpp
trunk/src/options/suppressions.h
trunk/src/options/vk_suppressions_dialog.cpp
Modified: trunk/src/options/suppressions.cpp
===================================================================
--- trunk/src/options/suppressions.cpp 2011-06-27 15:01:58 UTC (rev 533)
+++ trunk/src/options/suppressions.cpp 2011-06-28 11:19:19 UTC (rev 534)
@@ -27,7 +27,6 @@
#include <QFile>
-SuppRanges *SuppRanges::s_instance = 0;
/*!
class SuppRanges
@@ -88,6 +87,9 @@
+
+
+
/*!
class Suppression
*/
@@ -123,14 +125,14 @@
}
QRegExp re( list[0], Qt::CaseInsensitive );
- int idx = SuppRanges::instance()->kindTools.indexOf( re );
+ int idx = SuppRanges::instance().getKindTools().indexOf( re );
if ( idx == -1 ) {
vkPrintErr("Bad Tool (%s) for this suppression (%s).",
qPrintable(list[0]), qPrintable(m_name));
return false;
}
else {
- QStringList kindTypes = SuppRanges::instance()->kindTypes[idx];
+ const QStringList kindTypes = SuppRanges::instance().getKindTypes()[idx];
if ( !kindTypes.contains( list[1], Qt::CaseInsensitive ) ) {
vkPrintErr("Bad SupprType (%s) for Tool (%s) for this suppression (%s).",
qPrintable(list[1]), qPrintable(list[0]), qPrintable(m_name));
@@ -163,7 +165,7 @@
return false;
}
- if ( !SuppRanges::instance()->frameTypes.contains( list[0], Qt::CaseInsensitive ) ) {
+ if ( !SuppRanges::instance().getFrameTypes().contains( list[0], Qt::CaseInsensitive ) ) {
vkPrintErr( "Unsupported frame type (%s) for suppression '%s'.",
qPrintable(list[0]), qPrintable(m_name) );
return false;
Modified: trunk/src/options/suppressions.h
===================================================================
--- trunk/src/options/suppressions.h 2011-06-27 15:01:58 UTC (rev 533)
+++ trunk/src/options/suppressions.h 2011-06-28 11:19:19 UTC (rev 534)
@@ -29,31 +29,35 @@
#define MAX_SUPP_FRAMES 20
-
// ============================================================
-// Singleton class holding some handy reference data
+// SuppRanges: read-only configuration data for Suppressions
+// - implemented as a stack-based singleton
class SuppRanges
{
+private:
+ SuppRanges();
+ SuppRanges(SuppRanges const&); // Not implemented
+ SuppRanges& operator=(SuppRanges const&); // Not implemented
+
public:
- static SuppRanges *instance()
- {
- if (!s_instance)
- s_instance = new SuppRanges;
- return s_instance;
+ static SuppRanges& instance() {
+ static SuppRanges theInstance;
+ return theInstance;
}
+ ~SuppRanges() {};
+ // limit access to read-only, so issues with global access
+ const QStringList& getKindTools() { return kindTools; }
+ const QList<QStringList>& getKindTypes() { return kindTypes; }
+ const QStringList& getFrameTypes() { return frameTypes; }
+
+private:
QStringList kindTools; // Memcheck|...
QList<QStringList> kindTypes; // list for every tool
QStringList frameTypes; // obj|fun
-
-private:
- SuppRanges();
- static SuppRanges *s_instance;
};
-
-
// ============================================================
class Suppression
{
Modified: trunk/src/options/vk_suppressions_dialog.cpp
===================================================================
--- trunk/src/options/vk_suppressions_dialog.cpp 2011-06-27 15:01:58 UTC (rev 533)
+++ trunk/src/options/vk_suppressions_dialog.cpp 2011-06-28 11:19:19 UTC (rev 534)
@@ -51,7 +51,7 @@
frame_cmb = new QComboBox();
frame_cmb->setMinimumWidth( width_col1 );
- frame_cmb->addItems( SuppRanges::instance()->frameTypes );
+ frame_cmb->addItems( SuppRanges::instance().getFrameTypes() );
frame_le = new QLineEdit();
@@ -125,7 +125,7 @@
// Kind-Tool
QLabel* tool_lbl = new QLabel("Kind-Tool:");
tool_cmb = new QComboBox();
- tool_cmb->addItems( SuppRanges::instance()->kindTools );
+ tool_cmb->addItems( SuppRanges::instance().getKindTools() );
connect( tool_cmb, SIGNAL(currentIndexChanged(int)), this, SLOT(ToolChanged(int)) );
// Kind-Type
@@ -249,7 +249,7 @@
void VkSuppressionsDialog::ToolChanged( int idx )
{
type_cmb->clear();
- type_cmb->addItems( SuppRanges::instance()->kindTypes[idx] );
+ type_cmb->addItems( SuppRanges::instance().getKindTypes()[idx] );
}
void VkSuppressionsDialog::TypeChanged( int )
|