external: Add some headers from my util-headers project.

This commit is contained in:
Ryan Pavlik 2022-03-11 12:16:19 -06:00 committed by Jakob Bornecrantz
parent 12bb18a34c
commit 6bb976e47f
4 changed files with 294 additions and 0 deletions

View file

@ -24,6 +24,12 @@ endif()
add_library(xrt-external-flexkalman INTERFACE)
target_include_directories(xrt-external-flexkalman INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/flexkalman)
# FlexKalman
add_library(xrt-external-util-headers INTERFACE)
target_include_directories(
xrt-external-util-headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/util-headers
)
# Glad
add_library(xrt-external-glad INTERFACE)
target_include_directories(xrt-external-glad INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)

117
src/external/util-headers/util/Finally.h vendored Normal file
View file

@ -0,0 +1,117 @@
/** @file
@brief Header declaring a C++11 `finally` or "scope-guard" construct.
Inspirations are many - Alexandrescu's original and C++11 ScopeGuard, and
the Guideline Support Library's (GSL) `final_act`/`finally`
https://github.com/Microsoft/GSL/blob/0cf947db7760bf5756e4cb0d47c72a257ed527c5/include/gsl_util.h
come to mind, but this has been written and re-written numerous times
since its introduction into the C++ global consciousness, and this
implementation was written independently after I couldn't find a
previous independent implementation I had written a few weeks earlier in
an implementation file. -- Ryan Pavlik
See UniqueDestructionActionWrapper for a "generalized" (in some sense)
version of this.
Originally written for use in OSVR for Sensics <http://sensics.com/osvr>,
relicensed to BSL 1.0 with permission.
This header is maintained as a part of 'util-headers' - you can always
find the latest version online at https://github.com/rpavlik/util-headers
This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
This copy of the header is from the revision that Git calls
1a8444782d15cb9458052e3d8251c4f5b8e808d5
Commit date: "2022-03-11 12:11:32 -0600"
@date 2016
@author
Ryan Pavlik
<ryan.pavlik@gmail.com>
<http://ryanpavlik.com>
*/
// Copyright 2016, Sensics, Inc.
//
// SPDX-License-Identifier: BSL-1.0
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA
#define INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA
// Internal Includes
// - none
// Library/third-party includes
// - none
// Standard includes
#include <utility>
namespace util {
namespace detail {
/// Allows you to run a callable something at the end of a scope.
///
/// The class that provides the scope-guard behavior. Often not referred to
/// by name because auto is useful here, and often not created by a direct
/// constructor call because of the finally() convenience functions combined
/// with lambdas.
template <typename F> class FinalTask {
public:
/// Explicit constructor from something callable.
explicit FinalTask(F f) : f_(std::move(f)) {}
/// Move constructor - cancels the moved-from task.
FinalTask(FinalTask &&other) : f_(std::move(other.f_)), do_(other.do_) {
other.cancel();
}
/// non-copyable
FinalTask(FinalTask const &) = delete;
/// non-assignable
FinalTask &operator=(FinalTask const &) = delete;
/// Destructor - if we haven't been cancelled, do our callable thing.
~FinalTask() {
if (do_) {
f_();
}
}
/// Cancel causes us to not do our final task on destruction.
void cancel() { do_ = false; }
private:
/// Our callable task to do at destruction.
F f_;
/// Whether we should actually do it.
bool do_ = true;
};
} // namespace detail
/// Creation free function for final tasks to run on scope exit. Works great
/// when paired with lambdas (particularly with `[&]` reference capture).
/// Use like:
/// `auto f = finally([&]{ dothis(); });` to have `dothis()` called when `f`
/// goes out of scope, no matter how.
template <typename F> inline detail::FinalTask<F> finally(F &&f) {
/// Perfect forwarding version.
return detail::FinalTask<F>(std::forward<F>(f));
}
/// @overload
template <typename F> inline detail::FinalTask<F> finally(F const &f) {
// Added this overload because GSL had it and GSL is supposed to be best
// practices guidelines...
return detail::FinalTask<F>(f);
}
} // namespace util
#endif // INCLUDED_Finally_h_GUID_D925FE58_9C57_448B_C0BB_19A42B3243BA

