00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <cassert>
00021 #include "Tokeniser.h"
00022
00023 using namespace std;
00024
00025 namespace mdw
00026 {
00027
00028 Tokeniser::Tokeniser (StreamSizeServer &server) : _server (server)
00029 {
00030 }
00031
00032
00033 Tokeniser::~Tokeniser()
00034 {
00035 }
00036
00037 void Tokeniser::accept (TokeniserVisitor &visitor, int secondTimeOut, int microTimeOut)
00038 {
00039 _currentVisitor = &visitor;
00040 _server.accept (*this, secondTimeOut, microTimeOut);
00041 }
00042
00043 void Tokeniser::visitRead (char * buffer, int size, int currentOffset,
00044 int currentTotalSize, StreamInfo &info)
00045 {
00046 assert (currentOffset == 0);
00047 assert (currentTotalSize == size);
00048 vector<string> tokens;
00049 State_t state = OutToken_e;
00050 string *currentToken;
00051 for (int i = 0; i < size; ++i)
00052 {
00053 char current = buffer[i];
00054 switch (state)
00055 {
00056 case OutToken_e:
00057 if (current == ' ' || current == '\t' || current == '\r' || current == '\n')
00058 {
00059
00060 }
00061 else
00062 {
00063 string aStr;
00064 tokens.push_back (aStr);
00065 currentToken = &*tokens.rbegin();
00066 currentToken->push_back (current);
00067 state = InToken_e;
00068 }
00069 break;
00070 case InToken_e:
00071 if (current == ' ' || current == '\t' || current == '\r' || current == '\n')
00072 {
00073 state = OutToken_e;
00074 }
00075 else
00076 {
00077 currentToken->push_back (current);
00078 }
00079 break;
00080 }
00081 }
00082 if (!tokens.empty())
00083 {
00084 _currentVisitor->visitTokens (tokens, info);
00085 }
00086
00087 }
00088 void Tokeniser::visitConnect (StreamInfo &info)
00089 {
00090 _currentVisitor->visitConnect (info);
00091 }
00092 void Tokeniser::visitDisconnect (StreamInfo &info)
00093 {
00094 _currentVisitor->visitDisconnect (info);
00095 }
00096
00097 Stream &Tokeniser::outStream(StreamInfo &info)
00098 {
00099 return _server.outStream(info.getStreamId());
00100 }
00101 }