src/graph/example/WordParser.h

00001 #ifndef HT_EXAMPLE_WORD_PARSER_
00002 #define HT_EXAMPLE_WORD_PARSER_
00003 
00004 #include <graph/example/FileReader.h>
00005 #include <graph/NodeBase.h>
00006 #include <options/Config.h>
00007 #include <string>
00008 
00009 #define MONONODE(T)                                                     \
00010         public:                                                         \
00011             virtual void configured() const {                           \
00012                 if (!next_)                                             \
00013                     throw ht::options::ConfigError("No follow-on node for node " + name()); \
00014             }                                                           \
00015             void connect(Node *n)                                       \
00016             {                                                           \
00017                 next_ = dynamic_cast<T *>(n);                           \
00018             }                                                           \
00019             void disconnect(Node *n) {                                  \
00020                 if (n == next_)                                         \
00021                     next_ = 0;                                          \
00022             }                                                           \
00023         private:                                                        \
00024             T *next_
00025         
00026 
00027 namespace ht {
00028     namespace example {
00029 
00031         struct WordBuffer
00032         {
00034             size_t row;
00036             size_t col;
00038             const char * word;
00040             size_t length;
00042             bool isWS;
00044             WordBuffer() : row(1), col(1), word(0), length(0), isWS(false) {}
00045         };
00046 
00048         class WordReader : public ht::graph::NodeBase
00049         {
00050         public:
00052             virtual void process(const WordBuffer & buf) = 0;
00053         };
00054 
00056         class WordParser : public BlockReader
00057         {
00058             MONONODE(WordReader);
00059             WordBuffer word_;
00060             std::string partial_;
00061             void sendWord(const char *p, size_t len);
00062         public:
00063             WordParser() : next_(0) {}
00064             virtual void process(const ByteBuffer & buf);
00065             virtual void stop();
00066         };
00067     }
00068 }
00069 
00070 
00071 #endif

Generated on Thu Jan 3 15:26:45 2008 by  doxygen 1.5.2