Music Hub  ..
A session-wide music playback service
core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType > Class Template Reference

IntWrapper is a type-safe integer that allows for encoding/enforcing semantics by means of tags. More...

#include <dimensions.h>

+ Collaboration diagram for core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >:

Public Types

typedef IntegerType ValueType
 

Public Member Functions

 IntWrapper ()
 
template<typename AnyInteger >
 IntWrapper (AnyInteger value)
 
template<typename T = IntegerType>
as () const
 

Detailed Description

template<DimensionTag Tag, typename IntegerType>
class core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >

IntWrapper is a type-safe integer that allows for encoding/enforcing semantics by means of tags.

Template Parameters
TagHint for the compiler on the semantics of the underlying integer.
IntegerTypeThe underlying integer type.

Handling dimensions like width and height with raw integer values is tedious and error prone as the compiler has no way of distinguishing a width from a height, or an x coordinate from a y coordinate. The problem is solvable with the tagged integer type presented here. Consider the following example:

typedef IntWrapper<DimensionTag::width, std::uint32_t> Width;
typedef IntWrapper<DimensionTag::height, std::uint32_t> Height;
void an_unsafe_function_expecting_width_and_height(std::uint32_t width, std::uint32_t height);
void a_safe_function_expecting_width_and_height(Width width, Height height);
int main()
{
std::uint unsafe_width{640}, unsafe_height{480};
Width width{640}; Height height{480};
// This will compile but is still wrong
an_unsafe_function_expecting_width_and_height(unsafe_height, unsafe_width);
// This will not compile
a_safe_function_expecting_width_and_height(height, width);
}

Definition at line 68 of file dimensions.h.

Member Typedef Documentation

◆ ValueType

template<DimensionTag Tag, typename IntegerType>
typedef IntegerType core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >::ValueType

Definition at line 71 of file dimensions.h.

Constructor & Destructor Documentation

◆ IntWrapper() [1/2]

template<DimensionTag Tag, typename IntegerType>
core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >::IntWrapper ( )
inline

Definition at line 74 of file dimensions.h.

◆ IntWrapper() [2/2]

template<DimensionTag Tag, typename IntegerType>
template<typename AnyInteger >
core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >::IntWrapper ( AnyInteger  value)
inlineexplicit

Definition at line 76 of file dimensions.h.

Member Function Documentation

◆ as()

template<DimensionTag Tag, typename IntegerType>
template<typename T = IntegerType>
T core::ubuntu::media::video::detail::IntWrapper< Tag, IntegerType >::as ( ) const
inline

Definition at line 79 of file dimensions.h.


The documentation for this class was generated from the following file: