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()(cons t 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 0 1101 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 reuse for various template
parameters. I wonder if there exist techniques for achieving
a dynamic polymorphism using the generic programming. Is this
possible? If yes, can anyone show me simple examples in C++
|
by: Pascal Costanza |
last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monday, February 13, 2006, VUB Campus Etterbeek
The VUB (Programming Technology Lab, System and Software Engineering
Lab), ULB (deComp) and the Belgian Association for Dynamic Languages
(BADL) are very pleased to invite you to a whole day of presentations
about the programming languages Self, Smalltalk and Common Lisp by
experts in...
|
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
|
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, or
equivalently in my case, templates vs abstract base classes.
Let me be concrete. I have a class for performing a geometry operation
which takes a collection of line segments and breaks them into minimal
nonintersecting subsegments. I wrote...
|
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 Nicolai M. Josuttis. Chapter 14.)
How to implement analogue of this technique via static polymorphism?
Perhaps there is special design pattern for this purpose...
| |
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;
}
|
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 of xml data type. i was
successful in inserting the static
value inside my table.by following code:---
UPDATE docs
|
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 programming. It will not be a
manual of a "proper" way to use OOP inheritance but a compilation so a
description of _all_ OOP paradigms that had been used or are being
used in Javascript commercial solutions: starting from the prototype
inheritance of...
|
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
algorithm to solve a certain messy problem, and many different things.
For that I often use several general modules that I have written, like
implementation of certain data structures, and small general "utility"
functions/classes, plus of course...
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: 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: 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();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |