+ if (ServerInstance && ServerInstance->Logs)
+ ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::+ @%p", (void*)this);
+}
+
+CullResult classbase::cull()
+{
+ if (ServerInstance && ServerInstance->Logs)
+ ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::-%s @%p",
+ typeid(*this).name(), (void*)this);
+ return CullResult();
+}
+
+classbase::~classbase()
+{
+ if (ServerInstance && ServerInstance->Logs)
+ ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::~ @%p", (void*)this);
+}
+
+CullResult::CullResult()
+{
+}
+
+// This trick detects heap allocations of refcountbase objects
+static void* last_heap = NULL;
+
+void* refcountbase::operator new(size_t size)
+{
+ last_heap = ::operator new(size);
+ return last_heap;
+}
+
+void refcountbase::operator delete(void* obj)
+{
+ if (last_heap == obj)
+ last_heap = NULL;
+ ::operator delete(obj);
+}
+
+refcountbase::refcountbase() : refcount(0)
+{
+ if (this != last_heap)
+ throw CoreException("Reference allocate on the stack!");
+}
+
+refcountbase::~refcountbase()
+{
+ if (refcount && ServerInstance && ServerInstance->Logs)
+ ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %d",
+ (void*)this, refcount);
+}
+
+usecountbase::~usecountbase()
+{
+ if (usecount && ServerInstance && ServerInstance->Logs)
+ ServerInstance->Logs->Log("CULLLIST", DEBUG, "usecountbase::~ @%p with refcount %d",
+ (void*)this, usecount);
+}
+
+ServiceProvider::~ServiceProvider()
+{
+}
+
+ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : ServiceProvider(mod, Key, SERVICE_METADATA)
+{
+}
+
+ExtensionItem::~ExtensionItem()
+{
+}
+
+void* ExtensionItem::get_raw(const Extensible* container) const
+{
+ Extensible::ExtensibleStore::const_iterator i =
+ container->extensions.find(const_cast<ExtensionItem*>(this));
+ if (i == container->extensions.end())
+ return NULL;
+ return i->second;
+}
+
+void* ExtensionItem::set_raw(Extensible* container, void* value)
+{
+ std::pair<Extensible::ExtensibleStore::iterator,bool> rv =
+ container->extensions.insert(std::make_pair(this, value));
+ if (rv.second)
+ {
+ return NULL;
+ }
+ else
+ {
+ void* old = rv.first->second;
+ rv.first->second = value;
+ return old;
+ }
+}
+
+void* ExtensionItem::unset_raw(Extensible* container)
+{
+ Extensible::ExtensibleStore::iterator i = container->extensions.find(this);
+ if (i == container->extensions.end())
+ return NULL;
+ void* rv = i->second;
+ container->extensions.erase(i);
+ return rv;
+}
+
+void ExtensionManager::Register(ExtensionItem* item)
+{
+ types.insert(std::make_pair(item->name, item));
+}
+
+void ExtensionManager::BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list)
+{
+ std::map<std::string, reference<ExtensionItem> >::iterator i = types.begin();
+ while (i != types.end())
+ {
+ std::map<std::string, reference<ExtensionItem> >::iterator me = i++;
+ ExtensionItem* item = me->second;
+ if (item->creator == module)
+ {
+ list.push_back(item);
+ types.erase(me);
+ }
+ }
+}
+
+ExtensionItem* ExtensionManager::GetItem(const std::string& name)
+{
+ std::map<std::string, reference<ExtensionItem> >::iterator i = types.find(name);
+ if (i == types.end())
+ return NULL;
+ return i->second;