tagged_integer.h
Go to the documentation of this file.
/*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef CORE_TRUST_TAGGED_INTEGER_H_
#define CORE_TRUST_TAGGED_INTEGER_H_
#include <cstdint>
#include <ostream>
#include <type_traits>
#include <sys/types.h>
namespace core
{
namespace trust
{
template<typename Tag, typename Integer>
struct TaggedInteger
{
static_assert(std::is_integral<Integer>::value, "Integer has to be an integral type");
typedef Tag TagType;
typedef Integer IntegerType;
TaggedInteger() : value{}
{
}
explicit TaggedInteger(Integer value) : value{value}
{
}
Integer value;
};
template<typename Tag, typename Integer>
inline bool operator==(const TaggedInteger<Tag, Integer>& lhs, const TaggedInteger<Tag, Integer>& rhs)
{
return lhs.value == rhs.value;
}
template<typename Tag, typename Integer>
inline bool operator!=(const TaggedInteger<Tag, Integer>& lhs, const TaggedInteger<Tag, Integer>& rhs)
{
return lhs.value != rhs.value;
}
template<typename Tag, typename Integer>
inline bool operator<(const TaggedInteger<Tag, Integer>& lhs, const TaggedInteger<Tag, Integer>& rhs)
{
return lhs.value < rhs.value;
}
template<typename Tag, typename Integer>
inline std::ostream& operator<<(std::ostream& out, const TaggedInteger<Tag, Integer>& ti)
{
return out << ti.value;
}
namespace tag
{
// Tags a group id
struct Gid {};
// Tags a process id
struct Pid {};
// Tags a user id
struct Uid {};
// Tags a service-specific feature
struct Feature {};
}
typedef TaggedInteger<tag::Gid, gid_t> Gid;
typedef TaggedInteger<tag::Pid, pid_t> Pid;
typedef TaggedInteger<tag::Uid, uid_t> Uid;
typedef TaggedInteger<tag::Feature, std::uint64_t> Feature;
}
}
#endif // CORE_TRUST_TAGGED_INTEGER_H_
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::TaggedInteger::TaggedInteger
TaggedInteger()
Construct an instance with a default value.
Definition: tagged_integer.h:46
core::trust::Uid
TaggedInteger< tag::Uid, uid_t > Uid
Our internal user id type.
Definition: tagged_integer.h:104
core::trust::tag::Feature
Definition: tagged_integer.h:96
core::trust::tag::Pid
Definition: tagged_integer.h:92
core::trust::tag::Uid
Definition: tagged_integer.h:94
core::trust::TaggedInteger::value
Integer value
The contained integer value.
Definition: tagged_integer.h:56
core::trust::tag::Gid
Definition: tagged_integer.h:90
core
Definition: agent.h:28
core::trust::TaggedInteger
Helper structure for tagging integer types with certain semantics.
Definition: tagged_integer.h:35
core::trust::TaggedInteger::TaggedInteger
TaggedInteger(Integer value)
Construct an instance from an existing integer type.
Definition: tagged_integer.h:51
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::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::IntegerType
Integer IntegerType
Stores the Integer type.
Definition: tagged_integer.h:43
core::trust::Gid
TaggedInteger< tag::Gid, gid_t > Gid
Our internal group id type.
Definition: tagged_integer.h:100
core::trust::Pid
TaggedInteger< tag::Pid, pid_t > Pid
Our internal process id type.
Definition: tagged_integer.h:102
core::trust::Feature
TaggedInteger< tag::Feature, std::uint64_t > Feature
Our internal service-feature type.
Definition: tagged_integer.h:106