trust-store  2.0.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>
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_
core::trust::operator<
bool operator<(const TaggedInteger< Tag, Integer > &lhs, const TaggedInteger< Tag, Integer > &rhs)
Returns true iff the left-hand-side integer instance is smaller than the right-hand-side.
Definition: tagged_integer.h:75
core::trust::TaggedInteger
Helper structure for tagging integer types with certain semantics.
Definition: tagged_integer.h:35
core::trust::Uid
TaggedInteger< tag::Uid, uid_t > Uid
Our internal user id type.
Definition: tagged_integer.h:104
core::trust::tag::Gid
Definition: tagged_integer.h:90
core::trust::tag::Pid
Definition: tagged_integer.h:92
core::trust::tag::Uid
Definition: tagged_integer.h:94
core::trust::TaggedInteger::TaggedInteger
TaggedInteger(Integer value)
Construct an instance from an existing integer type.
Definition: tagged_integer.h:51
core::trust::operator<<
CORE_TRUST_DLL_PUBLIC std::ostream & operator<<(std::ostream &out, const Request::Answer &a)
operator << pretty prints answers to the provided output stream.
core
Definition: agent.h:28
core::trust::TaggedInteger::TagType
Tag TagType
We bail out if the Integral type is not an integral one.
Definition: tagged_integer.h:38
core::trust::operator!=
bool operator!=(const TaggedInteger< Tag, Integer > &lhs, const TaggedInteger< Tag, Integer > &rhs)
Returns true iff both tagged integer instances are not equal.
Definition: tagged_integer.h:68
core::trust::Pid
TaggedInteger< tag::Pid, pid_t > Pid
Our internal process id type.
Definition: tagged_integer.h:102
core::trust::TaggedInteger::IntegerType
Integer IntegerType
Stores the Integer type.
Definition: tagged_integer.h:43
core::trust::TaggedInteger::value
Integer value
The contained integer value.
Definition: tagged_integer.h:56
core::trust::operator==
CORE_TRUST_DLL_PUBLIC bool operator==(const Agent::RequestParameters &lhs, const Agent::RequestParameters &rhs)
Returns true iff lhs and rhs are equal.
core::trust::TaggedInteger::TaggedInteger
TaggedInteger()
Construct an instance with a default value.
Definition: tagged_integer.h:46
core::trust::Gid
TaggedInteger< tag::Gid, gid_t > Gid
Our internal group id type.
Definition: tagged_integer.h:100
core::trust::Feature
TaggedInteger< tag::Feature, std::uint64_t > Feature
Our internal service-feature type.
Definition: tagged_integer.h:106
core::trust::tag::Feature
Definition: tagged_integer.h:96