473,770 Members | 6,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#include <boost/intrusive_ptr.h pp>

I'm trying to create an baseclass that will serve as a parent for reference
counted objects handled by boost::intrusiv e_ptr<>. The documentation
didn't provide much in the way of describing what the functions
intrusive_ptr_a dd_ref and intrusive_ptr_r elease 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_a dd_ref and intrusive_ptr_r elease
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::Reference d, 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*****@globals ymmetry.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.h pp>
#include <boost/mem_fn.hpp>
namespace util {

class Referenced_IF {
friend void intrusive_ptr_a dd_ref(const Referenced_IF* r);
friend void intrusive_ptr_r elease(const Referenced_IF* r);

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

protected:
virtual ~Referenced_IF( ) {}
};

typedef boost::intrusiv e_ptr<Reference d_IF> iref_ptr;

inline void intrusive_ptr_a dd_ref(const Referenced_IF* r)
{ r->increment(); }
inline void intrusive_ptr_r elease(const Referenced_IF* r)
{ r->decrement(); }

}
#endif

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

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

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

class SignalListener_ IF: public util::Reference d_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::intrusiv e_ptr<SignalLis tener_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(_listen ers.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.remo ve(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::sig nal)); }

std::list<Liste ner_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 2519
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
2583
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 available to the scripts). I ran into trouble trying to expose a specific instance (or even a function returning the instance). Here is a simplification of my problem in code (c++): <code> class A{ public:
4
3152
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 after A has been defined };
0
2214
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 described in the Bridge-Pattern. Therefore I have the following classes: Instrument InstrumentImpl InstrumentData
1
2090
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(',')); but it gives the weird messages:
7
1671
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 work with. For instance, if you want to default initialise something, you have to know what kind of type you're dealing with. A) Intrinsic int a = 0; char* p = 0;
3
2397
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 using namespace boost::python; static PyObject * proc_buf(PyObject *self, PyObject *args) { PyObject *resultobj;
1
4159
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 headers), or is it for general "stable" include files? What about the grey areas in between these and actual application code, e.g. headers for a library that is under my control but external to the project being compiled? I know both styles...
27
4359
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 type was the target of a cast. Of course with a reinterpret_cast nothing complains until the UB bites you in the ass. It seems to me that there ought to be a way to deal with these kinds of functions yet still retain some semblance of type...
3
6410
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 getting this // Include files #include <cmath> #include <iostream> #include <vector>
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.