blob: 5286c8accebbd222ef1dd093b457d111dfc8d724 [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"
weijia yuan82cf9142018-10-21 12:25:02 -070024#include <string>
25#include <iostream>
26#include <stdlib.h>
Weiqi Shif0330d52014-07-09 10:54:27 -070027
28namespace repo {
29
30/**
31 * @brief Storage is a virtual abstract class which will be called by SqliteStorage
32 */
33class Storage : noncopyable
34{
35public:
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
Weiqi Shif0330d52014-07-09 10:54:27 -070046 class ItemMeta
47 {
48 public:
49 int64_t id;
50 Name fullName;
51 ndn::ConstBufferPtr keyLocatorHash;
52 };
53
Davide Pesaventof43a03e2018-02-21 22:04:21 -050054public:
Weiqi Shif0330d52014-07-09 10:54:27 -070055 virtual
Davide Pesaventof43a03e2018-02-21 22:04:21 -050056 ~Storage() = default;
Weiqi Shif0330d52014-07-09 10:54:27 -070057
58 /**
59 * @brief put the data into database
60 * @param data the data should be inserted into databse
61 */
62 virtual int64_t
63 insert(const Data& data) = 0;
64
65 /**
66 * @brief remove the entry in the database by using id
67 * @param id id number of entry in the database
68 */
69 virtual bool
70 erase(const int64_t id) = 0;
71
72 /**
73 * @brief get the data from database
74 * @param id id number of each entry in the database, used to find the data
75 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070076 virtual std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070077 read(const int64_t id) = 0;
78
79 /**
80 * @brief return the size of database
81 */
82 virtual int64_t
83 size() = 0;
84
85 /**
86 * @brief enumerate each entry in database and call the function
87 * insertItemToIndex to reubuild index from database
88 */
89 virtual void
Wentao Shanga8f3c402014-10-30 14:03:27 -070090 fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f) = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070091};
92
93} // namespace repo
94
Davide Pesaventof43a03e2018-02-21 22:04:21 -050095#endif // REPO_STORAGE_STORAGE_HPP