blob: abda77c72bc525a1446c7b2e6311e5dc11d5ebd5 [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventof43a03e2018-02-21 22:04:21 -05002/*
Davide Pesavento11904062022-04-14 22:33:28 -04003 * Copyright (c) 2014-2022, Regents of the University of California.
Weiqi Shif0330d52014-07-09 10:54:27 -07004 *
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 Pesaventof43a03e2018-02-21 22:04:21 -050022
Weiqi Shif0330d52014-07-09 10:54:27 -070023#include "../common.hpp"
24
25namespace repo {
26
27/**
Davide Pesavento11904062022-04-14 22:33:28 -040028 * @brief Storage is a virtual abstract class which will be called by SqliteStorage
29 */
Weiqi Shif0330d52014-07-09 10:54:27 -070030class Storage : noncopyable
31{
32public:
33 class Error : public std::runtime_error
34 {
35 public:
Davide Pesavento11904062022-04-14 22:33:28 -040036 using std::runtime_error::runtime_error;
Weiqi Shif0330d52014-07-09 10:54:27 -070037 };
38
Davide Pesaventof43a03e2018-02-21 22:04:21 -050039public:
Weiqi Shif0330d52014-07-09 10:54:27 -070040 virtual
Davide Pesaventof43a03e2018-02-21 22:04:21 -050041 ~Storage() = default;
Weiqi Shif0330d52014-07-09 10:54:27 -070042
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 yuan3aa8d2b2018-03-06 15:35:57 -080051 * @brief remove the entry in the database by full name
52 * @param full name full name of the data
Weiqi Shif0330d52014-07-09 10:54:27 -070053 */
54 virtual bool
weijia yuan3aa8d2b2018-03-06 15:35:57 -080055 erase(const Name& name) = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070056
57 /**
58 * @brief get the data from database
weijia yuan3aa8d2b2018-03-06 15:35:57 -080059 * @param full name full name of the data
Weiqi Shif0330d52014-07-09 10:54:27 -070060 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070061 virtual std::shared_ptr<Data>
weijia yuan3aa8d2b2018-03-06 15:35:57 -080062 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 Shif0330d52014-07-09 10:54:27 -070077
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040078 /**
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 Shif0330d52014-07-09 10:54:27 -070084 /**
85 * @brief return the size of database
86 */
weijia yuan3aa8d2b2018-03-06 15:35:57 -080087 virtual uint64_t
Weiqi Shif0330d52014-07-09 10:54:27 -070088 size() = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070089};
90
91} // namespace repo
92
Davide Pesaventof43a03e2018-02-21 22:04:21 -050093#endif // REPO_STORAGE_STORAGE_HPP