Re: Defining protocols - what data structure/algorithms?



In message <O8XJg.228$MF1.3@xxxxxxxxxxxxxxxxxxxxxxxxxx>, Phlip <phlipcpp@xxxxxxxxx> writes


Look up State Pattern and State Table.

Would using a static array (holding the protocol commands/responses) and
then looping thorough this to match the incoming data work, or is that
silly?

Make the current State a pointer into the State Table. That's a table of
derived states, each with its behavior as virtual functions.

Each State has a map of inputs and transitions to other States. By "map",
it's a C++ std::map<string, State *>, so you don't loop, you just query with
.find().

My Shlaer Mellor is rusty: I seem to recall the State Table maps State and
Transition tuples to target states. So you might go with one big map
containing std::map<std::pair<string, State *>, State * >.



That's brilliant, thanks. My C++ is really rusty, unfortunately, hence the reason I'm doing a C++ project. I'm off to look at the state pattern and table, thanks for the pointer (no pun intended).

Cheers,



--
Jeffrey Spoon

.



Relevant Pages

  • Re: Defining protocols - what data structure/algorithms?
    ... Other than a huge if statement or switch statement, ... Each State has a map of inputs and transitions to other States. ... Transition tuples to target states. ...
    (comp.programming)
  • Code to map a network drive and more..
    ... but havent really touched in about 4 to 5 years so my VBS is VERY rusty. ... I need to map a drive K in a Server 2000 with Win2000 workstations and possible future XP Pro workstations. ...
    (microsoft.public.windows.server.scripting)