Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost State Chart] Where to include, where to declare?
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2012-04-15 13:25:11


Hi Philipp

> ############# Outer.h ##############
>
> struct Inner1
> struct Inner2
>
> struct Outer < Context, InnerDefaults< Inner1, Inner2> > {
> // implementation
> }
>
> #include Inner1 // this is the really important part
> #include Inner2
>
> ############## Inner(1|2).h ########
>
> struct Inner(1|2) < Outer > {
> // implementation
> }
>
> #################################

Sorry, to me the pseudo-code borders on being useless, because it doesn't show
whether the states derive from the correct base classes, pass the correct
parameters, etc.

> Doing so, I am able to use Outer in the Inner files without including
> something and so on -- but as soon as I start to create a file called
> "Inner1.cpp" and only write '#include "Inner.h" ' the problems start and
> the compiler complains that "Outer" ist not declared (what is true I
> guess). What works is to include the "Outermost" which is the state
> machine in my case ... but this would mean that every state knows about
> my state machine. Also, in my approach the cpp files need to be
> recompiled completely every time I think also if only the header of a
> completely unrelated state changes (because each cpp includes the
> complete state chain).
>
> So ... what's the suggested way to go? I'd like to have as little
> dependencies as possible, so not "all_forward_declarations.h" or some
> such. I had it like that, and it was a big mess. And I like the states
> to be separated ...

The type argument passed for the Context parameter of the simple_state and
state class templates must be a complete type, see the table under the "Class
template simple_state parameters" heading here:

<http://www.boost.org/doc/libs/1_49_0/libs/statechart/doc/reference.html#ClassT
emplatesimple_state>

So, assuming that the declaration for each state resides in its own header
file, you must #include the header file of the direct outer state into each
inner state header file.

A state declaration therefore only needs to "know" its direct and indirect
outer states and the state machine.

HTH,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap from 
the address shown in the header.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net