/usr/include/r3/r3.hpp is in libr3-dev 1.3.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | /*
* r3.hpp
* Copyright (C) 2014 whitglint <whitglint.tw@gmail.com>
*
* Distributed under terms of the MIT license.
*/
#ifndef R3_HPP
#define R3_HPP
#include <cstring>
#include <r3.h>
namespace r3 {
template <typename T>
class Base {
public:
Base(T* p)
: p_(p) {
}
void* data() const {
return p_->data;
}
T* get() const {
return p_;
}
bool is_null() const {
return p_ == NULL;
}
operator void*() const {
return p_;
}
private:
T* p_;
};
typedef Base<node> Node;
typedef Base<route> Route;
class MatchEntry : public Base<match_entry> {
public:
explicit MatchEntry(const char* path)
: Base(match_entry_create(path)) {
}
MatchEntry(const char* path, int path_len)
: Base(match_entry_createl(path, path_len)) {
}
~MatchEntry() {
if (get()) {
match_entry_free(get());
}
}
int request_method() const {
return get()->request_method;
}
void set_request_method(int request_method) {
get()->request_method = request_method;
}
private:
MatchEntry(const MatchEntry&);
MatchEntry& operator =(const MatchEntry&);
};
class Tree : public Base<node> {
public:
explicit Tree(int cap)
: Base(r3_tree_create(cap)) {
}
~Tree() {
if (get()) {
r3_tree_free(get());
}
}
int compile(char** errstr = NULL) {
return r3_tree_compile(get(), errstr);
}
void dump(int level) const {
r3_tree_dump(get(), level);
}
Node insert_path(const char* path, void* data, char** errstr = NULL) {
return r3_tree_insert_pathl_ex(get(), path, std::strlen(path), NULL,
data, errstr);
}
Node insert_pathl(const char* path, int path_len, void* data,
char** errstr = NULL) {
return r3_tree_insert_pathl_ex(get(), path, path_len, NULL, data,
errstr);
}
Route insert_route(int method, const char* path, void* data,
char** errstr = NULL) {
return r3_tree_insert_routel_ex(get(), method, path,
std::strlen(path), data, errstr);
}
Route insert_routel(int method, const char* path, int path_len,
void* data, char** errstr = NULL) {
return r3_tree_insert_routel_ex(get(), method, path, path_len, data,
errstr);
}
Node match(const char* path, MatchEntry* entry = NULL) const {
return r3_tree_match(get(), path,
entry != NULL ? entry->get() : NULL);
}
Node matchl(const char* path, int path_len, MatchEntry* entry = NULL)
const {
return r3_tree_matchl(get(), path, path_len,
entry != NULL ? entry->get() : NULL);
}
Node match_entry(MatchEntry& entry) const {
return r3_tree_match_entry(get(), entry.get());
}
Route match_route(MatchEntry& entry) const {
return r3_tree_match_route(get(), entry.get());
}
private:
Tree(const Tree&);
Tree& operator =(const Tree&);
};
}
#endif // R3_HPP
|