$search
00001 /* -*- mode: C++ -*- 00002 * 00003 * Commander finite state machine interface 00004 * 00005 * Copyright (C) 2007, 2010, Austin Robot Technology 00006 * 00007 * License: Modified BSD Software License Agreement 00008 * 00009 * $Id: State.h 435 2010-08-20 15:24:22Z jack.oquin $ 00010 */ 00011 00012 #ifndef __CMDR_STATE_H__ 00013 #define __CMDR_STATE_H__ 00014 00015 class CmdrState 00016 { 00017 public: 00018 // Commander states 00019 typedef enum 00020 { 00021 Done, // mission completed 00022 Init, // initial state 00023 Road, // travelling on road 00024 N_states // total number of states 00025 } state_t; 00026 00027 // return name of each state as a C string 00028 const char *Name(void) 00029 { 00030 static const char *state_name[N_states] = 00031 { 00032 "Done", 00033 "Init", 00034 "Road", 00035 }; 00036 return state_name[state]; 00037 } 00038 00039 CmdrState() 00040 { 00041 this->state = Init; // initial state 00042 } 00043 00044 CmdrState(state_t val) 00045 { 00046 this->state = val; 00047 } 00048 00049 state_t Value(void) 00050 { 00051 return this->state; 00052 } 00053 00054 void operator=(state_t newval) 00055 { 00056 this->state = newval; 00057 } 00058 00059 bool operator==(CmdrState newval) 00060 { 00061 return this->state == newval.state; 00062 } 00063 00064 bool operator==(state_t newval) 00065 { 00066 return this->state == newval; 00067 } 00068 00069 bool operator!=(CmdrState newval) 00070 { 00071 return this->state != newval.state; 00072 } 00073 00074 bool operator!=(state_t newval) 00075 { 00076 return this->state != newval; 00077 } 00078 00079 private: 00080 state_t state; // current state 00081 }; 00082 00083 #endif // __CMDR_STATE_H__