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#define THROWS(x) throw(x)
39#define THROWS_ANY throw()
41#define THROW(x) ::abort()
61 inline void release(
void) {
70 inline void retain(
void) {
75 inline void set(T* ptr) {
85 if(
object == ref.object)
103 inline explicit pointer(T* ptr = NULL) : object(ptr) {
124 inline pointer& operator=(T *ptr) {
133 inline T& operator*()
const {
137 inline T* operator->()
const {
141 inline bool operator!()
const {
145 inline operator bool()
const {
163 inline void release(
void) {
172 inline void retain(
void) {
177 inline void set(T* ptr) {
187 if(array == ref.array)
235 inline T* operator*()
const {
239 inline T& operator[](
size_t offset)
const {
240 return array[offset];
243 inline T* operator()(
size_t offset)
const {
244 return &array[offset];
247 inline bool operator!()
const {
251 inline operator bool()
const {
275 original = &object; temp = object;
292inline bool is(T&
object) {
293 return object.operator bool();
304 return (
bool)(
object.operator*() ==
nullptr);
315 return (
bool)(
object->operator*() ==
nullptr);
324inline T*
dup(
const T&
object) {
325 return new T(
object);
329inline void dupfree(T
object) {
334inline char *dup<char>(
const char&
object) {
335 return strdup(&
object);
339inline void dupfree<char*>(
char*
object) {
349 new((caddr_t)&
object) T;
358 memset((
void *)&
object, 0,
sizeof(T));
new((caddr_t)&
object) T;
368 memcpy((
void *)target, (
void *)source,
sizeof(T));
378 memcpy((
void *)&target, (
void *)source,
sizeof(T));
387inline void swap(T& o1, T& o2) {
400inline T&
copy(
const T& src, T& to) {
401 new((caddr_t)&to) T(src);
410 memcpy((
void *)&to, (
void *)&src,
sizeof(T));
411 new((caddr_t)&src) T();
416inline T& clear(T& o) {
418 new((caddr_t)&o) T();
431 if(pointer < base || pointer >= &base[count])
433 if(((
size_t)
pointer) %
sizeof(T))
445inline T& (
max)(T& o1, T& o2) {
446 return o1 > o2 ? o1 : o2;
456inline T& (
min)(T& o1, T& o2) {
457 return o1 < o2 ? o1 : o2;
468inline T& (
limit)(T& value, T& low, T& high) {
469 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.
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.
T & max(T &o1, T &o2)
Convenience function to return max of two objects.
T & limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
bool bound(const T *pointer, const T *base, size_t count)
Convenience function to check memory arrays.
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 & min(T &o1, T &o2)
Convenience function to return min of two objects.
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.