Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
New parser model for Code completion
anonuser:
Would you like an example state machine?
I have a little state machine for parsing xml across the network. It parses exactly one xml message. There are also fail safes in place so invalid data won't crash it. Let me know and I'll paste an exert.
rickg22:
sure, why not :)
Altho i was more interested in replicating the tokenizer.cpp functionality (see source code)... but you're welcome to post your code. Specially when I have NOT designed any state machine yet.
anonuser:
Alright here codes.
This is C++ and its just the statemachine but it should be obvious what's going on. Sorry if anything is sloppy.
The networking is abstracted, getData(false) means do not return a copy of the data to keep things clean.
here are the eStates:
here's the header for clarity's sake
(rid of code to make thread easier to read)
rickg22:
Hmmm... very interesting. However, I have a question.
--- Quote ---switch(eState) {
case Begin:
...
case WaitOpen:
...
case StoreName:
...
case WaitClose:
...
case Quote:
...
case WaitEscape:
--- End quote ---
Let me guess - Those are the states of your state machine?
anonuser:
Exactly. State machines are simple by design but can be complex when implementing them.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version