473,756 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Introducting the "Medusa Class"


It started out as an ugly hack and it turned out to be very easy to do
but I'm concerned about wether I'm not seeing somthing so I'm asking the
wise ladies and gents of clc++ as to wether they turn to stone.

The problem goes like this. I have a class that uses an intrusive
reference count to manage the it's life-time. This class has multiple
interfaces e.g.

(using Austria C++ type smart pointers)...

struct A
: PtrTarget_MT
{
// ... things about A
};

struct B
: A
{
// ... things about B
};

In this system, it's good to know when all pointers to an objects B
interface have been released and it would be nice to do this automatically.

e.g.

Ptr<B*> l_b = new B;

Ptr<A*> l_a = l_b;

l_b = 0; // I'd like a special thing to happen in B here.

l_a = 0; // the object is now deleted as normal
With Austria smart pointers, you get to define a "PtrSelect" template
that can be used to select different behaviour for particular pointers.

template <
typename w_ClassRef,
typename w_First,
typename w_Second
class PtrSelect
{
public:
typedef w_First type;
};

Where type here is usually a

template<typena me w_ClassRef>
class at::PtrTraits< w_ClassRef >

see:
http://austria.sourceforge.net/dox/h...PtrTraits.html

All that's needed here is to create a partial specialization of
PtrSelect based on B (like so)

template <
typename w_First,
typename w_Second

class PtrSelect< B *, w_First, w_Second >
{
public:
typedef SpecialPtrTrait s<B *> type;
};

and viola, any increments and decrements from only the B class is now
tallied separately to A, and B can do somthing special when no more
pointers to B exist (not necessarily delete, or anything else that makes
sense).

The pro's to this are:

a) no new mechanisms to learn
b) infrastructure to do this is quite easy

The cons to this :

a) Unsuspecting programmer might not quite understand the relevance of
dropping a pointer to B and might turn to stone once they see it.

Has anyone else done somthing like this ?

PtrSelect<> was put there to do exactly this sort of thing, but the
twist is doing in the same class (different interfaces). I'd resisted
doing it in the past but this time (in this particular application) it
appears to be the best solution (for thread safety issues).

Opinions ?

Jul 22 '05 #1
0 1236

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

Similar topics

1
5666
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC { background-color: green} <div id="div1" class="classA classB" ... but then want to dynamically assign a new class
6
2517
by: dpr | last post by:
I have come accross a piece of C++ code with the construct: MyClass *c = new class MyClass(); Is there a difference between this and: MyClass *c = new MyClass(); ?
4
2496
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
3
1877
by: Alexander Farber | last post by:
Hi, does anyone have an idea, why do I get the following error (I have to use g++296 on RedHat Linux as compiler): In file included from r_dir.cpp:9: r_obey.h:262: declaration of `const AreaSet &CObeyFile::AreaSet () const' r_areaset.h:197: changes meaning of `AreaSet' from `class AreaSet'
1
2235
by: timbobd | last post by:
I have encountered a situation that I don't understand. When I call a sub of Friend scope (in an object with Friend scope), I am getting an error "Public member 'subname' not found in type 'myType'". Any idea why? Since Friend scope should be visible within my assembly, and everying is taking place within a single project, I don't understand why this error is occuring. Here is some illustrative code, where I would get the error in the...
9
3350
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
1
4286
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the book's instructions) and Line.h in included in Day10Doc.cpp Here is the contents of Day10Doc.h #if !defined(AFX_DAY10DOC_H__16736853_CB29_49E7_A8ED_C912CAE666EC__INCLUDED_) #define AFX_DAY10DOC_H__16736853_CB29_49E7_A8ED_C912CAE666EC__INCLUDED_ ...
2
4004
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down arrow and you see the entries in a dropdown. But how would I control this thing from javascript? Here is the HTML: <div class="selection" style="top:0; left:89; width:159; height:21;"
3
3351
by: Matt | last post by:
Hi everyone, can someone point out the difference between defining a class with the public access modifier and just leaving it as it is (default in vs.net "class") I think that the default access modifier applied if one isn't defined; so class would in fact be read as "private class" when it's compiled, but that isn't the case.
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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
7248
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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

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.