Commit cedfc1af authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

The ImportAndResetPointList() has now a parameter more that

allows it pre-reserve the list (std::vector) to some (over)estimated
length.

This function and the ImportPointList() can now issue a simple warning
to inform user that something may go wrong.

M    importexport.cpp
M    importexport.h
parent d515ee65
Loading
Loading
Loading
Loading
+18 −3
Original line number Original line Diff line number Diff line
@@ -195,7 +195,8 @@ size_t ExportPointList(std::vector< T /**/> const &PList,
template <class T>
template <class T>
size_t ImportAndResetPointList(std::vector< T /**/> &PList,
size_t ImportAndResetPointList(std::vector< T /**/> &PList,
										 i3d::Vector3d<float>* Pcentre,
										 i3d::Vector3d<float>* Pcentre,
										 const char* fileName)
										 const char* fileName,
										 const size_t estCount)
{
{
	std::ifstream pointFile(fileName);
	std::ifstream pointFile(fileName);
	if (!pointFile.is_open()) {
	if (!pointFile.is_open()) {
@@ -205,6 +206,8 @@ size_t ImportAndResetPointList(std::vector< T /**/> &PList,
	}
	}


	PList.clear();
	PList.clear();
	//if a reservation hint was supplied, use it...
	if (estCount > 0) PList.reserve(estCount);


	//centre point
	//centre point
	double cx=0., cy=0., cz=0.;
	double cx=0., cy=0., cz=0.;
@@ -246,6 +249,11 @@ size_t ImportAndResetPointList(std::vector< T /**/> &PList,
	DEBUG_REPORT("Successfully imported " << PList.size()
	DEBUG_REPORT("Successfully imported " << PList.size()
					<< " points from " << fileName); 
					<< " points from " << fileName); 


	if (PList.size() > estCount)
		REPORT("Warning: reserved only for " << estCount
					<< " points but imported more ("
					<< PList.size() << ")!");

	return (PList.size());
	return (PList.size());
}
}


@@ -304,6 +312,11 @@ size_t ImportPointList(std::vector< T /**/> &PList,
	DEBUG_REPORT("Successfully imported " << counter
	DEBUG_REPORT("Successfully imported " << counter
					<< " points from " << fileName); 
					<< " points from " << fileName); 


	if (counter != maxCnt)
		REPORT("Warning: expected " << maxCnt
					<< " points but imported less ("
					<< counter << ")!");

	return (counter);
	return (counter);
}
}


@@ -344,11 +357,13 @@ size_t ExportPointList(std::vector< Molecule > const &PList,
template
template
size_t ImportAndResetPointList(std::vector< i3d::Vector3d<float> > &PList,
size_t ImportAndResetPointList(std::vector< i3d::Vector3d<float> > &PList,
										 i3d::Vector3d<float>* Pcentre,
										 i3d::Vector3d<float>* Pcentre,
										 const char* fileName);
										 const char* fileName,
										 const size_t estCount);
template
template
size_t ImportAndResetPointList(std::vector< Molecule > &PList,
size_t ImportAndResetPointList(std::vector< Molecule > &PList,
										 i3d::Vector3d<float>* Pcentre,
										 i3d::Vector3d<float>* Pcentre,
										 const char* fileName);
										 const char* fileName,
										 const size_t estCount);


template
template
size_t ImportPointList(std::vector< i3d::Vector3d<float> > &PList,
size_t ImportPointList(std::vector< i3d::Vector3d<float> > &PList,
+8 −1
Original line number Original line Diff line number Diff line
@@ -80,6 +80,12 @@ size_t ExportPointList(std::vector< T /**/> const &PList,
 * \param[out] PList		a vector (a list) of points to be imported
 * \param[out] PList		a vector (a list) of points to be imported
 * \param[out] Pcentre	an average coordinate of the imported points
 * \param[out] Pcentre	an average coordinate of the imported points
 * \param[in] fileName	filename of the input file
 * \param[in] fileName	filename of the input file
 * \param[in] estCount	(over)estimate of how many points are ought to be read
 *
 * \note One may use the \e estCount parameter to aid the routine, which
 * can reserve adequate buffer, which makes the program run considerably
 * faster and which allows to obtain continuous IDs (in dot lists that support
 * dot IDs). Therefore, a decent overestimate is better than underestimate.
 *
 *
 * \return The number of actually read points; basically, the length
 * \return The number of actually read points; basically, the length
 * of the new point list.
 * of the new point list.
@@ -87,7 +93,8 @@ size_t ExportPointList(std::vector< T /**/> const &PList,
template <class T>
template <class T>
size_t ImportAndResetPointList(std::vector< T /**/> &PList,
size_t ImportAndResetPointList(std::vector< T /**/> &PList,
										 i3d::Vector3d<float>* Pcentre,
										 i3d::Vector3d<float>* Pcentre,
										 const char* fileName);
										 const char* fileName,
										 const size_t estCount=0);


/**
/**
 * Reads the input file \e fileName with point coordinates and fills
 * Reads the input file \e fileName with point coordinates and fills