EgtGeomKernel :
- cambiato Load, con uso di NgeReader.
This commit is contained in:
+206
@@ -0,0 +1,206 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2014
|
||||
//----------------------------------------------------------------------------
|
||||
// File : NgeReader.cpp Data : 14.04.14 Versione : 1.5d5
|
||||
// Contenuto : Implementazione della classe NgeReader.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 14.04.14 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "NgeReader.h"
|
||||
#include "NgeKeyW.h"
|
||||
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::Init( const std::string& sFileIn)
|
||||
{
|
||||
m_iPosStart = string::npos ;
|
||||
m_sLine.reserve( 128) ;
|
||||
m_sToken.reserve( 48) ;
|
||||
return m_Scan.Init( sFileIn) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::Close( void)
|
||||
{
|
||||
return m_Scan.Terminate() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
NgeReader::GetCurrPos( void)
|
||||
{
|
||||
return m_Scan.GetCurrLineNbr() ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::GetToken( std::string& sToken, const char* szSep, bool bEndL)
|
||||
{
|
||||
// se necessario, lettura nuova linea
|
||||
if ( m_iPosStart == string::npos) {
|
||||
if ( ! m_Scan.GetLine( m_sLine))
|
||||
return false ;
|
||||
m_iPosStart = 0 ;
|
||||
}
|
||||
// se richiesta ricerca separatore
|
||||
if ( szSep != nullptr) {
|
||||
// cerco il primo separatore nella linea
|
||||
string::size_type iPosEnd = m_sLine.find_first_of( szSep, m_iPosStart) ;
|
||||
sToken = m_sLine.substr( m_iPosStart, iPosEnd - m_iPosStart) ;
|
||||
// passo al prossimo
|
||||
m_iPosStart = m_sLine.find_first_not_of( szSep, iPosEnd) ;
|
||||
if ( bEndL)
|
||||
return ( m_iPosStart == string::npos) ;
|
||||
else
|
||||
return ( m_iPosStart != string::npos) ;
|
||||
}
|
||||
// altrimenti, deve essere tutto con endl obbligatorio
|
||||
else {
|
||||
sToken = m_sLine.substr( m_iPosStart, string::npos) ;
|
||||
m_iPosStart = string::npos ;
|
||||
return bEndL ;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadUchar( unsigned char& ucVal, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
int nVal ;
|
||||
if ( ! FromString( m_sToken, nVal))
|
||||
return false ;
|
||||
ucVal = nVal ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadBool( bool& bVal, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, bVal) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadInt( int& nVal, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, nVal) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadDouble( double& dVal, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, dVal) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadVector( Vector3d& vtV, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, vtV) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadPoint( Point3d& ptP, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, ptP) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadPointW( Point3d& ptP, double& dW, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, ptP, dW) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadFrame( Frame3d& frF, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, frF) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadString( string& sVal, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// lo copio nella stringa
|
||||
sVal = m_sToken ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadKey( int& nKey)
|
||||
{
|
||||
// recupero la linea
|
||||
if ( ! GetToken( m_sToken, nullptr, true))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
for ( int i = 0 ; i <= NGE_LAST_ID ; ++ i) {
|
||||
if ( m_sToken == NgeAscKeyW[i]) {
|
||||
nKey = i ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
NgeReader::ReadCol( Color& cCol, const char* szSep, bool bEndL)
|
||||
{
|
||||
// recupero il token
|
||||
if ( ! GetToken( m_sToken, szSep, bEndL))
|
||||
return false ;
|
||||
// ricavo il valore
|
||||
return FromString( m_sToken, cCol) ;
|
||||
}
|
||||
Reference in New Issue
Block a user