crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
URI.hpp
Go to the documentation of this file.
1 /*
2  *
3  * ---
4  *
5  * Copyright (C) 2020 Anselm Schmidt (ans[ät]ohai.su)
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version in addition to the terms of any
11  * licences already herein identified.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  *
21  * ---
22  *
23  * URI.hpp
24  *
25  * Wrapper for pointer to URI structure.
26  * Structure is only created when needed.
27  *
28  * Created on: Feb 7, 2019
29  * Author: ans
30  */
31 
32 #ifndef WRAPPER_URI_HPP_
33 #define WRAPPER_URI_HPP_
34 
35 #include <uriparser/Uri.h>
36 
37 #include <memory> // std::make_unique, std::unique_ptr
38 #include <utility> // std::move
39 
40 namespace crawlservpp::Wrapper {
41 
42  /*
43  * DECLARATION
44  */
45 
47 
57  class URI {
58  public:
61 
63  URI() = default;
64 
65  virtual ~URI();
66 
70 
71  [[nodiscard]] UriUriA * get() noexcept;
72  [[nodiscard]] const UriUriA * getc() const noexcept;
73  [[nodiscard]] bool valid() const noexcept;
74 
78 
79  void create();
80  void clear();
81 
83 
86 
89  URI(URI&) = delete;
90 
92  URI& operator=(URI&) = delete;
93 
95  URI(URI&& other) = default;
96 
98  URI& operator=(URI&& other) = default;
99 
101 
102  private:
103  // underlying smart pointer
104  std::unique_ptr<UriUriA> ptr;
105  };
106 
107  /*
108  * IMPLEMENTATION
109  */
110 
111  /*
112  * CONSTRUCTION AND DESTRUCTION
113  */
114 
116 
119  inline URI::~URI() {
120  this->clear();
121  }
122 
123  /*
124  * GETTERS
125  */
126 
128 
131  inline UriUriA * URI::get() noexcept {
132  return this->ptr.get();
133  }
134 
136 
139  inline const UriUriA * URI::getc() const noexcept {
140  return this->ptr.get();
141  }
142 
144 
148  inline bool URI::valid() const noexcept {
149  return this->ptr.operator bool();
150  }
151 
152  /*
153  * CREATION AND CLEANUP
154  */
155 
157 
160  inline void URI::create() {
161  this->clear();
162 
163  this->ptr = std::make_unique<UriUriA>();
164  }
165 
167 
172  inline void URI::clear() {
173  if(this->ptr) {
174  uriFreeUriMembersA(this->ptr.get());
175 
176  this->ptr.reset();
177  }
178  }
179 
180 } /* namespace crawlservpp::Wrapper */
181 
182 #endif /* WRAPPER_URI_HPP_ */
void create()
Creates a new and empty URI.
Definition: URI.hpp:160
const UriUriA * getc() const noexcept
Gets a const pointer to the underlying URI structure.
Definition: URI.hpp:139
URI & operator=(URI &)=delete
Deleted copy assignment operator.
URI()=default
Default constructor.
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
bool valid() const noexcept
Checks whether the URI is valid.
Definition: URI.hpp:148
RAII wrapper for the RFC 3986 URI structure used by uriparser.
Definition: URI.hpp:57
UriUriA * get() noexcept
Gets a pointer to the underlying URI structure.
Definition: URI.hpp:131
void clear()
Frees the current URI.
Definition: URI.hpp:172
virtual ~URI()
Destructor freeing the URI if necessary.
Definition: URI.hpp:119