diff --git a/CurveArc.cpp b/CurveArc.cpp index c127362..3862630 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -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 diff --git a/CurveArc.h b/CurveArc.h index 5b0e9ed..10407c2 100644 --- a/CurveArc.h +++ b/CurveArc.h @@ -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) ; diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 6951157..c6a2679 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -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 diff --git a/CurveBezier.h b/CurveBezier.h index 0a49418..12c9f24 100644 --- a/CurveBezier.h +++ b/CurveBezier.h @@ -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) ; diff --git a/CurveComposite.cpp b/CurveComposite.cpp index 97bb6b0..e331db0 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -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 diff --git a/CurveComposite.h b/CurveComposite.h index 6487e1a..ed6595b 100644 --- a/CurveComposite.h +++ b/CurveComposite.h @@ -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) ; diff --git a/CurveLine.cpp b/CurveLine.cpp index a027598..f10ab11 100644 --- a/CurveLine.cpp +++ b/CurveLine.cpp @@ -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 diff --git a/CurveLine.h b/CurveLine.h index 336d0b2..f79a832 100644 --- a/CurveLine.h +++ b/CurveLine.h @@ -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) ; diff --git a/GdbObj.cpp b/GdbObj.cpp index 056d1e8..2cc0662 100644 --- a/GdbObj.cpp +++ b/GdbObj.cpp @@ -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 ; diff --git a/GeoObj.cpp b/GeoObj.cpp index 212ff61..d63c7f0 100644 --- a/GeoObj.cpp +++ b/GeoObj.cpp @@ -20,7 +20,7 @@ using namespace std ; //---------------------------------------------------------------------------- IGeoObj* -CreateGeoObj( string sKey) +CreateGeoObj( int nType) { - return GEOOBJ_CREATE( sKey) ; + return GEOOBJ_CREATE( nType) ; } \ No newline at end of file diff --git a/GeoObjFactory.h b/GeoObjFactory.h index dba73f2..d1f0f74 100644 --- a/GeoObjFactory.h +++ b/GeoObjFactory.h @@ -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 #include "/EgtDev/Include/EGkGeoObj.h" - //---------------------------------------------------------------------------- -#define GEOOBJ_REGISTER( sKey, T) static const bool bReg_##T = GeoObjRegister::DoRegister( sKey) -#define GEOOBJ_GETKEY( T) GeoObjRegister::GetKey() -#define GEOOBJ_CREATE( sKey) GeoObjFactory::Create( sKey) +#define GEOOBJ_REGISTER(nKey,sKey,T) static const bool bReg_##T = GeoObjRegister::DoRegister(nKey,sKey) +#define GEOOBJ_GETTYPE( T) GeoObjRegister::GetType() +#define GEOOBJ_GETKEY( T) GeoObjRegister::GetKey() +#define GEOOBJ_KEYTOTYPE( sKey) GeoObjFactory::KeyToType( sKey) +#define GEOOBJ_CREATE( nKey) GeoObjFactory::Create( nKey) //---------------------------------------------------------------------------- template 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 CreatorMap ; - // + // definizione del tipo mappa con coppie nome, tipo + typedef std::unordered_map 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 CreatorMap ; + // metodo di accesso alla mappa statica static CreatorMap& GetCreatorMap( void) { static CreatorMap s_CreatorMap ; return s_CreatorMap ; } diff --git a/GeoPoint3d.cpp b/GeoPoint3d.cpp index a6875e0..f1fa1ca 100644 --- a/GeoPoint3d.cpp +++ b/GeoPoint3d.cpp @@ -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 diff --git a/GeoPoint3d.h b/GeoPoint3d.h index 2acba78..08a684a 100644 --- a/GeoPoint3d.h +++ b/GeoPoint3d.h @@ -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) ; diff --git a/GeoVector3d.cpp b/GeoVector3d.cpp index ea8f09b..279c972 100644 --- a/GeoVector3d.cpp +++ b/GeoVector3d.cpp @@ -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 diff --git a/GeoVector3d.h b/GeoVector3d.h index d7982b5..ef41c9d 100644 --- a/GeoVector3d.h +++ b/GeoVector3d.h @@ -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) ;