// $Source$ // $Revision$ // $Date$ // $Author$ #ifndef __rf_symbol_ih__ #define __rf_symbol_ih__ #include "rf_symbol.hh" #include "rf_macros.hh" namespace rftype { using namespace rfrt ; template inline Symbol::Symbol () : Term (get_type()) { new (&ptr_data2) C(); } template template inline Symbol::Symbol (CppType1 const& _arg1) : Term (get_type()) { new (&ptr_data2) C(_arg1); } template template inline Symbol::Symbol ( CppType1 const& _arg1, CppType2 const& _arg2 ) : Term (get_type()) { new (&ptr_data2) C(_arg1, _arg2); } template template inline Symbol::Symbol ( CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 ) : Term (get_type()) { new (&ptr_data2) C(_arg1, _arg2, _arg3); } template inline C const& Symbol::get_object () const { return *reinterpret_cast(&int_data2); } template void Symbol::ctor ( Symbol* _to, Symbol const* _from ) { _to->data1 = _from->data1; _to->int_data2 = _from->int_data2; } template void Symbol::dtor (Symbol*) {} template bool Symbol::eq ( Symbol const* _s1, Symbol const* _s2 ) { return _s1->int_data2 == _s2->int_data2; } template int Symbol::compare ( Symbol const* _s1, Symbol const* _s2 ) { if (_s1->int_data2 > _s2->int_data2) return 1; if (_s1->int_data2 < _s2->int_data2) return -1; return 0; } template WString Symbol::to_string ( Symbol const* _s ) { wchar_t s[2]; s[0] = _s->int_data2; s[1] = '\0'; return WString(s, 1); } template size_t Symbol::get_name ( Symbol const*, wchar_t const** ) { return (size_t)-1; } template short_type_funcs_t Symbol::funcs = { 0, (void (*)(Term*, Term const*)) (Symbol::ctor), (void (*)(Term*)) (Symbol::dtor), (bool (*)(Term const*, Term const*)) (Symbol::eq), (int (*)(Term const*, Term const*)) (Symbol::compare), null, // (uint32_t (*)(Term const*)) (Symbol::hash), (pxx::WString (*)(Term const*)) (Symbol::to_string), (size_t (*)(Term const*, wchar_t const**)) (Symbol::get_name) }; template inline unsigned Symbol::get_type () { return reg.get_type(); } template template inline size_t Symbol::compute_length (CppType const* _array) { size_t len = 0; while (*_array++) len++; return len; } template inline Symbol::Symbol (C* _p) : Term (get_type(), _p) {} template inline C* Symbol::get_obj_ptr () const { return static_cast(ptr_data2); } template void Symbol::ctor ( Symbol* _to, Symbol const* _from ) { _to->data1 = _from->data1; _to->ptr_data2 = _from->ptr_data2; } template void Symbol::dtor (Symbol*) {} template bool Symbol::eq ( Symbol const* _s1, Symbol const* _s2 ) { return _s1->get_obj_ptr() == _s2->get_obj_ptr(); } template int Symbol::compare ( Symbol const* _s1, Symbol const* _s2 ) { if (_s1->get_obj_ptr() > _s2->get_obj_ptr()) return 1; if (_s1->get_obj_ptr() < _s2->get_obj_ptr()) return -1; return 0; } template pxx::WString Symbol::to_string ( Symbol const* _s ) { size_t max_len = hex_ptr_len + max_int_len + 4; wchar_t* str = static_cast(alloca(max_len * sizeof(wchar_t))); C* ptr = _s->get_obj_ptr(); int len = swprintf(str, max_len, L"<%u|%p>", get_type(), ptr); if (-1 == len) FATAL("<%u|%p> is more then %u wide characters", get_type(), ptr, max_len); return pxx::WString(str, len); } template size_t Symbol::get_name ( Symbol const* _s, wchar_t const** _np ) { return (size_t)-1; } template short_type_funcs_t Symbol::funcs = { 0, (void (*)(Term*, Term const*)) (Symbol::ctor), (void (*)(Term*)) (Symbol::dtor), (bool (*)(Term const*, Term const*)) (Symbol::eq), (int (*)(Term const*, Term const*)) (Symbol::compare), null, // (uint32_t (*)(Term const*)) (Symbol::hash), (pxx::WString (*)(Term const*)) (Symbol::to_string), (size_t (*)(Term const*, wchar_t const**)) (Symbol::get_name) }; template inline unsigned Symbol::get_type () { return reg.get_type(); } template inline Symbol::Symbol () : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) C(); w->ref_count = 1; ptr_data2 = w; } template template inline Symbol::Symbol (CppType1 const& _arg1) : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) C(_arg1); w->ref_count = 1; ptr_data2 = w; } template template inline Symbol::Symbol ( CppType1 const& _arg1, CppType2 const& _arg2 ) : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) C(_arg1, _arg2); w->ref_count = 1; ptr_data2 = w; } template template inline Symbol::Symbol ( CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 ) : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) C(_arg1, _arg2, _arg3); w->ref_count = 1; ptr_data2 = w; } template inline void Symbol::replace_object () { C* p = get_obj_ptr(); p->~C(); new (p) C(); } template template inline void Symbol::replace_object (CppType1 const& _arg1) { C* p = get_obj_ptr(); p->~C(); new (p) C(_arg1); } template template inline void Symbol::replace_object ( CppType1 const& _arg1, CppType2 const& _arg2 ) { C* p = get_obj_ptr(); p->~C(); new (p) C(_arg1, _arg2); } template template inline void Symbol::replace_object ( CppType1 const& _arg1, CppType2 const& _arg2, CppType3 const& _arg3 ) { C* p = get_obj_ptr(); p->~C(); new (p) C(_arg1, _arg2, _arg3); } template inline C const& Symbol::get_object () const { return static_cast(ptr_data2)->object; } template inline C* Symbol::get_obj_ptr () const { return &static_cast(ptr_data2)->object; } template void Symbol::ctor ( Symbol* _to, Symbol const* _from ) { _to->data1 = _from->data1; _to->ptr_data2 = _from->ptr_data2; static_cast(_to->ptr_data2)->ref_count++; } template void Symbol::dtor (Symbol* _s) { Wrapper* w = static_cast(_s->ptr_data2); if (--(w->ref_count) == 0) { w->object.~C(); allocator->deallocate(w); } } template bool Symbol::eq ( Symbol const* _s1, Symbol const* _s2 ) { return _s1->get_obj_ptr() == _s2->get_obj_ptr(); } template int Symbol::compare ( Symbol const* _s1, Symbol const* _s2 ) { if (_s1->get_obj_ptr() > _s2->get_obj_ptr()) return 1; if (_s1->get_obj_ptr() < _s2->get_obj_ptr()) return -1; return 0; } template pxx::WString Symbol::to_string ( Symbol const* _s ) { size_t max_len = hex_ptr_len + 15; wchar_t* str = static_cast(alloca(max_len * sizeof(wchar_t))); C* ptr = _s->get_obj_ptr(); int len = swprintf(str, max_len, L"", ptr); if (-1 == len) FATAL(" is more then %u wide characters", ptr, max_len); return pxx::WString(str, len); } template short_type_funcs_t Symbol::funcs = { 0, (void (*)(Term*, Term const*)) (Symbol::ctor), (void (*)(Term*)) (Symbol::dtor), (bool (*)(Term const*, Term const*)) (Symbol::eq), (int (*)(Term const*, Term const*)) (Symbol::compare), null, // (uint32_t (*)(Term const*)) (Symbol::hash), (pxx::WString (*)(Term const*)) (Symbol::to_string), null }; template inline Symbol, ObjectTerm>::Symbol () : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) NamedObject(); w->ref_count = 1; ptr_data2 = w; } template template inline Symbol, ObjectTerm>::Symbol (CppType1 _arg1) : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) NamedObject(_arg1); w->ref_count = 1; ptr_data2 = w; } template template inline Symbol, ObjectTerm>::Symbol (CppType1 _arg1, CppType2 _arg2) : Term (reg.get_type()) { Wrapper* w = static_cast(allocator->allocate(sizeof(Wrapper))); new (&(w->object)) NamedObject(_arg1, _arg2); w->ref_count = 1; ptr_data2 = w; } template inline NamedObject const& Symbol, ObjectTerm>::get_object () const { return static_cast(ptr_data2)->object; } template inline NamedObject* Symbol, ObjectTerm>::get_obj_ptr () const { return &static_cast(ptr_data2)->object; } template void Symbol, ObjectTerm>::dtor (Symbol, ObjectTerm>* _s) { Wrapper* w = static_cast(_s->ptr_data2); if (--(w->ref_count) == 0) { w->object.~NamedObject(); allocator->deallocate(w); } } template pxx::WString Symbol, ObjectTerm>::to_string ( Symbol, ObjectTerm> const* _s ) { NamedObject* ptr = _s->get_obj_ptr(); return ptr->name; } template size_t Symbol, ObjectTerm>::get_name ( Symbol, ObjectTerm> const* _s, wchar_t const** _np ) { NamedObject* ptr = _s->get_obj_ptr(); *_np = ptr->name.get_data(); return ptr->name.get_length(); } template short_type_funcs_t Symbol, ObjectTerm>::funcs = { 0, (void (*)(Term*, Term const*)) (Symbol::ctor), (void (*)(Term*)) (Symbol, ObjectTerm>::dtor), (bool (*)(Term const*, Term const*)) (Symbol::eq), (int (*)(Term const*, Term const*)) (Symbol::compare), null, // (uint32_t (*)(Term const*)) (Symbol::hash), (pxx::WString (*)(Term const*)) (Symbol, ObjectTerm>::to_string), (size_t (*)(Term const*, wchar_t const**)) (Symbol, ObjectTerm>::get_name) }; /* template const TypeRegister Symbol::reg(&Symbol::funcs); */ template inline unsigned Symbol::get_type () { return reg.get_type(); } } #endif // __rf_symbol_ih__