Hyperpage
 
Loading...
Searching...
No Matches
hyperpage.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Maxtek Consulting
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#ifndef HYPERPAGE_HPP
24#define HYPERPAGE_HPP
25
31
32#include <functional>
33#include <memory>
34#include <stdexcept>
35#include <string>
36
37namespace hyperpage
38{
45 class page
46 {
47 public:
51 virtual const std::string &get_path() const = 0;
52
56 virtual const std::string &get_mime_type() const = 0;
57
63 virtual const uint8_t *get_content() const = 0;
64
70 virtual size_t get_length() const = 0;
71 };
72
78 class reader
79 {
80 public:
86 reader(const std::string &db_path);
87
94 std::unique_ptr<page> load(const std::string &page_path);
95
96 private:
97 std::unique_ptr<void, std::function<void(void *)>> _handle;
98 };
99
105 class writer
106 {
107 public:
113 writer(const std::string &db_path);
119 void store(const page &page);
120
121 private:
122 std::unique_ptr<void, std::function<void(void *)>> _handle;
123 };
124
125 std::string mime_type(const std::string &path);
126}
127
128#endif
Definition hyperpage.hpp:46
virtual const std::string & get_mime_type() const =0
gets the MIME type of the page.
virtual const std::string & get_path() const =0
gets the URI path of the page.
virtual size_t get_length() const =0
gets the content length of the page.
virtual const uint8_t * get_content() const =0
gets the content of the page.
reader(const std::string &db_path)
Constructs a reader for the hyperpage database.
std::unique_ptr< page > load(const std::string &page_path)
Loads a page from the hyperpage database.
void store(const page &page)
Stores a page in the hyperpage database.
writer(const std::string &db_path)
Constructs a writer for the hyperpage database.
Definition hyperpage.hpp:38
std::string mime_type(const std::string &path)