Avoid memleak on ColorMap during normal usage
This commit is contained in:
parent
9349158d02
commit
1b5db6cb66
|
@ -2,6 +2,7 @@ include_directories(
|
||||||
"${CMAKE_SOURCE_DIR}/lib_dxf"
|
"${CMAKE_SOURCE_DIR}/lib_dxf"
|
||||||
"${CMAKE_SOURCE_DIR}/utils/idftools"
|
"${CMAKE_SOURCE_DIR}/utils/idftools"
|
||||||
${OPENGL_INCLUDE_DIR}
|
${OPENGL_INCLUDE_DIR}
|
||||||
|
${Boost_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
link_directories(
|
link_directories(
|
||||||
|
@ -17,6 +18,8 @@ add_executable( idfrect idf_rect.cpp )
|
||||||
add_executable( dxf2idf dxf2idfmain.cpp dxf2idf.cpp )
|
add_executable( dxf2idf dxf2idfmain.cpp dxf2idf.cpp )
|
||||||
add_executable( idf2vrml idf2vrml.cpp )
|
add_executable( idf2vrml idf2vrml.cpp )
|
||||||
|
|
||||||
|
add_dependencies( idf2vrml boost )
|
||||||
|
|
||||||
target_link_libraries( dxf2idf lib_dxf idf3 ${wxWidgets_LIBRARIES} )
|
target_link_libraries( dxf2idf lib_dxf idf3 ${wxWidgets_LIBRARIES} )
|
||||||
|
|
||||||
target_link_libraries( idf2vrml idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
target_link_libraries( idf2vrml idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <boost/ptr_container/ptr_map.hpp>
|
||||||
|
|
||||||
#include <idf_helpers.h>
|
#include <idf_helpers.h>
|
||||||
#include <idf_common.h>
|
#include <idf_common.h>
|
||||||
|
@ -63,6 +64,7 @@ extern char* optarg;
|
||||||
extern int optopt;
|
extern int optopt;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
#define CLEANUP do { \
|
#define CLEANUP do { \
|
||||||
setlocale( LC_ALL, "C" ); \
|
setlocale( LC_ALL, "C" ); \
|
||||||
|
@ -122,7 +124,7 @@ bool WriteTriangles( std::ofstream& file, VRML_IDS* vID, VRML_LAYER* layer, bool
|
||||||
bool top, double top_z, double bottom_z, int precision, bool compact );
|
bool top, double top_z, double bottom_z, int precision, bool compact );
|
||||||
inline void TransformPoint( IDF_SEGMENT& seg, double frac, bool bottom,
|
inline void TransformPoint( IDF_SEGMENT& seg, double frac, bool bottom,
|
||||||
double dX, double dY, double angle );
|
double dX, double dY, double angle );
|
||||||
VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap,
|
VRML_IDS* GetColor( boost::ptr_map<const std::string, VRML_IDS>& cmap,
|
||||||
int& index, const std::string& uid );
|
int& index, const std::string& uid );
|
||||||
|
|
||||||
|
|
||||||
|
@ -743,7 +745,7 @@ bool MakeComponents( IDF3_BOARD& board, std::ofstream& file, bool compact )
|
||||||
bool bottom;
|
bool bottom;
|
||||||
IDF3::IDF_LAYER lyr;
|
IDF3::IDF_LAYER lyr;
|
||||||
|
|
||||||
std::map< std::string, VRML_IDS*> cmap; // map colors by outline UID
|
boost::ptr_map< const std::string, VRML_IDS> cmap; // map colors by outline UID
|
||||||
VRML_IDS* vcp;
|
VRML_IDS* vcp;
|
||||||
IDF3_COMP_OUTLINE* pout;
|
IDF3_COMP_OUTLINE* pout;
|
||||||
|
|
||||||
|
@ -861,14 +863,14 @@ bool MakeComponents( IDF3_BOARD& board, std::ofstream& file, bool compact )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap, int& index, const std::string& uid )
|
VRML_IDS* GetColor( boost::ptr_map<const std::string, VRML_IDS>& cmap, int& index, const std::string& uid )
|
||||||
{
|
{
|
||||||
static int refnum = 0;
|
static int refnum = 0;
|
||||||
|
|
||||||
if( index < 2 )
|
if( index < 2 )
|
||||||
index = 2; // 0 and 1 are special (BOARD, UID=NOGEOM_NOPART)
|
index = 2; // 0 and 1 are special (BOARD, UID=NOGEOM_NOPART)
|
||||||
|
|
||||||
std::map<std::string, VRML_IDS*>::iterator cit = cmap.find( uid );
|
boost::ptr_map<const std::string, VRML_IDS>::iterator cit = cmap.find( uid );
|
||||||
|
|
||||||
if( cit == cmap.end() )
|
if( cit == cmap.end() )
|
||||||
{
|
{
|
||||||
|
@ -886,7 +888,7 @@ VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap, int& index, const st
|
||||||
if( showObjectMapping )
|
if( showObjectMapping )
|
||||||
cout << "* " << ostr.str() << " = '" << uid << "'\n";
|
cout << "* " << ostr.str() << " = '" << uid << "'\n";
|
||||||
|
|
||||||
cmap.insert( std::pair<std::string, VRML_IDS*>(uid, id) );
|
cmap.insert( uid, id );
|
||||||
|
|
||||||
if( index >= NCOLORS )
|
if( index >= NCOLORS )
|
||||||
index = 2;
|
index = 2;
|
||||||
|
@ -922,7 +924,7 @@ bool MakeOtherOutlines( IDF3_BOARD& board, std::ofstream& file )
|
||||||
bool bottom;
|
bool bottom;
|
||||||
int nvcont;
|
int nvcont;
|
||||||
|
|
||||||
std::map< std::string, VRML_IDS*> cmap; // map colors by outline UID
|
boost::ptr_map< const std::string, VRML_IDS> cmap; // map colors by outline UID
|
||||||
VRML_IDS* vcp;
|
VRML_IDS* vcp;
|
||||||
OTHER_OUTLINE* pout;
|
OTHER_OUTLINE* pout;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue