-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.h
42 lines (36 loc) · 1.3 KB
/
response.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
#ifndef TEXAS_HOLDEM_UTIL_RESPONSE_H_
#define TEXAS_HOLDEM_UTIL_RESPONSE_H_
#include <sstream>
#include <string>
#include "header.h"
namespace Base {
class Response {
public:
Response();
Response(int code, const char *status, const char *protocol);
~Response();
static Response parse(std::string str);
static Response parse(std::istringstream iss);
int getStatusCode() {return code_;}
std::string getStatus() {return status_;}
std::string getProtocol() {return protocol_;}
void setStatusCode(int code) {code_ = code;}
void setStatus(std::string status) {status_ = status;}
void setProtocol(std::string protocol) {protocol_ = protocol;}
template<typename T> void set(std::string key, T value) { header_.set(key, value); }
std::optional<std::string> operator[](std::string key);
operator std::string() const {
std::ostringstream oss;
oss << protocol_ << " " << code_ << " " << status_ << "\x0d\x0a";
oss << static_cast<std::string>(header_);
oss << "\x0d\x0a";
return oss.str();
}
private:
int code_;
std::string status_;
std::string protocol_;
Header header_;
};
}
#endif // TEXAS_HOLDEM_UTIL_RESPONSE_H_