25#ifndef _UCOMMON_GENERICS_H_
26#define _UCOMMON_GENERICS_H_
28#ifndef _UCOMMON_CPR_H_
36#ifndef UCOMMON_SYSRUNTIME
37#define THROW(x) throw x
38#if __cplusplus > 199711L
42#define THROWS(x) throw(x)
43#define THROWS_ANY throw()
46#define THROW(x) ::abort()
66 inline void release(
void) {
75 inline void retain(
void) {
80 inline void set(T* ptr) {
90 if(
object == ref.object)
108 inline explicit pointer(T* ptr = NULL) : object(ptr) {
129 inline pointer& operator=(T *ptr) {
138 inline T& operator*()
const {
142 inline T* operator->()
const {
146 inline bool operator!()
const {
150 inline operator bool()
const {
168 inline void release(
void) {
177 inline void retain(
void) {
182 inline void set(T* ptr) {
192 if(array == ref.array)
240 inline T* operator*()
const {
244 inline T& operator[](
size_t offset)
const {
245 return array[offset];
248 inline T* operator()(
size_t offset)
const {
249 return &array[offset];
252 inline bool operator!()
const {
256 inline operator bool()
const {
280 original = &object; temp = object;
297inline bool is(T&
object) {
298 return object.operator bool();
309 return (
bool)(
object.operator*() ==
nullptr);
320 return (
bool)(
object->operator*() ==
nullptr);
329inline T*
dup(
const T&
object) {
330 return new T(
object);
334inline void dupfree(T
object) {
339inline char *dup<char>(
const char&
object) {
340 return strdup(&
object);
344inline void dupfree<char*>(
char*
object) {
354 new((caddr_t)&
object) T;
363 memset((
void *)&
object, 0,
sizeof(T));
new((caddr_t)&
object) T;
373 memcpy((
void *)target, (
void *)source,
sizeof(T));
383 memcpy((
void *)&target, (
void *)source,
sizeof(T));
392inline void swap(T& o1, T& o2) {
405inline T&
copy(
const T& src, T& to) {
406 new((caddr_t)&to) T(src);
415 memcpy((
void *)&to, (
void *)&src,
sizeof(T));
416 new((caddr_t)&src) T();
421inline T& clear(T& o) {
423 new((caddr_t)&o) T();
436 if(pointer < base || pointer >= &base[count])
438 if(((
size_t)
pointer) %
sizeof(T))
450inline T& (
max)(T& o1, T& o2) {
451 return o1 > o2 ? o1 : o2;
461inline T& (
min)(T& o1, T& o2) {
462 return o1 < o2 ? o1 : o2;
473inline T& (
limit)(T& value, T& low, T& high) {
474 return (value < low) ? low : ((value > high) ? high : value);
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
Common namespace for all ucommon objects.
T &() min(T &o1, T &o2)
Convenience function to return min of two objects.
void store_unsafe(T &target, const T *source)
Convenience function to store object pointer into object.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
bool isnullp(T *object)
Convenience function to test pointer-pointer object.
bool bound(const T *pointer, const T *base, size_t count)
Convenience function to check memory arrays.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
void reset_unsafe(T &object)
Convenience function to reset an existing object.
T & deref_pointer(T *pointer)
Convert a pointer to a reference with type checking.
void swap(T &o1, T &o2)
Convenience function to swap objects.
T & move(T &src, T &to)
Convenience function to move objects.
void zero_unsafe(T &object)
Convenience function to zero an object and restore type info.
T copy(const T &src)
Convenience function to copy objects.
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
bool isnull(T &object)
Convenience function to test pointer object.
void copy_unsafe(T *target, const T *source)
Convenience function to copy class.
bool is(T &object)
Convenience function to validate object assuming it is castable to bool.
Automatic integer counting class.
Generic smart pointer class.
Generic smart array class.
Save and restore global objects in function call stack frames.
~save_restore()
Restore original when stack frame is released.
save_restore(T &object)
Save object into local copy and keep reference to the original object.