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 {
155 template <
typename T>
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;
292 inline bool is(T&
object) {
293 return object.operator bool();
304 return (
bool)(
object.operator*() ==
nullptr);
315 return (
bool)(
object->operator*() ==
nullptr);
324 inline T*
dup(
const T&
object) {
325 return new T(
object);
329 inline void dupfree(T
object) {
334 inline char *dup<char>(
const char&
object) {
335 return strdup(&
object);
339 inline 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));
387 inline void swap(T& o1, T& o2) {
400 inline T&
copy(
const T& src, T& to) {
401 new((caddr_t)&to) T(src);
409 inline T&
move(T& src, T& to) {
410 memcpy((
void *)&to, (
void *)&src,
sizeof(T));
411 new((caddr_t)&src) T();
416 inline T& clear(T& o) {
418 new((caddr_t)&o) T();
433 if(((
size_t)
pointer) %
sizeof(T))
445 inline T& (
max)(T& o1, T& o2) {
446 return o1 > o2 ? o1 : o2;
456 inline T& (
min)(T& o1, T& o2) {
457 return o1 < o2 ? o1 : o2;
468 inline T& (
limit)(T& value, T& low, T& high) {
469 return (value < low) ? low : ((value > high) ? high : value);
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
void copy_unsafe(T *target, const T *source)
Convenience function to copy class.
T & move(T &src, T &to)
Convenience function to move objects.
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
~save_restore()
Restore original when stack frame is released.
bool isnull(T &object)
Convenience function to test pointer object.
void zero_unsafe(T &object)
Convenience function to zero an object and restore type info.
void reset_unsafe(T &object)
Convenience function to reset an existing object.
bool is(T &object)
Convenience function to validate object assuming it is castable to bool.
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
Save and restore global objects in function call stack frames.
T &() min(T &o1, T &o2)
Convenience function to return min of two objects.
bool bound(const T *pointer, const T *base, size_t count)
Convenience function to check memory arrays.
void store_unsafe(T &target, const T *source)
Convenience function to store object pointer into object.
Common namespace for all ucommon objects.
save_restore(T &object)
Save object into local copy and keep reference to the original object.
Automatic integer counting class.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
T copy(const T &src)
Convenience function to copy objects.
bool isnullp(T *object)
Convenience function to test pointer-pointer object.
Generic smart array class.
void swap(T &o1, T &o2)
Convenience function to swap objects.
Generic smart pointer class.
T & deref_pointer(T *pointer)
Convert a pointer to a reference with type checking.