aboutsummaryrefslogtreecommitdiff
path: root/src/kconfig_compiler/kconfig_compiler.cpp
diff options
context:
space:
mode:
authorMartin Gräßlin <mgraesslin@kde.org>2016-11-16 14:59:28 +0100
committerMartin Gräßlin <mgraesslin@kde.org>2017-01-06 09:52:45 +0100
commite0db2422362260a2fea3a8e1de4c64011d2f183d (patch)
tree59b5ba0e74c5d24d27156e51e54eb1fc0eb02623 /src/kconfig_compiler/kconfig_compiler.cpp
parent7d53de59b6e65b0cbdf6eaad4f5dbcd341307003 (diff)
downloadkconfig-e0db2422362260a2fea3a8e1de4c64011d2f183d.tar.gz
kconfig-e0db2422362260a2fea3a8e1de4c64011d2f183d.tar.bz2
Generate an instance with KSharedConfig::Ptr for singleton and arg
Summary: In case a kcfg with arg="true" was used and singleton the static instance method only accepted a QString config name. This made it impossible to combine a singleton config with an already existing and open KSharedConfig::Ptr. With this change an overloaded instance method is added which takes a KSharedConfig::Ptr as argument. The private ctor, though, only takes a KSharedConfig::Ptr and the instance method taking a QString argument uses KSharedConfig::openConfig on the config file name. The change is source-incompatible in the following situation: * kcfgfile arg="true" * Singleton = true * Inherits is specified In this situation the previous revision created an instance method with a QString argument and passed that to the parent constructor. This is not in accordance with the documentation. Any user of this behavior was relying on a bug. With this change now the call to the parent constructor carries a KSharedConfigPtr. Test Plan: kconfigcompiler tests still pass and a config with singleton and arg="true" generates the code as I need it Reviewers: #frameworks, dfaure, mdawson Differential Revision: https://phabricator.kde.org/D3690
Diffstat (limited to 'src/kconfig_compiler/kconfig_compiler.cpp')
-rw-r--r--src/kconfig_compiler/kconfig_compiler.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp
index 5c3f478f..c836252f 100644
--- a/src/kconfig_compiler/kconfig_compiler.cpp
+++ b/src/kconfig_compiler/kconfig_compiler.cpp
@@ -1893,6 +1893,7 @@ int main(int argc, char **argv)
h << " static " << cfg.className << " *self();" << endl;
if (cfgFileNameArg) {
h << " static void instance(const QString& cfgfilename);" << endl;
+ h << " static void instance(KSharedConfig::Ptr config);" << endl;
}
}
@@ -2115,7 +2116,7 @@ int main(int argc, char **argv)
if (cfg.singleton) {
h << " " << cfg.className << "(";
if (cfgFileNameArg) {
- h << "const QString& arg";
+ h << "KSharedConfig::Ptr config";
}
h << ");" << endl;
h << " friend class " << cfg.className << "Helper;" << endl << endl;
@@ -2320,15 +2321,25 @@ int main(int argc, char **argv)
cpp << "}" << endl << endl;
if (cfgFileNameArg) {
- cpp << "void " << cfg.className << "::instance(const QString& cfgfilename)" << endl;
- cpp << "{" << endl;
- cpp << " if (s_global" << cfg.className << "()->q) {" << endl;
- cpp << " qDebug() << \"" << cfg.className << "::instance called after the first use - ignoring\";" << endl;
- cpp << " return;" << endl;
- cpp << " }" << endl;
- cpp << " new " << cfg.className << "(cfgfilename);" << endl;
- cpp << " s_global" << cfg.className << "()->q->read();" << endl;
- cpp << "}" << endl << endl;
+ auto instance = [&cfg, &cpp] (const QString &type, const QString arg, bool wrap) {
+ cpp << "void " << cfg.className << "::instance(" << type << " " << arg << ")" << endl;
+ cpp << "{" << endl;
+ cpp << " if (s_global" << cfg.className << "()->q) {" << endl;
+ cpp << " qDebug() << \"" << cfg.className << "::instance called after the first use - ignoring\";" << endl;
+ cpp << " return;" << endl;
+ cpp << " }" << endl;
+ cpp << " new " << cfg.className << "(";
+ if (wrap) {
+ cpp << "KSharedConfig::openConfig(" << arg << ")";
+ } else {
+ cpp << arg;
+ }
+ cpp << ");" << endl;
+ cpp << " s_global" << cfg.className << "()->q->read();" << endl;
+ cpp << "}" << endl << endl;
+ };
+ instance(QStringLiteral("const QString&"), QStringLiteral("cfgfilename"), true);
+ instance(QStringLiteral("KSharedConfig::Ptr"), QStringLiteral("config"), false);
}
}
@@ -2339,7 +2350,7 @@ int main(int argc, char **argv)
// Constructor
cpp << cfg.className << "::" << cfg.className << "( ";
if (cfgFileNameArg) {
- if (!cfg.singleton && ! cfg.forceStringFilename) {
+ if (! cfg.forceStringFilename) {
cpp << " KSharedConfig::Ptr config";
} else {
cpp << " const QString& config";