I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do this
non-intrusively -- I.e., without, for example, typedef'ing the types
in every compilation unit?
Background:
Our code base has assert macros that need to reboot the system after
notifying components via a single templatized Component object that
contains the IPC object. I made the macro call a reboot function, but
that function needs to access the IPC object. I want to singleton'ize
the Component object to provide access to the IPC object, but don't
want to hand-code the template parameters in each compilation unit for
each getInstance call.
Code:
// I want to call retrieve a templatized object via a call to
getInstance
// without supplying the objects template parameters.
// Is there any way to do this, perhaps using template meta-
programming (TMP) techniques?
#include <string>
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class Component
{
public:
static Component<T1, T2getInstance()
{
static Component<T1, T2t;
return t;
}
};
int main()
{
// after the initial call to getInstance, here
Component<int, string& r1 = Component<int,
string>::getInstance();
// I then want to call getInstance to obtain the same Component
without specifying the template params.
Component<something generic& r2 = Component<something
generic>::getInstance();
} 3 3243
On Jun 5, 8:05 pm, gary.bernst...@gmail.com wrote:
I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do this
non-intrusively -- I.e., without, for example, typedef'ing the types
in every compilation unit?
Background:
Our code base has assert macros that need to reboot the system after
notifying components via a single templatized Component object that
contains the IPC object. I made the macro call a reboot function, but
that function needs to access the IPC object. I want to singleton'ize
the Component object to provide access to the IPC object, but don't
want to hand-code the template parameters in each compilation unit for
each getInstance call.
Code:
// I want to call retrieve a templatized object via a call to
getInstance
// without supplying the objects template parameters.
// Is there any way to do this, perhaps using template meta-
programming (TMP) techniques?
#include <string>
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class Component
{
public:
static Component<T1, T2getInstance()
{
static Component<T1, T2t;
return t;
}
};
int main()
{
// after the initial call to getInstance, here
Component<int, string& r1 = Component<int,
string>::getInstance();
// I then want to call getInstance to obtain the same Component
without specifying the template params.
Component<something generic& r2 = Component<something
generic>::getInstance();
}
I like to play with my balls. First I juggle the right ball, then I
toggle on the left.
Will this suffice?
On Jun 5, 8:05 pm, gary.bernst...@gmail.com wrote:
I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do this
non-intrusively -- I.e., without, for example, typedef'ing the types
in every compilation unit?
Background:
Our code base has assert macros that need to reboot the system after
notifying components via a single templatized Component object that
contains the IPC object. I made the macro call a reboot function, but
that function needs to access the IPC object. I want to singleton'ize
the Component object to provide access to the IPC object, but don't
want to hand-code the template parameters in each compilation unit for
each getInstance call.
Code:
// I want to call retrieve a templatized object via a call to
getInstance
// without supplying the objects template parameters.
// Is there any way to do this, perhaps using template meta-
programming (TMP) techniques?
#include <string>
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class Component
{
public:
static Component<T1, T2getInstance()
{
static Component<T1, T2t;
return t;
}
};
int main()
{
// after the initial call to getInstance, here
Component<int, string& r1 = Component<int,
string>::getInstance();
// I then want to call getInstance to obtain the same Component
without specifying the template params.
Component<something generic& r2 = Component<something
generic>::getInstance();
}
I may be able to, instead, simple singleton'ize the internal IPC
object I'm trying to use, which isn't templatized, but I'm still very
curious as to how a templatized object can be retrieved via
getInstance without providing the objects template parameters. ga************@gmail.com wrote:
I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do this
non-intrusively -- I.e., without, for example, typedef'ing the types
in every compilation unit?
What you're asking (having peeked in your source code, I'm guessing)
is to declare/define an object without specifying the actual type of
the object. That's impossible in C++.
Perhaps you can review your source and amend it with some kind of
example of how you're going to actually *use* the "object" you want
to retrieve?
Background:
Our code base has assert macros that need to reboot the system after
notifying components via a single templatized Component object that
contains the IPC object. I made the macro call a reboot function, but
that function needs to access the IPC object. I want to singleton'ize
the Component object to provide access to the IPC object, but don't
want to hand-code the template parameters in each compilation unit for
each getInstance call.
So, put them into a macro and set them at compilation time with -D or
some such option of the compiler...
>
Code:
// I want to call retrieve a templatized object via a call to
getInstance
// without supplying the objects template parameters.
// Is there any way to do this, perhaps using template meta-
programming (TMP) techniques?
#include <string>
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class Component
{
public:
static Component<T1, T2getInstance()
{
static Component<T1, T2t;
return t;
}
};
int main()
{
// after the initial call to getInstance, here
Component<int, string& r1 = Component<int,
string>::getInstance();
// I then want to call getInstance to obtain the same Component
without specifying the template params.
Component<something generic& r2 = Component<something
generic>::getInstance();
}
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Eskie |
last post by:
Lets say I want to make multiply classes as singletons. A singleton skeleton
would be with a static member variable of the instance and a GetInstance
function.
Currently I have this functionality...
|
by: Matt Eberts |
last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object
instantiated via a constructor using the arguments object and have it
expanded, so to speak, so that it doesn't appear as...
|
by: Chr?stian Rousselle |
last post by:
Hello,
I want to do derive a class from a Singleton template base class. Is
there a way to solve the following problem:
template<class T>
class CSingleton
{
public:
static T&...
|
by: Ryan Mitchley |
last post by:
Hi all
I have code for an object factory, heavily based on an article by Jim Hyslop
(although I've made minor modifications). The factory was working fine using
g++, but since switching to the...
|
by: Gregg Altschul |
last post by:
I have a Shared Object which its sole purpose is to create objects of
a certain type and return a pointer to the object to the user.
Therefore, the user becomes the owner of this object and is...
|
by: Thomas Lorenz |
last post by:
Hello,
a standard template singleton looks basically like this:
template<class T>
class Singleton1 {
private:
Singleton1();
static Singleton1* m_Instance;
public:
|
by: John Ratliff |
last post by:
When I dereference a pointer, does it make a copy of the object?
Say I had a singleton, and wanted an static method to retrieve it from
the class.
class foo {
private:
static foo *bar;
...
|
by: Rich |
last post by:
The following code produced a singleton object with application scope
when it should have had page scope:
public class Singleton
{
private static Singleton uniqueInstance = null;
private...
|
by: windandwaves |
last post by:
Hi gurus
I have a class from which I create an object. I want this object to be
available in all my functions for my application. Basically, I want to
make the object global. What is the best...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |