avec le petit bout de code en fin de message, les images d'olena
sont compatibles avec les conteneurs de la bibliothèque std
et avec ses algos.
pour un type I d'image, il suffit de former
std::container< boxed<I> > ou std::container< boxed<const I> >
et pour accéder aux images, il suffit de sortir l'image de la boîte.
avec un vecteur v :
unbox(v[0]).npoints()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
template <class T>
struct boxed {
boxed(T ref) : ref(ref) {}
boxed(const boxed<T>& rhs) : ref(rhs.ref) {}
boxed<T>& operator=(boxed<T>& rhs) { this->ref = rhs.ref; return
*this; }
operator T() { return ref; }
T& unbox() { return ref; }
const T& unbox() const { return ref; }
friend class boxed<const T>;
private:
mutable T ref;
};
template <class T>
struct boxed <const T> {
boxed(const T& ref) : ref(const_cast<T&>(ref)) {}
boxed(const boxed<T>& rhs) : ref(const_cast<T&>(rhs.ref)) {}
boxed(const boxed<const T>& rhs) : ref(const_cast<T&>(rhs.ref)) {}
boxed<const T>& operator=(const boxed<const T>& rhs)
{
this->ref = const_cast<T&>(rhs.ref);
return *this;
}
operator const T() const { return ref; }
const T& unbox() const { return ref; }
private:
mutable T ref;
};
template <class T> T& unbox(boxed<T>& b) {return b.unbox(); }
template <class T> const T& unbox(const boxed<T>& b) {return
b.unbox(); }