473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing which methods a class has by deriving from a template argument

Hi,

Is is possible to set the 'policy' of a class by allowing the user to specify
a template argument that defines what some functions will be based on the
template argument given?

Basically, it's the old 'make the user derive from a virtual base class' vs.
'use attachable callbacks (or in this case signals/slots)' problem - and I'm
thinking of solving it by allowing the user to choose.

So, I need to define an interface that allows users to attach 'callbacks' to
an object.

struct StateBody
{
virtual ~StateBody() {}
virtual void atentry() {}
virtula void atexit() {}
};

template<class PolicyT>
class StateMachine : public PolicyT
{
};

class MyStateBody : public StateBody
{
public:
void atentry() {...}
};

strict MyEntrySlot{ void operator()() {...} };

void my_exit_slot() {}

StateMachine<VO bjectHandler<De refCall> > sm1;

State<VObjectHa ndler<DerefCall > >& state1 = sm1.add_state(" state1",
boost::shared_p tr<MyStateBody> (new MyStateBody()) );

StateMachine<VO bjectHandler<Di rectCall> > sm2;

CompositeState< VObjectHandler< DirectCall> >& state2 =
sm2.add_composi te_state("state 2", MyStateBody());

StateMachine<Sl otHandler> sm3;

State<SlotHandl er>& state3 =
sm3.add_state(" state3", MyEntrySlot(), &my_exit_slo t);

Would this be possible? What about feasibility? The 'add_state()' method in
each case has a different prototype - the template argument type has an
'add_state' method of the needed definition, and StateMachine derives from it
thereby obtaining it as well.

I'm also thinking of allowing the type used for the names "state1", "state2",
etc. to be configurable - i.e. using basic_string<Ch arT>, where CharT is
supplied as another template parameter.

Thoughts? Spot anything of concern?

Thanks,
Asfand Yar

--
To reply, take of all ZIGs !!
Feb 24 '06 #1
0 1114

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

Similar topics

11
4576
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member variables". However, this doesn't seem entirely correct. It also doesn't mention whether static member functions can access protected and private member...
2
5665
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have seen commercial programs print output to the screen as well as to a log file. depending on the user and other situations, i might want to turn off...
5
2039
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After some investigating, I narrowed this down to a very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is declared as...
2
1766
by: Oenone | last post by:
I could use a little advice to help prevent me making a possible mess of a project. :) In VB6, I once created a project that exposed a public interface class. I then Implemented this in various plug-in DLLs so that I could early-bind to the plug-ins by declaring objects of the interface class type. This worked fine, until one day I found...
5
2658
by: Vincent RICHOMME | last post by:
Hi, First my questions are related to C++ even if I am talking about managed c++(.NET)... I am currently implementing some interesting .NET classes in c++(native code) and I am not an expert with static methods. Here is what I am doing (class to manage processes) :
2
1770
by: montyshasta | last post by:
Take this code as a base case, it compiles successfully: struct R { int i; }; class S : public R { void F(void) {i = 0;} };
2
4222
by: vilarneto | last post by:
Hello everyone, I'm facing a particular situation about template class derivation. The subject is old -- deriving a non-template class from a template base class -- but my problem is that the base class has a pure virtual method. For instance: template<class T> class A { public:
6
1285
by: Klaus | last post by:
Hi all: I want to have something like the following (incorrect!): class Base { public: virtual void MakeSomething(); }; class BehaviourModelOne {
2
2642
by: canderse | last post by:
I am beginning to use templates alot (in visual studio 2008) but I writing this simple template that has a method which takes a function pointer as an argument and i cant figure out why the will not compile LONG __cdecl FilterListProc(LPVOID Item1,LPVOID Item2,LPVOID pParam = NULL); template<class TItemList,class TItemData> class...
0
7391
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...
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
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...
0
5962
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...
0
4941
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...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
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
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
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...

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.