Commit 788c3128 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new concept of container of const

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1199
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent e7e9fdb8
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_dec.h,v 1.6 2002-12-13 23:48:28 forbrig Exp $
* $Id: array_dec.h,v 1.7 2002-12-16 20:16:06 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -11,14 +11,15 @@
*
* \note
* This should never be included directly. Use array.h or binarray.h instead.
*
* \todo
* Do we need the using directive?
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 08/12/2002 V1.0 copied from libcontxx
* - 16/12/2002 V1.1 (thof)
* - introduced new concept of const-correctness;
* this should work for passing arrays as intrinsic
* references for const element type
*
* ============================================================================
*/
......@@ -27,9 +28,9 @@
#ifndef AFF_ARRAY_DEC_H_VERSION
#define AFF_ARRAY_DEC_H_VERSION \
"AFF_ARRAY_DEC_H V1.0 "
"AFF_ARRAY_DEC_H V1.1"
#define AFF_ARRAY_DEC_H_CVSID \
"$Id: array_dec.h,v 1.6 2002-12-13 23:48:28 forbrig Exp $"
"$Id: array_dec.h,v 1.7 2002-12-16 20:16:06 forbrig Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/lib/strided.h>
......@@ -82,7 +83,7 @@ namespace prebuilt {
*/
template<class T>
class Array:
public aff::Strided, public aff::SharedHeap<T>
public Array<const T>
{
public:
/*! \name Various types
......@@ -95,26 +96,12 @@ namespace prebuilt {
* \sa aff::util::Qualified<T>
*/
//@{
//! Type of representation
typedef aff::SharedHeap<T> Trepresentation;
//! Type of subscriptor
typedef aff::Strided Tshape;
//! Element type
typedef typename Trepresentation::Tvalue Tvalue;
//! Type of pointer to element
typedef typename Trepresentation::Tpointer Tpointer;
//! Type of reference to element
typedef typename Trepresentation::Treference Treference;
//! Type of const reference to element
typedef typename Trepresentation::Tconst_reference Tconst_reference;
//! Type to be used as data representation
typedef typename Trepresentation::Tmutable_value Tmutable_value;
//! Type to be used as element for const version
typedef typename Trepresentation::Tconst_value Tconst_value;
//! Type of this array
typedef Array<T> Tcontainer;
//! base is container of const (see specialization below)
typedef Array<const T> Tbase;
//! Type of the array of const values
typedef Array<Tconst_value> Tcontainer_of_const;
typedef Tbase Tcontainer_of_const;
/*! \brief short for Tcontainer_of_const
*
* We generally distinguish between constness of the array and
......@@ -133,7 +120,17 @@ namespace prebuilt {
* myfunction(A);
* \endcode
*/
typedef Array<Tconst_value> Tcoc;
typedef Tbase Tcoc;
//! Type of representation
typedef Tbase::Trepresentation Trepresentation;
//! Type of subscriptor
typedef Tbase::Tshape Tshape;
//! Element type
typedef T Tvalue;
//! Type of pointer to element
typedef T* Tpointer;
//! Type of reference to element
typedef T& Treference;
//@}
/*-----------------------------------------------------------------*/
......@@ -150,54 +147,158 @@ namespace prebuilt {
*/
//@{
//! construct from nothing (empty)
Array() { }
Array(): Tbase() { }
//! construct from shape and representation
Array(const Tshape& shape,
const Trepresentation& representation);
const Trepresentation& representation):
Tbase(shape, representation) { }
//! construct from shape (defines size and layout)
explicit Array(const Tshape& shape);
explicit Array(const Tshape& shape):
Tbase(shape) { }
//! construct from index range limit
explicit Array(const Tsize& s0);
explicit Array(const Tsize& s0):
Tbase(s0) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1);
Array(const Tsize& s0, const Tsize& s1):
Tbase(s0, s1) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1, const Tsize& s2);
Array(const Tsize& s0, const Tsize& s1, const Tsize& s2):
Tbase(s0, s1, s2) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1,
const Tsize& s2, const Tsize& s3);
const Tsize& s2, const Tsize& s3):
Tbase(s0, s1, s2, s3) { }
//@}
/*-----------------------------------------------------------------*/
/*! \name Access operators
/*! \name Data modification functions
*
* These functions are declared protected in the base class. Make them
* visible here.
*/
//@{
//! full dimensionality access
Tvalue& operator()(const TIndexVec& index)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(index))); }
{ return(this->Tbase::operator()(index)); }
//! access from 1 index value
Tvalue& operator()(const Tsubscript& i0)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0))); }
{ return(this->Tbase::operator()(i0)); }
//! access from 2 index values
Tvalue& operator()(const Tsubscript& i0,
const Tsubscript& i1)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1))); }
const Tsubscript& i1)
{ return(this->Tbase::operator()(i0, i1)); }
//! access from 3 index values
Tvalue& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2))); }
const Tsubscript& i1,
const Tsubscript& i2)
{ return(this->Tbase::operator()(i0, i1, i2)); }
//! access from 4 index values
Tvalue& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2, i3))); }
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3)
{ return(this->Tbase::operator()(i0, i1, i2, i3)); }
//! set whole array to value
Array& operator=(const T& value)
{ return(this->Tbase::operator=(value)); }
//! copy in from other array
template<class TT>
Array& copyin(const Array<TT>& a)
{ return(this->Tbase::copyin(a)); }
//@}
//! tricky: only this class allows the conversion
operator Trepresentation()
{ return (Trepresentation(this->Tbase)); }
}; // class Array
/*======================================================================*/
/*! \brief specialization for const data
*/
template<class T>
class Array<const T>:
public aff::Strided, private aff::SharedHeap<T>
{
public:
/*! \name Various types
*
* In particular due to our concept of const-correctness we need
* several typedefs to declare types derived from the element type of
* the array.
*
* \sa \ref sec_main_constness
* \sa aff::util::Qualified<T>
*/
//@{
//! Type of representation
typedef aff::SharedHeap<T> Trepresentation;
//! Type of subscriptor
typedef aff::Strided Tshape;
//! Element type
typedef const T Tvalue;
//! Type of pointer to element
typedef const T* Tpointer;
//! Type of reference to element
typedef const T& Treference;
//! Type of this array
typedef Array<T> Tcontainer;
//! Type of the array of const values
typedef Tcontainer Tcontainer_of_const;
/*! \brief short for Tcontainer_of_const
*
* We generally distinguish between constness of the array and
* constness of the contained data (see \ref sec_main_constness).
* There will be situations, when you want to promise that a function
* will not change the contents of an array. In this case you may use
* a declaration (prototype) like
* \code
* typedef aff::Array<int> Tmyarray;
* void myfunction(const Tmyarray::Tcoc& array);
* \endcode
* and you may use this function like
* \code
* Tmyarray A(6,7);
* A=4;
* myfunction(A);
* \endcode
*/
typedef Tcontainer Tcoc;
//@}
/*-----------------------------------------------------------------*/
/*! \name Constructors
*
* \note
* We use the default copy constructor, which automatically invokes
* the copy constructors of the base classes aff::Strided and
* aff::SharedHeap<T>. This essentially is a shallow copy of the
* array, i.e. the copy will reference to the same elements in memory.
* See aff::Array<T>::copyin() and aff::Array<T>::copyout() for deep
* copy operations.
*/
//@{
//! construct from nothing (empty)
Array() { }
//! construct from shape and representation
Array(const Tshape& shape,
const Trepresentation& representation);
//! construct from shape (defines size and layout)
explicit Array(const Tshape& shape);
//! construct from index range limit
explicit Array(const Tsize& s0);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1, const Tsize& s2);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1,
const Tsize& s2, const Tsize& s3);
//@}
/*-----------------------------------------------------------------*/
......@@ -212,26 +313,26 @@ namespace prebuilt {
*/
//@{
//! full dimensionality access
const Tvalue& operator()(const TIndexVec& index) const
const T& operator()(const TIndexVec& index) const
{ return(this->Trepresentation::operator[](
this->Tshape::offset(index))); }
//! access from 1 index value
const Tvalue& operator()(const Tsubscript& i0) const
const T& operator()(const Tsubscript& i0) const
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0))); }
//! access from 2 index values
const Tvalue& operator()(const Tsubscript& i0,
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1) const
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1))); }
//! access from 3 index values
const Tvalue& operator()(const Tsubscript& i0,
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2) const
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2))); }
//! access from 4 index values
const Tvalue& operator()(const Tsubscript& i0,
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3) const
......@@ -241,13 +342,6 @@ namespace prebuilt {
/*-----------------------------------------------------------------*/
//! conversion to container of const values
operator Tcontainer_of_const() const
{
Tcontainer_of_const retval(*this, *this);
return(retval);
}
/*! \name Shape access
*/
//@{
......@@ -265,13 +359,7 @@ namespace prebuilt {
Tsize size() const
{ return(this->Tshape::size()); }
//@}
//! set whole array to value
Array& operator=(const T& value);
/*! \name Deep copy
*/
//@{
/*! \brief create an identical copy (deep copy) of this array
*
* This is mainly used to create a copy of a truely identical array
......@@ -292,6 +380,14 @@ namespace prebuilt {
*/
Array copyout() const;
//! offer conversion only to constant version of representation
operator Trepresentation::Tcoc() const
{ return (*this); }
/*-----------------------------------------------------------------*/
// here starts the PROTECTED section!
// ----------------------------------
protected:
/*! \brief copy values (deep copy) from other array of convertible type
*
* This member function reads the element values of another array of
......@@ -317,9 +413,52 @@ namespace prebuilt {
*/
template<class TT>
Array& copyin(const Array<TT>& a);
/*-----------------------------------------------------------------*/
//! set whole array to value
Array& operator=(const T& value);
/*-----------------------------------------------------------------*/
/*! \name Access operators
*/
//@{
//! full dimensionality access
T& operator()(const TIndexVec& index)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(index))); }
//! access from 1 index value
T& operator()(const Tsubscript& i0)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0))); }
//! access from 2 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1))); }
//! access from 3 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2))); }
//! access from 4 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2, i3))); }
//@}
}; // class Array
/*-----------------------------------------------------------------*/
//! conversion to full representation is protected
operator Trepresentation()
{ return (*this); }
}; // class Array<const T>
#ifdef AFF_PREBUILT
} // namespace prebuilt
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_def.h,v 1.4 2002-12-13 23:48:29 forbrig Exp $
* $Id: array_def.h,v 1.5 2002-12-16 20:16:06 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -15,15 +15,16 @@
* yourself. It is included via array.h if you use the full template evrsion
* of the library.
*
* \todo
* Do we need the using directive?
*
* \todo rework the whole aff::Array definitions
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 08/12/2002 V1.0 copied from libcontxx
* - 16/12/2002 V1.1 (thof)
* - definitions are now for base class
* (i.e. spcialization for const T)
* - added standard constructors
*
* ============================================================================
*/
......@@ -36,9 +37,11 @@
#ifndef AFF_ARRAY_DEF_H_VERSION
#define AFF_ARRAY_DEF_H_VERSION \
"AFF_ARRAY_DEF_H V1.0 "
"AFF_ARRAY_DEF_H V1.1"
#define AFF_ARRAY_DEF_H_CVSID \
"$Id: array_def.h,v 1.4 2002-12-13 23:48:29 forbrig Exp $"
"$Id: array_def.h,v 1.5 2002-12-16 20:16:06 forbrig Exp $"
#include<aff/lib/error.h>
namespace aff {
......@@ -46,12 +49,6 @@ namespace aff {
namespace prebuilt {
#endif
//#ifdef AFF_PREBUILT
// using namespace aff::prebuilt::shape;
//#else
// using namespace aff::shape;
//#endif
#ifdef AFF_PREBUILT
#ifndef FF_COMPILING_LIBRARY
#error "definition read in prebuilt mode and not during library compilation"
......@@ -61,29 +58,74 @@ namespace prebuilt {
/*----------------------------------------------------------------------*/
template<class T>
Array<T>::Array(const Tshape& shape,
const Trepresentation& representation)
Array<const T>::Array(const Tsize& s0): Tshape(s0)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
template<class T>
Array<const T>::Array(const Tsize& s0,
const Tsize& s1): Tshape(s0, s1)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
template<class T>
Array<const T>::Array(const Tsize& s0,
const Tsize& s1,
const Tsize& s2): Tshape(s0, s1, s2)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
template<class T>
Array<const T>::Array(const Tsize& s0,
const Tsize& s1,
const Tsize& s2,
const Tsize& s3): Tshape(s0, s1, s2, s3)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
template<class T>
Array<const T>::Array(const Tshape& shape,
const Trepresentation& representation)
{
AFF_assert((shape.first_offset()>=0),
"ERROR (Array): invalid shape in constructor");
AFF_assert((shape.last_offset()<representation.size()),
"ERROR (Array): shape and representation are inconsistent");
this->Tshape::operator=(shape);
this->Trepresentation::operator=(representation);
AFF_abort("check consitency (not yet implemented)");
}
/*----------------------------------------------------------------------*/
template<class T>
Array<T>::Array(const Tshape& shape)
Array<const T>::Array(const Tshape& shape): Tshape(shape)
{
this->Tshape::operator=(shape);
this->Trepresentation::operator=(
Trepresentation(this->Tshape::size()));
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
template<class T>
Array<T>& Array<T>::operator=(const T& value)
Array<const T>& Array<const T>::operator=(const T& value)
{
AFF_abort("Array<const T>::operator= not yet implemented")
/*
typename Tshape::Tstepper st(this->Tshape::stepper());
st.tofirst();
......
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