···11+/** @file
22+ @brief Header declaring a C++11 `finally` or "scope-guard" construct.
33+44+ Inspirations are many - Alexandrescu's original and C++11 ScopeGuard, and
55+ the Guideline Support Library's (GSL) `final_act`/`finally`
66+ https://github.com/Microsoft/GSL/blob/0cf947db7760bf5756e4cb0d47c72a257ed527c5/include/gsl_util.h
77+ come to mind, but this has been written and re-written numerous times
88+ since its introduction into the C++ global consciousness, and this
99+ implementation was written independently after I couldn't find a
1010+ previous independent implementation I had written a few weeks earlier in
1111+ an implementation file. -- Ryan Pavlik
1212+1313+ See UniqueDestructionActionWrapper for a "generalized" (in some sense)
1414+ version of this.
1515+1616+ Originally written for use in OSVR for Sensics <http://sensics.com/osvr>,
1717+ relicensed to BSL 1.0 with permission.
1818+1919+ This header is maintained as a part of 'util-headers' - you can always
2020+ find the latest version online at https://github.com/rpavlik/util-headers
2121+2222+ This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
2323+2424+ This copy of the header is from the revision that Git calls
2525+ 1a8444782d15cb9458052e3d8251c4f5b8e808d5
2626+2727+ Commit date: "2022-03-11 12:11:32 -0600"
2828+2929+ @date 2016
3030+3131+ @author
3232+ Ryan Pavlik
3333+ <ryan.pavlik@gmail.com>
3434+ <http://ryanpavlik.com>
3535+*/
3636+3737+// Copyright 2016, Sensics, Inc.
3838+//
3939+// SPDX-License-Identifier: BSL-1.0
4040+//
4141+// Distributed under the Boost Software License, Version 1.0.
4242+// (See accompanying file LICENSE_1_0.txt or copy at
4343+// http://www.boost.org/LICENSE_1_0.txt)
4444+4545+#ifndef INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA
4646+#define INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA
4747+4848+// Internal Includes
4949+// - none
5050+5151+// Library/third-party includes
5252+// - none
5353+5454+// Standard includes
5555+#include <utility>
5656+5757+namespace util {
5858+namespace detail {
5959+ /// Allows you to run a callable something at the end of a scope.
6060+ ///
6161+ /// The class that provides the scope-guard behavior. Often not referred to
6262+ /// by name because auto is useful here, and often not created by a direct
6363+ /// constructor call because of the finally() convenience functions combined
6464+ /// with lambdas.
6565+ template <typename F> class FinalTask {
6666+ public:
6767+ /// Explicit constructor from something callable.
6868+ explicit FinalTask(F f) : f_(std::move(f)) {}
6969+7070+ /// Move constructor - cancels the moved-from task.
7171+ FinalTask(FinalTask &&other) : f_(std::move(other.f_)), do_(other.do_) {
7272+ other.cancel();
7373+ }
7474+7575+ /// non-copyable
7676+ FinalTask(FinalTask const &) = delete;
7777+7878+ /// non-assignable
7979+ FinalTask &operator=(FinalTask const &) = delete;
8080+8181+ /// Destructor - if we haven't been cancelled, do our callable thing.
8282+ ~FinalTask() {
8383+ if (do_) {
8484+ f_();
8585+ }
8686+ }
8787+ /// Cancel causes us to not do our final task on destruction.
8888+ void cancel() { do_ = false; }
8989+9090+ private:
9191+ /// Our callable task to do at destruction.
9292+ F f_;
9393+ /// Whether we should actually do it.
9494+ bool do_ = true;
9595+ };
9696+} // namespace detail
9797+9898+/// Creation free function for final tasks to run on scope exit. Works great
9999+/// when paired with lambdas (particularly with `[&]` reference capture).
100100+/// Use like:
101101+/// `auto f = finally([&]{ dothis(); });` to have `dothis()` called when `f`
102102+/// goes out of scope, no matter how.
103103+template <typename F> inline detail::FinalTask<F> finally(F &&f) {
104104+ /// Perfect forwarding version.
105105+ return detail::FinalTask<F>(std::forward<F>(f));
106106+}
107107+108108+/// @overload
109109+template <typename F> inline detail::FinalTask<F> finally(F const &f) {
110110+ // Added this overload because GSL had it and GSL is supposed to be best
111111+ // practices guidelines...
112112+ return detail::FinalTask<F>(f);
113113+}
114114+115115+} // namespace util
116116+117117+#endif // INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA
···11+/** @file
22+ @brief Header providing C++-enhanced versions of the various string
33+ functions that work on fixed-length buffers, inspired by
44+ https://randomascii.wordpress.com/2013/04/03/stop-using-strncpy-already/
55+66+ @date 2015
77+88+ This header is maintained as a part of 'util-headers' - you can always
99+ find the latest version online at https://github.com/rpavlik/util-headers
1010+1111+ This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
1212+1313+ This copy of the header is from the revision that Git calls
1414+ 1a8444782d15cb9458052e3d8251c4f5b8e808d5
1515+1616+ Commit date: "2022-03-11 12:11:32 -0600"
1717+1818+ @author
1919+ Sensics, Inc.
2020+ <http://sensics.com/osvr>
2121+*/
2222+2323+// Copyright 2015, Sensics, Inc.
2424+// Copyright 2022, Collabora, Ltd.
2525+//
2626+// SPDX-License-Identifier: BSL-1.0
2727+//
2828+// Distributed under the Boost Software License, Version 1.0.
2929+// (See accompanying file LICENSE_1_0.txt or copy at
3030+// http://www.boost.org/LICENSE_1_0.txt)
3131+3232+#ifndef INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9
3333+#define INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9
3434+3535+// Internal Includes
3636+// - none
3737+3838+// Library/third-party includes
3939+// - none
4040+4141+// Standard includes
4242+#include <stddef.h>
4343+#include <stdexcept>
4444+#include <string.h>
4545+4646+#ifdef _MSC_VER
4747+#define UTILHEADERS_STR_MSRUNTIME
4848+#else
4949+#include <limits.h>
5050+#ifndef _WIN32
5151+#include <sys/types.h>
5252+#endif
5353+#if defined(__KLIBC__) || defined(__BIONIC__) || \
5454+ (!defined(__GLIBC__) && defined(_BSD_SOURCE))
5555+// strlcpy providers:
5656+// klibc
5757+// bionic
5858+// musl if _GNU_SOURCE or _BSD_SOURCE defined (_BSD_SOURCE defined by default) -
5959+// but not glibc!
6060+#define UTILHEADERS_STR_STRLCPY
6161+#elif defined(__DARWIN_C_LEVEL) && defined(__DARWIN_C_FULL) && \
6262+ (__DARWIN_C_LEVEL >= __DARWIN_C_FULL)
6363+// Also provided in cases on Darwin
6464+#define UTILHEADERS_STR_STRLCPY
6565+#endif
6666+#endif
6767+6868+namespace util {
6969+/// @brief Copy a string into a char array, guaranteed to null-terminate and not
7070+/// overrun. Does not correctly handle UTF-8 (may truncate in the middle of a
7171+/// codepoint).
7272+template <size_t N> inline void strcpy_safe(char (&dest)[N], const char *src) {
7373+#if defined(UTILHEADERS_STR_STRLCPY)
7474+ strlcpy(dest, src, N);
7575+#elif defined(UTILHEADERS_STR_MSRUNTIME)
7676+ strncpy_s(dest, src, _TRUNCATE);
7777+#else
7878+ strncpy(dest, src, N);
7979+ dest[N - 1] = '\0';
8080+#endif
8181+}
8282+} // namespace util
8383+8484+#endif // INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9
+87
src/external/util-headers/util/Stride.h
···11+/** @file
22+ @brief A class for handling "do this every n times"
33+44+ This header is maintained as a part of 'util-headers' - you can always
55+ find the latest version online at https://github.com/rpavlik/util-headers
66+77+ This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
88+99+ This copy of the header is from the revision that Git calls
1010+ 1a8444782d15cb9458052e3d8251c4f5b8e808d5
1111+1212+ Commit date: "2022-03-11 12:11:32 -0600"
1313+1414+ @date
1515+ 2009-2010
1616+1717+ @author
1818+ Ryan Pavlik
1919+ <rpavlik@iastate.edu> and <abiryan@ryand.net>
2020+ http://academic.cleardefinition.com/
2121+ Iowa State University Virtual Reality Applications Center
2222+ Human-Computer Interaction Graduate Program
2323+*/
2424+2525+// Copyright 2009-2010, Iowa State University.
2626+//
2727+// SPDX-License-Identifier: BSL-1.0
2828+//
2929+// Distributed under the Boost Software License, Version 1.0.
3030+// (See accompanying file LICENSE_1_0.txt or copy at
3131+// http://www.boost.org/LICENSE_1_0.txt)
3232+3333+#pragma once
3434+#ifndef INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
3535+#define INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
3636+3737+// Local includes
3838+// - none
3939+4040+// Library includes
4141+// - none
4242+4343+// Standard includes
4444+// - none
4545+4646+namespace util {
4747+4848+/// @addtogroup Other Other Utility Classes
4949+/// @{
5050+5151+/// Handle the task of "do this every n times" in an easy way.
5252+ class Stride {
5353+ public:
5454+ Stride(const unsigned int n) :
5555+ _stride(n),
5656+ _step(0) { }
5757+5858+ void advance() {
5959+ _step = (_step + 1) % _stride;
6060+ }
6161+6262+ Stride operator++() {
6363+ Stride temp = *this;
6464+ advance();
6565+ return temp;
6666+ }
6767+6868+ Stride & operator++(int) {
6969+ advance();
7070+ return *this;
7171+ }
7272+7373+ operator bool() const {
7474+ return _step == 0;
7575+ }
7676+7777+ private:
7878+ unsigned int _stride;
7979+ unsigned int _step;
8080+ };
8181+8282+/// @}
8383+8484+} // end of util namespace
8585+8686+#endif // INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
8787+