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 
25 namespace core
26 {
27 namespace ubuntu
28 {
29 namespace media
30 {
31 namespace video
32 {
33 namespace detail
34 {
35 enum class DimensionTag { width, height };
36 
67 template<DimensionTag Tag, typename IntegerType>
69 {
70 public:
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 
85 private:
86  ValueType value;
87 };
88 
89 template<DimensionTag Tag, typename IntegerType>
90 std::ostream& operator<<(std::ostream& out, IntWrapper<Tag, IntegerType> const& value)
91 {
92  out << value.template as<>();
93  return out;
94 }
95 
96 template<DimensionTag Tag, typename IntegerType>
98 {
99  return lhs.template as<>() == rhs.template as<>();
100 }
101 
102 template<DimensionTag Tag, typename IntegerType>
104 {
105  return lhs.template as<>() != rhs.template as<>();
106 }
107 
108 template<DimensionTag Tag, typename IntegerType>
109 inline bool operator <= (IntWrapper<Tag, IntegerType> const& lhs, IntWrapper<Tag, IntegerType> const& rhs)
110 {
111  return lhs.template as<>() <= rhs.template as<>();
112 }
113 
114 template<DimensionTag Tag, typename IntegerType>
116 {
117  return lhs.template as<>() >= rhs.template as<>();
118 }
119 
120 template<DimensionTag Tag, typename IntegerType>
121 inline bool operator < (IntWrapper<Tag, IntegerType> const& lhs, IntWrapper<Tag, IntegerType> const& rhs)
122 {
123  return lhs.template as<>() < rhs.template as<>();
124 }
125 
126 template<DimensionTag Tag, typename IntegerType>
128 {
129  return lhs.template as<>() > rhs.template as<>();
130 }
131 } // namespace detail
132 
137 
139 typedef std::tuple<Height, Width> Dimensions;
140 }
141 }
142 }
143 }
144 
145 #endif // CORE_UBUNTU_MEDIA_VIDEO_DIMENSIONS_H_
std::tuple< Height, Width > Dimensions
Height and Width of a video.
Definition: dimensions.h:139
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:97
Definition: player.h:32
detail::IntWrapper< detail::DimensionTag::height, std::uint32_t > Height
The integer Height of a video.
Definition: dimensions.h:134
detail::IntWrapper< detail::DimensionTag::width, std::uint32_t > Width
The integer Width of a video.
Definition: dimensions.h:136
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:115
IntWrapper is a type-safe integer that allows for encoding/enforcing semantics by means of tags...
Definition: dimensions.h:68