Hi.
This might be to basic, or of topic, or just plain silly. But, Is there
a nice way to
construct objects dynamically from a data stream (file, socket, memory)
without
prior enumerating classes?
With enumerating classes I mean solutions like:
(pseudo code 1)
class B
{
tClasses type;
B(tClasses iType=classB){}
};
class D:public B
{
D():B(classD){}
};
B* CreateObject(tC lasses Class)
{
switch(Class)
{
case classD: return new D;
}
}
(end pseudo code 1)
or
(pseudo code 2)
map<tClasses,Cr eateObjectFunct ionPtr> CreateFunctions ;
....
D(){CreateFunct ions[tClasses]=CreateClassDOb ject;}
....
(end pseudo code 2)
My question is, is there a way in the standard that involves less work?
(I might be
as lazy as they come), I have a project with a map of objects which can
be any of 200 or so classes. Now I need to save this map to file and
restore it. Any Input? 1 1466
* je****@alphacas h.se: Hi. This might be to basic, or of topic, or just plain silly. But, Is there a nice way to construct objects dynamically from a data stream (file, socket, memory) without prior enumerating classes? With enumerating classes I mean solutions like: (pseudo code 1) class B { tClasses type; B(tClasses iType=classB){} };
class D:public B { D():B(classD){} };
B* CreateObject(tC lasses Class) { switch(Class) { case classD: return new D; } } (end pseudo code 1) or (pseudo code 2) map<tClasses,Cr eateObjectFunct ionPtr> CreateFunctions ; ... D(){CreateFunct ions[tClasses]=CreateClassDOb ject;} ... (end pseudo code 2)
My question is, is there a way in the standard that involves less work? (I might be as lazy as they come), I have a project with a map of objects which can be any of 200 or so classes. Now I need to save this map to file and restore it. Any Input?
To avoid work you should probably use some library solution such as e.g.
boost's serialization support (haven't used it myself). But in order to
do that you need to understand serialization, which is what you don't.
First, it's explained in the FAQ (but that might be hard to understand),
second, I've written a little about it* at the absolute novice level
(but I use a lot of words to get to the point), and third, I'm sure
you'll find it explained in some textbook -- but which one?
Hth.,
- Alf
*) <url: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf>
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: nog |
last post by:
What's the best approach to creating many objects of a
class?
I have in mind using something analogous to a table to hold
the data - which is in a form similar to (char name, char
address, date joinDate) - and being able to declare each
row, one after another by looping.
With about 30 instances to create, I feel there must be a
better way than making an individual declaration for each
one.
TIA.
|
by: grocery_stocker |
last post by:
Why would someone go through the trouble of constructing an error
handling function using variable-length argument lists? Why not just
use something like printf()?
|
by: Chris Capel |
last post by:
I've heard a lot of talk on the forum about memory managment in .NET and
disposing things, finalizing them, garbage collection, etc. My question is
which managed types need to be disposed after being used, and for which is
it OK to simply let the garbage collector do its work, without worrying
about calling Dispose? Is there a general rule that most don't need to be
explicitly disposed, with an exception here and there? Or the other way...
|
by: Daniel Goldman |
last post by:
Hi,
Any advice about both a BinaryReader and BinaryWriter
containing same FileStream at same time? Like:
Stream fs = new FileStream("output.dbf", FileMode.Create);
BinaryReader br = new BinaryReader(fs);
BinaryWriter bw = new BinaryWriter(fs);
/* BinaryWriter writes, flushes, etc */
/* BinaryReader seeks, reads, etc */
|
by: Dennis C. Drumm |
last post by:
I have a class derived from a SortedList called SystemList that contains a
list of objects indexed with a string value.
The definition of the objects contained in the SortedList have a boolean
field and an event that is fired if the boolean field value changes.
The derived SortedList class has an override for the Add method. The Add
method adds an event handler for the object's event for each new item added
to the list. In the...
| |
by: Peter Rilling |
last post by:
Is there anyway of being notified when a Stream is modified? Basically, If
one of my objects is passed a stream, I would like to initialize an object
cache. Then when the Stream changes, I would like to update the cache.
Does not look like the stream has any event that I can hook.
|
by: Ashura |
last post by:
H
I want to make a project where one or more object could be shared between 2 applications
For example : the first application create a connection to a web-service, this connection is stored in an object (through a service perhaps). A second application is launch and I want this application, use the same connection as the frst one (so retrieve the object where the connection is stored)
Any idee of th process ??
I think I need to...
|
by: JackRazz |
last post by:
I'm trying to serialize a collection to a file stream by serializing each object
individually. The code below works fine with the BinaryFormatter, but the
SoapFormatter reads the first object and just goes to the end of the file. After
reading the first object, the fStream.Position is pointed to the end of the file.
The collection serializes/deserilizes fine when I just serialize the hashtable vs.
each object in the hashtable.
Does...
|
by: |
last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and release...
Is there anyone out there that considers themselves a threading / sockets / serialization guru? Not sure if it's appropriate to post an entire project here and the issues discussion is probably a bit too complex for newsgroup back and...
|
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: 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: 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...
|
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: 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...
| |