473,403 Members | 2,284 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,403 software developers and data experts.

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<VObjectHandler<DerefCall> > sm1;

State<VObjectHandler<DerefCall> >& state1 = sm1.add_state("state1",
boost::shared_ptr<MyStateBody>(new MyStateBody()) );

StateMachine<VObjectHandler<DirectCall> > sm2;

CompositeState<VObjectHandler<DirectCall> >& state2 =
sm2.add_composite_state("state2", MyStateBody());

StateMachine<SlotHandler> sm3;

State<SlotHandler>& state3 =
sm3.add_state("state3", MyEntrySlot(), &my_exit_slot);

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<CharT>, 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 1110

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

Similar topics

11
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...
2
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...
5
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...
2
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...
5
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...
2
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
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...
6
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
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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
isladogs
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...

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.