473,387 Members | 1,493 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,387 software developers and data experts.

extending C++ class template (Boost++ state machines)

This is probably extremely simple, but I am not comfortable with templates.

The Boost++ libraries define two templates which I wish to extend ...

template< class MostDerived,
class InitialState,
class Allocator = std::allocator< void >,
class ExceptionTranslator = null_exception_translator >
class state_machine : noncopyable
{};

template< class MostDerived,
class Context,
class InnerInitial = mpl::list<>,
history_mode historyMode = has_no_history >
class simple_state : public detail::simple_state_base_type< MostDerived,
typename Context::inner_context_type, InnerInitial >::type
{};

I would like to add a few more parameters, let's keep it simple and just start with a string which is state name or FSM name to use for debug tracing.

How do I extend these? And how do I declare an object of each of my new classes?

Thanks in advance for any help.
Sep 9 '08 #1
4 3199
weaknessforcats
9,208 Expert Mod 8TB
These templates are empty classes. And they are concrete (you can have objects of these classes).

You do not derive from concrete classes.

Do the Boost folks say what the purpose of the templates is?
Sep 9 '08 #2
Well, the docs are on http://www.boost.org/doc/libs/1_36_0/libs/statechart/doc/index.html It all looks very good, but I'd like to add a few things. Just for starters, I'd like to pass a string giving the name of the state machine or state, which I can then use in debug tracing. When I get that working I can add more stuff.

I'd prefer to pass it in the constructor, rather than add a new method to set it, but I appear to be too dumb to do that :-(
Sep 10 '08 #3
Well, I figure the extension ought to be

template< class fsmName, // Hint: pass a std::string
class MostDerived,
class InitialState,
class Allocator = std::allocator< void >,
class ExceptionTranslator = null_exception_translator >
class myFsm : public sc::state_machine <MostDerived, InitialState, Allocator, ExceptionTranslator>
{
};

template< class fsmStateName, // Hint: pass a std::string
class MostDerived,
class Context,
class InnerInitial = mpl::list<>,
history_mode historyMode = has_no_history >
class myFsmState : public sc::simple_state <MostDerived, Context>
{
};

Butt I can't figure out how to declare an object for a state machine and one for a state :-(
Sep 11 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
If you have a template, say line this:
Expand|Select|Wrap|Line Numbers
  1. template<class T, class U>
  2. class MyClass
  3. {
  4.    T data;
  5.    U data1;
  6.  
  7. };
  8.  
You create objects by specializing the template. That is, you specify at compile time what the template will be converted into.

Expand|Select|Wrap|Line Numbers
  1. MyClass<string, int> obj;
  2. MyClass<int, double> obj1;
  3.  
There's no "passing to the contructor".

You do understand that the compiler makes a copy of the template and replaces the placeholders (like T and U) with the actual types and it is this copy that is compiled and used in your program?

If fsmStateName or fsmName are strings, then call out a string as the first parameter of your template.

Expand|Select|Wrap|Line Numbers
  1. myFsm<string, etc...> mystatemachine;
  2. myFsmState<string, etc.....> mystate;
  3.  
Sep 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
3
by: Michal Nazarewicz | last post by:
Let say I have a class template Pair representing an ordered pair, ie: #v+ template<class T1, class T2> class Pair { T1 a; T2 b; public: Pair() : a(), b() { } Pair(const Pair<T1, T2&p) :...
9
by: Bit Byte | last post by:
Can't seem to get my head around the point of a trait class - no matter how many times I read up on it - why not simply use functors or function pointers ? Anyone care to explain this in a...
25
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example...
2
by: Simon G Best | last post by:
Hello! I'm trying to specialize a member function template of a class template, like this:- template<typename Tclass thingy { public: template<typename UT f (const U &) const; };
6
by: jamesrjones | last post by:
I'm writing a template library that models the IEEE754(r) decimal arithmetic standard, and I'd like to provide numeric_limits<for my templates. The problem is that I'm not sure how to do this. ...
7
by: Kevin | last post by:
I'm creating a template to support state machines. In doing so, I need to pass an enumeration for the number of transitions and a non type parameter for the range of the enum (to allow me to...
6
by: alan | last post by:
I'm creating a sort-of "wrapper" class which (partly) acts like a variable. Something like: template<class t> class cell{ t curval; public: /*public for debugging only - will be private in...
1
by: Chris M. Thomasson | last post by:
FWIW, here is a quick example (in the form of a fully compliable program with error checking omitted) of how I use POSIX threads within a C++ environment:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.