473,396 Members | 1,877 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,396 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 1093

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 polymorphism of the various code fragments, and their...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
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 have a constructor with an int argument
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 currently pondering is static vs. dynamic polymorphism,...
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++ Templates: The Complete Guide" by David Vandevoorde and...
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: explicit Bar(){ cout<<"bar default"<<endl; }
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 and etc. in my main table i have created a column...
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 inheritance schema currently used in Javascript...
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 data munging, to apply a randomized optimization...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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
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
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,...

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.