Commit 734d4cf0 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Avoid use of boost::get for isInitialized()

Replace with visitor pattern that avoids the need for catching the exception.
Update the HDF5Writer to use stringstreams for error message output for
concatenating strings and error codes.
parent 62b12316
......@@ -441,6 +441,34 @@ private:
XdmfArray * const mArray;
};
class XdmfArray::IsInitialized : public boost::static_visitor<bool> {
public:
IsInitialized()
{
}
bool
operator()(const boost::blank & array) const
{
return false;
}
template<typename T>
bool
operator()(const shared_ptr<std::vector<T> > & array) const
{
return true;
}
template<typename T>
bool
operator()(const boost::shared_array<const T> & array) const
{
return true;
}
};
class XdmfArray::Reserve : public boost::static_visitor<void> {
public:
......@@ -739,13 +767,8 @@ XdmfArray::insert(const unsigned int startIndex,
bool
XdmfArray::isInitialized() const
{
try {
boost::get<boost::blank>(mArray);
return false;
}
catch(const boost::bad_get & exception) {
}
return true;
return boost::apply_visitor(IsInitialized(),
mArray);
}
void
......
......@@ -501,6 +501,7 @@ private:
template <typename T> class Insert;
class InsertArray;
class InternalizeArrayPointer;
class IsInitialized;
struct NullDeleter;
template <typename T> class PushBack;
class Reserve;
......
......@@ -800,7 +800,7 @@ XdmfArray::swap(std::vector<T> & array)
currArray->swap(array);
return true;
}
catch(const boost::bad_get& exception) {
catch(const boost::bad_get & exception) {
return false;
}
}
......
......@@ -343,9 +343,11 @@ XdmfHDF5Writer::write(XdmfArray & array,
property,
H5P_DEFAULT);
if(dataset < 0) {
std::stringstream error;
error << "H5Dcreate returned failure in XdmfHDF5Writer::write -- "
<< "dataset: " << dataset;
XdmfError::message(XdmfError::FATAL,
"H5Dcreate returned failure in "
"XdmfHDF5Writer::write -- status: " + dataset);
error.str());
}
status = H5Pclose(property);
}
......@@ -420,9 +422,11 @@ XdmfHDF5Writer::write(XdmfArray & array,
NULL) ;
if(status < 0) {
std::stringstream error;
error << "H5Dset_extent returned failure in XdmfHDF5Writer::write "
<< "-- status: " << status;
XdmfError::message(XdmfError::FATAL,
"H5Dset_extent returned failure in "
"XdmfHDF5Writer::write -- status: " + status);
error.str());
}
}
......@@ -434,9 +438,11 @@ XdmfHDF5Writer::write(XdmfArray & array,
array.getValuesInternal());
if(status < 0) {
std::stringstream error;
error << "H5Dwrite returned failure in XdmfHDF5Writer::write "
<< "-- status: " << status;
XdmfError::message(XdmfError::FATAL,
"H5Dwrite returned failure in XdmfHDF5Writer::write "
"-- status: " + status);
error.str());
}
if(dataspace != H5S_ALL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment