[Boost State Chart] Where to include, where to declare?
Hi all, today I face some major problems with the state charts. Mostly this comes from incorrect forward declarations and so on. I use this scheme for e.g. decaring a state which has orthogonal substates. I hope my pseudocode is readable. ############# 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 } ################################# 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 ... Best regards, Philipp
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#Clas... 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.
participants (2)
-
Andreas Huber
-
Philipp Bender