From a6a88eb88ddd2b9500c63a1e3d7a3df57ab027d0 Mon Sep 17 00:00:00 2001 From: Raoul Gough Date: Wed, 10 Sep 2003 11:24:21 +0000 Subject: [PATCH] Simple int wrapper with optional tracing for test purposes [SVN r1519] --- .../python/suite/indexing/IntWrapper.cpp | 128 ++++++++++++++++++ .../python/suite/indexing/IntWrapper.hpp | 53 ++++++++ 2 files changed, 181 insertions(+) create mode 100755 include/boost/python/suite/indexing/IntWrapper.cpp create mode 100755 include/boost/python/suite/indexing/IntWrapper.hpp diff --git a/include/boost/python/suite/indexing/IntWrapper.cpp b/include/boost/python/suite/indexing/IntWrapper.cpp new file mode 100755 index 00000000..f5c6dc04 --- /dev/null +++ b/include/boost/python/suite/indexing/IntWrapper.cpp @@ -0,0 +1,128 @@ +// -*- mode:c++ -*- +// +// Module IntWrapper.cpp +// +// Copyright (c) 2003 Raoul M. Gough +// +// This material is provided "as is", with absolutely no warranty expressed +// or implied. Any use is at your own risk. +// +// Permission to use or copy this material for any purpose is hereby +// granted without fee, provided the above notices are retained on all +// copies. Permission to modify the material and to distribute modified +// versions is granted, provided the above notices are retained, and a +// notice that the material was modified is included with the above +// copyright notice. +// +// History +// ======= +// 2003/ 9/10 rmg File creation +// +// $Id$ +// + +#include "IntWrapper.hpp" +#include + +bool IntWrapper::gIntWrapperTrace = true; + +unsigned IntWrapper::ourObjectCounter = 0; + +IntWrapper::IntWrapper () + : mObjNumber (ourObjectCounter++) + , mI (0) +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u ()\n", mObjNumber); + } +} + +IntWrapper::IntWrapper (int i) + : mObjNumber (ourObjectCounter++) + , mI (i) +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u (%d)\n" + , mObjNumber + , mI); + } +} + +IntWrapper::IntWrapper (IntWrapper const &other) + : mObjNumber (ourObjectCounter++) + , mI (other.mI) +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u (IntWrapper %u)\n" + , mObjNumber + , other.mObjNumber); + } +} + +IntWrapper &IntWrapper::operator= (IntWrapper const &other) +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u = IntWrapper %u\n" + , mObjNumber + , other.mObjNumber); + } + + mI = other.mI; + + return *this; +} + +IntWrapper::~IntWrapper () +{ + if (gIntWrapperTrace) + { + printf ("~IntWrapper %u\n", mObjNumber); + } + + mI = 0xbaaaaaad; +} + +void IntWrapper::increment() +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u::increment\n", mObjNumber); + } + + ++mI; +} + +IntWrapper::operator boost::shared_ptr () const +{ + if (gIntWrapperTrace) + { + printf ("IntWrapper %u shared_ptr conversion\n", mObjNumber); + } + + return boost::shared_ptr (new IntWrapper (*this)); +} + +void IntWrapper::setTrace (int onoff) +{ + gIntWrapperTrace = onoff; +} + +bool operator== (IntWrapper const &lhs, IntWrapper const &rhs) +{ + return lhs.mI == rhs.mI; +} + +bool operator< (IntWrapper const &lhs, IntWrapper const &rhs) +{ + return lhs.mI < rhs.mI; +} + +std::ostream &operator<< (std::ostream &strm, IntWrapper const &iw) +{ + strm << iw.mI; + return strm; +} diff --git a/include/boost/python/suite/indexing/IntWrapper.hpp b/include/boost/python/suite/indexing/IntWrapper.hpp new file mode 100755 index 00000000..c992063f --- /dev/null +++ b/include/boost/python/suite/indexing/IntWrapper.hpp @@ -0,0 +1,53 @@ +// -*- mode:c++ -*- +// +// Header file IntWrapper.hpp +// +// Copyright (c) 2003 Raoul M. Gough +// +// This material is provided "as is", with absolutely no warranty expressed +// or implied. Any use is at your own risk. +// +// Permission to use or copy this material for any purpose is hereby +// granted without fee, provided the above notices are retained on all +// copies. Permission to modify the material and to distribute modified +// versions is granted, provided the above notices are retained, and a +// notice that the material was modified is included with the above +// copyright notice. +// +// History +// ======= +// 2003/ 9/10 rmg File creation +// +// $Id$ +// + +#ifndef IntWrapper_rmg_20030910_included +#define IntWrapper_rmg_20030910_included + +#include +#include + +struct IntWrapper { + static bool gIntWrapperTrace; + static unsigned ourObjectCounter; + int mObjNumber; + int mI; + + IntWrapper (); + explicit IntWrapper (int i); + IntWrapper (IntWrapper const &other); + IntWrapper &operator= (IntWrapper const &other); + ~IntWrapper (); + + void increment(); + + operator boost::shared_ptr () const; + + static void setTrace (int onoff); +}; + +bool operator== (IntWrapper const &lhs, IntWrapper const &rhs); +bool operator< (IntWrapper const &lhs, IntWrapper const &rhs); +std::ostream &operator<< (std::ostream &strm, IntWrapper const &iw); + +#endif // IntWrapper_rmg_20030910_included