Commit 56279c6d authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

IoNg: vector of things of different sizes

parent b050135b
......@@ -140,7 +140,7 @@ public:
/* write functions START */
template<typename T>
void write(String name2,
bool write(String name2,
const T& what,
WriteMode allowOverwrite = NO_OVERWRITE,
typename EnableIf<Loki::TypeTraits<T>::isArith ||
......@@ -152,9 +152,10 @@ public:
dims[0] = 1;
if (allowOverwrite)
overwrite<T>(name, ptr, dims, 1);
return overwrite<T>(name, ptr, dims, 1);
else
internalWrite<T>(name, ptr, dims, 1);
return true;
}
void write(String name2, String what, WriteMode allowOverwrite = NO_OVERWRITE)
......@@ -627,13 +628,21 @@ private:
}
template<typename SomeType>
void overwrite(String name, const void* ptr, hsize_t dims[], SizeType ndims)
bool overwrite(String name, const void* ptr, hsize_t dims[], SizeType ndims)
{
try {
hdf5file_->unlink(name);
} catch (...) {}
} catch (...) {
std::cerr<<"Cannot unlink "<<name<<"\n";
}
internalWrite<SomeType>(name, ptr, dims, ndims);
try {
internalWrite<SomeType>(name, ptr, dims, ndims);
} catch (...) {
return false;
}
return true;
}
template<typename SomeType>
......
......@@ -153,8 +153,11 @@ public:
IoSerializer& ioSerializer,
IoSerializer::WriteMode wM = IoSerializer::NO_OVERWRITE) const
{
bool flag = false;
if (wM == IoSerializer::ALLOW_OVERWRITE)
return overwrite(label, ioSerializer);
flag = overwrite(label, ioSerializer);
if (flag) return;
ioSerializer.createGroup(label);
ioSerializer.write(label + "/nrow_", nrow_);
......@@ -163,12 +166,17 @@ public:
ioSerializer.write(label + "/data_", data_);
}
void overwrite(String label, IoSerializer& ioSerializer) const
bool overwrite(String label, IoSerializer& ioSerializer) const
{
ioSerializer.write(label + "/nrow_", nrow_, IoSerializer::ALLOW_OVERWRITE);
ioSerializer.write(label + "/ncol_", ncol_, IoSerializer::ALLOW_OVERWRITE);
if (nrow_ == 0 || ncol_ == 0) return;
bool b = ioSerializer.write(label + "/nrow_", nrow_, IoSerializer::ALLOW_OVERWRITE);
if (!b) return b;
b = ioSerializer.write(label + "/ncol_", ncol_, IoSerializer::ALLOW_OVERWRITE);
if (!b) return b;
if (nrow_ == 0 || ncol_ == 0) return b;
ioSerializer.write(label + "/data_", data_, IoSerializer::ALLOW_OVERWRITE);
return true;
}
void print(int fd) const
......
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