40 using namespace basis;
52 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s))
79 default:
return "unknown!";
83 #define TEST(action) \
85 deadly_error(class_name(), "setup", a_sprintf("failed on %s", #action))
87 void test_state_machine::setup_state_machine(
transition_map &recog)
125 if (recog.
validate(hosed) != transition_map::OKAY)
127 astring(astring::SPRINTF,
"invalid state_machine due to state %d", hosed).s());
130 test_state_machine::test_state_machine()
136 critical_events::alert_message(
"\
137 This program demonstrates the state machine class by constructing a machine\n\
138 that recognizes the regular expression *.[cho], which is all strings ending\n\
139 in a period followed by c, h, or o. The first parameter is the name of a\n\
140 file to load strings from.\n");
143 int test_state_machine::execute()
147 setup_state_machine(recog);
152 filename =
"./input_data_state_machine.txt";
175 fil.getline(typed_string, 900);
177 int len = int(strlen((
char *)typed_string.access()));
182 recog.
pulse(m, typed_string[position++]);
186 LOG((
char *)typed_string.access());
190 LOG(
"unknown final state!");
int print_instructions(bool good, const astring &program_name)
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
A very common template for a dynamic array of bytes.
Provides file managment services using the standard I/O support.
Provides operations commonly needed on file names.
Monitors objects with multiple states and the transitions between states.
int current() const
returns the current state.
The transition_map manages state machines and causes state changes to occur.
bool add_range_transition(int current, int next, int low, int high)
adds a transition that listens to triggers in the pulse() method.
bool set_start(int starting_state)
assigns a state as the first state.
bool pulse(state_machine &m, int trigger)
applies a "trigger" to possibly cause a range transition.
bool reset(state_machine &m)
bool add_state(int state_number)
registers a legal state in the transition_map.
basis::outcome validate(int &examine)
checks to that all required transition conditions are satisfied.
#define deadly_error(c, f, i)
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
Useful support functions for unit testing, especially within hoople.
astring state_text(recognizer_states to_show)