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 | /* |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2019, 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" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <iostream> |
| 26 | #include <stdlib.h> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 27 | |
| 28 | namespace repo { |
| 29 | |
| 30 | /** |
| 31 | * @brief Storage is a virtual abstract class which will be called by SqliteStorage |
| 32 | */ |
| 33 | class Storage : noncopyable |
| 34 | { |
| 35 | public: |
| 36 | class Error : public std::runtime_error |
| 37 | { |
| 38 | public: |
| 39 | explicit |
| 40 | Error(const std::string& what) |
| 41 | : std::runtime_error(what) |
| 42 | { |
| 43 | } |
| 44 | }; |
| 45 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 46 | public: |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 47 | virtual |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 48 | ~Storage() = default; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * @brief put the data into database |
| 52 | * @param data the data should be inserted into databse |
| 53 | */ |
| 54 | virtual int64_t |
| 55 | insert(const Data& data) = 0; |
| 56 | |
| 57 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 58 | * @brief remove the entry in the database by full name |
| 59 | * @param full name full name of the data |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 60 | */ |
| 61 | virtual bool |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 62 | erase(const Name& name) = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * @brief get the data from database |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 66 | * @param full name full name of the data |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 67 | */ |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 68 | virtual std::shared_ptr<Data> |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 69 | read(const Name& name) = 0; |
| 70 | |
| 71 | /** |
| 72 | * @brief check if database already has the data |
| 73 | * @param full name full name of the data |
| 74 | */ |
| 75 | virtual bool |
| 76 | has(const Name& name) = 0; |
| 77 | |
| 78 | /** |
| 79 | * @brief find the data in database by full name and return it |
| 80 | * @param full name full name of the data |
| 81 | */ |
| 82 | virtual std::shared_ptr<Data> |
| 83 | find(const Name& name, bool exactMatch = false) = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame^] | 85 | /** |
| 86 | * @brief Enumerate each entry in database and call @p f with name of stored data |
| 87 | */ |
| 88 | virtual void |
| 89 | forEach(const std::function<void(const Name&)>& f) = 0; |
| 90 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 91 | /** |
| 92 | * @brief return the size of database |
| 93 | */ |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 94 | virtual uint64_t |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 95 | size() = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace repo |
| 99 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 100 | #endif // REPO_STORAGE_STORAGE_HPP |