crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
Memory.hpp
Go to the documentation of this file.
1 /*
2  *
3  * ---
4  *
5  * Copyright (C) 2021 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  * Memory.hpp
24  *
25  * Helper functions for memory operations.
26  *
27  * Created on: Feb 21, 2021
28  * Author: ans
29  */
30 
31 #ifndef HELPER_MEMORY_HPP_
32 #define HELPER_MEMORY_HPP_
33 
36 
38 
42  template<class T> static void free(T& target) {
43  T{}.swap(target);
44  }
45 
47 
52  template<class T> static void freeIf(bool isFree, T& target) {
53  if(isFree) {
54  free(target);
55  }
56  }
57 
58 } /* namespace crawlservpp::Helper::Memory */
59 
60 #endif /* HELPER_MEMORY_HPP_ */
Namespace for global memory helper functions.
Definition: Memory.hpp:35
static void freeIf(bool isFree, T &target)
Frees memory early by swapping, if necessary.
Definition: Memory.hpp:52
static void free(T &target)
Frees memory by swapping.
Definition: Memory.hpp:42