Re: Defining protocols - what data structure/algorithms?
- From: Jeffrey Spoon <JeffreySpoon@xxxxxxxxxxx>
- Date: Sat, 02 Sep 2006 14:09:06 GMT
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
.
- References:
- Defining protocols - what data structure/algorithms?
- From: Jeffrey Spoon
- Re: Defining protocols - what data structure/algorithms?
- From: Phlip
- Defining protocols - what data structure/algorithms?
- Prev by Date: Re: Using Excel data in a VB6 database
- Next by Date: Re: modulo
- Previous by thread: Re: Defining protocols - what data structure/algorithms?
- Next by thread: Bash programming
- Index(es):
Relevant Pages
|