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

changed template argument of FortranArray

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.
f77test now checks SizeCheckedCast


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1259
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent d7357918
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.30 2003-01-03 13:12:17 forbrig Exp $
* $Id: README.changelog,v 1.31 2003-01-03 16:56:40 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,7 +21,7 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.30 2003-01-03 13:12:17 forbrig Exp $
$Id: README.changelog,v 1.31 2003-01-03 16:56:40 forbrig Exp $
\sa \ref page_project_status
......@@ -29,6 +29,7 @@
- \b 03/01/2003 (thof)
- introduced lib/checkedcast.h and aff::util::SizeCheckedCast
- \b !! aff::FortranArray now takes container type as template argument
- \b 31/12/2002 (thof)
- NULL is deprecated as pointed out by Wolfgang (replaced by literal 0 in
......@@ -151,7 +152,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.30 2003-01-03 13:12:17 forbrig Exp $
$Id: README.changelog,v 1.31 2003-01-03 16:56:40 forbrig Exp $
\sa \ref page_changelog
......@@ -219,7 +220,7 @@
<TD>has no code</TD><TD>20/12/02</TD><TD>has no code</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/checkedcast.h</TD>
<TD>03/01/2003</TD><TD>03/01/2003</TD><TD></TD><TD> </TD>
<TD>03/01/2003</TD><TD>03/01/2003</TD><TD>03/01/2003</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/deepcopy.h</TD>
<TD>29/12/02</TD><TD>29/12/2002</TD><TD>29/12/02</TD><TD> </TD>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: fortranshape.h,v 1.4 2003-01-03 13:12:17 forbrig Exp $
* $Id: fortranshape.h,v 1.5 2003-01-03 16:56:41 forbrig Exp $
* \author Thomas Forbriger
* \date 23/12/2002
*
......@@ -15,6 +15,8 @@
* - 23/12/2002 V1.0 Thomas Forbriger
* - 03/01/2003 V1.1 (thof)
* - now offers a casted pointer
* - FortranArray now takes container type as template
* argument
*
* ============================================================================
*/
......@@ -25,7 +27,7 @@
#define AFF_FORTRANSHAPE_H_VERSION \
"AFF_FORTRANSHAPE_H V1.1"
#define AFF_FORTRANSHAPE_H_CVSID \
"$Id: fortranshape.h,v 1.4 2003-01-03 13:12:17 forbrig Exp $"
"$Id: fortranshape.h,v 1.5 2003-01-03 16:56:41 forbrig Exp $"
#include<aff/array.h>
#include<aff/lib/checkedcast.h>
......@@ -84,11 +86,11 @@ namespace util {
*
* \sa aff::util::FortranShape
*/
template<class T>
template<class C>
class FortranArray: private aff::util::FortranShape {
public:
//! type of corresponding array
typedef typename aff::Array<T> Tarray;
typedef C Tarray;
//! shape class
typedef typename Tarray::Tshape Tshape;
//! representation class
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: f77interface.cc,v 1.5 2003-01-03 13:12:19 forbrig Exp $
* $Id: f77interface.cc,v 1.6 2003-01-03 16:56:49 forbrig Exp $
* \author Thomas Forbriger
* \date 23/12/2002
*
......@@ -18,13 +18,15 @@
* - 29/12/2002 V1.1 now uses aff::subarray
* - 03/01/2003 V1.2 (thof)
* - use aff::util::SizeCheckedCast
* - FortranArray now takes container type as template
* argument
*
* ============================================================================
*/
#define AFF_F77INTERFACE_CC_VERSION \
"AFF_F77INTERFACE_CC V1.2"
#define AFF_F77INTERFACE_CC_CVSID \
"$Id: f77interface.cc,v 1.5 2003-01-03 13:12:19 forbrig Exp $"
"$Id: f77interface.cc,v 1.6 2003-01-03 16:56:49 forbrig Exp $"
// include assertions
#include<aff/lib/error.h>
......@@ -73,7 +75,7 @@ namespace f77interface {
//! interface function to Fortran77 subroutine fill
int fill(const aff::Array<int>& a)
{
aff::FortranArray<int> fa(a);
aff::FortranArray<aff::Array<int> > fa(a);
integer* pa=fa.castedpointer<integer>();
integer n1=fa.last(0);
integer n2=fa.last(1);
......@@ -90,7 +92,7 @@ int fill(const aff::Array<int>& a)
int fillarray(const aff::Array<float>& v1,
const aff::Array<float>& v2)
{
aff::FortranArray<float> fv1(v1),fv2(v2);
aff::FortranArray<aff::Array<float> > fv1(v1),fv2(v2);
real* p1=fv1.castedpointer<real>();
real* p2=fv2.castedpointer<real>();
integer n1=fv1.last(0);
......@@ -109,7 +111,7 @@ Tcarray sums()
comdim_(&maxa, &maxb);
Tcarray result(maxa);
// prepare Fortran view
aff::FortranArray<Tcvalue> fa(result);
aff::FortranArray<Tcarray> fa(result);
complex* p=fa.castedpointer<complex>();
integer size;
sums_(p, &maxa, &size);
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: f77test.cc,v 1.7 2002-12-29 23:02:16 forbrig Exp $
* $Id: f77test.cc,v 1.8 2003-01-03 16:56:49 forbrig Exp $
* \author Thomas Forbriger
* \date 22/12/2002
*
......@@ -18,6 +18,8 @@
* - 29/12/2002 V1.1 (thof)
* - new uses new function aff::subarray
* - new uses new function aff::slice
* - 03/01/2003 V1.2 (thof)
* - test aff::util::SizeCheckedCast
*
* ============================================================================
*/
......@@ -32,6 +34,7 @@
* - aff::FortranArray
* - aff::FortranShape
* - aff::Array
* - aff::util::SizeCheckedCast
* - #DUMP
* - #CODE
*
......@@ -40,9 +43,9 @@
*/
#define AFF_F77TEST_CC_VERSION \
"AFF_F77TEST_CC V1.1"
"AFF_F77TEST_CC V1.2"
#define AFF_F77TEST_CC_CVSID \
"$Id: f77test.cc,v 1.7 2002-12-29 23:02:16 forbrig Exp $"
"$Id: f77test.cc,v 1.8 2003-01-03 16:56:49 forbrig Exp $"
#include <aff/array.h>
#include <aff/fortranshape.h>
......@@ -50,6 +53,7 @@
#include <aff/shaper.h>
#include <aff/subarray.h>
#include <aff/slice.h>
#include <aff/lib/checkedcast.h>
#include "f77proto.h"
using std::cout;
......@@ -149,6 +153,59 @@ int main()
CODE(dump_array(Z));
CODE(dump_array(f77interface::sums()));
}
/*----------------------------------------------------------------------*/
section("Size-checked casts:", '=');
{
CODE(typedef std::complex<int> Ticvalue);
CODE(typedef std::complex<float> Tcvalue);
CODE(Array<Ticvalue> v1(1));
CODE(ConstArray<Ticvalue> v2(v1));
CODE(FortranArray<Array<Ticvalue> > fv1(v1));
CODE(FortranArray<ConstArray<Ticvalue> > fv2(v2));
CODE(v1(1)=Ticvalue(3,7));
CODE(cout << v1(1) << ", " << v2(1) << endl);
CODE(Ticvalue *icp=fv1.castedpointer<Ticvalue>());
CODE(*icp=Ticvalue(35,60));
CODE(cout << v1(1) << ", " << v2(1) << endl);
CODE(const Ticvalue *cicp1=fv1.castedpointer<const Ticvalue>());
CODE(const Ticvalue *cicp2=fv2.castedpointer<const Ticvalue>());
CODE(cout << *cicp1 << ", " << *cicp2 << endl);
section("That's dangerous:",' ');
CODE(Tcvalue *cp=fv1.castedpointer<Tcvalue>());
CODE(*cp=Ticvalue(35,60));
CODE(cout << v1(1) << ", " << v2(1) << endl);
CODE(double *dp=fv1.castedpointer<double>());
CODE(*dp=35.e12);
CODE(cout << v1(1) << ", " << v2(1) << endl);
#ifdef ILLEGAL1
#warning intentionally compiling illegal code:
#warning direct discard of const qualifier in conversion from non-const
CODE(Ticvalue *ip1=fv1.castedpointer<const Ticvalue>());
#endif
#ifdef ILLEGAL2
#warning intentionally compiling illegal code:
#warning direct discard of const qualifier in conversion from const array
CODE(Ticvalue *ip2=fv2.castedpointer<const Ticvalue>());
#endif
#ifdef ILLEGAL3
#warning intentionally compiling illegal code:
#warning discards const in conversion (reinterpret_cast)
CODE(Ticvalue *ip3=fv2.castedpointer<Ticvalue>());
#endif
#ifdef ILLEGAL4
#warning intentionally compiling illegal code:
#warning direct type mismatch
CODE(float *ip4=fv1.castedpointer<Ticvalue>());
#endif
#ifdef ILLEGAL5
#warning intentionally compiling illegal code:
#warning wrong type size in conversion through reinterpret_cast
CODE(float *ip5=fv1.castedpointer<float>());
#endif
}
} // main
/* ----- END OF f77test.cc ----- */
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