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

new throws exception in case of too many dimension-brackets in

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.
either shaper, slice or subarray


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1283
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 1178735b
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
* $Id: README.changelog,v 1.35 2003-01-09 17:30:07 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,12 +21,17 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
$Id: README.changelog,v 1.35 2003-01-09 17:30:07 forbrig Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 09/01/2003 (thof)
- aff::Shaper, aff::util::Subarray, and aff::util::Slice now throw
exceptions in case the user tries to specify too many dimensions by
bracket operators.
- \b 04/01/2003 (thof)
- aff::deepcopy now converts to Tcontainer. And aff::util::Subarray
and aff::util::Slice therefore provide a Tcontainer typedef. See also
......@@ -163,7 +168,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
$Id: README.changelog,v 1.35 2003-01-09 17:30:07 forbrig Exp $
\sa \ref page_changelog
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: shaper.h,v 1.6 2002-12-18 09:58:50 forbrig Exp $
* $Id: shaper.h,v 1.7 2003-01-09 17:30:07 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -22,6 +22,9 @@
* - never place in namspace prebuilt
* - 18/12/2002 V1.4 (thof)
* - small but essential correction in operator()
* - 09/01/2003 V1.5 (thof)
* - now throws exception in case of too many
* concatenated bracket operators
*
* ============================================================================
*/
......@@ -30,9 +33,9 @@
#ifndef AFF_SHAPER_H_VERSION
#define AFF_SHAPER_H_VERSION \
"AFF_SHAPER_H V1.4"
"AFF_SHAPER_H V1.5"
#define AFF_SHAPER_H_CVSID \
"$Id: shaper.h,v 1.6 2002-12-18 09:58:50 forbrig Exp $"
"$Id: shaper.h,v 1.7 2003-01-09 17:30:07 forbrig Exp $"
#include<aff/lib/strided.h>
#include<aff/lib/error.h>
......@@ -98,22 +101,22 @@ class Shaper
Shaper& operator() (const Tsubscript& last)
{
AFF_assert((last>=1), "ERROR (shaper): invalid limit");
check_dim();
Mfirst[Mdim]=1;
Mlast[Mdim]=last;
Mmaxlast[Mdim]=last;
// foolproof
if (Mdim<(Tshape::Mmax_dimen-1)) Mdim++;
Mdim++;
return(*this);
}
//! Other dimensions are defined by bracket operator
Shaper& operator() (const Tsubscript& first, const Tsubscript& last)
{
AFF_assert((last>=first), "ERROR (shaper): invalid index range");
check_dim();
Mfirst[Mdim]=first;
Mlast[Mdim]=last;
Mmaxlast[Mdim]=last;
// foolproof
if (Mdim<(Tshape::Mmax_dimen-1)) Mdim++;
Mdim++;
return(*this);
}
//! Other dimensions are defined by bracket operator
......@@ -122,11 +125,11 @@ class Shaper
{
AFF_assert((last>=first), "ERROR (shaper): invalid index range");
AFF_assert((maxlast>=last), "ERROR (shaper): invalid alloc size");
check_dim();
Mfirst[Mdim]=first;
Mlast[Mdim]=last;
Mmaxlast[Mdim]=maxlast;
// foolproof
if (Mdim<(Tshape::Mmax_dimen-1)) Mdim++;
Mdim++;
return(*this);
}
//! Return the shape class
......@@ -137,6 +140,12 @@ class Shaper
return(shape);
}
private:
//! check dimensions
void check_dim() const
{
AFF_assert((Mdim<Tshape::Mmax_dimen),
"ERROR (Shaper): you use too many dimensions!");
}
//! limits
Tshape::TIndexVec Mfirst, Mlast, Mmaxlast;
//! next dimension to set
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: slice.h,v 1.5 2003-01-04 11:10:23 forbrig Exp $
* $Id: slice.h,v 1.6 2003-01-09 17:30:07 forbrig Exp $
* \author Thomas Forbriger
* \date 19/12/2002
*
......@@ -23,6 +23,9 @@
* - 04/01/2003 V1.3 (thof)
* - now provides a Tcontainer typedef (see
* aff::deepcopy)
* - 09/01/2003 V1.4 (thof)
* - now throws exception in case of too many
* concatenated bracket operators
*
* ============================================================================
*/
......@@ -31,9 +34,9 @@
#ifndef AFF_SLICE_H_VERSION
#define AFF_SLICE_H_VERSION \
"AFF_SLICE_H V1.3"
"AFF_SLICE_H V1.4"
#define AFF_SLICE_H_CVSID \
"$Id: slice.h,v 1.5 2003-01-04 11:10:23 forbrig Exp $"
"$Id: slice.h,v 1.6 2003-01-09 17:30:07 forbrig Exp $"
#include<aff/array.h>
......@@ -79,14 +82,15 @@ namespace util {
//! skip this dimension
Slice& operator()()
{
this->next();
++Mdim;
return(*this);
}
//! slice next dimension
Slice& operator()(const Tsubscript& index)
{
this->check_dim();
Mshape.collapse(Mdim, index);
this->next();
++Mdim;
return(*this);
}
//! slice dimention \p dim
......@@ -110,9 +114,12 @@ namespace util {
operator Tarray() const
{ return(Tarray(Mshape,Mrepresentation)); }
private:
//! next dimension
void next()
{ if (Mdim<(Tshape::Mmax_dimen-1)) ++Mdim; }
//! check dimension
void check_dim() const
{
AFF_assert((Mdim<Tshape::Mmax_dimen),
"ERROR (Slice): you use too many dimension-brackets!");
}
//! Shape to process
Tshape Mshape;
//! Representation to use
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: subarray.h,v 1.4 2003-01-04 11:10:23 forbrig Exp $
* $Id: subarray.h,v 1.5 2003-01-09 17:30:07 forbrig Exp $
* \author Thomas Forbriger
* \date 19/12/2002
*
......@@ -21,6 +21,9 @@
* - 04/01/2003 V1.2 (thof)
* - now provides a Tcontainer typedef (see
* aff::deepcopy)
* - 09/01/2003 V1.3 (thof)
* - now throws exception in case of too many
* concatenated bracket operators
*
* ============================================================================
*/
......@@ -29,9 +32,9 @@
#ifndef AFF_SUBARRAY_H_VERSION
#define AFF_SUBARRAY_H_VERSION \
"AFF_SUBARRAY_H V1.2"
"AFF_SUBARRAY_H V1.3"
#define AFF_SUBARRAY_H_CVSID \
"$Id: subarray.h,v 1.4 2003-01-04 11:10:23 forbrig Exp $"
"$Id: subarray.h,v 1.5 2003-01-09 17:30:07 forbrig Exp $"
#include<aff/array.h>
......@@ -83,20 +86,22 @@ namespace util {
}
//! use full range of this dimension
Subarray& operator()()
{ this->next(); return(*this); }
{ ++Mdim; return(*this); }
//! set last index of this dimension
Subarray& operator()(const Tsubscript& last)
{
this->check_dim();
Mshape.shrink(Mdim, last);
this->next();
++Mdim;
return(*this);
}
//! set first and last index of this dimension
Subarray& operator()(const Tsubscript& first,
const Tsubscript& last)
{
this->check_dim();
Mshape.shrink(Mdim, first, last);
this->next();
++Mdim;
return(*this);
}
//! provide value assignment to a subarray
......@@ -114,9 +119,12 @@ namespace util {
operator Tarray() const
{ return(Tarray(Mshape,Mrepresentation)); }
private:
//! next dimension
void next()
{ if (Mdim<(Tshape::Mmax_dimen-1)) ++Mdim; }
//! check dimensions
void check_dim() const
{
AFF_assert((Mdim<Tshape::Mmax_dimen),
"ERROR (Subarray): you use too many dimension-brackets!");
}
//! Shape to process
Tshape Mshape;
//! Representation to use
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: shapetest.cc,v 1.6 2002-12-29 00:09:07 forbrig Exp $
* $Id: shapetest.cc,v 1.7 2003-01-09 17:30:11 forbrig Exp $
* \author Thomas Forbriger
* \date 25/05/2002
*
......@@ -18,13 +18,16 @@
* - test works
* - 19/12/2002 V1.2 (thof)
* - print valid() of stepper too
* - 09/01/2003 V1.3 (thof)
* - using too many bracket operators now triggers
* an exception in aff::Shaper
*
* ============================================================================
*/
#define AFF_SHAPETEST_CC_VERSION \
"AFF_SHAPETEST_CC V1.1"
"AFF_SHAPETEST_CC V1.3"
#define AFF_SHAPETEST_CC_CVSID \
"$Id: shapetest.cc,v 1.6 2002-12-29 00:09:07 forbrig Exp $"
"$Id: shapetest.cc,v 1.7 2003-01-09 17:30:11 forbrig Exp $"
#include<iostream>
#include<aff/dump.h>
......@@ -126,8 +129,11 @@ int main()
cout << endl << "Basic usage:" << endl;
DUMP( Shaper(10)(12) );
cout << endl << "Fool proof with limited dimensionality:" << endl;
#ifdef ILLEGAL1
#warning intentionally compiling illegal code
cout << endl << "Illegal with limited dimensionality:" << endl;
DUMP( Shaper(2,10)(-12,12)(9)(2,7)(3,4) );
#endif
cout << endl << "Usage for an external Fortran shape:" << endl;
DUMP( Shaper(1,6,10)(1,12,30)(1,10) );
......
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