Skip to content

Commit

Permalink
PolicyKeyFeature: avoid complex global constants
Browse files Browse the repository at this point in the history
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 [#9]
Change-Id: Ifa6dcd44ce059cf3ec8c99764bd6ea0c677cdd6d
Signed-off-by: Patrick Ohly <[email protected]>
Signed-off-by: Radoslaw Bartosiak <[email protected]>
  • Loading branch information
pohly authored and rdkb committed Jun 30, 2015
1 parent d8cb892 commit bbbadeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/common/types/PolicyKey.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,8 +29,15 @@

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();
Expand Down
12 changes: 6 additions & 6 deletions src/common/types/PolicyKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ friend class PolicyKey;
}

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)
Expand Down Expand Up @@ -86,8 +86,8 @@ friend class PolicyKey;

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();
Expand All @@ -106,8 +106,8 @@ friend class PolicyKey;
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
Expand Down

0 comments on commit bbbadeb

Please sign in to comment.