1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef I_KV_DB_RESULT_SET_H 17 #define I_KV_DB_RESULT_SET_H 18 19 #include "macro_utils.h" 20 #include "db_types.h" 21 22 namespace DistributedDB { 23 24 enum class ResultSetType : int { 25 KEYPREFIX = 0, 26 QUERY = 1, 27 }; 28 29 constexpr int INIT_POSITION = -1; 30 31 class IKvDBResultSet { 32 public: 33 IKvDBResultSet() = default; ~IKvDBResultSet()34 virtual ~IKvDBResultSet() {} 35 36 DISABLE_COPY_ASSIGN_MOVE(IKvDBResultSet); 37 38 // Initialize logic 39 virtual int Open(bool isMemDb) = 0; 40 41 // Get total entries count. 42 // >= 0: count, < 0: errCode. 43 virtual int GetCount() const = 0; 44 45 // Get current read position. 46 // >= 0: position, < 0: errCode 47 virtual int GetPosition() const = 0; 48 49 virtual int Move(int offset) const = 0; 50 51 // Move the read position to an absolute position value. 52 virtual int MoveTo(int position) const = 0; 53 54 virtual int MoveToFirst() = 0; 55 56 virtual int MoveToLast() = 0; 57 58 virtual bool IsFirst() const = 0; 59 60 virtual bool IsLast() const = 0; 61 62 virtual bool IsBeforeFirst() const = 0; 63 64 virtual bool IsAfterLast() const = 0; 65 66 // Get the entry of current position. 67 virtual int GetEntry(Entry &entry) const = 0; 68 69 // Finalize logic 70 virtual int Close() = 0; 71 }; 72 } // namespace DistributedDB 73 74 #endif // I_KV_DB_RESULT_SET_H 75