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

introduced Iterator stuff

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: 1223
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 49a5f6b3
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.9 2002-12-20 10:18:59 forbrig Exp $
# $Id: Makefile,v 1.10 2002-12-20 12:21:04 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -52,7 +52,7 @@ HEADERS=$(shell find . -name \*.h)
# (see below for the configuration of a preinstantiated version of template
# code)
SRC=lib/error.cc dump.cc lib/strided.cc lib/stridedstepper.cc \
lib/seriesstepper.cc
lib/seriesstepper.cc
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.12 2002-12-20 10:18:59 forbrig Exp $
* $Id: README.changelog,v 1.13 2002-12-20 12:21:04 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -20,7 +20,7 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.12 2002-12-20 10:18:59 forbrig Exp $
$Id: README.changelog,v 1.13 2002-12-20 12:21:04 forbrig Exp $
\sa \ref page_project_status
......@@ -29,6 +29,14 @@
- \b 20/12/2002 (thof)
- introduced aff/lib/seriesstepper.h and aff/lib/seriesstepper.cc
which define aff::util::SeriesStepper
- Access declarations are nor useable with functions
that return a reference to *this. They must be
reimplemented.
- introduced class aff::LinearShape
- provide appropriate Tstepper typedef in shape classes (requires forward
declarations of stepper classes, because we do not like to include the
full stepper header if we don't use it).
- introduced aff::Iterator class template
- \b 19/12/2002 (thof)
- \b !! aff::Array provides access to base classes through access
......@@ -64,7 +72,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.12 2002-12-20 10:18:59 forbrig Exp $
$Id: README.changelog,v 1.13 2002-12-20 12:21:04 forbrig Exp $
\sa \ref page_changelog
......@@ -97,7 +105,7 @@
<TD>19/12/2002</TD><TD> </TD><TD> </TD><TD> </TD>
</TR>
<TR><TD>libaff/iterator.h</TD>
<TD> </TD><TD> </TD><TD> </TD><TD> </TD>
<TD>20/12/2002</TD><TD> </TD><TD> </TD><TD> </TD>
</TR>
<TR><TD>libaff/series.h</TD>
<TD>17/12/02</TD><TD> </TD><TD> </TD><TD> </TD>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_dec.h,v 1.12 2002-12-19 18:30:01 forbrig Exp $
* $Id: array_dec.h,v 1.13 2002-12-20 12:21:04 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -30,6 +30,10 @@
* constructor with default arguments
* - distinguish between mutable and non-mutable
* representation
* - 20/12/2002 V1.4 (thof)
* - Access declarations are nor useable with functions
* that return a reference to *this. They must be
* reimplemented.
*
* ============================================================================
*/
......@@ -40,11 +44,10 @@
#define AFF_ARRAY_DEC_H_VERSION \
"AFF_ARRAY_DEC_H V1.3"
#define AFF_ARRAY_DEC_H_CVSID \
"$Id: array_dec.h,v 1.12 2002-12-19 18:30:01 forbrig Exp $"
"$Id: array_dec.h,v 1.13 2002-12-20 12:21:04 forbrig Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/lib/strided.h>
// #include <aff/lib/range.h>
namespace aff {
......@@ -181,6 +184,21 @@ namespace prebuilt {
Tbase::copyin;
Tbase::shape;
//@}
//! set whole array to value
Array& operator=(const T& value)
{
this->Tbase::operator=(value);
return(*this);
}
//! copy in is allowed here (delegate to base)
template<class TT>
Array& copyin(const Array<TT>& a)
{
this->Tbase::copyin(a);
return(*this);
}
//! return full access representation
const Trepresentation& representation()
......@@ -217,7 +235,7 @@ namespace prebuilt {
typedef aff::SharedHeap<T> Tmutable_representation;
//! Type of representation
typedef aff::SharedHeap<const T> Trepresentation;
//! Type of subscriptor
//! Type of shape
typedef aff::Strided Tshape;
//! Element type
typedef const T Tvalue;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_def.h,v 1.9 2002-12-19 18:30:02 forbrig Exp $
* $Id: array_def.h,v 1.10 2002-12-20 12:21:04 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -47,7 +47,7 @@
#define AFF_ARRAY_DEF_H_VERSION \
"AFF_ARRAY_DEF_H V1.3"
#define AFF_ARRAY_DEF_H_CVSID \
"$Id: array_def.h,v 1.9 2002-12-19 18:30:02 forbrig Exp $"
"$Id: array_def.h,v 1.10 2002-12-20 12:21:04 forbrig Exp $"
#include<aff/lib/error.h>
#include<aff/lib/stridedstepper.h>
......@@ -59,7 +59,7 @@ namespace prebuilt {
#endif
#ifdef AFF_PREBUILT
#ifndef FF_COMPILING_LIBRARY
#ifndef AFF_COMPILING_LIBRARY
#error "definition read in prebuilt mode and not during library compilation"
#endif
#endif
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: iterator.h,v 1.2 2002-12-08 22:33:53 forbrig Exp $
* $Id: iterator.h,v 1.3 2002-12-20 12:21:04 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -24,12 +24,81 @@
#ifndef AFF_ITERATOR_H_VERSION
#define AFF_ITERATOR_H_VERSION \
"AFF_ITERATOR_H V1.0 "
"AFF_ITERATOR_H V1.0"
#define AFF_ITERATOR_H_CVSID \
"$Id: iterator.h,v 1.2 2002-12-08 22:33:53 forbrig Exp $"
"$Id: iterator.h,v 1.3 2002-12-20 12:21:04 forbrig Exp $"
#include<aff/lib/types.h>
#include<aff/lib/stridedstepper.h>
#include<aff/lib/seriesstepper.h>
namespace aff {
/*! \brief Iterator (and Browser)
*
* \note
* This class holds an intrinsic reference to the Container components.
*
* \param C any container with appropriate interface (e.g. aff::Array,
* aff::Series)
*
* \todo
* Define requirements for the interface a container must provide.
*/
template<class C>
class Iterator: private typename C::Tshape::Tstepper {
public:
//! representation class
typedef typename C::Trepresentation Trepresentation;
//! shape class
typedef typename C::Tshape Tshape;
//! stepper base class
typedef typename C::Tshape::Tstepper Tstepper;
//! value type
typedef typename C::Tvalue Tvalue;
//! value type
typedef typename C::Treference Treference;
//! value type
typedef typename C::Tpointer Tpointer;
//! only this constructor
Iterator(C& c):
Tstepper(c.shape()), Mrepresentation(c.representation()) { }
//! access declarations
//@{
Tstepper::more;
Tstepper::less;
Tstepper::valid;
//@}
//! reimplement functions that return reference to *this
//@{
Iterator& incr() { this->Tstepper::incr(); return(*this); }
Iterator& decr() { this->Tstepper::decr(); return(*this); }
Iterator& tofirst() { this->Tstepper::tofirst(); return(*this); }
Iterator& tolast() { this->Tstepper::tolast(); return(*this); }
//@}
//! synonym for increment
Iterator& operator++()
{ this->incr(); return(*this); }
//! synonym for decrement
Iterator& operator--()
{ this->decr(); return(*this); }
//! access element
Treference operator*()
{ return(Mrepresentation[this->Tstepper::current()]); }
//! member selection operator
Tpointer operator->()
{ return(&(Mrepresentation[this->Tstepper::current()])); }
private:
Trepresentation Mrepresentation;
}; // class Iterator
} // namespace aff
#endif // AFF_ITERATOR_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: strided.h,v 1.12 2002-12-19 18:30:06 forbrig Exp $
* $Id: strided.h,v 1.13 2002-12-20 12:21:05 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -37,6 +37,9 @@
* - 16/12/2002 V1.5 (thof)
* - renamed subarray and slice function
* - added shift and setfirst
* - 20/12/2002 V1.6 (thof)
* - forward declaration of StridedStepper
* - typedef Tstepper
*
* ============================================================================
*/
......@@ -47,13 +50,18 @@
#define AFF_STRIDED_H_VERSION \
"AFF_STRIDED_H V1.5"
#define AFF_STRIDED_H_CVSID \
"$Id: strided.h,v 1.12 2002-12-19 18:30:06 forbrig Exp $"
"$Id: strided.h,v 1.13 2002-12-20 12:21:05 forbrig Exp $"
#include<aff/lib/types.h>
#include<aff/lib/simplearray.h>
namespace aff {
namespace util {
//! forward declaration of stepper class
class StridedStepper;
} // namespace util
/*! \brief Shape for a rectangular array layout.
*
* A rectangular array layout is the usual layout for multi-dimensional
......@@ -104,6 +112,8 @@ namespace aff {
typedef SimpleRigidArray<Tsize, Mmax_dimen> TSizeVec;
//! type of limit arrays (any sign)
typedef SimpleRigidArray<Tsubscript, Mmax_dimen> TIndexVec;
//! type of stepper
typedef aff::util::StridedStepper Tstepper;
/*-----------------------------------------------------------------*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: series.h,v 1.3 2002-12-17 19:41:21 forbrig Exp $
* $Id: series.h,v 1.4 2002-12-20 12:21:04 forbrig Exp $
* \author Thomas Forbriger
* \date 17/12/2002
*
......@@ -13,6 +13,10 @@
*
* REVISIONS and CHANGES
* - 17/12/2002 V1.0 Thomas Forbriger
* - 20/12/2002 V1.1 (thof)
* - introduced LinearShape
* - forward declaration of StridedStepper
* - typedef Tstepper
*
* ============================================================================
*/
......@@ -21,15 +25,53 @@
#ifndef AFF_SERIES_H_VERSION
#define AFF_SERIES_H_VERSION \
"AFF_SERIES_H V1.0"
"AFF_SERIES_H V1.1"
#define AFF_SERIES_H_CVSID \
"$Id: series.h,v 1.3 2002-12-17 19:41:21 forbrig Exp $"
"$Id: series.h,v 1.4 2002-12-20 12:21:04 forbrig Exp $"
#include<aff/lib/sharedheap.h>
#include<aff/lib/error.h>
namespace aff {
namespace util {
//! forward declaration of stepper class
class SeriesStepper;
} // namespace util
/*! \brief Shape for class aff::Series
*
* aff::Series needs its own shape class to provide an Array compatible
* interface to Iterator.
*/
class LinearShape
{
public:
typedef aff::util::SeriesStepper Tstepper;
LinearShape(): Mfirst(1), Mlast(1), Mbase(1) { }
LinearShape(const Tsubscript& first,
const Tsubscript& last,
const Tsize& base):
Mfirst(first), Mlast(last), Mbase(base)
{
AFF_assert((Mlast>Mfirst),
"ERROR (LinearShape): inconsistent constructor arguments");
}
const Tsubscript& first() const { return(Mfirst); }
const Tsubscript& last() const { return(Mlast); }
Tsubscript offset(const Tsubscript& i) const { return(i-Mbase); }
const Tsize& base() const { return(Mbase); }
//! by size we mean the size defined by the shape
Tsize size() const
{ return(static_cast<Tsize>(Mlast-Mfirst+1)); }
private:
Tsubscript Mfirst; //!< first valie index
Tsubscript Mlast; //!< last valid index
Tsize Mbase; //!< base for access to representation
}; // LinearShape
/*======================================================================*/
/*! \brief A base class for time series and spectra
*
*/
......@@ -46,6 +88,8 @@ namespace aff {
typedef Series<const T> Tbase;
//! Type of the array of const values
typedef Tbase Tcontainer_of_const;
//! Type of shape
typedef aff::LinearShape Tshape;
/*! \brief short for Tcontainer_of_const
*
* We generally distinguish between constness of the array and
......@@ -106,14 +150,14 @@ namespace aff {
/*-----------------------------------------------------------------*/
//! Data modofication access
T& operator()(const Tsubscript& i)
{ return(this->Tbase::operator()(i)); }
//! Data read access
const T& operator()(const Tsubscript& i) const
{ return(this->Tbase::operator()(i)); }
//! \name access declarations
//@{
//! access to base class function
Tbase::operator();
Tbase::operator=;
//@}
//! set whole array to value
//! set whole series to value
Series& operator=(const T& value)
{
this->Tbase::operator=(value);
......@@ -130,7 +174,14 @@ namespace aff {
//! tricky: only this class allows the conversion
operator Trepresentation()
{ return (Trepresentation(Tbase(*this))); }
{ return (this->Tbase::mutable_representation()); }
private:
//! reimplement copy operator for base class to override access
//! declaration
Tcontainer& operator=(const Tcoc& series)
{ AFF_abort("illegal call"); return(*this); }
}; // class series
/*======================================================================*/
......@@ -139,7 +190,7 @@ namespace aff {
*/
template<class T>
class Series<const T>:
private aff::SharedHeap<T>
private aff::LinearShape, private aff::SharedHeap<T>
{
public:
/*! \name Various types
......@@ -153,7 +204,11 @@ namespace aff {
*/
//@{
//! Type of representation
typedef aff::SharedHeap<T> Trepresentation;
typedef aff::SharedHeap<T> Tmutable_representation;
//! Type of representation
typedef aff::SharedHeap<const T> Trepresentation;
//! Type of shape
typedef aff::LinearShape Tshape;
//! Element type
typedef const T Tvalue;
//! Type of pointer to element
......@@ -199,22 +254,18 @@ namespace aff {
*/
//@{
//! construct from nothing (empty)
Series(): Trepresentation(), Mfirst(1), Mlast(1), Mbase(1) { }
Series(): Tshape(), Trepresentation(this->Tshape::size()) { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsubscript& first=1):
Trepresentation(representation), Mfirst(first),
Mlast(representation.size()+first-1), Mbase(first) { }
Tshape(first,representation.size()+first-1,first),
Trepresentation(representation) { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsize& size, const Tsize& shift=0,
const Tsubscript& first=1):
Trepresentation(representation), Mfirst(first),
Mlast(representation.size()-shift+first-1), Mbase(first-shift)
{
AFF_assert((Mlast>Mfirst),
"ERROR (Series): inconsistent constructor arguments");
}
Tshape(first, (representation.size()-shift+first-1), first-shift),
Trepresentation(representation) { }
//! construct from index range limit
explicit Series(const Tsize& size, const Tsubscript& first=1):
Trepresentation(size), Mfirst(first),
......@@ -225,7 +276,8 @@ namespace aff {
//! Data read access
const T& operator()(const Tsubscript& i) const
{ return(this->Trepresentation::operator[](i-Mbase)); }
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i))); }
/*-----------------------------------------------------------------*/
......@@ -238,16 +290,14 @@ namespace aff {
//! (short for) last valid index
const Tsubscript& l() const
{ return(this->last()); }
//! first valid index
const Tsubscript& first() const
{ return(Mfirst); }
//! last valid index
const Tsubscript& last() const
{ return(Mlast); }
//! by size we mean the size defined by the shape
Tsize size() const
{ return(static_cast<Tsize>(Mlast-Mfirst+1)); }
//@}
//! \name access declarations
//@{
//! access to base class function
Tshape::first;
Tshape::last;
Tshape::size;
//@}
/*! \brief create an identical copy (deep copy) of this array
......@@ -271,8 +321,12 @@ namespace aff {
Series copyout() const;
//! offer conversion only to constant version of representation
operator aff::SharedHeap<const T>() const
const Trepresentation& representation() const
{ return (*this); }
//! provide access to const shape
const Tshape& shape() const
{ return(*this); }
/*-----------------------------------------------------------------*/
// here starts the PROTECTED section!
......@@ -311,18 +365,15 @@ namespace aff {
//! Data modofication access
T& operator()(const Tsubscript& i)
{ return(this->Trepresentation::operator[](i-Mbase)); }
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i))); }
/*-----------------------------------------------------------------*/
//! tricky: only this class allows the conversion
operator Trepresentation()
const Tmutable_representation& mutable_representation()
{ return (*this); }
private:
Tsubscript Mfirst; //!< first valie index
Tsubscript Mlast; //!< last valid index
Tsize Mbase; //!< base for access to representation
}; // class series<const T>
/*======================================================================*/
......
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