trust-store  1.1.0
Provides a common implementation of a trust store to be used by trusted helpers.
tagged_integer.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_TRUST_TAGGED_INTEGER_H_
20 #define CORE_TRUST_TAGGED_INTEGER_H_
21 
22 #include <cstdint>
23 
24 #include <ostream>
25 #include <type_traits>
26 
27 #include <sys/types.h>
28 
29 namespace core
30 {
31 namespace trust
32 {
34 template<typename Tag, typename Integer>
36 {
38  static_assert(std::is_integral<Integer>::value, "Integer has to be an integral type");
39 
41  typedef Tag TagType;
43  typedef Integer IntegerType;
44 
47  {
48  }
49 
51  explicit TaggedInteger(Integer value) : value{value}
52  {
53  }
54 
56  Integer value;
57 };
58 
60 template<typename Tag, typename Integer>
62 {
63  return lhs.value == rhs.value;
64 }
65 
67 template<typename Tag, typename Integer>
69 {
70  return lhs.value != rhs.value;
71 }
72 
74 template<typename Tag, typename Integer>
75 inline bool operator<(const TaggedInteger<Tag, Integer>& lhs, const TaggedInteger<Tag, Integer>& rhs)
76 {
77  return lhs.value < rhs.value;
78 }
79 
81 template<typename Tag, typename Integer>
82 inline std::ostream& operator<<(std::ostream& out, const TaggedInteger<Tag, Integer>& ti)
83 {
84  return out << ti.value;
85 }
86 
87 namespace tag
88 {
89 // Tags a group id
90 struct Gid {};
91 // Tags a process id
92 struct Pid {};
93 // Tags a user id
94 struct Uid {};
95 // Tags a service-specific feature
96 struct Feature {};
97 }
98 
107 }
108 }
109 
110 #endif // CORE_TRUST_TAGGED_INTEGER_H_
Tag TagType
We bail out if the Integral type is not an integral one.
TaggedInteger()
Construct an instance with a default value.
TaggedInteger< tag::Uid, uid_t > Uid
Our internal user id type.
Integer value
The contained integer value.
Definition: agent.h:28
Helper structure for tagging integer types with certain semantics.
TaggedInteger(Integer value)
Construct an instance from an existing integer type.
bool operator!=(const TaggedInteger< Tag, Integer > &lhs, const TaggedInteger< Tag, Integer > &rhs)
Returns true iff both tagged integer instances are not equal.
CORE_TRUST_DLL_PUBLIC bool operator==(const Agent::RequestParameters &lhs, const Agent::RequestParameters &rhs)
Returns true iff lhs and rhs are equal.
Integer IntegerType
Stores the Integer type.
TaggedInteger< tag::Gid, gid_t > Gid
Our internal group id type.
TaggedInteger< tag::Pid, pid_t > Pid
Our internal process id type.
TaggedInteger< tag::Feature, std::uint64_t > Feature
Our internal service-feature type.