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

code to handle virtual base classes

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: 1799
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 32299b97
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: handle.h,v 1.3 2005-07-04 13:06:10 tforb Exp $
* $Id: handle.h,v 1.4 2005-07-04 13:37:59 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
......@@ -23,7 +23,7 @@
#define TF_HANDLE_H_VERSION \
"TF_HANDLE_H V1.0 "
#define TF_HANDLE_H_CVSID \
"$Id: handle.h,v 1.3 2005-07-04 13:06:10 tforb Exp $"
"$Id: handle.h,v 1.4 2005-07-04 13:37:59 tforb Exp $"
namespace tfxx {
......@@ -55,7 +55,7 @@ namespace tfxx {
*
* @author Bjarne Stroustrup,
* @author Thomas Forbriger
* @version V1.0 (#$Revision: 1.3 $ $Date: 2005-07-04 13:06:10 $#)
* @version V1.0 (#$Revision: 1.4 $ $Date: 2005-07-04 13:37:59 $#)
* @memo template providing a handle to an object of any type
*/
template<class X>
......@@ -73,22 +73,25 @@ class ConstHandle {
*
* This constructor is used in the following way:
*
* #THandle<X> handle(new X);#
* #THandle<X> handle(X);#
*
* @memo init constructor
ConstHandle(Tobject* p): Mrep(p), Mpcount(new int(1)) { }
*/
/** constructor #tfxx::THandle<class X>::THandle#:
ConstHandle(Treference p):
Mrep(new Tmutableobject(p)), Mpcount(new int(1)) { }
/*! Constructor to handle virtual base classes
*
* This constructor is used in the following way:
* This constructor \b must be used in the following way:
*
* #THandle<X> handle(X);#
* #THandle<X> handle(new X);#
*
* @memo init constructor
* \note
* Do not pass any other pointer, since the destructor will call the
* delete operator on p.
*/
ConstHandle(Treference p):
Mrep(new Tmutableobject(p)), Mpcount(new int(1)) { }
ConstHandle(Tmutableobject* p):
Mrep(p), Mpcount(new int(1)) { }
/** constructor #tfxx::THandle<class X>::THandle#:
*
......@@ -170,6 +173,18 @@ class Handle: public ConstHandle<X> {
*/
Handle(const Treference p): Tbase(p) { }
/*! Constructor to handle virtual base classes
*
* This constructor \b must be used in the following way:
*
* #THandle<X> handle(new X);#
*
* \note
* Do not pass any other pointer, since the destructor will call the
* delete operator on p.
*/
Handle(Tpointer p): Tbase(p) { }
/** constructor #tfxx::THandle<class X>::THandle#:
*
* This constructor is used in the following way together with another
......@@ -181,11 +196,6 @@ class Handle: public ConstHandle<X> {
*/
Handle(const Handle& h): Tbase(h) { }
/** desctructor #tfxx::THandle<class X>::~THandle#
* @memo book-keeping destructor
~Handle() { }
*/
/** operator #tfxx::THandle<class X>::operator->()#
* @return returns pointer to object of type #class X#
* @memo dereferencing operator
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: handletest.cc,v 1.1 2005-07-04 13:06:11 tforb Exp $
* $Id: handletest.cc,v 1.2 2005-07-04 13:37:59 tforb Exp $
* \author Thomas Forbriger
* \date 04/07/2005
*
......@@ -19,9 +19,10 @@
#define HANDLETEST_VERSION \
"HANDLETEST V1.0 test handle containers"
#define HANDLETEST_CVSID \
"$Id: handletest.cc,v 1.1 2005-07-04 13:06:11 tforb Exp $"
"$Id: handletest.cc,v 1.2 2005-07-04 13:37:59 tforb Exp $"
#include <iostream>
#include <string>
#include <tfxx/commandline.h>
#include <tfxx/handle.h>
#include <tfxx/range.h>
......@@ -46,6 +47,28 @@ std::ostream& operator << (std::ostream& os,
const tfxx::ConstHandle<Tirange>& r)
{ os << r->first() << "-" << r->last(); }
class Any {
public:
virtual ~Any() { }
virtual void print() const { cout << "ERROR: called base!" << endl; }
}; // class Any
class Int: public Any {
public:
Int(const int& v): Mv(v) { }
void print() const { cout << Mv << endl; }
private:
int Mv;
}; // class Int
class String: public Any {
public:
String(const std::string& v): Mv(v) { }
void print() const { cout << Mv << endl; }
private:
std::string Mv;
}; // class Int
int main(int iargc, char* argv[])
{
......@@ -110,6 +133,22 @@ int main(int iargc, char* argv[])
ILLEGAL( ch1->shift(10) );
CODE( cout << *h1 << ", " << h1 << endl );
CODE( cout << *ch1 << ", " << ch1 << endl );
CODE( String s1("Hi there") );
CODE( s1.print() );
CODE( Int i1(13) );
CODE( i1.print() );
CODE( typedef tfxx::Handle<Any> Tanyhandle );
CODE( Tanyhandle ah1(s1) );
CODE( ah1->print() );
CODE( Tanyhandle ah2(new String("ein string")) );
CODE( ah2->print() );
CODE( Tanyhandle ah3(ah2) );
CODE( ah3->print() );
CODE( Tanyhandle ah4(new Int(4321)) );
CODE( ah4->print() );
CODE( ah3=ah4 );
CODE( ah3->print() );
}
/* ----- END OF handletest.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