Remove PolicyBucket() constructor
[platform/core/security/cynara.git] / src / common / types / PolicyBucket.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        src/common/types/PolicyBucket.h
18  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
20  * @version     1.0
21  * @brief       This file defines PolicyBucket type - a policy aggregation
22                 entity name
23  */
24
25 #ifndef SRC_COMMON_TYPES_POLICYBUCKET_H_
26 #define SRC_COMMON_TYPES_POLICYBUCKET_H_
27
28 #include <algorithm>
29 #include <memory>
30 #include <string>
31
32 #include <exceptions/NotImplementedException.h>
33 #include <types/pointers.h>
34 #include <types/Policy.h>
35 #include <types/PolicyBucketId.h>
36 #include <types/PolicyCollection.h>
37 #include <types/PolicyKey.h>
38 #include <types/PolicyType.h>
39
40 namespace Cynara {
41
42 // TODO: Move this const somewhere else
43 const PolicyBucketId defaultPolicyBucketId("");
44
45 class PolicyBucket {
46 public:
47
48     typedef PolicyCollection::value_type value_type;
49     typedef const_policy_iterator const_iterator;
50
51     // TODO: Review usefulness of ctors
52     //delete default constructor in order to prevent creation of buckets with no id
53     PolicyBucket() = delete;
54     PolicyBucket(const PolicyBucketId &id,
55                  const PolicyResult &defaultPolicy = PredefinedPolicyType::DENY)
56         : m_defaultPolicy(defaultPolicy),
57           m_id(id) {}
58     PolicyBucket(const PolicyBucketId &id,
59                  const PolicyCollection &policies)
60         : m_policyCollection(makePolicyMap(policies)),
61           m_defaultPolicy(PredefinedPolicyType::DENY),
62           m_id(id) {}
63     PolicyBucket(const PolicyBucketId &id,
64                  const PolicyResult &defaultPolicy,
65                  const PolicyCollection &policies)
66         : m_policyCollection(makePolicyMap(policies)),
67           m_defaultPolicy(defaultPolicy),
68           m_id(id) {}
69
70     PolicyBucket filtered(const PolicyKey &key) const;
71     void insertPolicy(PolicyPtr policy);
72     void deletePolicy(const PolicyKey &key);
73
74     // TODO: Try to change interface, so this method is not needed
75     void deletePolicy(std::function<bool(PolicyPtr)> predicate);
76
77     static PolicyMap makePolicyMap(const PolicyCollection &policies);
78
79 private:
80     PolicyMap m_policyCollection;
81     PolicyResult m_defaultPolicy;
82     PolicyBucketId m_id;
83
84 public:
85
86     const_policy_iterator begin(void) const {
87         return const_policy_iterator(m_policyCollection.begin());
88     }
89
90     const_policy_iterator end(void) const {
91         return const_policy_iterator(m_policyCollection.end());
92     }
93
94     PolicyMap::size_type size(void) const {
95         return m_policyCollection.size();
96     }
97
98     bool empty(void) const {
99         return m_policyCollection.empty();
100     }
101
102     const PolicyResult &defaultPolicy(void) const {
103         return m_defaultPolicy;
104     }
105
106     const PolicyBucketId &id(void) const {
107         return m_id;
108     }
109
110     // TODO: Consider StorageBackend to be only one to alter this property
111     void setDefaultPolicy(const PolicyResult &defaultPolicy) {
112         m_defaultPolicy = defaultPolicy;
113     }
114 };
115
116 } /* namespace Cynara */
117 #endif /* SRC_COMMON_TYPES_POLICYBUCKET_H_ */