EgtGeomKernel : GeoFactory ora usa nType invece di sKey,

aggiunto map da sKey a nType.
This commit is contained in:
Dario Sassi
2013-11-26 20:53:50 +00:00
parent 81a1e3d994
commit cc2db726db
15 changed files with 97 additions and 32 deletions
+8 -1
View File
@@ -21,7 +21,7 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_CRV_ARC, CurveArc) ;
GEOOBJ_REGISTER( CRV_ARC, "C_ARC", CurveArc) ;
//----------------------------------------------------------------------------
CurveArc::CurveArc( void)
@@ -113,6 +113,13 @@ CurveArc::Clone( void) const
return pCrv ;
}
//----------------------------------------------------------------------------
const string&
CurveArc::GetKey( void) const
{
return GEOOBJ_GETKEY( CurveArc) ;
}
//----------------------------------------------------------------------------
bool
CurveArc::Save( ostream& osOut) const
+1 -1
View File
@@ -23,7 +23,7 @@ class CurveArc : public ICurveArc
virtual ~CurveArc( void) ;
virtual CurveArc* Clone( void) const ;
virtual GeoObjType GetType( void) const { return CRV_ARC ; }
virtual std::string GetKey( void) const { return KEY_CRV_ARC ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return ( m_nStatus == OK) ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;
+8 -1
View File
@@ -21,7 +21,7 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_CRV_BEZ, CurveBezier) ;
GEOOBJ_REGISTER( CRV_BEZ, "C_BEZ", CurveBezier) ;
//----------------------------------------------------------------------------
CurveBezier::CurveBezier( void)
@@ -188,6 +188,13 @@ CurveBezier::Clone( void) const
return pCrv ;
}
//----------------------------------------------------------------------------
const string&
CurveBezier::GetKey( void) const
{
return GEOOBJ_GETKEY( CurveBezier) ;
}
//----------------------------------------------------------------------------
bool
CurveBezier::Save( ostream& osOut) const
+1 -1
View File
@@ -23,7 +23,7 @@ class CurveBezier : public ICurveBezier
virtual ~CurveBezier( void) ;
virtual CurveBezier* Clone( void) const ;
virtual GeoObjType GetType( void) const { return CRV_BEZ ; }
virtual std::string GetKey( void) const { return KEY_CRV_BEZ ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return ( m_nStatus == OK) ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;
+11 -2
View File
@@ -21,7 +21,7 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_CRV_COMPO, CurveComposite) ;
GEOOBJ_REGISTER( CRV_COMPO, "C_CMP", CurveComposite) ;
//----------------------------------------------------------------------------
CurveComposite::CurveComposite( void)
@@ -158,6 +158,13 @@ CurveComposite::Clone( void) const
return pCrv ;
}
//----------------------------------------------------------------------------
const string&
CurveComposite::GetKey( void) const
{
return GEOOBJ_GETKEY( CurveComposite) ;
}
//----------------------------------------------------------------------------
bool
CurveComposite::Save( ostream& osOut) const
@@ -192,6 +199,7 @@ CurveComposite::Save( ostream& osOut) const
bool
CurveComposite::Load( CScan& TheScanner)
{
int nType ;
string sLine ;
STRVECTOR vsParams ;
bool bOk ;
@@ -218,7 +226,8 @@ CurveComposite::Load( CScan& TheScanner)
if ( ! TheScanner.GetLine( sLine))
return false ;
// creo l'oggetto
pGeoO = GEOOBJ_CREATE( sLine) ;
nType = GEOOBJ_KEYTOTYPE( sLine) ;
pGeoO = GEOOBJ_CREATE( nType) ;
if ( pGeoO == nullptr)
return false ;
// recupero la linea con il nome
+1 -1
View File
@@ -27,7 +27,7 @@ class CurveComposite : public ICurveComposite
virtual ~CurveComposite( void) ;
virtual CurveComposite* Clone( void) const ;
virtual GeoObjType GetType( void) const { return CRV_COMPO ; }
virtual std::string GetKey( void) const { return KEY_CRV_COMPO ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return ( m_nStatus == OK) ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;
+8 -1
View File
@@ -21,7 +21,7 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_CRV_LINE, CurveLine) ;
GEOOBJ_REGISTER( CRV_LINE, "C_LIN", CurveLine) ;
//----------------------------------------------------------------------------
CurveLine::CurveLine( void)
@@ -61,6 +61,13 @@ CurveLine::Clone( void) const
return pCrv ;
}
//----------------------------------------------------------------------------
const string&
CurveLine::GetKey( void) const
{
return GEOOBJ_GETKEY( CurveLine) ;
}
//----------------------------------------------------------------------------
bool
CurveLine::Save( ostream& osOut) const
+1 -1
View File
@@ -23,7 +23,7 @@ class CurveLine : public ICurveLine
virtual ~CurveLine( void) ;
virtual CurveLine* Clone( void) const ;
virtual GeoObjType GetType( void) const { return CRV_LINE ; }
virtual std::string GetKey( void) const { return KEY_CRV_LINE ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return ( m_nStatus == OK) ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;
+3 -1
View File
@@ -82,6 +82,7 @@ GdbObj::Save( std::ostream& osOut) const
bool
GdbObj::Load( CScan& TheScanner, string& sErrLine)
{
int nType ;
string sLine ;
STRVECTOR vsParams ;
@@ -94,7 +95,8 @@ GdbObj::Load( CScan& TheScanner, string& sErrLine)
return false ;
// creo l'oggetto geometrico corrispondente
m_pGeoObj = GEOOBJ_CREATE( sLine) ;
nType = GEOOBJ_KEYTOTYPE( sLine) ;
m_pGeoObj = GEOOBJ_CREATE( nType) ;
if ( m_pGeoObj == nullptr) {
sErrLine = sLine ;
return false ;
+2 -2
View File
@@ -20,7 +20,7 @@ using namespace std ;
//----------------------------------------------------------------------------
IGeoObj*
CreateGeoObj( string sKey)
CreateGeoObj( int nType)
{
return GEOOBJ_CREATE( sKey) ;
return GEOOBJ_CREATE( nType) ;
}
+35 -15
View File
@@ -1,13 +1,13 @@
//----------------------------------------------------------------------------
// EgalS
//----------------------------------------------------------------------------
// File : GeoObjFactory.h Data : 13.10.13 Versione : 1.2a3
// File : GeoObjFactory.h Data : 26.11.13 Versione : 1.3a1
// Contenuto : Factory della classe CGeoObj.
//
//
//
// Modifiche : 13.10.13 DS Creazione modulo.
//
// 26.11.13 DS Aggiunta KeyToType e creazione da Type anzichè Key.
//
//----------------------------------------------------------------------------
@@ -17,30 +17,37 @@
#include <unordered_map>
#include "/EgtDev/Include/EGkGeoObj.h"
//----------------------------------------------------------------------------
#define GEOOBJ_REGISTER( sKey, T) static const bool bReg_##T = GeoObjRegister<class T>::DoRegister( sKey)
#define GEOOBJ_GETKEY( T) GeoObjRegister<class T>::GetKey()
#define GEOOBJ_CREATE( sKey) GeoObjFactory::Create( sKey)
#define GEOOBJ_REGISTER(nKey,sKey,T) static const bool bReg_##T = GeoObjRegister<class T>::DoRegister(nKey,sKey)
#define GEOOBJ_GETTYPE( T) GeoObjRegister<class T>::GetType()
#define GEOOBJ_GETKEY( T) GeoObjRegister<class T>::GetKey()
#define GEOOBJ_KEYTOTYPE( sKey) GeoObjFactory::KeyToType( sKey)
#define GEOOBJ_CREATE( nKey) GeoObjFactory::Create( nKey)
//----------------------------------------------------------------------------
template <class T>
class GeoObjRegister
{
public :
static bool DoRegister( std::string sKey)
{ if ( ! GeoObjFactory::Register( sKey, Create))
static bool DoRegister( int nKey, std::string sKey)
{ if ( ! GeoObjFactory::Register( nKey, sKey, Create))
return false ;
GetTypePrivate() = nKey ;
GetKeyPrivate() = sKey ;
return true ; }
static IGeoObj* Create( void)
{ return new(nothrow) T ; }
static const int& GetType( void)
{ return GetTypePrivate() ; }
static const std::string& GetKey( void)
{ return GetKeyPrivate() ; }
private :
GeoObjRegister( void) {}
~GeoObjRegister( void) {}
static int& GetTypePrivate( void)
{ static int s_nType ;
return s_nType ; }
static std::string& GetKeyPrivate( void)
{ static std::string s_sKey ;
return s_sKey ; }
@@ -53,11 +60,18 @@ class GeoObjFactory
// definizione del tipo funzione di creazione
typedef IGeoObj* ( *GeoCreator) ( void) ;
// per registrare le funzioni di creazione
static bool Register( std::string sKey, GeoCreator Creator)
{ return GetCreatorMap().insert( std::pair< std::string, GeoCreator>( sKey, Creator)).second ; }
static bool Register( int nKey, std::string sKey, GeoCreator Creator)
{ return GetKeyTypeMap().insert( std::pair< std::string, int>( sKey, nKey)).second &&
GetCreatorMap().insert( std::pair< int, GeoCreator>( nKey, Creator)).second ; }
// per restituire il tipo data la chiave
static int KeyToType( std::string sKey)
{ KeyTypeMap::iterator Iter = GetKeyTypeMap().find( sKey) ;
if ( Iter != GetKeyTypeMap().end())
return Iter->second ;
return 0 ; }
// per creare l'oggetto richiesto
static IGeoObj* Create( std::string sKey)
{ CreatorMap::iterator Iter = GetCreatorMap().find( sKey) ;
static IGeoObj* Create( int nKey)
{ CreatorMap::iterator Iter = GetCreatorMap().find( nKey) ;
if ( Iter != GetCreatorMap().end()) {
if ( Iter->second != nullptr)
return Iter->second() ;
@@ -67,9 +81,15 @@ class GeoObjFactory
private :
GeoObjFactory( void) {}
~GeoObjFactory( void) {}
// definizione del tipo mappa con coppie nome, funzione di creazione
typedef std::unordered_map<std::string, GeoCreator> CreatorMap ;
//
// definizione del tipo mappa con coppie nome, tipo
typedef std::unordered_map<std::string, int> KeyTypeMap ;
// metodo di accesso alla mappa statica
static KeyTypeMap& GetKeyTypeMap( void)
{ static KeyTypeMap s_KeyTypeMap ;
return s_KeyTypeMap ; }
// definizione del tipo mappa con coppie tipo, funzione di creazione
typedef std::unordered_map<int, GeoCreator> CreatorMap ;
// metodo di accesso alla mappa statica
static CreatorMap& GetCreatorMap( void)
{ static CreatorMap s_CreatorMap ;
return s_CreatorMap ; }
+8 -1
View File
@@ -21,7 +21,7 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_GEO_PNT3D, GeoPoint3d) ;
GEOOBJ_REGISTER( GEO_PNT3D, "G_PNT", GeoPoint3d) ;
//----------------------------------------------------------------------------
GeoPoint3d::GeoPoint3d( void)
@@ -58,6 +58,13 @@ GeoPoint3d::Clone( void) const
return pGPt ;
}
//----------------------------------------------------------------------------
const string&
GeoPoint3d::GetKey( void) const
{
return GEOOBJ_GETKEY( GeoPoint3d) ;
}
//----------------------------------------------------------------------------
bool
GeoPoint3d::Save( ostream& osOut) const
+1 -1
View File
@@ -23,7 +23,7 @@ class GeoPoint3d : public IGeoPoint3d
virtual ~GeoPoint3d( void) ;
virtual GeoPoint3d* Clone( void) const ;
virtual GeoObjType GetType( void) const { return GEO_PNT3D ; }
virtual std::string GetKey( void) const { return KEY_GEO_PNT3D ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return true ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;
+8 -2
View File
@@ -20,9 +20,8 @@
using namespace std ;
//----------------------------------------------------------------------------
GEOOBJ_REGISTER( KEY_GEO_VECT3D, GeoVector3d) ;
GEOOBJ_REGISTER( GEO_VECT3D, "G_VEC", GeoVector3d) ;
//----------------------------------------------------------------------------
GeoVector3d::GeoVector3d( void)
@@ -58,6 +57,13 @@ GeoVector3d::Clone( void) const
return pGVt ;
}
//----------------------------------------------------------------------------
const string&
GeoVector3d::GetKey( void) const
{
return GEOOBJ_GETKEY( GeoVector3d) ;
}
//----------------------------------------------------------------------------
bool
GeoVector3d::Save( ostream& osOut) const
+1 -1
View File
@@ -23,7 +23,7 @@ class GeoVector3d : public IGeoVector3d
virtual ~GeoVector3d( void) ;
virtual GeoVector3d* Clone( void) const ;
virtual GeoObjType GetType( void) const { return GEO_VECT3D ; }
virtual std::string GetKey( void) const { return KEY_GEO_VECT3D ; }
virtual const std::string& GetKey( void) const ;
virtual bool IsValid( void) const { return true ; }
virtual bool Save( std::ostream& osOut) const ;
virtual bool Load( CScan& TheScanner) ;