diff --git a/Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp b/Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp index 2a42d8e6b9..232078775e 100644 --- a/Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp +++ b/Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp @@ -27,10 +27,16 @@ namespace { -static QString PREFIX_EXECUTABLE = "executable:"; -static QString PREFIX_PARAMETER_GROUP = "paramGroup:"; -static QString PREFIX_PARAMETER_CONTAINER = "paramContainer:"; -static QString PREFIX_PARAMETER = "parameter:"; +template +constexpr QLatin1String make_constexpr_QLatin1String_(const char (&str)[N]) +{ + return QLatin1String{str, static_cast(N - 1)}; +} + +constexpr QLatin1String PREFIX_EXECUTABLE = make_constexpr_QLatin1String_("executable:"); +constexpr QLatin1String PREFIX_PARAMETER_GROUP = make_constexpr_QLatin1String_("paramGroup:"); +constexpr QLatin1String PREFIX_PARAMETER_CONTAINER= make_constexpr_QLatin1String_("paramContainer:"); +constexpr QLatin1String PREFIX_PARAMETER = make_constexpr_QLatin1String_("parameter:"); } diff --git a/Libs/PluginFramework/ctkBasicLocation.cpp b/Libs/PluginFramework/ctkBasicLocation.cpp index db969193b7..72821bee9b 100644 --- a/Libs/PluginFramework/ctkBasicLocation.cpp +++ b/Libs/PluginFramework/ctkBasicLocation.cpp @@ -37,8 +37,15 @@ #include #include -static const QString PROP_OSGI_LOCKING = "blueberry.locking"; -static const QString DEFAULT_LOCK_FILENAME = ".metadata/.lock"; +namespace { +template +constexpr QLatin1String make_constexpr_QLatin1String_(const char (&str)[N]) +{ + return QLatin1String{str, static_cast(N - 1)}; +} +constexpr QLatin1String PROP_OSGI_LOCKING = make_constexpr_QLatin1String_("blueberry.locking"); +constexpr QLatin1String DEFAULT_LOCK_FILENAME = make_constexpr_QLatin1String_(".metadata/.lock"); +} // namespace //---------------------------------------------------------------------------- diff --git a/Libs/PluginFramework/ctkLocationManager.cpp b/Libs/PluginFramework/ctkLocationManager.cpp index 3f57196968..0567a96bb4 100644 --- a/Libs/PluginFramework/ctkLocationManager.cpp +++ b/Libs/PluginFramework/ctkLocationManager.cpp @@ -36,23 +36,29 @@ namespace { +template +constexpr QLatin1String make_constexpr_QLatin1String_(const char (&str)[N]) +{ + return QLatin1String{str, static_cast(N - 1)}; +} + // Constants for configuration location discovery -static const QString CTK = "commontk"; -static const QString PRODUCT_SITE_MARKER = ".commontkproduct"; -static const QString PRODUCT_SITE_ID = "id"; -static const QString PRODUCT_SITE_VERSION = "version"; +constexpr QLatin1String CTK = make_constexpr_QLatin1String_("commontk"); +constexpr QLatin1String PRODUCT_SITE_MARKER = make_constexpr_QLatin1String_(".commontkproduct"); +constexpr QLatin1String PRODUCT_SITE_ID = make_constexpr_QLatin1String_("id"); +constexpr QLatin1String PRODUCT_SITE_VERSION = make_constexpr_QLatin1String_("version"); -static const QString CONFIG_DIR = "configuration"; +constexpr QLatin1String CONFIG_DIR = make_constexpr_QLatin1String_("configuration"); // Data mode constants for user, configuration and data locations. -static const QString NONE = "@none"; -static const QString NO_DEFAULT = "@noDefault"; -static const QString USER_HOME = "@user.home"; -static const QString USER_DIR = "@user.dir"; +constexpr QLatin1String NONE = make_constexpr_QLatin1String_("@none"); +constexpr QLatin1String NO_DEFAULT = make_constexpr_QLatin1String_("@noDefault"); +constexpr QLatin1String USER_HOME = make_constexpr_QLatin1String_("@user.home"); +constexpr QLatin1String USER_DIR = make_constexpr_QLatin1String_("@user.dir"); // Placeholder for hashcode of installation directory -static const QString INSTALL_HASH_PLACEHOLDER = "@install.hash"; +constexpr QLatin1String INSTALL_HASH_PLACEHOLDER = make_constexpr_QLatin1String_("@install.hash"); -static const QString INSTANCE_DATA_AREA_PREFIX = ".metadata/.plugins/"; +constexpr QLatin1String INSTANCE_DATA_AREA_PREFIX = make_constexpr_QLatin1String_(".metadata/.plugins/"); static QScopedPointer installLocation; static QScopedPointer configurationLocation; @@ -138,7 +144,7 @@ ctkBasicLocation* BuildLocation(const QString& property, const QUrl& defaultLoca int idx = location.indexOf(INSTALL_HASH_PLACEHOLDER); if (idx == 0) { - throw ctkRuntimeException("The location cannot start with '" + INSTALL_HASH_PLACEHOLDER + "': " + location); + throw ctkRuntimeException(QString("The location cannot start with '") + INSTALL_HASH_PLACEHOLDER + "': " + location); } else if (idx > 0) { @@ -280,7 +286,7 @@ static QString ComputeDefaultUserAreaLocation(const QString& pathAppendage) QFileInfo installDir(installURL.toLocalFile()); QString installDirHash = GetInstallDirHash(); - QString appName = "." + CTK; + QString appName = QString(".") + CTK; QFileInfo ctkProduct(QDir(installDir.absoluteFilePath()), PRODUCT_SITE_MARKER); if (ctkProduct.exists()) { diff --git a/Libs/PluginFramework/ctkPluginFrameworkDebug.cpp b/Libs/PluginFramework/ctkPluginFrameworkDebug.cpp index 101968372e..f3ce43c891 100644 --- a/Libs/PluginFramework/ctkPluginFrameworkDebug.cpp +++ b/Libs/PluginFramework/ctkPluginFrameworkDebug.cpp @@ -23,20 +23,6 @@ #include "ctkPluginFrameworkDebug_p.h" #include "ctkPluginFrameworkDebugOptions_p.h" -#include "ctkPluginFrameworkProperties_p.h" - -static QString CTK_OSGI = "org.commontk.pluginfw"; - -QString ctkPluginFrameworkDebug::OPTION_DEBUG_GENERAL = CTK_OSGI + "/debug"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_FRAMEWORK = CTK_OSGI + "/debug/framework"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_ERRORS = CTK_OSGI + "/debug/errors"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_HOOKS = CTK_OSGI + "/debug/hooks"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_LAZY_ACTIVATION = CTK_OSGI + "/debug/lazy_activation"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_LDAP = CTK_OSGI + "/debug/ldap"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_SERVICE_REFERENCE = CTK_OSGI + "/debug/service_reference"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_STARTLEVEL = CTK_OSGI + "/debug/startlevel"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_URL = CTK_OSGI + "/debug/url"; -QString ctkPluginFrameworkDebug::OPTION_DEBUG_RESOLVE = CTK_OSGI + "/debug/resolve"; //---------------------------------------------------------------------------- ctkPluginFrameworkDebug::ctkPluginFrameworkDebug() diff --git a/Libs/PluginFramework/ctkPluginFrameworkDebug_p.h b/Libs/PluginFramework/ctkPluginFrameworkDebug_p.h index 5a0aba97cc..1d61fb8d20 100644 --- a/Libs/PluginFramework/ctkPluginFrameworkDebug_p.h +++ b/Libs/PluginFramework/ctkPluginFrameworkDebug_p.h @@ -23,8 +23,24 @@ #ifndef CTKPLUGINFRAMEWORKDEBUG_P_H #define CTKPLUGINFRAMEWORKDEBUG_P_H +// Qt includes +#include + #include "ctkPluginFramework_global.h" +namespace { +/// Construct a QLatin1String from a string literal, deducing length at +/// compile time via the array-reference parameter. Avoids repeating +/// sizeof/static_cast at every definition site. +template +constexpr QLatin1String make_constexpr_QLatin1String_(const char (&str)[N]) +{ + return QLatin1String{str, static_cast(N - 1)}; +} +} // namespace + +#define CTK_OSGI "org.commontk.pluginfw" + /** * Variables that control debugging of the pluginfw code. */ @@ -34,37 +50,37 @@ class ctkPluginFrameworkDebug public: ctkPluginFrameworkDebug(); - static QString OPTION_DEBUG_GENERAL; + static constexpr QLatin1String OPTION_DEBUG_GENERAL = make_constexpr_QLatin1String_(CTK_OSGI "/debug"); bool enabled; /** * Report error handling events. */ - static QString OPTION_DEBUG_ERRORS; + static constexpr QLatin1String OPTION_DEBUG_ERRORS = make_constexpr_QLatin1String_(CTK_OSGI "/debug/errors"); bool errors; /** * Report pluginfw create, init, start, stop */ - static QString OPTION_DEBUG_FRAMEWORK; + static constexpr QLatin1String OPTION_DEBUG_FRAMEWORK = make_constexpr_QLatin1String_(CTK_OSGI "/debug/framework"); bool framework; /** * Report hooks handling */ - static QString OPTION_DEBUG_HOOKS; + static constexpr QLatin1String OPTION_DEBUG_HOOKS = make_constexpr_QLatin1String_(CTK_OSGI "/debug/hooks"); bool hooks; /** * Report triggering of lazy activation */ - static QString OPTION_DEBUG_LAZY_ACTIVATION; + static constexpr QLatin1String OPTION_DEBUG_LAZY_ACTIVATION = make_constexpr_QLatin1String_(CTK_OSGI "/debug/lazy_activation"); bool lazy_activation; /** * Report LDAP handling */ - static QString OPTION_DEBUG_LDAP; + static constexpr QLatin1String OPTION_DEBUG_LDAP = make_constexpr_QLatin1String_(CTK_OSGI "/debug/ldap"); bool ldap; /** @@ -72,27 +88,29 @@ class ctkPluginFrameworkDebug * and rejections due to missing permissions * for calling plug-ins. */ - static QString OPTION_DEBUG_SERVICE_REFERENCE; + static constexpr QLatin1String OPTION_DEBUG_SERVICE_REFERENCE = make_constexpr_QLatin1String_(CTK_OSGI "/debug/service_reference"); bool service_reference; /** * Report startlevel. */ - static QString OPTION_DEBUG_STARTLEVEL; + static constexpr QLatin1String OPTION_DEBUG_STARTLEVEL = make_constexpr_QLatin1String_(CTK_OSGI "/debug/startlevel"); bool startlevel; /** * Report url */ - static QString OPTION_DEBUG_URL; + static constexpr QLatin1String OPTION_DEBUG_URL = make_constexpr_QLatin1String_(CTK_OSGI "/debug/url"); bool url; /** * Report plug-in resolve progress */ - static QString OPTION_DEBUG_RESOLVE; + static constexpr QLatin1String OPTION_DEBUG_RESOLVE = make_constexpr_QLatin1String_(CTK_OSGI "/debug/resolve"); bool resolve; }; +#undef CTK_OSGI + #endif // CTKPLUGINFRAMEWORKDEBUG_P_H diff --git a/Libs/PluginFramework/ctkPluginFrameworkLauncher.cpp b/Libs/PluginFramework/ctkPluginFrameworkLauncher.cpp index a77a08ebf8..188d4a491e 100644 --- a/Libs/PluginFramework/ctkPluginFrameworkLauncher.cpp +++ b/Libs/PluginFramework/ctkPluginFrameworkLauncher.cpp @@ -82,7 +82,14 @@ const QString ctkPluginFrameworkLauncher::PROP_APPLICATION_LAUNCHDEFAULT = "ctk. const QString ctkPluginFrameworkLauncher::PROP_OSGI_RELAUNCH = "ctk.pluginfw.relaunch"; -static const QString PROP_FORCED_RESTART = "ctk.forcedRestart"; +namespace { +template +constexpr QLatin1String make_constexpr_QLatin1String_(const char (&str)[N]) +{ + return QLatin1String{str, static_cast(N - 1)}; +} +constexpr QLatin1String PROP_FORCED_RESTART = make_constexpr_QLatin1String_("ctk.forcedRestart"); +} // namespace class ctkPluginFrameworkLauncherPrivate {