#ifndef __rf_object_ih__ #define __rf_object_ih__ #include "rf_object.hh" #include "rf_common.ih" #include namespace rftype { using namespace rfrt ; inline Object::Object () : ref_count (0) { if (!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.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 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 !(self == _obj); } inline pxx::WString Object::to_string () const { size_t max_len = hex_ptr_len + 15; char str[max_len]; int len = snprintf(str, max_len, "", this); if (-1 == len) FATAL(" is more then %u characters", this, max_len); wchar_t wstr[len]; len = strtowstr(wstr, str, len); return pxx::WString(wstr, len); } } #endif // __rf_object_ih__