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

introduced class Series

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.
and introduced access declarations


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1204
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent fdff6e0a
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.6 2002-12-15 20:48:01 forbrig Exp $
# $Id: Makefile,v 1.7 2002-12-17 19:19:54 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -56,7 +56,7 @@ SRC=lib/error.cc dump.cc lib/strided.cc
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
README=$(shell find . -name README)
README=$(shell find . -name README) README.changelog
# place where we will copy header files
INCINSTALLPATH=$(LOCINCLUDEDIR)/aff
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README,v 1.4 2002-12-10 19:30:06 forbrig Exp $
* $Id: README,v 1.5 2002-12-17 19:19:54 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -48,7 +48,7 @@ namespace aff {
\since December 2002
\date December 2002
\version V1.0
$Id: README,v 1.4 2002-12-10 19:30:06 forbrig Exp $
$Id: README,v 1.5 2002-12-17 19:19:54 forbrig Exp $
Contents of this page:
- \ref sec_main_aims
......@@ -64,6 +64,7 @@ $Id: README,v 1.4 2002-12-10 19:30:06 forbrig Exp $
- \ref page_notes
- \ref page_naming
- \ref page_representation
- \ref page_changelog
\section sec_main_aims Aims of the library
......
/*! \file README.changelog
* \brief ChangeLog for C++ containers for numbers (libaff)
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.1 2002-12-17 19:19:54 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* C++ containers for numbers (libaff)
*
* This file contains:
* - \ref page_changelog
*
* REVISIONS and CHANGES
* - 17/12/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
/*! \page page_changelog ChangeLog
- 17/12/2002 (thof)
- introduced class Series
- Array now inherits privately from Strided
- use access declarations to declare base class functions that should be
visible in the public interface of aff::Array and aff::SharedHeap
*/
// ----- END OF README.changelog -----
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_dec.h,v 1.8 2002-12-16 21:03:25 uid1201 Exp $
* $Id: array_dec.h,v 1.9 2002-12-17 19:19:54 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -30,7 +30,7 @@
#define AFF_ARRAY_DEC_H_VERSION \
"AFF_ARRAY_DEC_H V1.1"
#define AFF_ARRAY_DEC_H_CVSID \
"$Id: array_dec.h,v 1.8 2002-12-16 21:03:25 uid1201 Exp $"
"$Id: array_dec.h,v 1.9 2002-12-17 19:19:54 forbrig Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/lib/strided.h>
......@@ -172,78 +172,22 @@ namespace prebuilt {
/*-----------------------------------------------------------------*/
/*! \name Data modification functions
*
* These functions are declared protected in the base class. Make them
* visible here.
*/
//! \name access declarations
//@{
//! full dimensionality access
T& operator()(const TIndexVec& index)
{ return(this->Tbase::operator()(index)); }
//! access from 1 index value
T& operator()(const Tsubscript& i0)
{ return(this->Tbase::operator()(i0)); }
//! access from 2 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1)
{ return(this->Tbase::operator()(i0, i1)); }
//! access from 3 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2)
{ return(this->Tbase::operator()(i0, i1, i2)); }
//! access from 4 index values
T& operator()(const Tsubscript& i0,
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)); }
//@}
/*! \name Data access operators
*
* These functions are declared protected in the base class. Make them
* visible here. Since we declare the non-const operators, the const
* operators of the base class are hidden. Redeclare them here.
*/
//@{
//! full dimensionality access
const T& operator()(const TIndexVec& index) const
{ return(this->Tbase::operator()(index)); }
//! access from 1 index value
const T& operator()(const Tsubscript& i0) const
{ return(this->Tbase::operator()(i0)); }
//! access from 2 index values
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1) const
{ return(this->Tbase::operator()(i0, i1)); }
//! access from 3 index values
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2) const
{ return(this->Tbase::operator()(i0, i1, i2)); }
//! access from 4 index values
const T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3) const
{ return(this->Tbase::operator()(i0, i1, i2, i3)); }
//! access to base class function
Tbase::operator();
Tbase::operator=;
Tbase::copyin;
//@}
//! tricky: only this class allows the conversion
operator Trepresentation()
{ return (Trepresentation(this->Tbase)); }
//! return a copy(!) of the shape
operator Tshape() const
{ Tshape retval(Tbase(*this)); return(retval); }
}; // class Array
/*======================================================================*/
......@@ -252,7 +196,7 @@ namespace prebuilt {
*/
template<class T>
class Array<const T>:
public aff::Strided, private aff::SharedHeap<T>
private aff::Strided, private aff::SharedHeap<T>
{
public:
/*! \name Various types
......@@ -276,7 +220,7 @@ namespace prebuilt {
//! Type of reference to element
typedef const T& Treference;
//! Type of this array
typedef Array<T> Tcontainer;
typedef Array<const T> Tcontainer;
//! Type of the array of const values
typedef Tcontainer Tcontainer_of_const;
/*! \brief short for Tcontainer_of_const
......@@ -410,10 +354,22 @@ namespace prebuilt {
*/
Array copyout() const;
//! \name access declarations
//@{
//! access to base class function
Tshape::first;
Tshape::last;
Tshape::size;
//@}
//! offer conversion only to constant version of representation
operator Trepresentation::Tcoc() const
{ return (*this); }
//! return a copy(!) of the shape
operator Tshape() const
{ Tshape retval(*this); return(retval); }
/*-----------------------------------------------------------------*/
// here starts the PROTECTED section!
// ----------------------------------
......
......@@ -53,6 +53,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
INPUT = ./
FILE_PATTERNS = README \
README.changelog \
*.h \
*.cc
RECURSIVE = YES
......
......@@ -53,6 +53,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
INPUT = ./
FILE_PATTERNS = README \
README.changelog \
*.h \
*.cc
RECURSIVE = YES
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap.h,v 1.10 2002-12-16 21:03:27 uid1201 Exp $
* $Id: sharedheap.h,v 1.11 2002-12-17 19:19:57 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -19,6 +19,8 @@
* - 16/12/2002 V1.1 (thof)
* - introduced new concept of const correct containers
* - moved AllocException to error.h
* - 17/12/2002 V1.2 (thof)
* - use access declarations (hint by wolle)
*
* ============================================================================
*/
......@@ -27,9 +29,9 @@
#ifndef AFF_SHAREDHEAP_H_VERSION
#define AFF_SHAREDHEAP_H_VERSION \
"AFF_SHAREDHEAP_H V1.1"
"AFF_SHAREDHEAP_H V1.2"
#define AFF_SHAREDHEAP_H_CVSID \
"$Id: sharedheap.h,v 1.10 2002-12-16 21:03:27 uid1201 Exp $"
"$Id: sharedheap.h,v 1.11 2002-12-17 19:19:57 forbrig Exp $"
#include<new>
#include<aff/lib/error.h>
......@@ -123,28 +125,13 @@ namespace prebuilt {
//! Deallocate heap memory if this is the last referencing instance.
~SharedHeap() { }
/*! Return size (always inline).
* \retval size of array on heap.
*/
inline
const Tsize& size() const
{ return(this->Tbase::size()); }
/*! Return array access.
* \return pointer to array on heap
*/
T* array()
{ return(this->Tbase::mutable_pointer()); }
//! Index operator (always inline).
inline
T& operator[](const Tsubscript& i)
{ return(this->Tbase::operator[](i)); }
//! Index operator (always inline).
inline
const T& operator[](const Tsubscript& i) const
{ return(this->Tbase::operator[](i)); }
//! \name access declarations
//@{
//! access to base class function
Tbase::size;
Tbase::operator[];
Tbase::array;
//@}
}; // class SharedHeap
......@@ -235,7 +222,7 @@ namespace prebuilt {
/*! Return array access.
* \return pointer to array on heap
*/
T* mutable_array()
T* array()
{ return(Mheapstruct->Mheap); }
private:
......
/*! \file series.h
* \brief linear series class (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: series.h,v 1.1 2002-12-17 19:19:54 forbrig Exp $
* \author Thomas Forbriger
* \date 17/12/2002
*
* linear series class (prototypes)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 17/12/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef AFF_SERIES_H_VERSION
#define AFF_SERIES_H_VERSION \
"AFF_SERIES_H V1.0"
#define AFF_SERIES_H_CVSID \
"$Id: series.h,v 1.1 2002-12-17 19:19:54 forbrig Exp $"
#include<aff/lib/sharedheap.h>
#include<aff/lib/error.h>
namespace aff {
/*! \brief A base class for time series and spectra
*
*/
template<class T>
class Series: public series<const T> {
public:
/*! \name Various types
*
*/
//@{
//! Type of this array
typedef Series<T> Tcontainer;
//! base is container of const (see specialization below)
typedef Series<const T> Tbase;
//! Type of the array of const values
typedef Tbase 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 Tbase Tcoc;
//! Type of representation
typedef Tbase::Trepresentation Trepresentation;
//! Element type
typedef T Tvalue;
//! Type of pointer to element
typedef T* Tpointer;
//! Type of reference to element
typedef T& Treference;
//@}
/*-----------------------------------------------------------------*/
/*! \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)
Series(): Tbase() { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsubscript& first=1):
Tbase(representation, first) { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsize& size, const Tsize& shift=0,
const Tsubscript& first=1):
Tbase(representation, size, shift, first) { }
//! construct from index range limit
explicit Series(const Tsize& size, const Tsubscript& first=1):
Tbase(size, first) { }
//@}
/*-----------------------------------------------------------------*/
//! 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)); }
//! set whole array to value
Series& operator=(const T& value)
{
this->Tbase::operator=(value);
return(*this);
}
//! copy in is allowed here (delegate to base)
template<class TT>
Series& copyin(const Series<TT>& a)
{
this->Tbase::copyin(a);
return(*this);
}
//! tricky: only this class allows the conversion
operator Trepresentation()
{ return (Trepresentation(Tbase(*this))); }
}; // class series
/*======================================================================*/
/*! \brief base class
*/
template<class T>
class Series<const T>:
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;
//! 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 Series<const 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)
Series(): Trepresentation(), Mfirst(1), Mlast(1), Mbase(1) { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsubscript& first=1):
Trepresentation(representation), Mfirst(first),
Mlast(representation.size()+first-1), Mbase(first) { }
//! 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");
}
//! construct from index range limit
explicit Series(const Tsize& size, const Tsubscript& first=1):
Trepresentation(size), Mfirst(first),
Mlast(size+first-1), Mbase(first) { }
//@}
/*-----------------------------------------------------------------*/
//! Data read access
const T& operator()(const Tsubscript& i) const
{ return(this->Trepresentation::operator[](i-Mbase)); }
/*-----------------------------------------------------------------*/
/*! \name Shape access
*/
//@{
//! (short for) first valid index
const Tsubscript& f() const
{ return(this->first()); }
//! (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)); }
//@}
/*! \brief create an identical copy (deep copy) of this array
*
* This is mainly used to create a copy of a truely identical array
* (i.e. array with same element type or at least const version of
* same element type). Use this function in conjunction with the
* assignment operator. E.g.:
* \code
* aff::Array<int> A(3,4);
* A=5.;
* aff::Array<int> B, C;
* B=A.copyout();
* C=A;
* \endcode
* Here arrays \c A and \c B have exactly the same contents but use
* different memory. While changes to elements of \c C will also
* affect elements of \c A, this not the case for changes applied to
* \c B.
*/
Series 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
* same shape and applies them to this array. In fact the shape needs
* not be the same. The copy is done through sequential access and as
* most number as possible will be copied in increasing memory address
* order.
*
* Example:
* \code
* aff::Array<float> A(24);
* A=15.
* aff::Array<double> B(3,8);
* B.copyin(A);
* \endcode
* \c B will preserve its shape but is filled with the contents of
* \c A (which are not where interesting in this example). Changes
* applied to the contents of B will not affect the contents of A.
*
* \param a other array with element type convertible to element type
* of this array
* \return itself
*/
template<class TT>
Series& copyin(const Series<TT>& a);
/*-----------------------------------------------------------------*/
//! set whole array to value
Series& operator=(const T& value);
//! Data modofication access
T& operator()(const Tsubscript& i)
{ return(this->Trepresentation::operator[](i-Mbase)); }
/*-----------------------------------------------------------------*/
//! tricky: only this class allows the conversion