1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #ifndef COMMAND_H
- #define COMMAND_H
- #include "Socket.h"
- #include <json/json.h>
- #include <iostream>
- #include <vector>
- #include "error.h"
- class Command
- {
- public:
- enum CommandReturn {CONTINUE, EXIT, CLOSE};
- Command(ISocket* sock);
- Command();
- Command(const Command& sock);
- virtual ~Command(){}
- virtual const Command& operator=(const Command&);
- virtual Json::Value& operator[](int i){return m_args[i];}
- void print();
- const std::string& get_name() const {return m_command;}
- std::vector<Json::Value>& get_args() {return m_args;}
- static Command parse(ISocket* s);
- std::string str() const;
- protected:
- std::string m_command;
- std::vector<Json::Value> m_args;
- ISocket* m_io;
- friend class CommandParser;
- };
- class CommandParser
- {
- public:
- enum Token {
- PV,
- IDENT,
- STRING,
- INT,
- FLOAT,
- BOOL
- };
- CommandParser(ISocket* sock) : m_io(sock){}
- virtual ~CommandParser(){}
- static Command parse(ISocket* sock)
- {
- CommandParser cp(sock);
- return cp._parse();
- }
- protected:
- Command _parse();
- Token _next();
- char _nc(){ return m_c=m_io->readc();}
- Token _set(Token t);
- ISocket* m_io;
- Token m_token;
- std::string m_current;
- Json::Value m_val;
- char m_c;
- };
- #endif // COMMAND_H
|