ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

numbers.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
27 #ifndef _UCOMMON_NUMBERS_H_
28 #define _UCOMMON_NUMBERS_H_
29 
30 #ifndef _UCOMMON_CONFIG_H_
31 #include <ucommon/platform.h>
32 #endif
33 
34 namespace ucommon {
35 
48 {
49 protected:
50  char *buffer;
51  unsigned size;
52 
53 public:
59  Number(char *buffer, unsigned size);
60 
65  void set(long value);
66 
71  inline const char *c_str() const {
72  return buffer;
73  }
74 
79  long get() const;
80 
85  inline long operator()() const {
86  return get();
87  }
88 
93  inline operator long() const {
94  return get();
95  }
96 
101  inline operator char*() const {
102  return buffer;
103  }
104 
110  long operator=(long value);
111 
117  long operator=(const Number& number);
118 
124  long operator+=(const long value);
125 
131  long operator-=(const long value);
132 
137  long operator--();
138 
143  long operator++();
144 
145  inline bool operator==(const long value) const {
146  return get() == value;
147  }
148 
149  inline bool operator!=(const long value) const {
150  return get() != value;
151  }
152 
153  inline bool operator<(const long value) const {
154  return get() < value;
155  }
156 
157  inline bool operator>(const long value) const {
158  return get() > value;
159  }
160 
161  inline bool operator<=(const long value) const {
162  return get() <= value;
163  }
164 
165  inline bool operator>=(const long value) const {
166  return get() >= value;
167  }
168 };
169 
176 class __EXPORT ZNumber : public Number
177 {
178 public:
184  ZNumber(char *pointer, unsigned size);
185 
191  void set(long value);
192 
198  long operator=(long value);
199 };
200 
204 typedef Number number_t;
205 
210 
216 template<typename T>
217 inline const T abs(const T& value)
218 {
219  if(value < (T)0)
220  return -value;
221  return value;
222 }
223 
224 
231 template<typename T>
232 inline const T (min)(const T& v1, const T& v2)
233 {
234  return ((v1 < v2) ? v1 : v2);
235 }
236 
243 template<typename T>
244 inline const T (max)(const T& v1, const T& v2)
245 {
246  return ((v1 > v2) ? v1 : v2);
247 }
248 
249 } // namespace ucommon
250 
251 #endif
ucommon::Number::operator==
bool operator==(const long value) const
Definition: numbers.h:145
ucommon::Number::operator()
long operator()() const
Definition: numbers.h:85
ucommon
Definition: access.cpp:23
ucommon::ZNumber
zero filled number manipulation.
Definition: numbers.h:176
ucommon::Number::operator!=
bool operator!=(const long value) const
Definition: numbers.h:149
ucommon::number_t
Number number_t
Definition: numbers.h:204
ucommon::min
T &() min(T &o1, T &o2)
Definition: generics.h:456
ucommon::abs
const T abs(const T &value)
Definition: numbers.h:217
ucommon::max
T &() max(T &o1, T &o2)
Definition: generics.h:445
__EXPORT
#define __EXPORT
Definition: config.h:49
ucommon::Number::operator>=
bool operator>=(const long value) const
Definition: numbers.h:165
ucommon::znumber_t
ZNumber znumber_t
Definition: numbers.h:209
ucommon::Number::buffer
char * buffer
Definition: numbers.h:50
ucommon::pointer
Definition: generics.h:54
ucommon::Number
number manipulation.
Definition: numbers.h:47
ucommon::Number::operator<=
bool operator<=(const long value) const
Definition: numbers.h:161
platform.h
ucommon::Number::size
unsigned size
Definition: numbers.h:51
buffer
static uint8_t buffer[65536]
Definition: zerofill.cpp:27
ucommon::Number::c_str
const char * c_str() const
Definition: numbers.h:71
ucommon::operator+=
std::string & operator+=(std::string &target, String &source)
Definition: stream.h:581
ucommon::Number::operator>
bool operator>(const long value) const
Definition: numbers.h:157
ucommon::Number::operator<
bool operator<(const long value) const
Definition: numbers.h:153