Commit 39961e00 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Raise an error if the application tries to update an immutable property.

parent bdecb3b2
......@@ -1363,6 +1363,7 @@ IZgyWriter::reopen(const ZgyWriterArgs& args)
ZgyWriterArgs newargs = ZgyWriterArgs()
.metafrom(reader)
.filename(args._filename);
const ZgyWriterArgs oldargs = newargs;
std::pair<bool,double> value =
reader->readconst(size3i_t{0,0,0}, reader->size(), 0, true);
reader->close();
......@@ -1388,6 +1389,19 @@ IZgyWriter::reopen(const ZgyWriterArgs& args)
.compressor(args._compressor)
.lodcompressor(args._lodcompressor);
// Since the current implementation creates a completely new empty file
// I could in fact have allowed changing these supposedly immutable
// properties. But code using that feature would break after a proper
// implementation is done. So, better to raise an error.
if (newargs._size != oldargs._size)
throw Errors::ZgyUserError("Cannot change the size of a ZGY file");
if (newargs._bricksize != oldargs._bricksize)
throw Errors::ZgyUserError("Cannot change the brick size of a ZGY file");
if (newargs._datatype != oldargs._datatype)
throw Errors::ZgyUserError("Cannot change the data type of a ZGY file");
if (newargs._datarange != oldargs._datarange)
throw Errors::ZgyUserError("Cannot change the data range of a ZGY file");
std::shared_ptr<IZgyWriter> writer = IZgyWriter::open(newargs);
// Cast is ok because all supported data types (int8, int16, float)
// can be cast to a single precision float without loss of accuracy.
......
Supports Markdown
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