CompilerStressTestEuml.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. // Copyright 2010 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <vector>
  11. #include <list>
  12. #include <set>
  13. #include <map>
  14. #include <iostream>
  15. // we need more than the default 10 states
  16. #define FUSION_MAX_VECTOR_SIZE 15
  17. #include <boost/msm/back/state_machine.hpp>
  18. #include <boost/msm/front/euml/euml.hpp>
  19. #include <boost/msm/front/euml/stl.hpp>
  20. using namespace std;
  21. using namespace boost::msm::front::euml;
  22. namespace msm = boost::msm;
  23. // how long the timer will ring when countdown elapsed.
  24. #define RINGING_TIME 5
  25. namespace // Concrete FSM implementation
  26. {
  27. // flag
  28. BOOST_MSM_EUML_FLAG(SomeFlag)
  29. // declares attributes with type and name. Can be used anywhere after
  30. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_song)
  31. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(int,m_song_id)
  32. // declare that a type inheriting from OneSongDef will get these 2 attributes
  33. BOOST_MSM_EUML_ATTRIBUTES((attributes_ << m_song << m_song_id ), OneSongDef)
  34. // events
  35. // this event is done "manually", not using any predefined macro
  36. struct OneSong_impl : euml_event<OneSong_impl>,OneSongDef
  37. {
  38. OneSong_impl(){}
  39. OneSong_impl(const string& asong)
  40. {
  41. get_attribute(m_song)=asong;
  42. get_attribute(m_song_id)=1;
  43. }
  44. OneSong_impl(const OneSong_impl& asong)
  45. {
  46. get_attribute(m_song)=asong.get_attribute(m_song);
  47. get_attribute(m_song_id)=1;
  48. }
  49. const string& get_data() const {return get_attribute(m_song);}
  50. };
  51. // declare an instance for use in the transition table
  52. OneSong_impl const OneSong;
  53. struct SongComparator : euml_action<SongComparator>
  54. {
  55. bool operator()(const OneSong_impl& lhs,const OneSong_impl& rhs)const
  56. {
  57. return lhs.get_data() == rhs.get_data();
  58. }
  59. };
  60. struct SongLessComparator : euml_action<SongLessComparator>
  61. {
  62. bool operator()(const OneSong_impl& lhs,const OneSong_impl& rhs)const
  63. {
  64. return lhs.get_data() < rhs.get_data();
  65. }
  66. };
  67. struct Comparator
  68. {
  69. template <class T>
  70. bool operator()(const T& lhs,const T& rhs)const
  71. {
  72. return lhs < rhs;
  73. }
  74. };
  75. struct RemoveDummy
  76. {
  77. bool operator()(const OneSong_impl& lhs)const
  78. {
  79. return (lhs.get_attribute(m_song).compare(std::string("She-Dummy. Remove this one"))==0 );
  80. }
  81. };
  82. template <int val>
  83. struct LookFor
  84. {
  85. template <class T>
  86. bool operator()(const T& lhs)const
  87. {
  88. return lhs == val;
  89. }
  90. };
  91. template <int val>
  92. struct LessThan
  93. {
  94. template <class T>
  95. bool operator()(const T& lhs)const
  96. {
  97. return lhs < val;
  98. }
  99. };
  100. BOOST_MSM_EUML_ACTION(SongDeleter)
  101. {
  102. bool operator()(const OneSong_impl& lhs)const
  103. {
  104. return lhs.get_data() == "Twist and Shout";
  105. }
  106. };
  107. struct Generator
  108. {
  109. int operator()()const
  110. {
  111. return 1;
  112. }
  113. };
  114. struct Print
  115. {
  116. template <class T>
  117. void operator()(const T& lhs)const
  118. {
  119. std::cout << "Song:" << lhs.get_data() << endl;
  120. }
  121. };
  122. BOOST_MSM_EUML_ATTRIBUTES((attributes_ << m_song ), NotFoundDef)
  123. // declare an event instance called NotFound with the defined attributes
  124. // these attributes can then be referenced anywhere (stt, state behaviors)
  125. BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(NotFound,NotFoundDef)
  126. BOOST_MSM_EUML_ATTRIBUTES((attributes_ << m_song ), FoundDef)
  127. struct Found_impl : euml_event<Found_impl>,FoundDef
  128. {
  129. Found_impl(){}
  130. Found_impl (const string& data)
  131. {
  132. get_attribute(m_song)=data;
  133. }
  134. int foo()const {std::cout << "foo()" << std::endl; return 0;}
  135. int foo(int i)const {std::cout << "foo(int):" << i << std::endl; return 1;}
  136. int foo(int i,int j)const {std::cout << "foo(int,int):" << i <<"," << j << std::endl; return 2;}
  137. };
  138. Found_impl const Found;
  139. // some functions to call
  140. // this macro creates a functor and an eUML function wrapper. Now, foo_ can be used anywhere
  141. BOOST_MSM_EUML_METHOD(FoundFoo_ , foo , foo_ , int , int )
  142. template <class T>
  143. int do_print(T& t ) {std::cout << "print(T):" << typeid(T).name() << std::endl;return 1;}
  144. BOOST_MSM_EUML_FUNCTION(PrintState_ , do_print , print_ , int , int )
  145. BOOST_MSM_EUML_EVENT(Done)
  146. // Concrete FSM implementation
  147. struct some_base
  148. {
  149. int foobar()const {std::cout << "foobar()" << std::endl; return 0;}
  150. int foobar(int i)const {std::cout << "foobar(int):" << i << std::endl; return 1;}
  151. int foobar(int i,int j)const {std::cout << "foobar(int,int):" << i <<"," << j << std::endl; return 2;}
  152. };
  153. // some functions to call
  154. BOOST_MSM_EUML_METHOD(FooBar_ , foobar , foobar_ , int , int )
  155. // fsm attributes
  156. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(vector<OneSong_impl>,m_src_container)
  157. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(list<OneSong_impl>,m_tgt_container)
  158. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(list<int>,m_var2)
  159. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(list<int>,m_var3)
  160. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(set<int>,m_var4)
  161. typedef std::map<int,int> int_int_map;
  162. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(int_int_map,m_var5)
  163. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_var6)
  164. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_var7)
  165. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(vector<int>,m_var8)
  166. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(vector<int>,m_var9)
  167. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(int,m_var10)
  168. // The list of FSM states
  169. BOOST_MSM_EUML_STATE(( ( insert_(fsm_(m_tgt_container),end_(fsm_(m_tgt_container)),
  170. append_(event_(m_song),fsm_(m_var7)) ),//foo_(event_,Int_<0>()) ,
  171. //foo_(event_,Int_<0>(),Int_<1>()),print_(state_),
  172. process_(Done/*,fsm_*/),if_then_(true_,true_) ),
  173. no_action
  174. ),Insert)
  175. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_letters)
  176. BOOST_MSM_EUML_STATE(( if_then_else_( (string_find_(event_(m_song),state_(m_letters),Size_t_<0>()) != Npos_<string>()&&
  177. string_find_(event_(m_song),Char_<'S'>(),Size_t_<0>()) != Npos_<string>()&&
  178. string_find_first_of_(event_(m_song),Char_<'S'>()) == Size_t_<0>() &&
  179. string_compare_(event_(m_song),Int_<0>(),size_(event_(m_song)),event_(m_song)) == Int_<0>()
  180. //&& is_flag_(SomeFlag(),fsm_())
  181. //&& ( event_(m_song_id) == Int_<1>())
  182. //&& string_find_(event_(m_song),String_<mpl::string<'Sh','e'> >())
  183. // != Npos_<string>()
  184. ),
  185. process2_(Found,
  186. //string_insert_(event_(m_song),Size_t_<0>(),fsm_(m_var6)) ),
  187. string_replace_(
  188. string_assign_(
  189. string_erase_(
  190. string_insert_(
  191. substr_(event_(m_song),Size_t_<1>()),
  192. Size_t_<0>(),
  193. Size_t_<1>(),
  194. Char_<'S'>()),
  195. Size_t_<0>(),
  196. Size_t_<1>() ),
  197. event_(m_song) ),
  198. Size_t_<0>(),
  199. Size_t_<1>(),
  200. c_str_(fsm_(m_var6))
  201. /*Size_t_<1>(),
  202. Char_<'s'>()*/ ) ),
  203. process2_(NotFound,event_(m_song),fsm_) ) ,
  204. no_action,
  205. attributes_ << m_letters,
  206. configure_<< SomeFlag ),StringFind)
  207. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(vector<OneSong_impl>::iterator,m_src_it)
  208. BOOST_MSM_EUML_STATE(( if_then_( (state_(m_src_it) != end_(fsm_(m_src_container)) &&
  209. //associative_find_(fsm_(m_var4),Int_<9>()) != end_(fsm_(m_var4))&&
  210. //associative_count_(fsm_(m_var4),Int_<9>()) == Size_t_<1>() &&
  211. //*associative_upper_bound_(fsm_(m_var4),Int_<8>()) == Int_<9>()&&
  212. //*associative_lower_bound_(fsm_(m_var4),Int_<9>()) == Int_<9>() &&
  213. //second_(associative_equal_range_(fsm_(m_var4),Int_<8>())) == associative_upper_bound_(fsm_(m_var4),Int_<8>()) &&
  214. //first_(associative_equal_range_(fsm_(m_var4),Int_<8>())) == associative_lower_bound_(fsm_(m_var4),Int_<8>())&&
  215. //second_(*associative_lower_bound_(fsm_(m_var5),Int_<0>())) == Int_<0>() && //map => pair as return
  216. //find_if_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Predicate_<LookFor<8> >()) != end_(fsm_(m_var4))&&
  217. //*lower_bound_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>(),Predicate_<std::less<int> >()) == Int_<9>()&&
  218. //*upper_bound_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<8>(),Predicate_<std::less<int> >()) == Int_<9>() &&
  219. //second_(equal_range_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<8>()))
  220. // == upper_bound_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<8>()) &&
  221. //first_(equal_range_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>(),Predicate_<std::less<int> >()))
  222. // == lower_bound_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>(),Predicate_<std::less<int> >())&&
  223. //binary_search_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>(),Predicate_<std::less<int> >())&&
  224. //binary_search_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>())&&
  225. //count_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Int_<9>()) == Int_<1>()&&
  226. //count_if_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Predicate_<LookFor<9> >()) == Int_<1>()&&
  227. //distance_(begin_(fsm_(m_var4)),end_(fsm_(m_var4))) == Int_<2>()&&
  228. //*min_element_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Predicate_<std::less<int> >()) == Int_<8>()&&
  229. //*max_element_(begin_(fsm_(m_var4)),end_(fsm_(m_var4)),Predicate_<std::less<int> >()) == Int_<9>()&&
  230. //adjacent_find_(begin_(fsm_(m_var4)),end_(fsm_(m_var4))) == end_(fsm_(m_var4))&&
  231. //*find_end_(begin_(fsm_(m_var8)),end_(fsm_(m_var8)),begin_(fsm_(m_var9)),end_(fsm_(m_var9)))
  232. // == Int_<1>()&&
  233. //*find_first_of_(begin_(fsm_(m_var8)),end_(fsm_(m_var8)),begin_(fsm_(m_var9)),end_(fsm_(m_var9)))
  234. // == Int_<1>()&&
  235. //equal_(begin_(fsm_(m_var9)),end_(fsm_(m_var9)),begin_(fsm_(m_var8)))&&
  236. //*search_(begin_(fsm_(m_var8)),end_(fsm_(m_var8)),begin_(fsm_(m_var9)),end_(fsm_(m_var9)))
  237. // == Int_<1>()&&
  238. //includes_(begin_(fsm_(m_var8)),end_(fsm_(m_var8)),begin_(fsm_(m_var9)),end_(fsm_(m_var9)))&&
  239. //!lexicographical_compare_(begin_(fsm_(m_var8)),end_(fsm_(m_var8)),
  240. // begin_(fsm_(m_var9)),end_(fsm_(m_var9)))&&
  241. //first_(mismatch_(begin_(fsm_(m_var9)),end_(fsm_(m_var9)),begin_(fsm_(m_var8))))
  242. // == end_(fsm_(m_var9)) &&
  243. accumulate_(begin_(fsm_(m_var9)),end_(fsm_(m_var9)),Int_<1>(),
  244. Predicate_<std::plus<int> >()) == Int_<1>()
  245. ),
  246. (process2_(OneSong,*(state_(m_src_it)++))/*,foobar_(fsm_,Int_<0>())*/ ) ),
  247. no_action,
  248. attributes_ << m_src_it
  249. , configure_<< SomeFlag ),Foreach)
  250. // replaces the old transition table
  251. BOOST_MSM_EUML_TRANSITION_TABLE((
  252. StringFind == Foreach + OneSong[if_then_else_(true_,true_,true_)],
  253. Insert == StringFind + Found / (if_then_(true_,no_action)),
  254. Foreach == StringFind + NotFound ,
  255. Foreach == Insert + Done
  256. // +------------------------------------------------------------------------------+
  257. ),transition_table )
  258. BOOST_MSM_EUML_ACTION(Log_No_Transition)
  259. {
  260. template <class FSM,class Event>
  261. void operator()(Event const& e,FSM&,int state)
  262. {
  263. std::cout << "no transition from state " << state
  264. << " on event " << typeid(e).name() << std::endl;
  265. }
  266. };
  267. // create a state machine "on the fly"
  268. BOOST_MSM_EUML_DECLARE_STATE_MACHINE(( transition_table, //STT
  269. init_ << Foreach, // Init
  270. //insert_(state_(m_var4),begin_(state_(m_var2)),end_(state_(m_var2))),
  271. (insert_(state_(m_var4),Int_<5>()),insert_(state_(m_var4),Int_<6>()),insert_(state_(m_var4),Int_<7>()),
  272. insert_(state_(m_var4),Int_<8>()),insert_(state_(m_var4),Int_<9>()),
  273. associative_erase_(state_(m_var4),Int_<6>()),associative_erase_(state_(m_var4),begin_(state_(m_var4))),
  274. associative_erase_(state_(m_var4),begin_(state_(m_var4)),++begin_(state_(m_var4))),
  275. insert_(state_(m_var2),begin_(state_(m_var2)),begin_(state_(m_var3)),end_(state_(m_var3))),
  276. state_(m_var5)[Int_<0>()]=Int_<0>(),state_(m_var5)[Int_<1>()]=Int_<1>()
  277. ,attribute_(substate_(Foreach,fsm_),m_src_it)
  278. = begin_(fsm_(m_src_container))
  279. //,fill_(begin_(state_(m_var9)),end_(state_(m_var9)),Int_<0>())
  280. //,fill_n_(begin_(state_(m_var9)),Size_t_<2>(),Int_<0>())
  281. //,transform_(begin_(state_(m_var4)),end_(state_(m_var4)),begin_(state_(m_var2)),begin_(state_(m_var4)),
  282. // Predicate_<std::plus<int> >())
  283. //,process_(Done,fsm_(),fsm_)
  284. //,process_(Done,fsm_)
  285. //,fsm_
  286. //,foobar_(state_,Int_<0>(),Int_<1>())
  287. //,nth_element_(begin_(state_(m_var9)),++begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  288. //,partial_sort_(begin_(state_(m_var9)),end_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  289. //,partial_sort_copy_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  290. //,list_sort_(state_(m_var2))
  291. //,sort_(begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  292. //,inner_product_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)),Int_<1>())
  293. //,replace_copy_(begin_(state_(m_var4)),end_(state_(m_var4)),begin_(state_(m_var4)),Int_<8>(),Int_<7>())
  294. //,replace_copy_if_(begin_(state_(m_var4)),end_(state_(m_var4)),begin_(state_(m_var4)),Predicate_<LookFor<9> >(),Int_<8>())
  295. //,replace_(begin_(state_(m_var4)),end_(state_(m_var4)),Int_<8>(),Int_<7>())
  296. //,replace_if_(begin_(state_(m_var4)),end_(state_(m_var4)),Predicate_<LookFor<9> >(),Int_<8>())
  297. //,adjacent_difference_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)))
  298. //,partial_sum_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)))
  299. //,inner_product_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)),Int_<1>())
  300. //,next_permutation_(begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  301. //,prev_permutation_(begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  302. //,set_union_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)))
  303. //,inplace_merge_(begin_(state_(m_var9)),end_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  304. //,merge_(begin_(state_(m_var9)),end_(state_(m_var9)),begin_(state_(m_var9)),end_(state_(m_var9))
  305. // ,begin_(state_(m_var9)),Predicate_<std::less<int> >())
  306. //,stable_sort_(begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<std::less<int> >())
  307. //,partition_(begin_(state_(m_var2)),end_(state_(m_var2)),Predicate_<LessThan<3> >())
  308. //,stable_partition_(begin_(state_(m_var2)),end_(state_(m_var2)),Predicate_<LessThan<3> >())
  309. //,rotate_copy_(begin_(state_(m_var2)),++begin_(state_(m_var2)),end_(state_(m_var2)),begin_(state_(m_var2)))
  310. //,rotate_(begin_(state_(m_var2)),++begin_(state_(m_var2)),end_(state_(m_var2)))
  311. //,unique_(begin_(state_(m_var2)),end_(state_(m_var2)))
  312. //,unique_copy_(begin_(state_(m_var2)),end_(state_(m_var2)),begin_(state_(m_var2)))
  313. //,random_shuffle_(begin_(state_(m_var9)),end_(state_(m_var9)))
  314. //,generate_(begin_(state_(m_var9)),end_(state_(m_var9)),Predicate_<Generator>())
  315. //,generate_n_(begin_(state_(m_var9)),Int_<2>(),Predicate_<Generator>())
  316. //,reverse_copy_(begin_(state_(m_var2)),end_(state_(m_var2)),begin_(state_(m_var2)))
  317. //erase_(state_(m_src_container),
  318. // remove_if_(begin_(state_(m_src_container)),end_(state_(m_src_container)),
  319. // Predicate_<RemoveDummy>()),
  320. // end_(state_(m_src_container))),
  321. //list_remove_(state_(m_var2),Int_<3>()),
  322. //remove_copy_if_(begin_(state_(m_var9)),end_(state_(m_var9)),back_inserter_(state_(m_var2)),
  323. // Predicate_<LookFor<2> >() )
  324. //for_each_(begin_(state_(m_src_container)),end_(state_m_src_container()),
  325. // Predicate_<Print>() ),
  326. //copy_(begin_(state_(m_var9)),end_(state_(m_var9)),inserter_(state_(m_var2),end_(state_(m_var2)))),
  327. //reverse_(begin_(state_(m_var2)),end_(state_(m_var2)))
  328. ),
  329. //no_action, // Entry
  330. //splice_(state_(m_var2),begin_(state_(m_var2)),state_(m_var3),begin_(state_(m_var3)),end_(state_(m_var3))),
  331. //(list_remove_(state_(m_var2),Int_<3>()),list_merge_(state_(m_var2),state_(m_var3),Comparator())),//no_action, // Entry
  332. no_action, // Exit
  333. attributes_ << m_src_container // song list
  334. << m_tgt_container // result
  335. << m_var2
  336. << m_var3
  337. << m_var4
  338. << m_var5
  339. << m_var6
  340. << m_var7
  341. << m_var8
  342. << m_var9
  343. << m_var10,
  344. configure_<< no_configure_,
  345. Log_No_Transition
  346. ),iPodSearch_helper)
  347. struct iPodSearch_ : public iPodSearch_helper, public some_base
  348. {
  349. };
  350. // choice of back-end
  351. typedef msm::back::state_machine<iPodSearch_> iPodSearch;
  352. void test()
  353. {
  354. iPodSearch search;
  355. // fill our song list
  356. //search.get_attribute<m_src_container>().push_back(OneSong("She-Dummy. Remove this one"));
  357. search.get_attribute(m_src_container).push_back(OneSong_impl("Let it be"));
  358. search.get_attribute(m_src_container).push_back(OneSong_impl("Yellow submarine"));
  359. search.get_attribute(m_src_container).push_back(OneSong_impl("Twist and Shout"));
  360. search.get_attribute(m_src_container).push_back(OneSong_impl("She Loves You"));
  361. search.get_attribute(m_var2).push_back(1);
  362. search.get_attribute(m_var2).push_back(3);
  363. search.get_attribute(m_var2).push_back(4);
  364. search.get_attribute(m_var3).push_back(2);
  365. search.get_attribute(m_var3).push_back(4);
  366. search.get_attribute(m_var6) = "S";
  367. search.get_attribute(m_var7) = "- Some text";
  368. search.get_attribute(m_var8).push_back(1);
  369. search.get_attribute(m_var8).push_back(2);
  370. search.get_attribute(m_var8).push_back(3);
  371. search.get_attribute(m_var8).push_back(4);
  372. search.get_attribute(m_var9).push_back(1);
  373. search.get_attribute(m_var9).push_back(2);
  374. // look for "She Loves You" using the first letters
  375. // BOOST_MSM_EUML_STATE_NAME returns the name of the event type of which StringFind is an instance
  376. search.get_state<BOOST_MSM_EUML_STATE_NAME(StringFind)&>().get_attribute(m_letters)="Sh";
  377. // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
  378. search.start();
  379. // display all the songs
  380. for (list<OneSong_impl>::const_iterator it = search.get_attribute(m_tgt_container).begin();
  381. it != search.get_attribute(m_tgt_container).end();++it)
  382. {
  383. cout << "candidate song:" << (*it).get_data() << endl;
  384. }
  385. for (list<int>::const_iterator iti = search.get_attribute(m_var2).begin();
  386. iti != search.get_attribute(m_var2).end();++iti)
  387. {
  388. cout << "int in attribute m_var2:" << (*iti) << endl;
  389. }
  390. for (set<int>::const_iterator its = search.get_attribute(m_var4).begin();
  391. its != search.get_attribute(m_var4).end();++its)
  392. {
  393. cout << "int in attribute m_var4:" << (*its) << endl;
  394. }
  395. cout << "search using more letters" << endl;
  396. // look for "She Loves You" using more letters
  397. search.get_state<BOOST_MSM_EUML_STATE_NAME(StringFind)&>().get_attribute(m_letters)="She";
  398. search.get_attribute(m_tgt_container).clear();
  399. search.start();
  400. // display all the songs
  401. for (list<OneSong_impl>::const_iterator it = search.get_attribute(m_tgt_container).begin();
  402. it != search.get_attribute(m_tgt_container).end();++it)
  403. {
  404. cout << "candidate song:" << (*it).get_data() << endl;
  405. }
  406. }
  407. }
  408. int main()
  409. {
  410. test();
  411. return 0;
  412. }