Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef REPO_STORAGE_STORAGE_HPP |
| 21 | #define REPO_STORAGE_STORAGE_HPP |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 22 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 23 | #include "../common.hpp" |
| 24 | |
| 25 | namespace repo { |
| 26 | |
| 27 | /** |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 28 | * @brief Storage is a virtual abstract class which will be called by SqliteStorage |
| 29 | */ |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 30 | class Storage : noncopyable |
| 31 | { |
| 32 | public: |
| 33 | class Error : public std::runtime_error |
| 34 | { |
| 35 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 36 | using std::runtime_error::runtime_error; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 39 | public: |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 40 | virtual |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 41 | ~Storage() = default; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * @brief put the data into database |
| 45 | * @param data the data should be inserted into databse |
| 46 | */ |
| 47 | virtual int64_t |
| 48 | insert(const Data& data) = 0; |
| 49 | |
| 50 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 51 | * @brief remove the entry in the database by full name |
| 52 | * @param full name full name of the data |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 53 | */ |
| 54 | virtual bool |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 55 | erase(const Name& name) = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * @brief get the data from database |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 59 | * @param full name full name of the data |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 60 | */ |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 61 | virtual std::shared_ptr<Data> |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 62 | read(const Name& name) = 0; |
| 63 | |
| 64 | /** |
| 65 | * @brief check if database already has the data |
| 66 | * @param full name full name of the data |
| 67 | */ |
| 68 | virtual bool |
| 69 | has(const Name& name) = 0; |
| 70 | |
| 71 | /** |
| 72 | * @brief find the data in database by full name and return it |
| 73 | * @param full name full name of the data |
| 74 | */ |
| 75 | virtual std::shared_ptr<Data> |
| 76 | find(const Name& name, bool exactMatch = false) = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 78 | /** |
| 79 | * @brief Enumerate each entry in database and call @p f with name of stored data |
| 80 | */ |
| 81 | virtual void |
| 82 | forEach(const std::function<void(const Name&)>& f) = 0; |
| 83 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 84 | /** |
| 85 | * @brief return the size of database |
| 86 | */ |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 87 | virtual uint64_t |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 88 | size() = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace repo |
| 92 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 93 | #endif // REPO_STORAGE_STORAGE_HPP |