#ifndef __rf_object_ih__ #define __rf_object_ih__ #include #include "pxx_heap_allocator.ih" #include "rf_object.hh" #include "rf_common.ih" #include "rf_sysdefs.hh" namespace rftype { using namespace rfrt ; inline Object::Object () : ref_count (0) { if (!allocator || !allocator->is_dyn_addr(this)) { // // Statically allocated object has one extra reference, so if all other // references are destroyed, the object still remain valid. ref_count++; } } inline Object::~Object () { // // Object destructor is called only in two cases: // 1) It is dynamically allocated and all references to it are destroyed. // 2) It is statically allocated and its life time is expired. if (!allocator || !allocator->is_dyn_addr(this)) { // // If an object was statically allcated, we remove its extra reference // and check if there are no other references to it. if (--ref_count > 0) { FATAL("Static object to be destroyed has extra references"); } } else { #ifdef PARANOIA // // Here an object was dynamically allocated, so its reference counter // should be zero. But if we are paranoid we chek this. if (ref_count > 0) { FATAL("Non-zero reference counter in destructor of dynamic object"); } #endif } } inline void* Object::operator new (size_t _size) { return allocator->allocate(_size); } inline void* Object::operator new (size_t, void* _ptr) { return _ptr; } inline void Object::operator delete (void* _ptr) { allocator->deallocate(_ptr); } inline uint32_t Object::hash () const { return 0; } inline int Object::compare (Object const& _obj) const { unsigned t1 = get_type(); unsigned t2 = _obj.get_type(); if (t1 < t2) return -1; else if (t1 > t2) return 1; else FATAL("Unable to compare objects without strict ordering"); return 0; } inline bool Object::operator == (Object const& _obj) const { return this == &_obj; } inline bool Object::operator != (Object const& _obj) const { return !(self == _obj); } inline pxx::WString Object::to_string () const { size_t max_len = hex_ptr_len + 15; wchar_t* str = static_cast(alloca(max_len * sizeof(wchar_t))); int len = swprintf(str, max_len, L"", this); if (-1 == len) FATAL(" is more then %u wide characters", this, max_len); return pxx::WString(str, len); } inline size_t Object::get_name (wchar_t const**) const { throw InvalidParameter(); } } #endif // __rf_object_ih__