File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 159159 <ClInclude Include =" preprocessor.h" />
160160 <ClInclude Include =" programmemory.h" />
161161 <ClInclude Include =" reverseanalyzer.h" />
162+ <ClInclude Include =" safeptr.h" />
162163 <ClInclude Include =" settings.h" />
163164 <ClInclude Include =" smallvector.h" />
164165 <ClInclude Include =" standards.h" />
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ HEADERS += $${PWD}/analyzer.h \
5454 $${PWD }/preprocessor.h \
5555 $${PWD }/programmemory.h \
5656 $${PWD }/reverseanalyzer.h \
57+ $${PWD }/safeptr.h \
5758 $${PWD }/settings.h \
5859 $${PWD }/smallvector.h \
5960 $${PWD }/standards.h \
Original file line number Diff line number Diff line change 1+ /*
2+ * Cppcheck - A tool for static C/C++ code analysis
3+ * Copyright (C) 2007-2023 Cppcheck team.
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+ // ---------------------------------------------------------------------------
20+ #ifndef safePtrH
21+ #define safePtrH
22+ // ---------------------------------------------------------------------------
23+
24+ #include " config.h"
25+
26+ // as std::optional behaves similarly so we could use that instead of if we ever move to C++17
27+ template <typename T>
28+ class safe_ptr
29+ {
30+ public:
31+ safe_ptr (T* p)
32+ : mPtr (p)
33+ {}
34+
35+ T* get () NOEXCEPT {
36+ return mPtr ;
37+ }
38+
39+ const T* get () const NOEXCEPT {
40+ return mPtr ;
41+ }
42+
43+ T* operator ->() NOEXCEPT {
44+ return mPtr ;
45+ }
46+
47+ const T* operator ->() const NOEXCEPT {
48+ return mPtr ;
49+ }
50+
51+ T& operator *() NOEXCEPT {
52+ return *mPtr ;
53+ }
54+
55+ const T& operator *() const NOEXCEPT {
56+ return *mPtr ;
57+ }
58+
59+ operator bool () const NOEXCEPT {
60+ return mPtr != nullptr ;
61+ }
62+
63+ private:
64+ T* mPtr ;
65+ };
66+
67+ #endif // safePtrH
Original file line number Diff line number Diff line change @@ -313,6 +313,7 @@ int main(int argc, char **argv)
313313 libfiles_h.emplace_back (" calculate.h" );
314314 libfiles_h.emplace_back (" config.h" );
315315 libfiles_h.emplace_back (" precompiled.h" );
316+ libfiles_h.emplace_back (" safeptr.h" );
316317 libfiles_h.emplace_back (" smallvector.h" );
317318 libfiles_h.emplace_back (" standards.h" );
318319 libfiles_h.emplace_back (" tokenrange.h" );
You can’t perform that action at this time.
0 commit comments