472,794 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 3157
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:...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.