473,406 Members | 2,208 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,406 software developers and data experts.

dynamic class members workaround

If I'm not mistaken, C++ doesn't have support for dynamic class
members. I'm considering if such a facility would be useful, and what
method would make a good workaround.

I have a generic buffer class, which can have one or more cursor
classes attached to it. Right now, they are both separate classes,
and I use them as follows:

class Buffer {
...
}
class Cursor {
...
}

pBuffer = new Buffer;
pCursor = pBuffer->CreateCursor();
pCursor->Insert();
....
pBuffer->DestroyCursor(pCursor);

The parent buffer of pCursor is implicit at the Insert() call, when it
would preferably be explicit. A cleaner facility might be to create a
dynamic member for each cursor. Below, the parameter to CreateCursor
is the new name of the dynamic member, and the function knows the type
to which it must be initialized. The syntax
"pBuffer->pCursor->Insert()" would trigger an overridable lookup and
dispatch function in the buffer class, followed by the Insert()
function of the particular cursor instance.

pBuffer = new Buffer;
pBuffer->CreateCursor("pCursor");
pBuffer->pCursor->Insert();
....
pBuffer->DestroyCursor("pCursor");

The only way I can think of to achieve this kind of behavior, short of
importing some specialized non-standard library, is to use handles, C
style. Statement (2) below was actually my original technique, but
then the cursor and buffer code was intermingled.

pBuffer = new Buffer;
HANDLE pCursor;
pCursor = pBuffer->CreateCursor();
(1) pBuffer->GetCursor(pCursor)->Insert();
-OR-
(2) pBuffer->Insert(pCursor);
....
pBuffer->DestroyCursor(pCursor);

The drawback of the handle technique is that handles must be
maintained outside of the class, but it is fast because the handles
can be the indexes into the cursor class instance pointers array. I
suppose I could create a hash table for cursor names, and then refer
to them using the string name, like this:

pBuffer = new Buffer;
pBuffer->CreateCursor("MyCursor");
pBuffer->GetCursor("MyCursor")->Insert();
....
pBuffer->DestroyCursor("MyCursor");

I like this solution, but there is performance overhead of using a
hash table to lookup the class instance for the given string at
runtime. Anyway, I'm just writing to clarify my thoughts. I will
probably use the split class method I outlined first just for its low
overhead. If you have any comments, feel free to reply.
Jul 22 '05 #1
0 1538

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

Similar topics

5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
2
by: twawsico | last post by:
I ran into this while converting some DX C# code to VB.NET (VS 2003), and I'm just curious as to whether this is intended behavior (and if so, where might I read up on it) or more of a bug. This...
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
2
by: msaladin | last post by:
Hi all, I spent today with finding an error, I found it, though I don't no why. I have a class with static constants, like this: class EXPORT_API BusConstants { public: static const...
3
by: Mark S. | last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my attempted workaround. Is what I'm doing possible? FYI, I already read all the "why in the world do you need dynamic...
14
by: Daniel Lidström | last post by:
Hello! I have just discovered a way to use the private implementation idiom (pimpl), without the overhead of dynamic memory allocation. For those of you who don't know what this is, Wikipedia...
15
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
5
by: subramanian100in | last post by:
Consider the following classes without ctors. class Sample { private: double d_val; double* d_ptr; }; class Test
7
by: santiagofs | last post by:
Hi, I want to know if it is any workaround for this: I have a class which models a database table behavior (table abstract class) I have several clases wich extends the table abstract class,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
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...
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.