blob: e1cb537c680ccf68b04f1ceb0e1166fc6033aadd [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/*
3 * Copyright (c) 2014-2018, 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/**
28 * @brief Storage is a virtual abstract class which will be called by SqliteStorage
29 */
30class Storage : noncopyable
31{
32public:
33 class Error : public std::runtime_error
34 {
35 public:
36 explicit
37 Error(const std::string& what)
38 : std::runtime_error(what)
39 {
40 }
41 };
42
Weiqi Shif0330d52014-07-09 10:54:27 -070043 class ItemMeta
44 {
45 public:
46 int64_t id;
47 Name fullName;
48 ndn::ConstBufferPtr keyLocatorHash;
49 };
50
Davide Pesaventof43a03e2018-02-21 22:04:21 -050051public:
Weiqi Shif0330d52014-07-09 10:54:27 -070052 virtual
Davide Pesaventof43a03e2018-02-21 22:04:21 -050053 ~Storage() = default;
Weiqi Shif0330d52014-07-09 10:54:27 -070054
55 /**
56 * @brief put the data into database
57 * @param data the data should be inserted into databse
58 */
59 virtual int64_t
60 insert(const Data& data) = 0;
61
62 /**
63 * @brief remove the entry in the database by using id
64 * @param id id number of entry in the database
65 */
66 virtual bool
67 erase(const int64_t id) = 0;
68
69 /**
70 * @brief get the data from database
71 * @param id id number of each entry in the database, used to find the data
72 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070073 virtual std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070074 read(const int64_t id) = 0;
75
76 /**
77 * @brief return the size of database
78 */
79 virtual int64_t
80 size() = 0;
81
82 /**
83 * @brief enumerate each entry in database and call the function
84 * insertItemToIndex to reubuild index from database
85 */
86 virtual void
Wentao Shanga8f3c402014-10-30 14:03:27 -070087 fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f) = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070088};
89
90} // namespace repo
91
Davide Pesaventof43a03e2018-02-21 22:04:21 -050092#endif // REPO_STORAGE_STORAGE_HPP