Mutable

Luis Ibanez ibanez at cs.unc.edu
Thu Mar 9 15:41:07 EST 2000


Hi,

This is one of the new things we learned
recently with the VIGRA code...

The mutable keyword allow us to modify the
value of a variable belonging to a "const" class.
(or just change its value inside a "const" method)

----

In our case, we keep explicitly in the image class,
the values of the maximum and minimum value of
the voxels.

the maximum is in     cDataMax
the minimum is in      cDataMin

and the boolean       cDataRangeDefined
indicates if the min and max values are valid or
need to be recomputed.

The reason to keep this data in the image is that
min and max are used very often, and we don't
want to recompute them every time.

---

In principle asking for the min or max of an image
is an operation that doesn't change the image. but
in our case, if    (cDataRangeDefined==false)
(ie the min and max are invalid) the min and max
will be recompute and *stored* in the image.

That precluded the dataMin() and dataMax()
methods to be "const".

---

The keyword "mutable" allow us to declare the methods
dataMin() and dataMax() as "const" methods, and to say
the compiler that we want to change the values of
cDataMin and cDataMax in them.

The idea is tha cDataMin and cDataMax don't really represent
the state of the image class, they serve only to push a little bit of
performance. With "mutable" we are saying to the compiler
that we don't consider cDataMin and cDataMax to be part
of the state of the class.

Any way, the "mutable" is something that we need to think
twice before using it.




Luis.








More information about the Insight-developers mailing list