mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 17:52:17 +00:00
Renamed IntWrapper to int_wrapper
[SVN r20384]
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
// -*- mode:c++ -*-
|
||||
//
|
||||
// Header file IntWrapper.hpp
|
||||
//
|
||||
// Copyright (c) 2003 Raoul M. Gough
|
||||
//
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
|
||||
// at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// History
|
||||
// =======
|
||||
// 2003/ 9/10 rmg File creation
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#ifndef IntWrapper_rmg_20030910_included
|
||||
#define IntWrapper_rmg_20030910_included
|
||||
|
||||
#include <ostream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
struct IntWrapper {
|
||||
static bool gIntWrapperTrace;
|
||||
static unsigned ourObjectCounter;
|
||||
int mObjNumber;
|
||||
int mI;
|
||||
|
||||
inline IntWrapper ();
|
||||
inline explicit IntWrapper (int i);
|
||||
inline IntWrapper (IntWrapper const &other);
|
||||
inline IntWrapper &operator= (IntWrapper const &other);
|
||||
inline ~IntWrapper ();
|
||||
|
||||
inline void increment();
|
||||
|
||||
inline operator boost::shared_ptr<IntWrapper> () const;
|
||||
|
||||
inline static void setTrace (bool onoff);
|
||||
};
|
||||
|
||||
inline bool operator== (IntWrapper const &lhs, IntWrapper const &rhs);
|
||||
inline bool operator!= (IntWrapper const &lhs, IntWrapper const &rhs);
|
||||
inline bool operator< (IntWrapper const &lhs, IntWrapper const &rhs);
|
||||
inline int compare (IntWrapper const &lhs, IntWrapper const &rhs);
|
||||
inline std::ostream &operator<< (std::ostream &strm, IntWrapper const &iw);
|
||||
|
||||
//
|
||||
// This is ugly. Put all of this stuff inline to avoid needing a
|
||||
// separate object file for testing (don't know how to do this in
|
||||
// Jam). Client module will have to define the following variables:
|
||||
//
|
||||
// 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 (bool 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;
|
||||
}
|
||||
|
||||
bool operator< (IntWrapper const &lhs, IntWrapper const &rhs)
|
||||
{
|
||||
return lhs.mI < rhs.mI;
|
||||
}
|
||||
|
||||
int compare (IntWrapper const &lhs, IntWrapper const &rhs)
|
||||
{
|
||||
if (lhs < rhs)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
else if (rhs < lhs)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<< (std::ostream &strm, IntWrapper const &iw)
|
||||
{
|
||||
strm << iw.mI;
|
||||
return strm;
|
||||
}
|
||||
|
||||
#endif // IntWrapper_rmg_20030910_included
|
||||
182
test/int_wrapper.hpp
Executable file
182
test/int_wrapper.hpp
Executable file
@@ -0,0 +1,182 @@
|
||||
// -*- mode:c++ -*-
|
||||
//
|
||||
// Header file int_wrapper.hpp
|
||||
//
|
||||
// Copyright (c) 2003 Raoul M. Gough
|
||||
//
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
|
||||
// at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// History
|
||||
// =======
|
||||
// 2003/ 9/10 rmg File creation as IntWrapper.hpp
|
||||
// 2003/10/15 rmg Renamed int_wrapper.hpp (Boost naming convention)
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#ifndef int_wrapper_rmg_20030910_included
|
||||
#define int_wrapper_rmg_20030910_included
|
||||
|
||||
#include <ostream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
struct int_wrapper {
|
||||
static bool our_trace_flag;
|
||||
static unsigned our_object_counter;
|
||||
int mObjNumber;
|
||||
int mI;
|
||||
|
||||
inline int_wrapper ();
|
||||
inline explicit int_wrapper (int i);
|
||||
inline int_wrapper (int_wrapper const &other);
|
||||
inline int_wrapper &operator= (int_wrapper const &other);
|
||||
inline ~int_wrapper ();
|
||||
|
||||
inline void increment();
|
||||
|
||||
inline operator boost::shared_ptr<int_wrapper> () const;
|
||||
|
||||
inline static void setTrace (bool onoff);
|
||||
};
|
||||
|
||||
inline bool operator== (int_wrapper const &lhs, int_wrapper const &rhs);
|
||||
inline bool operator!= (int_wrapper const &lhs, int_wrapper const &rhs);
|
||||
inline bool operator< (int_wrapper const &lhs, int_wrapper const &rhs);
|
||||
inline int compare (int_wrapper const &lhs, int_wrapper const &rhs);
|
||||
inline std::ostream &operator<< (std::ostream &strm, int_wrapper const &iw);
|
||||
|
||||
//
|
||||
// This is ugly. Put all of this stuff inline to avoid needing a
|
||||
// separate object file for testing (don't know how to do this in
|
||||
// Jam). Client module will have to define the following variables:
|
||||
//
|
||||
// bool int_wrapper::our_trace_flag = true;
|
||||
// unsigned int_wrapper::our_object_counter = 0;
|
||||
//
|
||||
|
||||
int_wrapper::int_wrapper ()
|
||||
: mObjNumber (our_object_counter++)
|
||||
, mI (0)
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u ()\n", mObjNumber);
|
||||
}
|
||||
}
|
||||
|
||||
int_wrapper::int_wrapper (int i)
|
||||
: mObjNumber (our_object_counter++)
|
||||
, mI (i)
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u (%d)\n"
|
||||
, mObjNumber
|
||||
, mI);
|
||||
}
|
||||
}
|
||||
|
||||
int_wrapper::int_wrapper (int_wrapper const &other)
|
||||
: mObjNumber (our_object_counter++)
|
||||
, mI (other.mI)
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u (int_wrapper %u)\n"
|
||||
, mObjNumber
|
||||
, other.mObjNumber);
|
||||
}
|
||||
}
|
||||
|
||||
int_wrapper &int_wrapper::operator= (int_wrapper const &other)
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u = int_wrapper %u\n"
|
||||
, mObjNumber
|
||||
, other.mObjNumber);
|
||||
}
|
||||
|
||||
mI = other.mI;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int_wrapper::~int_wrapper ()
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("~int_wrapper %u\n", mObjNumber);
|
||||
}
|
||||
|
||||
mI = 0xbaaaaaad;
|
||||
}
|
||||
|
||||
void int_wrapper::increment()
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u::increment\n", mObjNumber);
|
||||
}
|
||||
|
||||
++mI;
|
||||
}
|
||||
|
||||
int_wrapper::operator boost::shared_ptr<int_wrapper> () const
|
||||
{
|
||||
if (our_trace_flag)
|
||||
{
|
||||
printf ("int_wrapper %u shared_ptr conversion\n", mObjNumber);
|
||||
}
|
||||
|
||||
return boost::shared_ptr<int_wrapper> (new int_wrapper (*this));
|
||||
}
|
||||
|
||||
void int_wrapper::setTrace (bool onoff)
|
||||
{
|
||||
our_trace_flag = onoff;
|
||||
}
|
||||
|
||||
bool operator== (int_wrapper const &lhs, int_wrapper const &rhs)
|
||||
{
|
||||
return lhs.mI == rhs.mI;
|
||||
}
|
||||
|
||||
bool operator!= (int_wrapper const &lhs, int_wrapper const &rhs)
|
||||
{
|
||||
return lhs.mI != rhs.mI;
|
||||
}
|
||||
|
||||
bool operator< (int_wrapper const &lhs, int_wrapper const &rhs)
|
||||
{
|
||||
return lhs.mI < rhs.mI;
|
||||
}
|
||||
|
||||
int compare (int_wrapper const &lhs, int_wrapper const &rhs)
|
||||
{
|
||||
if (lhs < rhs)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
else if (rhs < lhs)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<< (std::ostream &strm, int_wrapper const &iw)
|
||||
{
|
||||
strm << iw.mI;
|
||||
return strm;
|
||||
}
|
||||
|
||||
#endif // int_wrapper_rmg_20030910_included
|
||||
Reference in New Issue
Block a user