diff --git a/toonz/sources/common/tcore/tidentifiable.cpp b/toonz/sources/common/tcore/tidentifiable.cpp deleted file mode 100644 index a58c29f..0000000 --- a/toonz/sources/common/tcore/tidentifiable.cpp +++ /dev/null @@ -1,87 +0,0 @@ - - -#include "tidentifiable.h" -#include - -namespace { - -class IdentifierTable { // singleton - - unsigned long m_lastId; - std::map m_table; - std::set m_objects; - - IdentifierTable() : m_lastId(0) {} - -public: - static IdentifierTable *instance() { - // NON DEVE MORIRE - // static IdentifierTable _instance; - // return &_instance; - static IdentifierTable *_instance = 0; - if (!_instance) _instance = new IdentifierTable; - return _instance; - } - - unsigned long getNextId() { return ++m_lastId; } - - void insert(TIdentifiable *o) { - unsigned long id = o->getIdentifier(); - std::map::iterator it = m_table.find(id); - if (it != m_table.end()) { - if (it->second == o) return; - m_objects.erase(it->second); - it->second = o; - } else { - m_table[id] = o; - } - m_objects.insert(o); - } - - void erase(TIdentifiable *o) { - unsigned long id = o->getIdentifier(); - m_table.erase(id); - m_objects.erase(o); - } - - TIdentifiable *fetch(unsigned long id) { - std::map::iterator it = m_table.find(id); - return it == m_table.end() ? 0 : it->second; - } -}; - -} // namespace - -TIdentifiable::TIdentifiable() : m_id(0) {} - -TIdentifiable::~TIdentifiable() { - if (m_id != 0) IdentifierTable::instance()->erase(this); -} - -TIdentifiable::TIdentifiable(const TIdentifiable &src) : m_id(src.m_id) {} - -const TIdentifiable &TIdentifiable::operator=(const TIdentifiable &src) { - if (src.m_id != m_id && m_id != 0) IdentifierTable::instance()->erase(this); - m_id = src.m_id; - return *this; -} - -void TIdentifiable::setIdentifier(unsigned long id) { - bool wasStored = m_id > 0 && IdentifierTable::instance()->fetch(m_id) == this; - if (m_id != id && m_id != 0) IdentifierTable::instance()->erase(this); - m_id = id; - if (wasStored) IdentifierTable::instance()->insert(this); -} - -void TIdentifiable::setNewIdentifier() { - setIdentifier(IdentifierTable::instance()->getNextId()); -} - -void TIdentifiable::storeByIdentifier() { - assert(getIdentifier() >= 1); - IdentifierTable::instance()->insert(this); -} - -TIdentifiable *TIdentifiable::fetchByIdentifier(unsigned long id) { - return IdentifierTable::instance()->fetch(id); -} diff --git a/toonz/sources/include/tidentifiable.h b/toonz/sources/include/tidentifiable.h deleted file mode 100644 index 2679d13..0000000 --- a/toonz/sources/include/tidentifiable.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#ifndef TIDENTIFIABLE_INCLUDED -#define TIDENTIFIABLE_INCLUDED - -#include "tutil.h" - -#undef DVAPI -#undef DVVAR -#ifdef TNZCORE_EXPORTS -#define DVAPI DV_EXPORT_API -#define DVVAR DV_EXPORT_VAR -#else -#define DVAPI DV_IMPORT_API -#define DVVAR DV_IMPORT_VAR -#endif - -//========================================================= - -class DVAPI TIdentifiable { - unsigned long m_id; - -public: - TIdentifiable(); - virtual ~TIdentifiable(); - TIdentifiable(const TIdentifiable &); - const TIdentifiable &operator=(const TIdentifiable &); - - unsigned long getIdentifier() const { return m_id; } - void setIdentifier(unsigned long id); - void setNewIdentifier(); - - void storeByIdentifier(); - static TIdentifiable *fetchByIdentifier(unsigned long id); -}; - -#endif diff --git a/toonz/sources/tnzcore/CMakeLists.txt b/toonz/sources/tnzcore/CMakeLists.txt index 6873c47..d637cd2 100644 --- a/toonz/sources/tnzcore/CMakeLists.txt +++ b/toonz/sources/tnzcore/CMakeLists.txt @@ -34,7 +34,6 @@ set(HEADERS ${MOC_HEADERS} ../include/tdebugmessage.h ../include/texception.h ../include/texpression.h - ../include/tidentifiable.h ../include/tmathutil.h ../include/tnztypes.h ../include/tproperty.h @@ -129,7 +128,6 @@ set(SOURCES ../common/tcore/tdebugmessage.cpp ../common/tcore/texception.cpp ../common/tcore/threadmessage.cpp - ../common/tcore/tidentifiable.cpp ../common/tcore/tmathutil.cpp ../common/tproperty.cpp ../common/tcore/trandom.cpp