PolicyKeyFeature: avoid complex global constants 53/41353/4
authorPatrick Ohly <patrick.ohly@intel.com>
Fri, 29 May 2015 10:41:34 +0000 (12:41 +0200)
committerRadoslaw Bartosiak <r.bartosiak@samsung.com>
Tue, 30 Jun 2015 09:22:39 +0000 (11:22 +0200)
PolicyKeyFeature is used by other global instances in cynara-test
and cannot assume that the initialization of its own static constants
happens first, unless it enforces initialization by embedding
these constants in method calls.

Upstream-status: Submitted [https://github.com/Samsung/cynara/issues/9]
Change-Id: Ifa6dcd44ce059cf3ec8c99764bd6ea0c677cdd6d
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Signed-off-by: Radoslaw Bartosiak <r.bartosiak@samsung.com>
src/common/types/PolicyKey.cpp
src/common/types/PolicyKey.h

index ffb1400..d792d45 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
 
 namespace Cynara {
 
-const std::string PolicyKeyFeature::m_wildcardValue = CYNARA_ADMIN_WILDCARD;
-const std::string PolicyKeyFeature::m_anyValue = CYNARA_ADMIN_ANY;
+const std::string &PolicyKeyFeature::wildcardValue(void) {
+    static const std::string value(CYNARA_ADMIN_WILDCARD);
+    return value;
+}
+
+const std::string &PolicyKeyFeature::anyValue(void) {
+    static const std::string value(CYNARA_ADMIN_ANY);
+    return value;
+}
 
 const std::string &PolicyKeyFeature::toString(void) const {
     return value();
index 4fed189..d495849 100644 (file)
@@ -49,11 +49,11 @@ public:
     }
 
     static PolicyKeyFeature createWildcard(void) {
-        return PolicyKeyFeature(m_wildcardValue);
+        return PolicyKeyFeature(wildcardValue());
     }
 
     static PolicyKeyFeature createAny(void) {
-        return PolicyKeyFeature(m_anyValue);
+        return PolicyKeyFeature(anyValue());
     }
 
     // TODO: Different features (client, user, privilege)
@@ -86,8 +86,8 @@ public:
 
 protected:
     explicit PolicyKeyFeature(const ValueType &value) : m_value(value),
-        m_isWildcard(value == PolicyKeyFeature::m_wildcardValue),
-        m_isAny(value == PolicyKeyFeature::m_anyValue) {}
+        m_isWildcard(value == wildcardValue()),
+        m_isAny(value == anyValue()) {}
 
     static bool anyAny(const PolicyKeyFeature &pkf1, const PolicyKeyFeature &pkf2) {
         return pkf1.isAny() || pkf2.isAny();
@@ -106,8 +106,8 @@ private:
     bool m_isWildcard;
     bool m_isAny;
 
-    const static std::string m_wildcardValue;
-    const static std::string m_anyValue;
+    const static std::string &wildcardValue(void);
+    const static std::string &anyValue(void);
 };
 
 class PolicyKey