Files
Dario Sassi 974d050025 EgtGeomKernel :
- migliorie a IdManager per aggiornamento dopo cancellazione entità.
2018-12-12 07:31:51 +00:00

70 lines
2.4 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2018
//----------------------------------------------------------------------------
// File : IdManager.h Data : 11.12.18 Versione : 1.9l2
// Contenuto : Dichiarazione e implementazione della classe IdManager.
//
//
//
// Modifiche : 02.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include <unordered_map>
//----------------------------------------------------------------------------
class IdManager
{
public :
IdManager( void)
: m_nMaxId( 0) {}
bool Init( int nBuckets)
{ m_GdbIdMap.rehash( nBuckets) ; return true ; }
bool Clear( void)
{ m_GdbIdMap.clear() ; m_nMaxId = 0 ; return true ; }
GdbObj* FindObj( int nId)
{ auto Iter = m_GdbIdMap.find( nId) ;
if ( Iter != m_GdbIdMap.end())
return Iter->second ;
else
return nullptr ; }
const GdbObj* FindObj( int nId) const
{ auto Iter = m_GdbIdMap.find( nId) ;
if ( Iter != m_GdbIdMap.end())
return Iter->second ;
else
return nullptr ; }
bool AddObj( int nId, GdbObj* pGObj)
{ if ( nId > m_nMaxId)
m_nMaxId = nId ;
return m_GdbIdMap.emplace( nId, pGObj).second ; }
bool RemoveObj( int nId)
{ m_GdbIdMap.erase( nId) ;
UpdateMaxId() ;
return true ; }
int GetNewId( void) const
{ return ( m_nMaxId + 1) ; }
int GetMaxId( void) const
{ return m_nMaxId ; }
void UpdateMaxId( int nId)
{ if ( nId > m_nMaxId)
m_nMaxId = nId ; }
void UpdateMaxId( void)
{ while ( m_nMaxId > 0) {
if ( m_GdbIdMap.find( m_nMaxId) == m_GdbIdMap.end())
-- m_nMaxId ;
else
return ;
} }
private :
typedef std::unordered_map< int, GdbObj*> INTPGDBO_UMAP ;
private :
int m_nMaxId ;
INTPGDBO_UMAP m_GdbIdMap ; // map basato sugli identificatori
} ;