From Ulrich Hertlein, "Based on the exchange on osg-users I went ahead and reworked shp/XBaseParser to avoid

weird behaviour (closing stdin) and leaking file descriptors, as well as some const-ness."
This commit is contained in:
Robert Osfield 2013-08-01 10:28:12 +00:00
parent 46ec50aecb
commit 14f63cbe67
3 changed files with 12 additions and 11 deletions

View File

@ -67,7 +67,7 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter
osg::Geode * geode = sp.getGeode();
unsigned int i = 0;
ESRIShape::XBaseParser::ShapeAttributeListList::iterator it, end = xbp.getAttributeList().end();
ESRIShape::XBaseParser::ShapeAttributeListList::const_iterator it, end = xbp.getAttributeList().end();
for (it = xbp.getAttributeList().begin(); it != end; ++it, ++i)
{
geode->getDrawable(i)->setUserData(it->get());

View File

@ -80,12 +80,12 @@ bool XBaseFieldDescriptor::read(int fd)
}
XBaseParser::XBaseParser(const std::string fileName):
XBaseParser::XBaseParser(const std::string& fileName):
_valid(false)
{
int fd = 0;
if (fileName.empty() == false)
if (!fileName.empty())
{
int fd = 0;
#ifdef WIN32
if( (fd = open( fileName.c_str(), O_RDONLY | O_BINARY )) < 0 )
#else
@ -93,11 +93,13 @@ XBaseParser::XBaseParser(const std::string fileName):
#endif
{
perror( fileName.c_str() );
return;
}
else
{
_valid = parse(fd);
close(fd);
}
}
_valid = parse(fd);
}
bool XBaseParser::parse(int fd)
@ -208,8 +210,6 @@ bool XBaseParser::parse(int fd)
delete [] record;
close (fd);
return true;
}

View File

@ -62,9 +62,10 @@ class XBaseParser
typedef std::vector< osg::ref_ptr<osgSim::ShapeAttributeList> > ShapeAttributeListList;
XBaseParser(const std::string fileName);
XBaseParser(const std::string& fileName);
~XBaseParser() {}
ShapeAttributeListList & getAttributeList() { return _shapeAttributeListList; }
const ShapeAttributeListList & getAttributeList() const { return _shapeAttributeListList; }
private: