Support NONE policy in storage
[platform/core/security/cynara.git] / src / common / types / PolicyResult.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        PolicyResult.h
18  * @author      Aleksander Zdyb <a.zdyb@partner.samsung.com>
19  * @version     1.0
20  * @brief       Definitions of PolicyResult and friends
21  */
22
23 #ifndef POLICYRESULT_H_
24 #define POLICYRESULT_H_
25
26 #include "types/PolicyType.h"
27
28 #include <tuple>
29
30 namespace Cynara {
31
32 class PolicyResult {
33 public:
34     typedef std::string PolicyMetadata;
35
36 public:
37     PolicyResult() : m_type(PredefinedPolicyType::DENY) {}
38     PolicyResult(const PolicyType &policyType) : m_type(policyType) {}
39     PolicyResult(const PolicyType &policyType, const PolicyMetadata &metadata)
40         : m_type(policyType), m_metadata(metadata) {}
41
42 private:
43     PolicyType m_type;
44     PolicyMetadata m_metadata;
45
46 public:
47     const PolicyType &policyType() const {
48         return m_type;
49     }
50
51     const PolicyMetadata& metadata() const {
52         return m_metadata;
53     }
54
55     bool operator <(const PolicyResult &other) const {
56         return this->m_type < other.m_type;
57     }
58
59     bool operator ==(const PolicyResult &other) const {
60         return std::tie(m_type, m_metadata) == std::tie(other.m_type, other.m_metadata);
61     }
62
63     bool operator !=(const PolicyResult &other) const {
64         return !(*this == other);
65     }
66
67     bool operator ==(const PolicyType &policyType) const {
68         return (m_type == policyType) && m_metadata.empty();
69     }
70
71     bool operator !=(const PolicyType &policyType) const {
72         return !(*this == policyType);
73     }
74 };
75
76 } // namespace Cynara
77
78
79 #endif /* POLICYRESULT_H_ */