mirror of
https://github.com/boostorg/python.git
synced 2026-01-30 20:12:37 +00:00
Simple int wrapper with optional tracing for test purposes
[SVN r1519]
This commit is contained in:
128
include/boost/python/suite/indexing/IntWrapper.cpp
Executable file
128
include/boost/python/suite/indexing/IntWrapper.cpp
Executable file
@@ -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 <ostream>
|
||||
|
||||
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<IntWrapper> () const
|
||||
{
|
||||
if (gIntWrapperTrace)
|
||||
{
|
||||
printf ("IntWrapper %u shared_ptr conversion\n", mObjNumber);
|
||||
}
|
||||
|
||||
return boost::shared_ptr<IntWrapper> (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;
|
||||
}
|
||||
53
include/boost/python/suite/indexing/IntWrapper.hpp
Executable file
53
include/boost/python/suite/indexing/IntWrapper.hpp
Executable file
@@ -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 <iosfwd>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
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<IntWrapper> () 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
|
||||
Reference in New Issue
Block a user