Use util namespace for range test

This commit is contained in:
Danny Robson 2011-08-29 14:40:05 +10:00
parent 3839ccad03
commit e816983869
3 changed files with 27 additions and 18 deletions

View File

@ -77,5 +77,5 @@ SUFFIXES = .cpp .cpp.rl
lib_LTLIBRARIES = libutil.la lib_LTLIBRARIES = libutil.la
libutil_la_SOURCES = $(UTIL_INCLUDE) $(UTIL_FILES) libutil_la_SOURCES = $(UTIL_INCLUDE) $(UTIL_FILES)
libutil_la_CXXFLAGS = -fPIC $(AM_CXXFLAGS) libutil_la_CXXFLAGS = -fPIC $(AM_CXXFLAGS) -lrt
libutil_la_LIBADD = $(BOOST_SYSTEM_LIB) libutil_la_LIBADD = $(BOOST_SYSTEM_LIB)

View File

@ -70,7 +70,6 @@ namespace util {
{ return; } { return; }
} }
template struct extent<unsigned int>; template struct extent<unsigned int>;
template struct extent<double>; template struct extent<double>;
@ -79,7 +78,7 @@ template struct extent<double>;
*/ */
template <typename T> template <typename T>
_region<T>::_region (T _x, T _y, T _width, T _height): region<T>::region (T _x, T _y, T _width, T _height):
x (_x), x (_x),
y (_y), y (_y),
width (_width), width (_width),
@ -89,25 +88,37 @@ _region<T>::_region (T _x, T _y, T _width, T _height):
template <typename T> template <typename T>
T T
_region<T>::area (void) const region<T>::area (void) const
{ return width * height; } { return width * height; }
template <typename T> template <typename T>
bool bool
_region<T>::empty (void) const region<T>::empty (void) const
{ return area () == 0; } { return almost_equal (area (), 0); }
template <typename T> template <typename T>
bool bool
_region<T>::operator ==(const _region& rhs) const region<T>::operator ==(const region& rhs) const
{ return x == rhs.x && { return almost_equal (x, rhs.x) &&
y == rhs.y && almost_equal (y, rhs.y) &&
width == rhs.width && almost_equal (width, rhs.width) &&
height == rhs.height; } almost_equal (height, rhs.height); }
template <typename T> template <typename T>
void _region<T>::sanity (void) const void region<T>::sanity (void) const
{ check (width >= 0 && height >= 0); } { check (width >= 0 && height >= 0); }
namespace util {
template <>
void region<unsigned int>::sanity (void) const
{ return; }
}
template struct region<unsigned int>;
template struct region<double>;

View File

@ -46,23 +46,21 @@ namespace util {
* A two-dimensional rectangle, with size and position. * A two-dimensional rectangle, with size and position.
*/ */
template <typename T> template <typename T>
struct _region { struct region {
T x, y; T x, y;
T width, height; T width, height;
_region (T _x, T _y, T _width, T _height); region (T _x, T _y, T _width, T _height);
T area (void) const; T area (void) const;
bool empty (void) const; bool empty (void) const;
bool operator ==(const _region<T>& rhs) const; bool operator ==(const region<T>& rhs) const;
bool operator !=(const _region<T>& rhs) const bool operator !=(const region<T>& rhs) const
{ return !(*this == rhs); } { return !(*this == rhs); }
void sanity (void) const; void sanity (void) const;
}; };
typedef _region<unsigned int> region;
} }
#endif #endif