blob: d724eb1d3e2ffdf53c8f957541a34f291385679d [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/*
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -04003 * Copyright (c) 2014-2019, 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
Davide Pesaventof43a03e2018-02-21 22:04:21 -050046public:
Weiqi Shif0330d52014-07-09 10:54:27 -070047 virtual
Davide Pesaventof43a03e2018-02-21 22:04:21 -050048 ~Storage() = default;
Weiqi Shif0330d52014-07-09 10:54:27 -070049
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 yuan3aa8d2b2018-03-06 15:35:57 -080058 * @brief remove the entry in the database by full name
59 * @param full name full name of the data
Weiqi Shif0330d52014-07-09 10:54:27 -070060 */
61 virtual bool
weijia yuan3aa8d2b2018-03-06 15:35:57 -080062 erase(const Name& name) = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070063
64 /**
65 * @brief get the data from database
weijia yuan3aa8d2b2018-03-06 15:35:57 -080066 * @param full name full name of the data
Weiqi Shif0330d52014-07-09 10:54:27 -070067 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070068 virtual std::shared_ptr<Data>
weijia yuan3aa8d2b2018-03-06 15:35:57 -080069 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 Shif0330d52014-07-09 10:54:27 -070084
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040085 /**
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 Shif0330d52014-07-09 10:54:27 -070091 /**
92 * @brief return the size of database
93 */
weijia yuan3aa8d2b2018-03-06 15:35:57 -080094 virtual uint64_t
Weiqi Shif0330d52014-07-09 10:54:27 -070095 size() = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070096};
97
98} // namespace repo
99
Davide Pesaventof43a03e2018-02-21 22:04:21 -0500100#endif // REPO_STORAGE_STORAGE_HPP