473,884 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help - class / templates use?

At the moment im experimenting with ideas in C++ and would really like to
solve the following, please please help.

Sorry i dont even know what the subject is this would come under? :(
Sorry if this is elsewhere in the newsgroup & please reply with links to
threads or something? (I dont know what to look for :( )
(Terms are prob. all wrong as well :( )

The problem:
I have a data structure represented by a class. Use a date class as an
example i guess.
I have a GUI that the user can output the data to, or a file it can be
formatted and cout used to output it.
There are thousands of these date objects that need to be output, to some
form of output device.

The output device is chosen at run-time and hence the class that will be
used to format the data, from the date objects
and output it.

A class may be a GUI, File, etc...

Is there anyway I could write some base class / interface in C++, that when
classes inherit the interface class
certain methods would have to be written?. I.E. all classes must have a
function that is void Output_Short_Da te?

I'm not sure where to start on this bit even? Any pointers?

The idea was to instant the appropiate class and then do function pointers
before the loop, so that one line in the code, would send
the date to the correct output.

Just to give idea - syntax is of course all out without editor to hand

switch (userChoice) {
case GUI:
//set outputDateForma tter to GUIFormatter
break;
case FILE:
//set outputDateForma tter to FileFormatter
break;
}

loop {
*outputDateForm atter (dateObject localDate);
}

would go to the correct instance of the outputter, and display the date.

The alternative is to use conditional checks but obviously these would slow
down the loops by quite a bit the higher the number of times they were
executed.

Any suggestions on what i can look up to do the above idea, (if your really
bored examples would be fantastic. My main problem is Im not sure how you
can use Templates in C++ to do this, function pointers, or what other
relevant stuff may help do this easily.

Anyway thanks for reading and any help would be great

Happy XMAS all.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.552 / Virus Database: 344 - Release Date: 15/12/2003
Jul 22 '05 #1
1 1645
"David Goodyear" <da**@kent.ac.u k> wrote...
At the moment im experimenting with ideas in C++ and would really like to
solve the following, please please help.

Sorry i dont even know what the subject is this would come under? :(
Seems like "serialisation" .
Sorry if this is elsewhere in the newsgroup & please reply with links to
threads or something? (I dont know what to look for :( )
Input/Output, serialisation.
(Terms are prob. all wrong as well :( )

The problem:
I have a data structure represented by a class. Use a date class as an
example i guess.
I have a GUI that the user can output the data to, or a file it can be
formatted and cout used to output it.
There are thousands of these date objects that need to be output, to some
form of output device.

The output device is chosen at run-time and hence the class that will be
used to format the data, from the date objects
and output it.
The device should really be in control, I guess.

A class may be a GUI, File, etc...

Is there anyway I could write some base class / interface in C++, that when classes inherit the interface class
certain methods would have to be written?.
Sure.
I.E. all classes must have a
function that is void Output_Short_Da te?
In most cases, if the number of different data structures is limited
and (which is more important) stable and static, then you can add as
many member functions to that base class as there are different data
structures. If (more difficult) the data are not known and just as
dynamic as the input source or output device, you will need some kind
of inter-binding schema, like IO for only basic (fundamental) types,
something like Output_Field_In t or Output_Field_St ring, and then make
your data structures form their own output from those fundamental
types (fields).

I'm not sure where to start on this bit even? Any pointers?
Go to comp.programmin g and ask about serialisation. It's not really
language-specific. Or ask in comp.object (if OOD is what you would
like to accomplish).
The idea was to instant the appropiate class and then do function pointers
before the loop, so that one line in the code, would send
the date to the correct output.


For that the mechanism (I know of) is called "serialiser factory" or
"serialiser registry". Basically, you make every type that wants to
be input/output register its serialiser. Then when it's time to be
output, match up (somehow; say, by the name of the serialiser) the
object with the serialiser, give the serialiser the device and let
it do its job...

Victor
Jul 22 '05 #2

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

Similar topics

21
8614
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
4
3920
by: Sebastian Faust | last post by:
Hi, I have 4 questions related to templates. I wanna do something like the following: template<typename T> class Template { public: Template_Test<T>()
4
6403
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument. How do I do this? Also, I want to have a data member for
4
1962
by: KK | last post by:
Hello all, I have class 'atr' which is based on templates. My idea was to initialize it two scenarios 1. std::string case 2. other data types I have defined the Init for the above different cases accordingly (code shown below). However, I get compiler error. Please help me resolve it. Thanks.
6
2771
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave no errors compiling this:
4
3343
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
8
2448
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A, typename B> class Base { public:
2
3093
by: thuythu | last post by:
Please help me.... I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the textbox value in the main page is undefined ---------------------------------------- here are code main page: ------------------------------------------- <script language="JavaScript"> var thedata; var newwin; var thenumber; function...
15
7884
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
9799
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
11167
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...
1
10868
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
10422
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
9591
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...
0
7137
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
5808
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...
1
4623
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
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.