/usr/include/ucommon/numbers.h is in libucommon-dev 3.2.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
//
// This file is part of GNU uCommon C++.
//
// GNU uCommon C++ is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU uCommon C++ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
/**
* Support classes for manipulation of numbers as strings. This is
* used for things which parse numbers out of strings, such as in the
* date and time classes. Other useful math related functions, templates,
* and macros may also be found here.
* @file ucommon/numbers.h
*/
#ifndef _UCOMMON_NUMBERS_H_
#define _UCOMMON_NUMBERS_H_
#ifndef _UCOMMON_CONFIG_H_
#include <ucommon/platform.h>
#endif
NAMESPACE_UCOMMON
/**
* A number manipulation class. This is used to extract, convert,
* and manage simple numbers that are represented in C ascii strings
* in a very quick and optimal way. This class modifies the string
* representation each time the value is changed. No math expressions
* or explicit comparison operators are supported for the Numbers class
* because these are best done by casting to long first.
*
* @author David Sugar <dyfet@ostel.com>
* @short number manipulation.
*/
class __EXPORT Number
{
protected:
char *buffer;
unsigned size;
public:
/**
* Create an instance of a number.
* @param buffer or NULL if created internally.
* @param size of field if not null terminated.
*/
Number(char *buffer, unsigned size);
/**
* Set string based on a new value.
* @param value to set.
*/
void set(long value);
/**
* Get string buffer representing the number.
* @return string buffer.
*/
inline const char *c_str() const
{return buffer;};
/**
* Get value of string buffer as a long integer.
* @return long interger value of string buffer.
*/
long get() const;
/**
* Get value of string buffer as expression of object.
* @return long interger value of string buffer.
*/
inline long operator()()
{return get();};
/**
* Cast string as long integer and get value of buffer.
* @return long integer value of string buffer.
*/
inline operator long()
{return get();};
/**
* Cast object as a string to retrieve buffer.
* @return string buffer of value.
*/
inline operator char*()
{return buffer;};
/**
* Assign a value to the number. This rewrites the string buffer.
* @param value to assign.
* @return new value of number object assigned.
*/
long operator=(long value);
/**
* Assign another number to this number.
* @param number to assign to assign.
* @return new value of number object assigned.
*/
long operator=(const Number& number);
/**
* Add a value to the number. This rewrites the string buffer.
* @param value to add.
* @return new value of number object.
*/
long operator+=(const long value);
/**
* Subtract a value from the number. This rewrites the string buffer.
* @param value to subtract.
* @return new value of number object.
*/
long operator-=(const long value);
/**
* Decrement the number object. This rewrites the string buffer.
* @return new value of number object.
*/
long operator--();
/**
* Increment the number object. This rewrites the string buffer.
* @return new value of number object.
*/
long operator++();
};
/**
* A number manipulation class that maintains a zero lead filled string.
*
* @author David Sugar <dyfet@ostel.com>
* @short zero filled number manipulation.
*/
class __EXPORT ZNumber : public Number
{
public:
/**
* Create a number class for zero fill.
* @param pointer to field.
* @param size of field to fill.
*/
ZNumber(char *pointer, unsigned size);
/**
* Set value of zero filled number.
* @param value to set.
*/
void set(long value);
/**
* Assign number from value.
* @param value to assign.
* @return value assigned.
*/
long operator=(long value);
};
/**
* A convenience type for number.
*/
typedef Number number_t;
/**
* A convenience type for znumber.
*/
typedef ZNumber znumber_t;
/**
* Template for absolute value of a type.
* @param value to check
* @return absolute value
*/
template<typename T>
inline const T abs(const T& value)
{
if(value < (T)0)
return -value;
return value;
}
/**
* Template for min value of a type.
* @param v1 value to check
* @param v2 value to check
* @return v1 if < v2, else v2
*/
template<typename T>
inline const T (min)(const T& v1, const T& v2)
{
return ((v1 < v2) ? v1 : v2);
}
/**
* Template for max value of a type.
* @param v1 value to check
* @param v2 value to check
* @return v1 if > v2, else v2
*/
template<typename T>
inline const T (max)(const T& v1, const T& v2)
{
return ((v1 > v2) ? v1 : v2);
}
END_NAMESPACE
#endif
|