crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
URIQueryList.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  * URIQueryList.hpp
24  *
25  * RAII wrapper for pointer to URI query list.
26  * Does NOT have ownership of the pointer!
27  *
28  * Created on: Feb 7, 2019
29  * Author: ans
30  */
31 
32 #ifndef WRAPPER_URIQUERYLIST_HPP_
33 #define WRAPPER_URIQUERYLIST_HPP_
34 
35 #include <uriparser/Uri.h>
36 
37 namespace crawlservpp::Wrapper {
38 
39  /*
40  * DECLARATION
41  */
42 
44 
56  class URIQueryList {
57  public:
60 
62  URIQueryList() = default;
63 
64  virtual ~URIQueryList();
65 
69 
70  [[nodiscard]] UriQueryListA * get() noexcept;
71  [[nodiscard]] const UriQueryListA * getc() const noexcept;
72  [[nodiscard]] UriQueryListA ** getPtr() noexcept;
73  [[nodiscard]] bool valid() const noexcept;
74 
78 
79  void clear() noexcept;
80 
82 
85 
88  URIQueryList(URIQueryList&) = delete;
89 
92 
93  URIQueryList(URIQueryList&& other) noexcept;
94  URIQueryList& operator=(URIQueryList&& other) noexcept;
95 
97 
98  private:
99  // underlying pointer, not owned by this class
100  UriQueryListA * ptr{nullptr};
101  };
102 
103  /*
104  * IMPLEMENTATION
105  */
106 
107  /*
108  * CONSTRUCTION AND DESTRUCTION
109  */
110 
113  this->clear();
114  }
115 
116  /*
117  * GETTERS
118  */
119 
121 
126  inline UriQueryListA * URIQueryList::get() noexcept {
127  return this->ptr;
128  }
129 
131 
136  inline const UriQueryListA * URIQueryList::getc() const noexcept {
137  return this->ptr;
138  }
139 
141 
147  inline UriQueryListA ** URIQueryList::getPtr() noexcept {
148  return &(this->ptr);
149  }
150 
152 
155  inline bool URIQueryList::valid() const noexcept {
156  return this->ptr != nullptr;
157  }
158 
160  inline void URIQueryList::clear() noexcept {
161  if(this->ptr != nullptr) {
162  uriFreeQueryListA(this->ptr);
163 
164  this->ptr = nullptr;
165  }
166  }
167 
168  /*
169  * COPY AND MOVE
170  */
171 
173 
183  inline URIQueryList::URIQueryList(URIQueryList&& other) noexcept : ptr(other.ptr) {
184  other.ptr = nullptr;
185  }
186 
188 
204  if(&other != this) {
205  this->clear();
206 
207  this->ptr = other.ptr;
208 
209  other.ptr = nullptr;
210  }
211 
212  return *this;
213  }
214 
215 } /* namespace crawlservpp::Wrapper */
216 
217 #endif /* WRAPPER_URIQUERYLIST_HPP_ */
UriQueryListA * get() noexcept
Gets a pointer to the underlying query list.
Definition: URIQueryList.hpp:126
bool valid() const noexcept
Checks whether the underlying query list is valid.
Definition: URIQueryList.hpp:155
URIQueryList()=default
Default constructor.
UriQueryListA ** getPtr() noexcept
Gets a pointer to the pointer containing the address of the underlying query list.
Definition: URIQueryList.hpp:147
const UriQueryListA * getc() const noexcept
Gets a const pointer to the underlying query list.
Definition: URIQueryList.hpp:136
virtual ~URIQueryList()
Destructor clearing the underlying query list if necessary.
Definition: URIQueryList.hpp:112
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
void clear() noexcept
Clears the underlying query list if necessary.
Definition: URIQueryList.hpp:160
URIQueryList & operator=(URIQueryList &)=delete
Deleted copy assignment operator.
RAII wrapper for the URI query list used by uriparser.
Definition: URIQueryList.hpp:56