ubuntu-location-service  ..
An aggregating location service providing positioning and geocoding capabilities to applications.
com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv > Class Template Reference

A helper class to handle bounded integer values, with an optional domain for tagging domain-specific types. More...

#include <bounded_integer.h>

+ Collaboration diagram for com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >:

Public Member Functions

 BoundedInteger ()
 Constructs an invalid instance. More...
 
 BoundedInteger (int value)
 Constructs an instance from a raw value. More...
 
 BoundedInteger (const BoundedInteger< Tag, min, max, inv > &rhs)
 Copy c'tor. More...
 
BoundedInteger< Tag, min, max, inv > & operator= (const BoundedInteger< Tag, min, max, inv > &rhs)
 Assignment operator. More...
 
bool operator== (const BoundedInteger< Tag, min, max, inv > &rhs) const
 Equality comparison operator. More...
 
 operator int () const
 Implicit casting operator to a raw integer value. More...
 
bool is_valid () const
 is_valid checks whether the contained value is in [min, max]. More...
 
int get () const
 Returns the raw integer value contained in this instance. More...
 
void set (int new_value)
 Assigns a new raw integer value. More...
 
void reset ()
 Resets the instance to an invalid value. More...
 

Static Public Member Functions

static int invalid ()
 Returns the invalid value for the specified range. More...
 
static int minimum ()
 Access the minimum value of the integer. More...
 
static int maximum ()
 Access the maximum value of the integer. More...
 
static int range ()
 Returns max - min. More...
 
static BoundedInteger< Tag, min, max, inv > from_percent (float percent)
 from_percent creates a new instance, mapping to the defined range of valid values. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const BoundedInteger< Tag, min, max, inv > &bi)
 operator << pretty prints an instance of BoundedInteger. More...
 

Detailed Description

template<typename Tag, int min, int max, int inv = min-1>
class com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >

A helper class to handle bounded integer values, with an optional domain for tagging domain-specific types.

Definition at line 37 of file bounded_integer.h.

Constructor & Destructor Documentation

template<typename Tag , int min, int max, int inv = min-1>
com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::BoundedInteger ( )
inline

Constructs an invalid instance.

Definition at line 91 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::BoundedInteger ( int  value)
inlineexplicit

Constructs an instance from a raw value.

Parameters
valueThe raw value.
Exceptions
std::runtime_errorif value is not in [min, max].

Definition at line 100 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::BoundedInteger ( const BoundedInteger< Tag, min, max, inv > &  rhs)
inline

Copy c'tor.

Parameters
rhsThe instance to copy from.

Definition at line 112 of file bounded_integer.h.

Member Function Documentation

template<typename Tag , int min, int max, int inv = min-1>
static BoundedInteger<Tag, min, max, inv> com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::from_percent ( float  percent)
inlinestatic

from_percent creates a new instance, mapping to the defined range of valid values.

Definition at line 77 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
int com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::get ( ) const
inline

Returns the raw integer value contained in this instance.

Exceptions
std::runtime_errorif is_valid() returns false.

Definition at line 159 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
static int com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::invalid ( )
inlinestatic

Returns the invalid value for the specified range.

Definition at line 45 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
bool com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::is_valid ( ) const
inline

is_valid checks whether the contained value is in [min, max].

Returns
true iff the contained integer value is in [min, max].

Definition at line 150 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
static int com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::maximum ( )
inlinestatic

Access the maximum value of the integer.

Definition at line 61 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
static int com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::minimum ( )
inlinestatic

Access the minimum value of the integer.

Definition at line 53 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::operator int ( ) const
inline

Implicit casting operator to a raw integer value.

Returns
The raw integer value.

Definition at line 141 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
BoundedInteger<Tag, min, max, inv>& com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::operator= ( const BoundedInteger< Tag, min, max, inv > &  rhs)
inline

Assignment operator.

Parameters
rhsThe instance to assign from.
Returns
A mutable reference to this instance.

Definition at line 121 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
bool com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::operator== ( const BoundedInteger< Tag, min, max, inv > &  rhs) const
inline

Equality comparison operator.

Parameters
rhsThe instance to compare to.
Returns
true iff both instances' value are equal.

Definition at line 132 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
static int com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::range ( )
inlinestatic

Returns max - min.

Definition at line 69 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
void com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::reset ( )
inline

Resets the instance to an invalid value.

Definition at line 180 of file bounded_integer.h.

template<typename Tag , int min, int max, int inv = min-1>
void com::ubuntu::location::connectivity::BoundedInteger< Tag, min, max, inv >::set ( int  new_value)
inline

Assigns a new raw integer value.

Parameters
new_valueThe new value.
Exceptions
std::runtime_errorif new_value is not in [min, max].

Definition at line 169 of file bounded_integer.h.

Friends And Related Function Documentation

template<typename Tag , int min, int max, int inv = min-1>
std::ostream& operator<< ( std::ostream &  out,
const BoundedInteger< Tag, min, max, inv > &  bi 
)
friend

operator << pretty prints an instance of BoundedInteger.

Parameters
outThe stream to print to.
biThe instance to print.
Returns
The stream that has been printed to.

Definition at line 191 of file bounded_integer.h.


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