mirror of
https://github.com/boostorg/utility.git
synced 2025-08-02 14:24:30 +02:00
*** empty log message ***
[SVN r2266]
This commit is contained in:
43
include/boost/utility/obj_id.hpp
Normal file
43
include/boost/utility/obj_id.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef UTILITY_OBJ_ID_HPP
|
||||
#define UTILITY_OBJ_ID_HPP
|
||||
namespace utility
|
||||
{
|
||||
struct obj_id
|
||||
/**@class obj_id
|
||||
* @brief Provide unique id for objects
|
||||
*/
|
||||
{
|
||||
typedef
|
||||
unsigned
|
||||
id_type
|
||||
;
|
||||
virtual //To make subj_described* start with obj_id*
|
||||
//See stl_container.log@@2003-06-05.0750
|
||||
~obj_id(void)
|
||||
{}
|
||||
obj_id(void)
|
||||
:m_id(the_last_id()++)
|
||||
{}
|
||||
obj_id(obj_id const&)
|
||||
:m_id(the_last_id()++)
|
||||
{}
|
||||
void
|
||||
operator=(obj_id const&)
|
||||
{}
|
||||
id_type
|
||||
id_get(void)const
|
||||
{ return m_id
|
||||
;}
|
||||
static
|
||||
id_type&
|
||||
the_last_id(void)
|
||||
//reference to count if id's created
|
||||
;
|
||||
private:
|
||||
id_type
|
||||
m_id
|
||||
;
|
||||
};//end obj_id struct
|
||||
}//exit utility namespace
|
||||
#endif
|
||||
|
89
include/boost/utility/object_tracked.hpp
Normal file
89
include/boost/utility/object_tracked.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
//Simple class which keeps track of members
|
||||
#ifndef UTILITY_OBJECT_TRACKED_HPP_LJE20040112
|
||||
#define UTILITY_OBJECT_TRACKED_HPP_LJE20040112
|
||||
#include <set>
|
||||
#include "boost/utility/obj_id.hpp"
|
||||
#include "boost/io/filters/mout.hpp"
|
||||
namespace utility
|
||||
{
|
||||
class object_tracked
|
||||
: public obj_id
|
||||
{
|
||||
public:
|
||||
struct
|
||||
set_of_objects_tracked
|
||||
: public std::set<object_tracked const*>
|
||||
{
|
||||
typedef
|
||||
std::set<object_tracked const*>
|
||||
super_type
|
||||
;
|
||||
set_of_objects_tracked(void)
|
||||
{}
|
||||
void
|
||||
reset(void)
|
||||
{
|
||||
super_type::clear();
|
||||
obj_id::the_last_id() = 0;
|
||||
}
|
||||
bool
|
||||
contains(object_tracked const*& a_obj)const
|
||||
{
|
||||
return find(a_obj) != end();
|
||||
}
|
||||
|
||||
};
|
||||
static
|
||||
set_of_objects_tracked
|
||||
our_members
|
||||
;
|
||||
static
|
||||
unsigned
|
||||
members_size(void)
|
||||
{
|
||||
return our_members.size();
|
||||
}
|
||||
|
||||
object_tracked(void)
|
||||
{
|
||||
our_members.insert(this);
|
||||
#ifdef UTILITY_OBJECT_TRACKED_TRACE_MODE
|
||||
mout()<<"object_tracked+:id="<<id_get()<<"\n";
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
virtual
|
||||
#endif
|
||||
~object_tracked(void)
|
||||
{
|
||||
#ifdef UTILITY_OBJECT_TRACKED_TRACE_MODE
|
||||
mout()<<"object_tracked-:id="<<id_get()<<":am_i_live="<<am_i_live()<<"\n";
|
||||
#endif
|
||||
utility::object_tracked const*me=this;
|
||||
our_members.erase(me);
|
||||
}
|
||||
bool
|
||||
am_i_live(void)const
|
||||
//Purpose:
|
||||
// Used to check for multiple destructor calls. Should always return true
|
||||
// if only place where our_members.erase is called is in
|
||||
// ~object_tracked.
|
||||
{
|
||||
utility::object_tracked const*me=this;
|
||||
bool result=utility::object_tracked::our_members.contains(me);
|
||||
return result;
|
||||
}
|
||||
static
|
||||
bool
|
||||
is_live(utility::object_tracked const*a_ot)
|
||||
{
|
||||
bool result=utility::object_tracked::our_members.contains(a_ot);
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}//exit utility namespace
|
||||
|
||||
#endif
|
||||
|
40
include/boost/utility/trace_scope.hpp
Normal file
40
include/boost/utility/trace_scope.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef TRACE_SCOPE_HPP
|
||||
#define TRACE_SCOPE_HPP
|
||||
#include "boost/io/filters/mout.hpp"
|
||||
#include <string>
|
||||
namespace utility
|
||||
{
|
||||
class
|
||||
trace_scope
|
||||
//Purpose:
|
||||
// Indicate on cout when a scope entered and exited.
|
||||
{
|
||||
public:
|
||||
trace_scope(char const* a_scopeName)
|
||||
: m_scopeName(a_scopeName)
|
||||
{ init()
|
||||
;}
|
||||
trace_scope(std::string const& a_scopeName)
|
||||
: m_scopeName(a_scopeName)
|
||||
{ init()
|
||||
;}
|
||||
~trace_scope(void)
|
||||
{
|
||||
; --mout()
|
||||
; std::string l_context("===>Exit:")
|
||||
; mout()<<l_context<<m_scopeName<<std::endl
|
||||
;}
|
||||
private:
|
||||
void
|
||||
init(void)
|
||||
{
|
||||
; std::string l_context("===>Enter:")
|
||||
; mout()<<l_context<<m_scopeName<<std::endl
|
||||
; ++mout()
|
||||
;}
|
||||
std::string
|
||||
m_scopeName
|
||||
;
|
||||
};//end trace_scope class
|
||||
}//exit utility namespace
|
||||
#endif
|
10
src/obj_id.cpp
Normal file
10
src/obj_id.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "boost/utility/obj_id.hpp"
|
||||
using namespace utility;
|
||||
// static
|
||||
obj_id::
|
||||
id_type&
|
||||
obj_id::
|
||||
the_last_id(void)
|
||||
{ static id_type last_id=0
|
||||
; return last_id
|
||||
;}
|
6
src/object_tracked.cpp
Normal file
6
src/object_tracked.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "boost/utility/object_tracked.hpp"
|
||||
using namespace utility;
|
||||
|
||||
utility::object_tracked::set_of_objects_tracked
|
||||
utility::object_tracked::our_members
|
||||
;
|
Reference in New Issue
Block a user