forked from hyphanet/lib-CppFCPLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessage.h
75 lines (52 loc) · 1.45 KB
/
Message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef MESSAGE_H_
#define MESSAGE_H_
#include <string>
#include <map>
#include <vector>
#include <ostream>
#include <istream>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>
namespace FCPLib {
class Message {
protected:
std::string repr;
std::string header;
std::map<std::string, std::string> fields;
bool isReprValid;
bool isDataType;
Message() :
isReprValid(false),
isDataType(false)
{}
public:
typedef boost::shared_ptr<Message> Ptr;
static Message::Ptr factory(std::string header, bool isData=false);
void setField(std::string key, std::string value);
void setFields(const std::map<std::string, std::string> &fields);
const std::string getField(std::string key) const;
const std::string& getHeader() const;
virtual void setStream(std::istream* s_, int dataLength);
virtual const std::string& toString();
virtual void toSocket(boost::asio::ip::tcp::socket& socket);
virtual ~Message() {}
};
class DataMessage : public Message {
friend class Message;
std::istream *stream_;
int dataLength_;
protected:
DataMessage()
: stream_(NULL),
dataLength_(0)
{ isDataType = true; }
public:
typedef boost::shared_ptr<DataMessage> Ptr;
void setStream(std::istream* s_, int dataLength);
const std::string& toString();
void toSocket(boost::asio::ip::tcp::socket& socket);
~DataMessage() { if (stream_ != NULL) delete stream_; }
};
typedef std::vector<Message::Ptr> MessagePtrContainer;
}
#endif