1 /************************************************************************** 2 Copyright (c) 2017 sewenew 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 *************************************************************************/ 16 17 #ifndef SEWENEW_REDISPLUSPLUS_COMMAND_OPTIONS_H 18 #define SEWENEW_REDISPLUSPLUS_COMMAND_OPTIONS_H 19 20 #include <string> 21 #include "utils.h" 22 23 namespace sw { 24 25 namespace redis { 26 27 enum class UpdateType { 28 EXIST, 29 NOT_EXIST, 30 ALWAYS 31 }; 32 33 enum class InsertPosition { 34 BEFORE, 35 AFTER 36 }; 37 38 enum class BoundType { 39 CLOSED, 40 OPEN, 41 LEFT_OPEN, 42 RIGHT_OPEN 43 }; 44 45 // (-inf, +inf) 46 template <typename T> 47 class UnboundedInterval; 48 49 // [min, max], (min, max), (min, max], [min, max) 50 template <typename T> 51 class BoundedInterval; 52 53 // [min, +inf), (min, +inf) 54 template <typename T> 55 class LeftBoundedInterval; 56 57 // (-inf, max], (-inf, max) 58 template <typename T> 59 class RightBoundedInterval; 60 61 template <> 62 class UnboundedInterval<double> { 63 public: 64 const std::string& min() const; 65 66 const std::string& max() const; 67 }; 68 69 template <> 70 class BoundedInterval<double> { 71 public: 72 BoundedInterval(double min, double max, BoundType type); 73 min()74 const std::string& min() const { 75 return _min; 76 } 77 max()78 const std::string& max() const { 79 return _max; 80 } 81 82 private: 83 std::string _min; 84 std::string _max; 85 }; 86 87 template <> 88 class LeftBoundedInterval<double> { 89 public: 90 LeftBoundedInterval(double min, BoundType type); 91 min()92 const std::string& min() const { 93 return _min; 94 } 95 96 const std::string& max() const; 97 98 private: 99 std::string _min; 100 }; 101 102 template <> 103 class RightBoundedInterval<double> { 104 public: 105 RightBoundedInterval(double max, BoundType type); 106 107 const std::string& min() const; 108 max()109 const std::string& max() const { 110 return _max; 111 } 112 113 private: 114 std::string _max; 115 }; 116 117 template <> 118 class UnboundedInterval<std::string> { 119 public: 120 const std::string& min() const; 121 122 const std::string& max() const; 123 }; 124 125 template <> 126 class BoundedInterval<std::string> { 127 public: 128 BoundedInterval(const std::string &min, const std::string &max, BoundType type); 129 min()130 const std::string& min() const { 131 return _min; 132 } 133 max()134 const std::string& max() const { 135 return _max; 136 } 137 138 private: 139 std::string _min; 140 std::string _max; 141 }; 142 143 template <> 144 class LeftBoundedInterval<std::string> { 145 public: 146 LeftBoundedInterval(const std::string &min, BoundType type); 147 min()148 const std::string& min() const { 149 return _min; 150 } 151 152 const std::string& max() const; 153 154 private: 155 std::string _min; 156 }; 157 158 template <> 159 class RightBoundedInterval<std::string> { 160 public: 161 RightBoundedInterval(const std::string &max, BoundType type); 162 163 const std::string& min() const; 164 max()165 const std::string& max() const { 166 return _max; 167 } 168 169 private: 170 std::string _max; 171 }; 172 173 struct LimitOptions { 174 long long offset = 0; 175 long long count = -1; 176 }; 177 178 enum class Aggregation { 179 SUM, 180 MIN, 181 MAX 182 }; 183 184 enum class BitOp { 185 AND, 186 OR, 187 XOR, 188 NOT 189 }; 190 191 enum class GeoUnit { 192 M, 193 KM, 194 MI, 195 FT 196 }; 197 198 template <typename T> 199 struct WithCoord : TupleWithType<std::pair<double, double>, T> {}; 200 201 template <typename T> 202 struct WithDist : TupleWithType<double, T> {}; 203 204 template <typename T> 205 struct WithHash : TupleWithType<long long, T> {}; 206 207 } 208 209 } 210 211 #endif // end SEWENEW_REDISPLUSPLUS_COMMAND_OPTIONS_H 212