| cpp_redis 4.0.0 cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.

reply.hpp
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22
23 #pragma once
24
25 #include <iostream>
26 #include <string>
27 #include <vector>
28
29 #include <stdint.h>
30
31 namespace cpp_redis {
32
37 class reply {
38 public:
39 #define __CPP_REDIS_REPLY_ERR 0
40 #define __CPP_REDIS_REPLY_BULK 1
41 #define __CPP_REDIS_REPLY_SIMPLE 2
42 #define __CPP_REDIS_REPLY_NULL 3
43 #define __CPP_REDIS_REPLY_INT 4
44 #define __CPP_REDIS_REPLY_ARRAY 5
45
49 enum class type {
50 error = __CPP_REDIS_REPLY_ERR,
51 bulk_string = __CPP_REDIS_REPLY_BULK,
52 simple_string = __CPP_REDIS_REPLY_SIMPLE,
53 null = __CPP_REDIS_REPLY_NULL,
54 integer = __CPP_REDIS_REPLY_INT,
55 array = __CPP_REDIS_REPLY_ARRAY
56 };
57
61 enum class string_type {
62 error = __CPP_REDIS_REPLY_ERR,
63 bulk_string = __CPP_REDIS_REPLY_BULK,
64 simple_string = __CPP_REDIS_REPLY_SIMPLE
65 };
66
67 public:
71 reply(void);
72
79 reply(const std::string& value, string_type reply_type);
80
86 reply(int64_t value);
87
94 reply(const std::vector<reply>& rows);
95
97 ~reply(void) = default;
99 reply(const reply&) = default;
101 reply& operator=(const reply&) = default;
102
103 public:
107 bool is_array(void) const;
108
112 bool is_string(void) const;
113
117 bool is_simple_string(void) const;
118
122 bool is_bulk_string(void) const;
123
127 bool is_error(void) const;
128
132 bool is_integer(void) const;
133
137 bool is_null(void) const;
138
139 public:
143 bool ok(void) const;
144
148 bool ko(void) const;
149
153 operator bool(void) const;
154
155 public:
159 const std::string& error(void) const;
160
164 const std::vector<reply>& as_array(void) const;
165
169 const std::string& as_string(void) const;
170
174 int64_t as_integer(void) const;
175
176 public:
180 void set(void);
181
188 void set(const std::string& value, string_type reply_type);
189
195 void set(int64_t value);
196
202 void set(const std::vector<reply>& rows);
203
210 reply& operator<<(const reply& reply);
211
212 public:
216 type get_type(void) const;
217
218 private:
219 type m_type;
220 std::vector<cpp_redis::reply> m_rows;
221 std::string m_strval;
222 int64_t m_intval;
223 };
224
225 } // namespace cpp_redis
226
228 std::ostream& operator<<(std::ostream& os, const cpp_redis::reply& reply);
cpp_redis::reply::ko
bool ko(void) const
cpp_redis::reply::operator<<
reply & operator<<(const reply &reply)
cpp_redis::reply::ok
bool ok(void) const
cpp_redis::reply::as_integer
int64_t as_integer(void) const
cpp_redis::reply
Definition: reply.hpp:37
cpp_redis::reply::as_array
const std::vector< reply > & as_array(void) const
cpp_redis::reply::as_string
const std::string & as_string(void) const
cpp_redis::reply::is_simple_string
bool is_simple_string(void) const
cpp_redis::reply::is_bulk_string
bool is_bulk_string(void) const
cpp_redis::reply::is_integer
bool is_integer(void) const
cpp_redis::reply::is_array
bool is_array(void) const
cpp_redis::reply::is_string
bool is_string(void) const
cpp_redis::reply::is_error
bool is_error(void) const
cpp_redis::reply::type
type
Definition: reply.hpp:49
cpp_redis::reply::string_type
string_type
Definition: reply.hpp:61
cpp_redis::reply::is_null
bool is_null(void) const
cpp_redis::reply::operator=
reply & operator=(const reply &)=default
assignment operator
cpp_redis::reply::~reply
~reply(void)=default
dtor
cpp_redis::reply::reply
reply(void)
cpp_redis
Definition: array_builder.hpp:29
cpp_redis::reply::get_type
type get_type(void) const