blob: bf7530687efa21691df9b82ab96869398f4155fe [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
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
22#include <string>
23#include <iostream>
24#include <stdlib.h>
25#include "../common.hpp"
26
27namespace repo {
28
29/**
30 * @brief Storage is a virtual abstract class which will be called by SqliteStorage
31 */
32class Storage : noncopyable
33{
34public:
35 class Error : public std::runtime_error
36 {
37 public:
38 explicit
39 Error(const std::string& what)
40 : std::runtime_error(what)
41 {
42 }
43 };
44
45public:
46 class ItemMeta
47 {
48 public:
49 int64_t id;
50 Name fullName;
51 ndn::ConstBufferPtr keyLocatorHash;
52 };
53
54public :
55
56 virtual
57 ~Storage()
58 {
59 };
60
61 /**
62 * @brief put the data into database
63 * @param data the data should be inserted into databse
64 */
65 virtual int64_t
66 insert(const Data& data) = 0;
67
68 /**
69 * @brief remove the entry in the database by using id
70 * @param id id number of entry in the database
71 */
72 virtual bool
73 erase(const int64_t id) = 0;
74
75 /**
76 * @brief get the data from database
77 * @param id id number of each entry in the database, used to find the data
78 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070079 virtual std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070080 read(const int64_t id) = 0;
81
82 /**
83 * @brief return the size of database
84 */
85 virtual int64_t
86 size() = 0;
87
88 /**
89 * @brief enumerate each entry in database and call the function
90 * insertItemToIndex to reubuild index from database
91 */
92 virtual void
Wentao Shanga8f3c402014-10-30 14:03:27 -070093 fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f) = 0;
Weiqi Shif0330d52014-07-09 10:54:27 -070094
95};
96
97} // namespace repo
98
99#endif // REPO_STORAGE_Storage_HPP