I'm trying to unserialize objects that are part of an inheritance
hierarchy. The advice in 36.8 of the FAQ seems perfect for what I'm
doing, except it leaves one critical question unanswered: how do I
populate the map that takes derived class names and gives me the
appropriate derived class constructor (or, alternatively, a
representative object of the appropriate derived class)?
Of course, I can always populate the map manually in main(), or
something equally ugly, but that requires that main() know about each
of the derived classes, and that main() be modified each time a new
derived class is added to my codebase (which happens rather
frequently). I'd rather have each derived class somehow take care of
adding an appropriate entry for itself to the map, but I'm not sure how
to do this.
One idea I had was to have in each DerivedClass.cp p a global variable
of that class type, initialized using a special constructor that adds
the appropriate entry to the map. This seems ugly, but is it my best
option?
Something like this:
// DerivedClass.cp p
#include "DerivedClass.h "
DerivedClass Foo("DerivedCla ss");
DerivedClass::D erivedClass(str ing s) {
BaseClass::addT oMap(s, this);
// adds an entry to the map with the string s
// as the key for the map, and this as a representative object
// of the class DerivedClass
}
DerivedClass * DerivedClass::c reate(std::istr eam& someStream) {
// etc
}
Assuming I use the Construct on First Use idiom for the map, and call
theMap["className"]->create() when I want to unserialize an object of
type "className" , will this work? Is it advised, or is there a Better
Way? 1 1187 tr*****@gmail.c om wrote: I'm trying to unserialize objects that are part of an inheritance hierarchy. The advice in 36.8 of the FAQ seems perfect for what I'm doing, except it leaves one critical question unanswered: how do I populate the map that takes derived class names and gives me the appropriate derived class constructor (or, alternatively, a representative object of the appropriate derived class)?
Use a small embedded class that adds the surrounding class to the map
and have a static instance of it as a member of the surrounding class.
class X
{
static std::string name();
struct Mapper
{
Mapper()
{
<someMap>[X::name()] = new X();
}
};
static Mapper mapper;
};
Ian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lamine Darbouche |
last post by:
Can anybody help?
I need to have three list boxes automatically populating each other, (ie
when region is selected from the first listbox, it will populate
automatically the second one which is the TOWNS and when the town is
selected is should populate the third one AREA) all data is in the database
in one table.
Any idea???
Many thanks in adavance.
Lamine
|
by: Billy Smith |
last post by:
How do you go about populating a select list from an XML file?
I can open the XML file fine and get at all of the data, but I'm stuck on
how to use that data in my <option> tags. Is it even possible?
Thanks.
|
by: sao |
last post by:
I am currently using Access 2000.
In my table it is the following fields that are set up:
1 - Staff Name
2 - Department
This table is already populated with 100+ records (staff along with
department.)
|
by: John Hargrove |
last post by:
I am building a database to manage test samples in an environmental
laboratory. I am learning Access as I go and don't know much about
the programming aspects. I hope to make the application user-friendly
for the sample login people by populating form controls. Using the
DLookup function, I am able to populate a form control in one record
using table data. I want to be able to populate multiple records of a
subform control (test...
|
by: Jason |
last post by:
I have a form that is used for entering and editing site address
information. The data in the form is from one table, named
Total_Site_Address. There are fields in this table (and controls on
the form) for entering in a new site address or choosing an existing
site address. There are two fields that address the existing site
addresses, one named ADDRESS, the other named TAX_NAME (contains
municipality info). The ADDRESS field is setup...
| |
by: msnews.microsoft.com |
last post by:
I'd like to hear your thoughts on best methods for populating drop down list
controls. I have states and countries drop down lists that don't change
often, so naturally I "hard code" them in the aspx page. But the problem is
these tend to really slow the development -- it takes up to 15 seconds for
the page to come up in VS.NET design environment, so I'm thinking about
taking these out and populating the controls dynamically using the...
|
by: msnews.microsoft.com |
last post by:
Hi Every Body,
I build an application using vb.net.
Now i m deploying on the client system.
I know that the deployment automatically check the .net framework on the client system at startup.
I include the .net framework in the deployment setup.
I want that if the framework is not installed on the client system then my deployment wizared automatically install the framework which i include in the deployment package.
How can i do this....
|
by: devagupt |
last post by:
I have 2 tables , Production table and the Total table. The production table is made from a form and the total table just has data in it. I need to populate 2 fields from the total table into the production table. They both have a common field being the Vial #. Sometimes there are 2 identical vial # for a product but they are packed on a different line. I need the line speeds the lines would run at and the # of people per line which is all...
|
by: Mary |
last post by:
I'll pulling my hair out on this one and would be so appreciative of
any help.
I am creating a data entry form to enter results of a student survey.
There are 40 questions on the survey. The first 7 have to do with
respondent information like grade, class and age. I have those in a
table with a PK of RespondentId, which is autonumbered. Questions 8-40
all have the same format. For these questions I have a table set up
with the...
|
by: ITHELP85 |
last post by:
using SQL Server 2005
I have a table SALES_ITEM, users should be able to input the Primary Keys (ItemNumberSK and InvoiceNumber), and Qty. I want the ItemName and UnitPrice fields to update automatically from the WAREHOUSE table.
I wrote a trigger already but something is wrong with it as I get this error (My code is listed under the error):
---------------------------
Microsoft SQL Server Management Studio
---------------------------...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |