1 #ifndef FUNCTIONS_GROUP
2 #define FUNCTIONS_GROUP
26 template <
class type> type
maximum(type a, type b)
27 {
return (a > b)? a : b; }
29 template <
class type> type
minimum(type a, type b)
30 {
return (a < b)? a : b; }
34 {
return (a >= 0)? a : -a; }
39 template <
class type>
bool positive(
const type &a) {
return a > 0; }
41 template <
class type>
bool non_positive(
const type a) {
return a <= 0; }
43 template <
class type>
bool negative(
const type &a) {
return a < 0; }
45 template <
class type>
bool non_negative(
const type &a) {
return a >= 0; }
52 template <
class T1,
class T2>
53 bool operator != (
const T1 &x,
const T2 &y) {
return !(x == y); }
55 template <
class T1,
class T2>
56 bool operator > (
const T1 &x,
const T2 &y) {
return y < x; }
58 template <
class T1,
class T2>
59 bool operator <= (
const T1 &x,
const T2 &y) {
return !(y < x); }
61 template <
class T1,
class T2>
62 bool operator >= (
const T1 &x,
const T2 &y) {
return !(x < y); }
67 template <
class target_type,
class source_type>
68 target_type *
cast_or_throw(source_type &to_cast,
const target_type &ignored)
71 target_type *cast =
dynamic_cast<target_type *
>(&to_cast);
72 if (!cast)
throw "error: casting problem, unknown RTTI cast.";
77 template <
class target_type,
class source_type>
78 const target_type *
cast_or_throw(
const source_type &to_cast,
const target_type &ignored)
81 const target_type *cast =
dynamic_cast<const target_type *
>(&to_cast);
82 if (!cast)
throw "error: casting problem, unknown RTTI cast.";
88 template <
class type>
bool range_check(
const type &c,
const type &low,
89 const type &high) {
return (c >= low) && (c <= high); }
92 template <
class type> type
square(
const type &a) {
return a * a; }
96 {
if (b < a) { type tmp = a; a = b; b = tmp; } }
100 {
if (b > a) { type tmp = a; a = b; b = tmp; } }
104 { type tmp = a; a = b; b = tmp; }
107 template <
class type> type
sign(type a)
108 {
if (a < 0)
return -1;
else if (a > 0)
return 1;
else return 0; }
120 template<
class contents>
130 static type local_bogon;
136 template <
class type>
138 {
return message_size / packet_size + ((message_size % packet_size) != 0); }
144 template <
class type>
146 {
return message_size % packet_size? message_size % packet_size : packet_size; }
Constants and objects used throughout HOOPLE.
#define NULL_POINTER
The value representing a pointer to nothing.
The guards collection helps in testing preconditions and reporting errors.
bool operator!=(const T1 &x, const T2 &y)
bool operator>=(const T1 &x, const T2 &y)
bool range_check(const type &c, const type &low, const type &high)
Returns true if "c" is between "low" and "high" inclusive.
type number_of_packets(type message_size, type packet_size)
Reports number of packets needed given a total size and the packet size.
bool positive(const type &a)
positive returns true if "a" is greater than zero, or false otherwise.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool operator<=(const T1 &x, const T2 &y)
void swap_values(type &a, type &b)
Exchanges the values held by "a" & "b".
type maximum(type a, type b)
minimum returns the lesser of two values.
bool non_positive(const type a)
non_positive returns true if "a" is less than or equal to zero.
type square(const type &a)
Returns the square of the object (which is a * a).
bool non_negative(const type &a)
non_negative returns true if "a" is greater than or equal to zero.
bool operator>(const T1 &x, const T2 &y)
void flip_decreasing(type &a, type &b)
Makes sure that two values are in decreasing order (a > b).
target_type * cast_or_throw(source_type &to_cast, const target_type &ignored)
dynamically converts a type to a target type, or throws an exception if it cannot.
type last_packet_size(type message_size, type packet_size)
Tells how many bytes are used within last packet.
type sign(type a)
Returns the numerical sign of a number "a".
void flip_increasing(type &a, type &b)
Makes sure that two values are in increasing order (a < b).
type minimum(type a, type b)
maximum returns the greater of two values.
bool negative(const type &a)
negative returns true if "a" is less than zero.
type absolute_value(type a)
Returns a if a is non-negative, and returns -a otherwise.
type & bogonic()
Returns an object that is defined statically.