473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

#include <boost/intrusive_ptr.hpp>

I'm trying to create an baseclass that will serve as a parent for reference
counted objects handled by boost::intrusive_ptr<>. The documentation
didn't provide much in the way of describing what the functions
intrusive_ptr_add_ref and intrusive_ptr_release should do, nor even what
their signatures should be. There is one comment that has me a bit unsure
about whether my approach is a good one:"On compilers that support
argument-dependent lookup, intrusive_ptr_add_ref and intrusive_ptr_release
should be defined in the namespace that corresponds to their parameter;
otherwise, the definitions need to go in namespace boost."

Note that my baseclass is util::Referenced, and my functions are
util::intrusive_ptr_add_ref, and util::intrusive_ptr_release. My hope is
that I can derive from these in other namespaces and rely on the fact that
the baseclass is in util to avoid the unspecified problems that would arise
if the parameter is not in a namespace corresponding to the functions.
/************************************************** *************************
* Copyright (C) 2005 by Steven T. Hatton *
* ha*****@globalsymmetry.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/
#ifndef UTIL_REFERENCED_IF_H
#define UTIL_REFERENCED_IF_H

#include <boost/intrusive_ptr.hpp>
#include <boost/mem_fn.hpp>
namespace util {

class Referenced_IF {
friend void intrusive_ptr_add_ref(const Referenced_IF* r);
friend void intrusive_ptr_release(const Referenced_IF* r);

mutable unsigned _r;
void increment() const { ++_r; }
void decrement() const { if(!--_r) delete this; }

protected:
virtual ~Referenced_IF() {}
};

typedef boost::intrusive_ptr<Referenced_IF> iref_ptr;

inline void intrusive_ptr_add_ref(const Referenced_IF* r)
{ r->increment(); }
inline void intrusive_ptr_release(const Referenced_IF* r)
{ r->decrement(); }

}
#endif

//---------------------------------------------------------

The following seems to work. Can anybody see anything blatantly wrong with
it?
#ifndef CONTROL_SIGNALLISTENER_IF_H
#define CONTROL_SIGNALLISTENER_IF_H

#include <util/Referenced_IF.h>
namespace control {

class SignalListener_IF: public util::Referenced_IF {
public:
virtual void signal()=0;
protected:
virtual ~SignalListener_IF() {}
};
}

#endif

//---------------------------------------------------------
#ifndef SIGNALGENERATOR_IF_HH
#define SIGNALGENERATOR_IF_HH

#include <list>
#include <algorithm>
#include <functional>

#include "SignalListener_IF.h"

namespace control {

/*!\brief The SignalGenerator_IF class template provides an interface for
signal generators.

SignalGenerator_IF maintains a list of \c SignalListener_IF observers,
and notifies them
when an event occurs.
*/
class SignalGenerator_IF {

public:
typedef SignalListener_IF Listener_T;
typedef boost::intrusive_ptr<SignalListener_IF> Listener_ptr_T;

/*!
Adds \a listener to the list of observers. Does nothing if \a listener
is already present.
*/
void attachListener(Listener_T* listener) {
using namespace std;
Listener_ptr_T lptr(listener);
if(find(_listeners.begin(), _listeners.end(), listener) ==
_listeners.end())
_listeners.push_back(listener);
}

/*!
Removes \a listener from the list of observers. Does nothing if \a
listener is not present.
*/
void detachListener(Listener_T* listener)
{ _listeners.remove(listener); }

protected:
/*!
Derived classes should call this to notify all listeners that an event
has occurred.
*/
void _generateSignal() { std::for_each(_listeners.begin(),
_listeners.end(), boost::mem_fn(&Listener_T::signal)); }

std::list<Listener_ptr_T> _listeners;
};
}

#endif

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #1
4 2491
Clearly OT! Why don't you ask at Boost?

Jul 23 '05 #2
Panjandrum wrote:
Clearly OT! Why don't you ask at Boost?

That's the first time I ever heard that boost was OT on this news group.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #3
Steven T. Hatton wrote:
That's the first time I ever heard that boost was OT on this news group.


From: ===Welcome to comp.lang.c++! Read this first.

"First of all, please keep in mind that comp.lang.c++ is a group for
discussion of general issues of the C++ programming language, as
defined by the ANSI/ISO language standard. If you have a problem that
is specific to a particular system or compiler, you are much more
likely to get complete and accurate answers in a group that specializes
in your platform."

Jul 23 '05 #4
Panjandrum wrote:
Steven T. Hatton wrote:
That's the first time I ever heard that boost was OT on this news group.


From: ===Welcome to comp.lang.c++! Read this first.

"First of all, please keep in mind that comp.lang.c++ is a group for
discussion of general issues of the C++ programming language, as
defined by the ANSI/ISO language standard. If you have a problem that
is specific to a particular system or compiler, you are much more
likely to get complete and accurate answers in a group that specializes
in your platform."


http://tinyurl.com/8k4fl

http://www.boost.org/libs/smart_ptr/smart_ptr.htm
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TheDustbustr | last post by:
I'm writing a game in C++ which calls out to python for scripting. I'd like to expose the instance of my Game class (a singleton) to python (so that the instances of Clock, Camera, etc are...
4
by: Philippe Guglielmetti | last post by:
I just ported old (VC6) working code to VC7.1 and have trouble with something like: class A; // forward typedef boost::smart_ptr<A> Aptr; class B{ Aptr a; virtual ~B(); // implemented...
0
by: Sebastian Faust | last post by:
Hi, I am thinking now for a while about a design decision. I would be glad if you can give me some advices which is maybe the better way for solving my problem. I wanna do something like...
1
by: Ingo Nolden | last post by:
Hi, I am using spirit 1.31 I have been trying the following example from the spirit docs. I tried it with int and double neither works: vector<int> v; rule<> r = list_p(int_p, ch_p(',')); ...
7
by: Tomás | last post by:
Let's write a header file which has all sorts of things in it which help a programmer overcome what some people may see as "warts in C++", or maybe things that are just more convenient or nicer to...
3
by: tkirke | last post by:
How does one transfer a buffer object from python -c and back again (assuming the data gets modified)? I can't seem to get this or anything else to work, but am clueless as to what I'm doing wrong...
1
by: Colin Caughie | last post by:
Is there a general rule/convention for when to use angle brackets and when to use quotes in #include statements? Is the angle bracket reserved for "system" header files (e.g. standard library...
27
by: Noah Roberts | last post by:
What steps do people take to make sure that when dealing with C API callback functions that you do the appropriate reinterpret_cast<>? For instance, today I ran into a situation in which the wrong...
3
by: Chris Jones | last post by:
Hi, I've experimenting with using boost::pool_allocator with std::vector and gcc (4.1)., and I am having problems with segmentation violations. Below I give a simple example of one way I am...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.