472,345 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

Dynamic types based on existing template code

I have a library that has a class Signal<T> whose data type is
templated. The class comes with a whole bunch of functions and objects
to do various processing on the signal.

What I would like to do is a DSignal class that does essentially the
same thing, but whose type is unknown at compile type. Since I have
already this template library with everything I want in it, I would
like to maximally reuse it and minimize overheads. It's the first time
I really sit and think about it and the more I do and the more it looks
like a nightmare.

I essentially see two parts in this process, that are not necessarily
completely distinct: (1), How would this DSignal class be build reusing
Signal<T>, and (2), How to import all goodies that were using Signal<T>
before.

At first, I thought I could save a lot of effort using the C++ build-in
dynamic type checking functionality, but now I realize that I won't go
very far with virtual functions, since declarations thereof should
match. E.g. I would have like to have a bottom-up approach, were the
only thing I would rewrite for DSignal would be accessors like
operator(),but that's just not possible, because the return type varies
for different signal precision.

So it seems that I would have to rewrite, for any function that exists,
an equivalent function taking a DSignal as an input and forking to
various implementation of this function with a given list of
types,using a switch, or a table of function pointers. Not really an
enthusiastic perspective.

For functors, maybe a template class could help, e.g. if I had an
inversion functor for Signal<T>, e.g. Inv()(s), I could have a functor
wrapper like

class Wrapper
{
public:
template < class Functor >
void operator()(const DSignal &s, const Functor &f)
{
if (s.getType() == DSignal::DOUBLE) f(s);
else ...
}
};

if I don't mind writting from now on Wrapper()(s, Inv()). Plus, I
cannot use the same Wrapper class to wrap Functors that have the same
arguments but different return values.

The problem of getting from Signal<T> to DSignal is also not that easy.
At first, I wanted not to have an enum in DSignal that would list all
the currently available types, and somehow use typeid instead, so that
maintenance and extension would be easier, but now I don't think that's
possible. In the same logic, I wanted to use inheritance to add
available types to DSignal -- but now I don't think I can. I would
rather not use a super class with each possible Signal<T> as a member,
because this looks super cumbersome. Union is probably not better. So
maybe some kind of smart pointer who would not be templated but uses a
void* and stores the type somewhere?

Any hint or pointer to hints/pieces of code/libraries addressing this
kind of issue would be highly appreciated.

Thanks

Bolin

Jul 23 '05 #1
0 1049

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

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.10.2004 Hello, As far as I understand, the generic programming basically consists in using templates for achieving a static...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus...
2
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will...
2
by: Mark P | last post by:
Still being relatively new to C++ I like to go back to review and rethink old designs to see where I could do things better. The issue I'm...
13
by: Krivenok Dmitry | last post by:
Hello all! Perhaps the most important feature of dynamic polymorphism is ability to handle heterogeneous collections of objects. ("C++...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public:...
3
by: Mukesh | last post by:
sir, i am developing a database, which will store the users profile both personal and professional which includes the address, telephone, gender...
9
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.