468,248 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

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 2940
weaknessforcats
9,207 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,207 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

Post your reply

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

Similar topics

3 posts views Thread by Michal Nazarewicz | last post: by
9 posts views Thread by Bit Byte | last post: by
25 posts views Thread by David Sanders | last post: by
6 posts views Thread by jamesrjones | last post: by
6 posts views Thread by alan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.