I get pretty low editing performance using the lastest version of VAX (10.4.1647.0) when editing a file contaning boost::statechart related code.
I just started with this file and am in the process of also learning boost::statechart so the code might be rather poor quality atm, but editing it is slow regardless. I am experiencing up to 1 second delays when typing even comments into this file.
The headers for the file are in my pch. (stdafx.h)
Below is the code.
#pragma once
namespace NavigatorStatemachine
{
namespace sc = boost::statechart;
//statemachine do
struct navigator;
//superstate :traveling
struct idle;
struct stop : sc::event < stop >{};
struct suspend : sc::event< suspend >{};
struct travel : sc::event< travel >{};
struct tick : sc::event< tick >{};
struct traveling : sc::simple_state<traveling, navigator, idle>
{
typedef mpl::list<
sc::transition<>,
sc::transition<>,
sc::transition<>,
sc::transition<>,
sc::custom_reaction<>
>
//event stop, idle, stop_moving
sc::result react(const stop &);
//event suspend, suspended
sc::result react(const suspend &);
//trans idle, travel, moving_to_wp, init_mover
//trans moving_to_wp, stop, stop_mover
//trans idle, tick, idle, update_positiojn
//trans idle, arrived, idle
//start_state idle
};
//superstate :moving_to_wp
struct moving;
struct stopped;
struct wp_reached : sc::event< wp_reached >{};
struct moving_to_wp : sc::simple_state<moving_to_wp, traveling, moving>
{
typedef mpl::list<
//event wp_reached, has_arrived
sc::transition<wp_reached, has_arrived>,
sc::custom_reaction<stop, stopped>
> reactions;
//event stop, stopped, stop_moving
sc::result react(const stop &);
//startstate moving
moving_to_wp()
{
//on_entry start_moving
};
};
struct not_reached_wp : sc::event< not_reached_wp >{};
struct position_updated : sc::simple_state<position_updated, moving_to_wp>
{
typedef sc::custom_reaction<not_reached_wp> reactions;
//event not_reached_wp, moving, correct_movement
sc::result react(const not_reached_wp &);
position_updated()
{
//on_entry check_position
};
};
struct arrived : sc::event<arrived>{};
struct not_arrived : sc::event<not_arrived>{};
struct has_arrived : sc::simple_state<has_arrived, traveling>
{
typedef mpl::list<
sc::custom_reaction< arrived >,
sc::custom_reaction< not_arrived>
> reactions;
//event arrived, idle, stop_mover
sc::result react(const arrived &);
//event not_arrived, moving_to_wp, move_to_next_waypoint
sc::result react(const not_arrived &);
has_arrived()
{
//on_entry check_progress
};
};
//superstate stuck
struct checking_stuck_state;
struct unsticking;
struct unstuck : sc::event< unstuck >{};
struct still_stuck : sc::event< still_stuck >{};
struct tick : sc::event< tick >{};
struct stuck : sc::simple_state<stuck, traveling, unsticking>
{
typedef mpl::list<
sc::custom_reaction<unstuck>,
sc::custom_reaction<still_stuck>,
sc::transition<tick, checking_stuck_state>
> rections;
//trans checking_stuck_state, unstuck, moving_to_wp
sc::result react(const unstuck &);
//trans checking_stuck_state, still_stuck, unsticking, unstick_me
sc::result react(const still_stuck &);
//trans unsticking, tick, checking_stuck_state
sc::result react(const tick &);
stuck()
{
//on_entry init_stuck_stuff
}
};
struct checking_stuck_state : sc::simple_state<checking_stuck_state, stuck>
{
checking_stuck_state()
{
if(/*stuck*/ true)
{
transit<moving_to_wp>()
}
else
{
transit<
}
}
};
struct navigator : sc::state_machine<navigator, traveling>
{
int start_moving();
int correct_movement();
int stop_moving();
//state has_arrived
int stop_mover();
//trans suspended, resume, traveling_H
//context waypoint_context (this)
//startstate traveling
};
};
//Superstate example.
//Forward declare start state:
struct Foo;
//Declare statemachine:
struct FooMachine : sc::state_machine<FooMachine, Foo>
{
//Context related functionality here.
int get_guard_value()
{
return 1;
}
};
//forward declare inner states;
struct Bar;
struct Baz;
//declare events:
struct EvFoo : sc::event< EvFoo >{};
struct EventQux : sc::event < EventQux >{};
struct EventQuux : sc::event< EventQuux >{};
//Declare superstate:
struct Foo : sc::simple_state<Foo, FooMachine, Bar> //bar is start state of superstate.
{
//Declare transitions and reactions to events using mpl::list
typedef mpl::list<
//declare a custom reaction that is not merely a simple transition. IE, we have an 'action'
sc::custom_reaction< EvFoo >,
//declare simple transition. params: event, final state
sc::transition< EventQux, Qux>,
//do some action prior to the transition.
sc::transition< EventQuux, Qux, Foo, &Foo::QuuxAction >
>
//on_entry action
Foo()
{
std::cout << "performed entry action" << std::endl;
}
//on_exit action
~Foo()
{
std::cout << "performed exit action" << std::endl;
}
void QuuxAction( const EventQuux &)
{
std::cout << "this is the shizznizzle" << std::endl;
}
//Declare handler for custom reaction;
sc::result react(const EvFoo &evt)
{
//Use a guard:
int guard_val = context<FooMachine>().get_guard_value();
switch(guard_val)
{
case 1:
//swallow event
discard_event();
break;
case 2:
//Take some transition action and end at state Qux.
return transit< Qux >( &Foo::stupid_action, evt );
break;
default:
//transition from state Foo to state Qux.
return transit<Qux>();
}
};
void stupid_action( const EvFoo &evt)
{
std::cout << "stupid reaction on event" << std::endl;
}
};
//declare states, 2nd param is outter/parent state.
struct Bar : sc::simple_state<Bar, Foo>
{
};
struct Baz : sc::simple_state<Baz, Foo>
{
};
//Declare global state IE: parent state is the statemachine
struct Qux : sc::simple_state<Qux, FooMachine>
{
};