View file

@ -0,0 +1,84 @@
/** @file
@brief Header providing C++-enhanced versions of the various string
functions that work on fixed-length buffers, inspired by
https://randomascii.wordpress.com/2013/04/03/stop-using-strncpy-already/
@date 2015
This header is maintained as a part of 'util-headers' - you can always
find the latest version online at https://github.com/rpavlik/util-headers
This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
This copy of the header is from the revision that Git calls
1a8444782d15cb9458052e3d8251c4f5b8e808d5
Commit date: "2022-03-11 12:11:32 -0600"
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
// Copyright 2015, Sensics, Inc.
// Copyright 2022, Collabora, Ltd.
//
// SPDX-License-Identifier: BSL-1.0
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9
#define INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9
// Internal Includes
// - none
// Library/third-party includes
// - none
// Standard includes
#include <stddef.h>
#include <stdexcept>
#include <string.h>
#ifdef _MSC_VER
#define UTILHEADERS_STR_MSRUNTIME
#else
#include <limits.h>
#ifndef _WIN32
#include <sys/types.h>
#endif
#if defined(__KLIBC__) || defined(__BIONIC__) || \
(!defined(__GLIBC__) && defined(_BSD_SOURCE))
// strlcpy providers:
// klibc
// bionic
// musl if _GNU_SOURCE or _BSD_SOURCE defined (_BSD_SOURCE defined by default) -
// but not glibc!
#define UTILHEADERS_STR_STRLCPY
#elif defined(__DARWIN_C_LEVEL) && defined(__DARWIN_C_FULL) && \
(__DARWIN_C_LEVEL >= __DARWIN_C_FULL)
// Also provided in cases on Darwin
#define UTILHEADERS_STR_STRLCPY
#endif
#endif
namespace util {
/// @brief Copy a string into a char array, guaranteed to null-terminate and not
/// overrun. Does not correctly handle UTF-8 (may truncate in the middle of a
/// codepoint).
template <size_t N> inline void strcpy_safe(char (&dest)[N], const char *src) {
#if defined(UTILHEADERS_STR_STRLCPY)
strlcpy(dest, src, N);
#elif defined(UTILHEADERS_STR_MSRUNTIME)
strncpy_s(dest, src, _TRUNCATE);
#else
strncpy(dest, src, N);
dest[N - 1] = '\0';
#endif
}
} // namespace util
#endif // INCLUDED_FixedLengthStringFunctions_h_GUID_34010E53_D3F3_42BD_FB36_6D00EA79C3A9

87
src/external/util-headers/util/Stride.h vendored Normal file
View file

@ -0,0 +1,87 @@
/** @file
@brief A class for handling "do this every n times"
This header is maintained as a part of 'util-headers' - you can always
find the latest version online at https://github.com/rpavlik/util-headers
This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
This copy of the header is from the revision that Git calls
1a8444782d15cb9458052e3d8251c4f5b8e808d5
Commit date: "2022-03-11 12:11:32 -0600"
@date
2009-2010
@author
Ryan Pavlik
<rpavlik@iastate.edu> and <abiryan@ryand.net>
http://academic.cleardefinition.com/
Iowa State University Virtual Reality Applications Center
Human-Computer Interaction Graduate Program
*/
// Copyright 2009-2010, Iowa State University.
//
// SPDX-License-Identifier: BSL-1.0
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#ifndef INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
#define INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
// Local includes
// - none
// Library includes
// - none
// Standard includes
// - none
namespace util {
/// @addtogroup Other Other Utility Classes
/// @{
/// Handle the task of "do this every n times" in an easy way.
class Stride {
public:
Stride(const unsigned int n) :
_stride(n),
_step(0) { }
void advance() {
_step = (_step + 1) % _stride;
}
Stride operator++() {
Stride temp = *this;
advance();
return temp;
}
Stride & operator++(int) {
advance();
return *this;
}
operator bool() const {
return _step == 0;
}
private:
unsigned int _stride;
unsigned int _step;
};
/// @}
} // end of util namespace
#endif // INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d