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

new concept of const correct containers does not use qualified anymore!

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.
moved AllocException to error.h and error.cc (iostream needs not be included
anymore)


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1200
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 788c3128
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.1 2002-12-10 19:30:07 forbrig Exp $
* $Id: error.cc,v 1.2 2002-12-16 20:41:53 forbrig Exp $
* \author Thomas Forbriger
* \date 27/11/2002
*
......@@ -13,13 +13,15 @@
*
* REVISIONS and CHANGES
* - 10/12/2002 V1.0 copied from libtfxx
* - 16/12/2002 V1.1 (thof)
* - now contains AllocException too
*
* ============================================================================
*/
#define AFF_ERROR_CC_VERSION \
"AFF_ERROR_CC V1.0 "
"AFF_ERROR_CC V1.1"
#define AFF_ERROR_CC_CVSID \
"$Id: error.cc,v 1.1 2002-12-10 19:30:07 forbrig Exp $"
"$Id: error.cc,v 1.2 2002-12-16 20:41:53 forbrig Exp $"
#include <iostream>
#include <aff/lib/error.h>
......@@ -104,6 +106,21 @@ namespace aff {
}
}
/*======================================================================*/
// AllocException code
//! instantiate AllocException
AllocException::AllocException(const Tsize& n, const Tsize& size):
Exception("ERROR: memory allocation failed!"), Mn(n), Msize(size) { }
//! report AllocException
void AllocException::report() const
{
base_report();
std::cout << " You requested " << Mn << " memory locations of "
<< Msize << " Bytes size." << std::endl;
}
} // namespace aff
/* ----- END OF error.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.3 2002-12-13 23:48:29 forbrig Exp $
* $Id: error.h,v 1.4 2002-12-16 20:41:53 forbrig Exp $
* \author Thomas Forbriger
* \date 27/11/2002
*
......@@ -18,6 +18,8 @@
*
* REVISIONS and CHANGES
* - 10/12/2002 V1.0 copied from libtfxx
* - 16/12/2002 V1.1 (thof)
* - now contains AllocException too
*
* ============================================================================
*/
......@@ -26,9 +28,9 @@
#ifndef AFF_ERROR_H_VERSION
#define AFF_ERROR_H_VERSION \
"AFF_ERROR_H V1.0 "
"AFF_ERROR_H V1.1"
#define AFF_ERROR_H_CVSID \
"$Id: error.h,v 1.3 2002-12-13 23:48:29 forbrig Exp $"
"$Id: error.h,v 1.4 2002-12-16 20:41:53 forbrig Exp $"
namespace aff {
......@@ -91,6 +93,26 @@ namespace aff {
const char* Mcondition;
}; // class Exception
/*----------------------------------------------------------------------*/
/*! \brief Exception thrown in case of allocation error
*
* \ingroup group_error
* \sa aff::Exception
*/
class AllocException:
public Exception
{
public:
//! take number of requested elements and their size
AllocException(const Tsize& n, const Tsize& size);
//! Screen report
virtual void report() const;
private:
//! members to remember
Tsize Mn, Msize;
}; // class AllocException
} // namespace aff
/*======================================================================*/
......
/*! \file qualified.h
* \brief qualified type names
*
* ----------------------------------------------------------------------------
*
* $Id: qualified.h,v 1.3 2002-12-15 20:48:01 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
* qualified type names: aff::util::Qualified
*
* \note
* This file is not ment to be included directly. It is read through array.h
* and binarray.h
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 08/12/2002 V1.0 copied from libcontxx
* - 15/12/2002 V1.1 (thof)
* - no need to place this in namespace prebuilt
*
* ============================================================================
*/
// include guard
#ifndef AFF_QUALIFIED_H_VERSION
#define AFF_QUALIFIED_H_VERSION \
"AFF_QUALIFIED_H V1.1"
#define AFF_QUALIFIED_H_CVSID \
"$Id: qualified.h,v 1.3 2002-12-15 20:48:01 forbrig Exp $"
namespace aff {
namespace util {
/*!\brief These are typedefs for types with/without const qualifier.
*
* \anchor anchor_qualified_base
*
* This is a traits like class definition. It simply defines derived
* typedefs for a given type passed through the template parameter.
* Our mechanism of converting an array to an array of const element type
* needs this class. Since the conversion operator must also be meaningful
* for arrays that are already defined for a const element type we have to
* ask aff::util::Qualified for the correct const version of the element
* type. A partial \ref anchor_qualified_special "specialization" provides
* the correct defintion for arrays that already have const element type.
*
* \sa \ref sec_main_constness
* \sa \ref sec_representation_const
*
* There exists a \ref anchor_qualified_special "specialization"
* aff::util::Qualified for const template argument type (see
* aff::util).
*
* This class is presented in util/qualified.h and namespace contxx::util
*/
template<class T>
class Qualified {
public:
typedef T Tvalue;
typedef T* Tpointer;
typedef T& Treference;
typedef const T Tconst_value;
typedef const T* Tconst_pointer;
typedef const T& Tconst_reference;
typedef T Tmutable_value;
typedef T* Tmutable_pointer;
typedef T& Tmutable_reference;
};
/*! \brief Partial specialization for const qualified types.
*
* \anchor anchor_qualified_special
*
* This is a specialization of the \ref anchor_qualified_base "normal"
* aff::util::Qualified for const template argument type (see
* aff::util).
*
* This class is presented in util/qualified.h and namespace contxx::util
*/
template<typename T>
class Qualified<const T> {
public:
typedef const T Tvalue;
typedef const T* Tpointer;
typedef const T& Treference;
typedef const T Tconst_value;
typedef const T* Tconst_pointer;
typedef const T& Tconst_reference;
typedef T Tmutable_value;
typedef T* Tmutable_pointer;
typedef T& Tmutable_reference;
};
} // namespace util
} // namespace aff
#endif // AFF_QUALIFIED_H_VERSION (includeguard)
/* ----- END OF qualified.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap.h,v 1.8 2002-12-16 18:02:01 forbrig Exp $
* $Id: sharedheap.h,v 1.9 2002-12-16 20:41:53 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -16,6 +16,9 @@
*
* REVISIONS and CHANGES
* - 08/12/2002 V1.0 copied from libcontxx
* - 16/12/2002 V1.1 (thof)
* - introduced new concept of const correct containers
* - moved AllocException to error.h
*
* ============================================================================
*/
......@@ -24,14 +27,13 @@
#ifndef AFF_SHAREDHEAP_H_VERSION
#define AFF_SHAREDHEAP_H_VERSION \
"AFF_SHAREDHEAP_H V1.2 "
"AFF_SHAREDHEAP_H V1.1"
#define AFF_SHAREDHEAP_H_CVSID \
"$Id: sharedheap.h,v 1.8 2002-12-16 18:02:01 forbrig Exp $"
"$Id: sharedheap.h,v 1.9 2002-12-16 20:41:53 forbrig Exp $"
#include<new>
#include<aff/lib/error.h>
#include<aff/lib/types.h>
#include<aff/lib/qualified.h>
namespace aff {
......@@ -39,30 +41,6 @@ namespace aff {
namespace prebuilt {
#endif
#ifdef AFF_PREBUILT
using namespace aff::prebuilt::util;
#else
using namespace aff::util;
#endif
/*! \brief Exception thrown in case of allocation error
*
* \ingroup group_error
* \sa aff::Exception
*/
class AllocException:
public Exception
{
public:
//! take number of requested elements and their size
AllocException(const Tsize& n, const Tsize& size);
//! Screen report
virtual void report() const;
private:
//! members to remember
Tsize Mn, Msize;
}; // class AllocException
/*----------------------------------------------------------------------*/
/*! \brief A structure to be shared between different SharedHeap instances.
......@@ -98,7 +76,7 @@ namespace prebuilt {
bool Mextern; //!< true if memory allocation is handled elsewhere
}; // struct SHeap
/*----------------------------------------------------------------------*/
/*======================================================================*/
/*! \brief A template class to share heap memory for different array
* projections.
......@@ -110,32 +88,83 @@ namespace prebuilt {
*
* \sa aff::SHeap
*/
template <typename T>
class SharedHeap
template <class T>
class SharedHeap: private SharedHeap<const T>
{
public:
//! Element type
typedef typename Qualified<T>::Tvalue Tvalue;
typedef T Tvalue;
//! Type of pointer to element
typedef typename Qualified<T>::Tpointer Tpointer;
typedef T* Tpointer;
//! Type of reference to element
typedef typename Qualified<T>::Treference Treference;
//! Type of const reference to element
typedef typename Qualified<T>::Tconst_reference Tconst_reference;
//! Type to be used as data representation
typedef typename Qualified<T>::Tmutable_value Tmutable_value;
//! Type to pass externally managed pointer to counted reference object
typedef typename Qualified<T>::Tmutable_pointer Tmutable_pointer;
//! Type to be used as element for const version
typedef typename Qualified<T>::Tconst_value Tconst_value;
typedef T& Treference;
//! base class
typedef SharedHeap<const T> Tbase;
//! Type of const version of SharedHeap
typedef SharedHeap<Tconst_value> Tcontainer_of_const;
typedef Tbase Tcontainer_of_const;
//! short for container of const
typedef SharedHeap<Tconst_value> Tcoc;
typedef Tbase Tcoc;
public:
//! Create from nothing.
SharedHeap(): Tbase() { }
//! Allocate new heap memory.
SharedHeap(const Tsize& size): Tbase(size) { }
//! Create representation for externally managed memory
SharedHeap(Tpointer* pointer, const Tsize& size):
Tbase(pointer, size) { }
//! Copy representation to share heap.
SharedHeap(const SharedHeap<T>& sharedheap):
Tbase(sharedheap) { }
//! 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)); }
}; // class SharedHeap
/*======================================================================*/
/*! \brief Specialization for const data (base class)
*/
template <class T>
class SharedHeap<const T>
{
public:
//! 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 const version of SharedHeap
typedef SharedHeap<const T> Tcontainer_of_const;
//! short for container of const
typedef SharedHeap<const T> Tcoc;
private:
//! Type of SHeap struct to be used in any case
typedef SHeap<Tmutable_value> Theapstruct;
typedef SHeap<T> Theapstruct;
public:
//! Create from nothing.
......@@ -145,10 +174,10 @@ namespace prebuilt {
SharedHeap(const Tsize& size);
//! Create representation for externally managed memory
SharedHeap(Tpointer* pointer, const Tsize& size);
SharedHeap(Tmutable_pointer* pointer, const Tsize& size);
//! Copy representation to share heap.
SharedHeap(const SharedHeap& sharedheap);
SharedHeap(const SharedHeap<const T>& sharedheap);
//! Copy representation to share heap.
SharedHeap(Theapstruct* heapstruct);
......@@ -157,7 +186,7 @@ namespace prebuilt {
~SharedHeap();
//! Copy representation to share heap.
SharedHeap& operator=(const SharedHeap& sharedheap);
SharedHeap<const T>& operator=(const SharedHeap<const T>& sharedheap);
/*! Return size (always inline).
* \retval size of array on heap.
......@@ -169,62 +198,44 @@ namespace prebuilt {
/*! Return array access.
* \return pointer to array on heap
*/
Tpointer array();
const T* array() const
{ return(Mheapstruct->Mheap); }
//! Index operator (always inline).
inline
Treference operator[](const Tsubscript& i)
const T& operator[](const Tsubscript& i) const
{
#ifdef AFF_INDEXCHECK
int ii=i;
if ((ii>=int(Mheapstruct->Msize)) || (ii<0))
{
throw "SharedHeap: illegal index position!";
}
AFF_assert(((ii<Tsubscript(Mheapstruct->Msize)) && (ii>0)),
"SharedHeap: illegal index position!");
#endif
return(Mheapstruct->Mheap[i]);
}
/*-----------------------------------------------------------------*/
// here starts the PROTECTED section!
// ----------------------------------
protected:
//! Index operator (always inline).
inline
Tconst_reference operator[](const Tsubscript& i) const
T& operator[](const Tsubscript& i)
{
#ifdef AFF_INDEXCHECK
int ii=i;
if ((ii>=int(Mheapstruct->Msize)) || (ii<0))
{
throw "SharedHeap: illegal index position!";
}
AFF_assert(((ii<Tsubscript(Mheapstruct->Msize)) && (ii>0)),
"SharedHeap: illegal index position!");
#endif
return(Mheapstruct->Mheap[i]);
}
/*! conversion operator
*
* \note
* This conversion operation does not work when passing a reference to
* a function! Declaring a function
* \code
* void func(const aff::SharedHeap<T>::Tcoc& sh);
* \endcode
* is useless. It will not implicitely convert a \c aff::SharedHeap<T>
* to a \c aff::SharedHeap<T>::Tcoc, because they are indipendent
* types which means a temporary object of type
* aff::SharedHeap<T>::Tcoc must be created. This only works with
* \code
* void func(aff::SharedHeap<T>::Tcoc sh);
* \endcode
* which is passing by value.
/*! Return array access.
* \return pointer to array on heap
*/
operator Tcontainer_of_const() const
{
Tcontainer_of_const retval(Mheapstruct);
return(retval);
}
T* mutable_array()
{ return(Mheapstruct->Mheap); }
private:
Theapstruct* Mheapstruct; //!< shared heap structure
}; // class SharedHeap
}; // class SharedHeap<const T>
#ifdef AFF_PREBUILT
} // namespace prebuilt
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap_def.h,v 1.6 2002-12-15 19:32:52 forbrig Exp $
* $Id: sharedheap_def.h,v 1.7 2002-12-16 20:41:53 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -31,9 +31,7 @@
#define AFF_SHAREDHEAP_DEF_H_VERSION \
"AFF_SHAREDHEAP_DEF_H V1.0 "
#define AFF_SHAREDHEAP_DEF_H_CVSID \
"$Id: sharedheap_def.h,v 1.6 2002-12-15 19:32:52 forbrig Exp $"
#include<iostream>
"$Id: sharedheap_def.h,v 1.7 2002-12-16 20:41:53 forbrig Exp $"
namespace aff {
......@@ -47,18 +45,6 @@ namespace prebuilt {
#endif
#endif
//! instantiate AllocException
AllocException::AllocException(const Tsize& n, const Tsize& size):
Exception("ERROR: memory allocation failed!"), Mn(n), Msize(size) { }
//! report AllocException
void AllocException::report() const
{
base_report();
std::cout << " You requested " << Mn << " memory locations of "
<< Msize << " Bytes size." << std::endl;
}
/*----------------------------------------------------------------------*/
//! create counted reference object
......@@ -99,13 +85,13 @@ namespace prebuilt {
//! create representation from nothing
template <typename T>
inline
SharedHeap<T>::SharedHeap()
SharedHeap<const T>::SharedHeap()
: Mheapstruct(new Theapstruct(0)) { }
//! create representation for given number of elements
template <typename T>
inline
SharedHeap<T>::SharedHeap(const Tsize& size)
SharedHeap<const T>::SharedHeap(const Tsize& size)
: Mheapstruct(new Theapstruct(size)) { }
/*! \brief create from externally managed memory
......@@ -119,37 +105,28 @@ namespace prebuilt {
*/
template <typename T>
inline
SharedHeap<T>::SharedHeap(Tpointer* pointer, const Tsize& size)
SharedHeap<const T>::SharedHeap(Tpointer* pointer, const Tsize& size)
: Mheapstruct(new Theapstruct(static_cast<Tmutable_pointer>(pointer),
size)) { }
//! create representation from counted reference
template <typename T>
inline
SharedHeap<T>::SharedHeap(Theapstruct* heapstruct)
SharedHeap<const T>::SharedHeap(Theapstruct* heapstruct)
: Mheapstruct(heapstruct)
{ ++(Mheapstruct->Mnref); }
//! create representation from another representation
template <typename T>
inline
SharedHeap<T>::SharedHeap(const SharedHeap<T>& sharedheap)
SharedHeap<const T>::SharedHeap(const SharedHeap<const T>& sharedheap)
: Mheapstruct(sharedheap.Mheapstruct)
{ ++(Mheapstruct->Mnref); }
// this does not work!
/*
template <typename T>
inline
SharedHeap<T>::SharedHeap(const Tcontainer_of_mutable& sharedheap)
: Mheapstruc(sharedheap.Mheapstruc)
{ ++(Mheapstruc->Mnref); }
*/
//! delete representation
template <typename T>
inline
SharedHeap<T>::~SharedHeap()
SharedHeap<const T>::~SharedHeap()
{
if (--(Mheapstruct->Mnref) < 1)
{
......@@ -160,8 +137,8 @@ namespace prebuilt {
//! copy representation by exchanging counted reference
template <typename T>
inline
SharedHeap<T>::SharedHeap&
SharedHeap<T>::operator=(const SharedHeap<T>& sharedheap)
SharedHeap<const T>&
SharedHeap<const T>::operator=(const SharedHeap<T>& sharedheap)
{
if (Mheapstruct != sharedheap.Mheapstruct)
{
......@@ -175,13 +152,6 @@ namespace prebuilt {
return(*this);
}
//! return pointer to memory location (why not defined in class declaration?)
template <typename T>
inline
SharedHeap<T>::Tpointer
SharedHeap<T>::array()
{ return(Mheapstruct->Mheap); }
#ifdef AFF_PREBUILT
} // namespace prebuilt
#endif
......
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