Music Hub ..
A session-wide music playback service
dimensions.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#ifndef CORE_UBUNTU_MEDIA_VIDEO_DIMENSIONS_H_
19#define CORE_UBUNTU_MEDIA_VIDEO_DIMENSIONS_H_
20
21#include <cstdint>
22
23#include <tuple>
24
25namespace core
26{
27namespace ubuntu
28{
29namespace media
30{
31namespace video
32{
33namespace detail
34{
35enum class DimensionTag { width, height };
36
67template<DimensionTag Tag, typename IntegerType>
69{
70public:
71 static_assert(std::is_integral<IntegerType>::value, "IntWrapper<> only supports integral types.");
72 typedef IntegerType ValueType;
73
74 IntWrapper() : value{0} {}
75 template<typename AnyInteger>
76 explicit IntWrapper(AnyInteger value) : value{static_cast<ValueType>(value)} {}
77
78 template<typename T = IntegerType>
79 T as() const
80 {
81 static_assert(std::is_arithmetic<T>::value, "as() only supports arithmetic types.");
82 return static_cast<T>(value);
83 }
84
85private:
86 ValueType value;
87};
88
89template<DimensionTag Tag, typename IntegerType>
90std::ostream& operator<<(std::ostream& out, IntWrapper<Tag, IntegerType> const& value)
91{
92 out << value.template as<>();
93 return out;
94}
95
96template<DimensionTag Tag, typename IntegerType>
98{
99 return lhs.template as<>() == rhs.template as<>();
100}
101
102template<DimensionTag Tag, typename IntegerType>
104{
105 return lhs.template as<>() != rhs.template as<>();
106}
107
108template<DimensionTag Tag, typename IntegerType>
110{
111 return lhs.template as<>() <= rhs.template as<>();
112}
113
114template<DimensionTag Tag, typename IntegerType>
116{
117 return lhs.template as<>() >= rhs.template as<>();
118}
119
120template<DimensionTag Tag, typename IntegerType>
122{
123 return lhs.template as<>() < rhs.template as<>();
124}
125
126template<DimensionTag Tag, typename IntegerType>
128{
129 return lhs.template as<>() > rhs.template as<>();
130}
131} // namespace detail
132
137
139typedef std::tuple<Height, Width> Dimensions;
140}
141}
142}
143}
144
145#endif // CORE_UBUNTU_MEDIA_VIDEO_DIMENSIONS_H_
IntWrapper is a type-safe integer that allows for encoding/enforcing semantics by means of tags.
Definition: dimensions.h:69
bool operator>=(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:115
bool operator<=(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:109
bool operator>(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:127
bool operator!=(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:103
bool operator<(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:121
bool operator==(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:97
std::ostream & operator<<(std::ostream &out, IntWrapper< Tag, IntegerType > const &value)
Definition: dimensions.h:90
detail::IntWrapper< detail::DimensionTag::width, std::uint32_t > Width
The integer Width of a video.
Definition: dimensions.h:136
std::tuple< Height, Width > Dimensions
Height and Width of a video.
Definition: dimensions.h:139
detail::IntWrapper< detail::DimensionTag::height, std::uint32_t > Height
The integer Height of a video.
Definition: dimensions.h:134
Definition: player.h:34