diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 60d7285..1f6bfb5 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/NgeWriter.cpp b/NgeWriter.cpp index 681e4d1..1328353 100644 --- a/NgeWriter.cpp +++ b/NgeWriter.cpp @@ -23,23 +23,23 @@ using namespace std ; //---------------------------------------------------------------------------- -inline bool -WriteStringOutTxt( gzFile OutTxtFile, const char* szVal, const char* szSep, bool bEndL) +static bool +WriteStringOutTxt( gzFile OutFile, const char* szVal, const char* szSep, bool bEndL) { // verifico apertura file - if ( OutTxtFile == nullptr) + if ( OutFile == nullptr) return false ; // scrivo stringa - if ( gzputs( OutTxtFile, szVal) == Z_ERRNO) + if ( gzputs( OutFile, szVal) == Z_ERRNO) return false ; // se fornito, scrivo separatore if ( szSep != nullptr && szSep[0] != '\0') { - if ( gzputs( OutTxtFile, szSep) == Z_ERRNO) + if ( gzputs( OutFile, szSep) == Z_ERRNO) return false ; } // se richiesto, scrivo fine linea if ( bEndL) { - if ( gzputs( OutTxtFile, "\r\n") == Z_ERRNO) + if ( gzputs( OutFile, "\r\n") == Z_ERRNO) return false ; } return true ; @@ -50,25 +50,22 @@ bool NgeWriter::Init( const string& sFileOut, int nFlag) { // salvo tipo file - m_bBinary = ( nFlag == GDB_SV_BIN) ; + m_bBinary = ( nFlag == GDB_SV_BIN || nFlag == GDB_SV_CMPBIN) ; // apertura del file di uscita - if ( m_bBinary) { - m_OutBinFile.open( stringtoW( sFileOut), ios::out | ios::binary, _SH_DENYWR) ; - return m_OutBinFile.good() ; + if ( nFlag == GDB_SV_TXT || nFlag == GDB_SV_BIN) { + m_OutFile = gzopen_w( stringtoW( sFileOut), "wbT") ; + return ( m_OutFile != nullptr) ; } - else { - if ( nFlag == GDB_SV_TXT) - m_OutTxtFile = gzopen_w( stringtoW( sFileOut), "wbT") ; - else // GDB_SV_CMPTXT - m_OutTxtFile = gzopen_w( stringtoW( sFileOut), "wb") ; - if ( m_OutTxtFile == nullptr) + else { // GDB_SV_CMPTXT o GDB_SV_CMPBIN + m_OutFile = gzopen_w( stringtoW( sFileOut), "wb") ; + if ( m_OutFile == nullptr) return false ; const int DIM_BUFFER = 65536 ; - if ( gzbuffer( m_OutTxtFile, DIM_BUFFER) != Z_OK) + if ( gzbuffer( m_OutFile, DIM_BUFFER) != Z_OK) return false ; const int COMPR_LEVEL = 3 ; // 0 = no compression ... 9 = max compression - if ( gzsetparams( m_OutTxtFile, COMPR_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) + if ( gzsetparams( m_OutFile, COMPR_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) return false ; return true ; } @@ -78,20 +75,12 @@ NgeWriter::Init( const string& sFileOut, int nFlag) bool NgeWriter::Close( void) { - if ( m_bBinary) { - bool bOk = ( m_OutBinFile.good() && m_OutBinFile.is_open()) ; - if ( m_OutBinFile.is_open()) - m_OutBinFile.close() ; + if ( m_OutFile != nullptr) { + bool bOk = ( gzclose( m_OutFile) == Z_OK) ; + m_OutFile = nullptr ; return bOk ; } - else { - if ( m_OutTxtFile != nullptr) { - bool bOk = ( gzclose( m_OutTxtFile) == Z_OK) ; - m_OutTxtFile = nullptr ; - return bOk ; - } - return true ; - } + return true ; } //---------------------------------------------------------------------------- @@ -99,13 +88,12 @@ bool NgeWriter::WriteUchar( unsigned char ucVal, const char* szSep, bool bEndL) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &ucVal, sizeof( ucVal)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &ucVal, sizeof( ucVal)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( ucVal).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( ucVal).c_str(), szSep, bEndL) ; } } @@ -114,13 +102,12 @@ bool NgeWriter::WriteBool( bool bVal, const char* szSep, bool bEndL) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &bVal, sizeof( bVal)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &bVal, sizeof( bVal)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( bVal).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( bVal).c_str(), szSep, bEndL) ; } } @@ -129,13 +116,12 @@ bool NgeWriter::WriteInt( int nVal, const char* szSep, bool bEndL) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &nVal, sizeof( nVal)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &nVal, sizeof( nVal)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( nVal).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( nVal).c_str(), szSep, bEndL) ; } } @@ -144,13 +130,12 @@ bool NgeWriter::WriteDouble( double dVal, const char* szSep, bool bEndL, int nPrec) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &dVal, sizeof( dVal)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &dVal, sizeof( dVal)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( dVal, nPrec).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( dVal, nPrec).c_str(), szSep, bEndL) ; } } @@ -159,15 +144,14 @@ bool NgeWriter::WriteString( const string& sVal, const char* szSep, bool bEndL) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - int nDim = int( sVal.size()) ; - m_OutBinFile.write( (char*) &nDim, sizeof( nDim)) ; - m_OutBinFile.write( sVal.c_str(), sVal.size()) ; - return m_OutBinFile.good() ; + int nDim = ssize( sVal) ; + return ( gzwrite( m_OutFile, (char*) &nDim, sizeof( nDim)) > 0 && + ( nDim == 0 || gzwrite( m_OutFile, sVal.c_str(), sVal.size()) > 0)) ; } else { - return WriteStringOutTxt( m_OutTxtFile, sVal.c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, sVal.c_str(), szSep, bEndL) ; } } @@ -176,13 +160,12 @@ bool NgeWriter::WriteVector( const Vector3d& vtV, const char* szSep, bool bEndL, int nPrec) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &vtV.v, sizeof( vtV.v)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &vtV.v, sizeof( vtV.v)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( vtV, nPrec).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( vtV, nPrec).c_str(), szSep, bEndL) ; } } @@ -191,13 +174,12 @@ bool NgeWriter::WritePoint( const Point3d& ptP, const char* szSep, bool bEndL, int nPrec) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &ptP.v, sizeof( ptP.v)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &ptP.v, sizeof( ptP.v)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( ptP, nPrec).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( ptP, nPrec).c_str(), szSep, bEndL) ; } } @@ -206,14 +188,13 @@ bool NgeWriter::WritePointW( const Point3d& ptP, double dW, const char* szSep, bool bEndL, int nPrecP, int nPrecW) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &ptP.v, sizeof( ptP.v)) ; - m_OutBinFile.write( (char*) &dW, sizeof( dW)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &ptP.v, sizeof( ptP.v)) > 0 && + gzwrite( m_OutFile, (char*) &dW, sizeof( dW)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( ptP, dW, nPrecP, nPrecW).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( ptP, dW, nPrecP, nPrecW).c_str(), szSep, bEndL) ; } } @@ -222,16 +203,15 @@ bool NgeWriter::WriteFrame( const Frame3d& frF, const char* szSep, bool bEndL, int nPrecP, int nPrecV) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &frF.Orig().v, sizeof( frF.Orig().v)) ; - m_OutBinFile.write( (char*) &frF.VersX().v, sizeof( frF.VersX().v)) ; - m_OutBinFile.write( (char*) &frF.VersY().v, sizeof( frF.VersY().v)) ; - m_OutBinFile.write( (char*) &frF.VersZ().v, sizeof( frF.VersZ().v)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &frF.Orig().v, sizeof( frF.Orig().v)) > 0 && + gzwrite( m_OutFile, (char*) &frF.VersX().v, sizeof( frF.VersX().v)) > 0 && + gzwrite( m_OutFile, (char*) &frF.VersY().v, sizeof( frF.VersY().v)) > 0 && + gzwrite( m_OutFile, (char*) &frF.VersZ().v, sizeof( frF.VersZ().v)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( frF, nPrecP, nPrecV).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( frF, nPrecP, nPrecV).c_str(), szSep, bEndL) ; } } @@ -243,13 +223,12 @@ NgeWriter::WriteKey( int nKey) return false ; if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; - m_OutBinFile.write( (char*) &NgeBinKeyW[nKey], sizeof( int)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) &NgeBinKeyW[nKey], sizeof( int)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, NgeAscKeyW[nKey].c_str(), nullptr, true) ; + return WriteStringOutTxt( m_OutFile, NgeAscKeyW[nKey].c_str(), nullptr, true) ; } } @@ -258,18 +237,17 @@ bool NgeWriter::WriteCol( const Color& cCol, const char* szSep, bool bEndL) { if ( m_bBinary) { - if ( ! m_OutBinFile.is_open()) + if ( m_OutFile == nullptr) return false ; unsigned char ucCol[4] ; ucCol[0] = cCol.GetIntRed() ; ucCol[1] = cCol.GetIntGreen() ; ucCol[2] = cCol.GetIntBlue() ; ucCol[3] = cCol.GetIntAlpha() ; - m_OutBinFile.write( (char*) ucCol, sizeof( ucCol)) ; - return m_OutBinFile.good() ; + return ( gzwrite( m_OutFile, (char*) ucCol, sizeof( ucCol)) > 0) ; } else { - return WriteStringOutTxt( m_OutTxtFile, ToString( cCol).c_str(), szSep, bEndL) ; + return WriteStringOutTxt( m_OutFile, ToString( cCol).c_str(), szSep, bEndL) ; } } @@ -277,9 +255,11 @@ NgeWriter::WriteCol( const Color& cCol, const char* szSep, bool bEndL) bool NgeWriter::WriteRemark( const string& sVal) { - if ( m_bBinary) + if ( m_bBinary) { return true ; - else - return ( WriteStringOutTxt( m_OutTxtFile, "//", nullptr, false) && - WriteStringOutTxt( m_OutTxtFile, sVal.c_str(), nullptr, true)) ; + } + else { + return ( WriteStringOutTxt( m_OutFile, "//", nullptr, false) && + WriteStringOutTxt( m_OutFile, sVal.c_str(), nullptr, true)) ; + } } diff --git a/NgeWriter.h b/NgeWriter.h index 3fc05b3..63b0139 100644 --- a/NgeWriter.h +++ b/NgeWriter.h @@ -16,7 +16,6 @@ #include "NgeConst.h" #include "/EgtDev/Include/EGkPoint3d.h" #include "/EgtDev/Include/EGkColor.h" -#include struct gzFile_s ; @@ -24,7 +23,7 @@ struct gzFile_s ; class NgeWriter { public : - NgeWriter( void) : m_bBinary( false), m_OutTxtFile( nullptr) {} + NgeWriter( void) : m_bBinary( false), m_OutFile( nullptr) {} ~NgeWriter( void) { Close() ; } bool Init( const std::string& sFileOut, int nFlag) ; @@ -44,9 +43,6 @@ class NgeWriter bool WriteRemark( const std::string& sVal /* bEndL = true*/) ; private : - bool m_bBinary ; - // per file binari - std::ofstream m_OutBinFile ; - // per file ASCII - gzFile_s* m_OutTxtFile ; + bool m_bBinary ; + gzFile_s* m_OutFile ; } ;