Files
EgtGeomKernel/IdManager.h
T

47 lines
1.8 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : IdManager.h Data : 02.12.13 Versione : 1.4a3
// Contenuto : Dichiarazione e implementazione della classe IdManager.
//
//
//
// Modifiche : 02.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include <unordered_map>
//----------------------------------------------------------------------------
typedef std::unordered_map< int, GdbNode*> INTPGDBN_UMAP ;
//----------------------------------------------------------------------------
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 ; }
GdbNode* FindNode( int nId)
{ INTPGDBN_UMAP::const_iterator Iter = m_GdbIdMap.find( nId) ;
if ( Iter != m_GdbIdMap.end())
return Iter->second ;
else
return nullptr ; }
bool AddNode( int nId, GdbNode* pGNode)
{ return m_GdbIdMap.insert( std::pair< int, GdbNode*>( nId, pGNode)).second ; }
bool RemoveNode( int nId)
{ m_GdbIdMap.erase( nId) ; return true ; }
int GetNewId( void) { return ++ m_nMaxId ; }
int GetMaxId( void) const { return m_nMaxId ; }
void UpdateMaxId( int nId) { if ( nId > m_nMaxId) m_nMaxId = nId ; }
private :
int m_nMaxId ;
INTPGDBN_UMAP m_GdbIdMap ; // map basato sugli identificatori
} ;