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;
103  reply(reply&&);
105  reply& operator=(reply&&);
106 
107 public:
111  bool is_array(void) const;
112 
116  bool is_string(void) const;
117 
121  bool is_simple_string(void) const;
122 
126  bool is_bulk_string(void) const;
127 
131  bool is_error(void) const;
132 
136  bool is_integer(void) const;
137 
141  bool is_null(void) const;
142 
143 public:
147  bool ok(void) const;
148 
152  bool ko(void) const;
153 
157  operator bool(void) const;
158 
159 public:
163  const std::string& error(void) const;
164 
168  const std::vector<reply>& as_array(void) const;
169 
173  const std::string& as_string(void) const;
174 
178  int64_t as_integer(void) const;
179 
180 public:
184  void set(void);
185 
192  void set(const std::string& value, string_type reply_type);
193 
199  void set(int64_t value);
200 
206  void set(const std::vector<reply>& rows);
207 
214  reply& operator<<(const reply& reply);
215 
216 public:
220  type get_type(void) const;
221 
222 private:
223  type m_type;
224  std::vector<cpp_redis::reply> m_rows;
225  std::string m_str_val;
226  int64_t m_int_val;
227 };
228 
229 } // namespace cpp_redis
230 
232 std::ostream& operator<<(std::ostream& os, const cpp_redis::reply& reply);
bool ko(void) const
reply & operator<<(const reply &reply)
bool ok(void) const
int64_t as_integer(void) const
Definition: reply.hpp:37
const std::vector< reply > & as_array(void) const
const std::string & as_string(void) const
bool is_simple_string(void) const
bool is_bulk_string(void) const
bool is_integer(void) const
bool is_array(void) const
bool is_string(void) const
bool is_error(void) const
type
Definition: reply.hpp:49
string_type
Definition: reply.hpp:61
bool is_null(void) const
reply & operator=(const reply &)=default
assignment operator
~reply(void)=default
dtor
const std::string & error(void) const
Definition: array_builder.hpp:29
type get_type(void) const