clean public header dependencies (#8725)
* remove io::ostream dependency from CString.h + clang tidy * remove ostream.h dependency from Invocable.h * remove Panic.h dependency from FixedCapacityVector.h * remove ostream.h dependency from backend/ headers * clang tidy Panic.h/Panic.cpp
This commit is contained in:
@@ -20,10 +20,15 @@
|
||||
#define TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class CallbackHandler;
|
||||
@@ -89,8 +94,8 @@ public:
|
||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
BufferDescriptor(void const* buffer, size_t size,
|
||||
Callback callback = nullptr, void* user = nullptr) noexcept
|
||||
BufferDescriptor(void const* buffer, size_t const size,
|
||||
Callback const callback = nullptr, void* user = nullptr) noexcept
|
||||
: buffer(const_cast<void*>(buffer)), size(size), mCallback(callback), mUser(user) {
|
||||
}
|
||||
|
||||
@@ -98,11 +103,12 @@ public:
|
||||
* Creates a BufferDescriptor that references a CPU memory-buffer
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param handler A custom handler for the callback
|
||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
BufferDescriptor(void const* buffer, size_t size,
|
||||
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||
BufferDescriptor(void const* buffer, size_t const size,
|
||||
CallbackHandler* handler, Callback const callback, void* user = nullptr) noexcept
|
||||
: buffer(const_cast<void*>(buffer)), size(size),
|
||||
mCallback(callback), mUser(user), mHandler(handler) {
|
||||
}
|
||||
@@ -116,8 +122,9 @@ public:
|
||||
*
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param data A pointer to the data
|
||||
* @param handler Handler to use to dispatch the callback, or nullptr for the default handler
|
||||
* @return a new BufferDescriptor
|
||||
* @return A new BufferDescriptor
|
||||
*/
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static BufferDescriptor make(void const* buffer, size_t size, T* data,
|
||||
@@ -164,7 +171,7 @@ public:
|
||||
* @param callback The new callback function
|
||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||
*/
|
||||
void setCallback(Callback callback, void* user = nullptr) noexcept {
|
||||
void setCallback(Callback const callback, void* user = nullptr) noexcept {
|
||||
this->mCallback = callback;
|
||||
this->mUser = user;
|
||||
this->mHandler = nullptr;
|
||||
@@ -176,7 +183,7 @@ public:
|
||||
* @param callback The new callback function
|
||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||
*/
|
||||
void setCallback(CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept {
|
||||
void setCallback(CallbackHandler* handler, Callback const callback, void* user = nullptr) noexcept {
|
||||
mCallback = callback;
|
||||
mUser = user;
|
||||
mHandler = handler;
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#include <backend/DriverApiForward.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
@@ -28,6 +26,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
void* allocateFromCommandStream(DriverApi& driver, size_t size, size_t alignment) noexcept;
|
||||
|
||||
@@ -25,12 +25,11 @@
|
||||
#include <backend/PresentCallable.h>
|
||||
|
||||
#include <utils/BitmaskEnum.h>
|
||||
#include <utils/CString.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/debug.h>
|
||||
#include <utils/ostream.h>
|
||||
#include <utils/StaticString.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include <math/vec4.h>
|
||||
|
||||
@@ -41,6 +40,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
/**
|
||||
* Types and enums used by filament's driver.
|
||||
*
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
#ifndef TNT_FILAMENT_BACKEND_HANDLE_H
|
||||
#define TNT_FILAMENT_BACKEND_HANDLE_H
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
#include <utils/ostream.h>
|
||||
#endif
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include <type_traits> // FIXME: STL headers are not allowed in public headers
|
||||
@@ -27,6 +24,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
struct HwBufferObject;
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
//! \privatesection
|
||||
|
||||
@@ -24,11 +24,14 @@
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/debug.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,12 +20,10 @@
|
||||
#include <utils/CString.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
@@ -33,6 +31,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Program {
|
||||
|
||||
@@ -19,22 +19,26 @@
|
||||
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
#include <utility>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
//! \privatesection
|
||||
|
||||
struct TargetBufferInfo {
|
||||
// note: the parameters of this constructor are not in the order of this structure's fields
|
||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level, uint16_t layer) noexcept
|
||||
: handle(handle), level(level), layer(layer) {
|
||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t const level, uint16_t const layer) noexcept
|
||||
: handle(std::move(handle)), level(level), layer(layer) {
|
||||
}
|
||||
|
||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t level) noexcept
|
||||
TargetBufferInfo(Handle<HwTexture> handle, uint8_t const level) noexcept
|
||||
: handle(handle), level(level) {
|
||||
}
|
||||
|
||||
@@ -70,11 +74,11 @@ private:
|
||||
TargetBufferInfo mInfos[MAX_SUPPORTED_RENDER_TARGET_COUNT];
|
||||
|
||||
public:
|
||||
TargetBufferInfo const& operator[](size_t i) const noexcept {
|
||||
TargetBufferInfo const& operator[](size_t const i) const noexcept {
|
||||
return mInfos[i];
|
||||
}
|
||||
|
||||
TargetBufferInfo& operator[](size_t i) noexcept {
|
||||
TargetBufferInfo& operator[](size_t const i) noexcept {
|
||||
return mInfos[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@
|
||||
#include <utils/Hash.h>
|
||||
#include <utils/PrivateImplementation.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "MetalContext.h"
|
||||
|
||||
#include <utils/Panic.h>
|
||||
|
||||
namespace filament {
|
||||
namespace backend {
|
||||
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include "private/backend/Driver.h"
|
||||
#include "backend/Program.h"
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Program.h>
|
||||
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
|
||||
#include <memory>
|
||||
#include <tsl/robin_map.h>
|
||||
|
||||
#include <utils/Hash.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <tsl/robin_map.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace filament {
|
||||
namespace backend {
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/BitmaskEnum.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <backend/CallbackHandler.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/PresentCallable.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
@@ -35,7 +34,7 @@ class Engine;
|
||||
/**
|
||||
* A swap chain represents an Operating System's *native* renderable surface.
|
||||
*
|
||||
* Typically it's a native window or a view. Because a SwapChain is initialized from a
|
||||
* Typically, it's a native window or a view. Because a SwapChain is initialized from a
|
||||
* native object, it is given to filament as a `void *`, which must be of the proper type
|
||||
* for each platform filament is running on.
|
||||
*
|
||||
@@ -158,7 +157,7 @@ public:
|
||||
/**
|
||||
* Requests a SwapChain with an alpha channel.
|
||||
*/
|
||||
static const uint64_t CONFIG_TRANSPARENT = backend::SWAP_CHAIN_CONFIG_TRANSPARENT;
|
||||
static constexpr uint64_t CONFIG_TRANSPARENT = backend::SWAP_CHAIN_CONFIG_TRANSPARENT;
|
||||
|
||||
/**
|
||||
* This flag indicates that the swap chain may be used as a source surface
|
||||
@@ -168,13 +167,13 @@ public:
|
||||
* @see
|
||||
* Renderer.copyFrame()
|
||||
*/
|
||||
static const uint64_t CONFIG_READABLE = backend::SWAP_CHAIN_CONFIG_READABLE;
|
||||
static constexpr uint64_t CONFIG_READABLE = backend::SWAP_CHAIN_CONFIG_READABLE;
|
||||
|
||||
/**
|
||||
* Indicates that the native X11 window is an XCB window rather than an XLIB window.
|
||||
* This is ignored on non-Linux platforms and in builds that support only one X11 API.
|
||||
*/
|
||||
static const uint64_t CONFIG_ENABLE_XCB = backend::SWAP_CHAIN_CONFIG_ENABLE_XCB;
|
||||
static constexpr uint64_t CONFIG_ENABLE_XCB = backend::SWAP_CHAIN_CONFIG_ENABLE_XCB;
|
||||
|
||||
/**
|
||||
* Indicates that the native window is a CVPixelBufferRef.
|
||||
@@ -186,7 +185,7 @@ public:
|
||||
* Filament. Filament will call CVPixelBufferRetain during Engine::createSwapChain, and
|
||||
* CVPixelBufferRelease when the swap chain is destroyed.
|
||||
*/
|
||||
static const uint64_t CONFIG_APPLE_CVPIXELBUFFER =
|
||||
static constexpr uint64_t CONFIG_APPLE_CVPIXELBUFFER =
|
||||
backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER;
|
||||
|
||||
/**
|
||||
@@ -303,6 +302,7 @@ public:
|
||||
*
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler.
|
||||
* @param callback Callback called when the frame is scheduled.
|
||||
* @param flags
|
||||
*
|
||||
* @remark Only Filament's Metal backend supports PresentCallables and frame callbacks. Other
|
||||
* backends ignore the callback (which will never be called) and proceed normally.
|
||||
@@ -314,7 +314,7 @@ public:
|
||||
FrameScheduledCallback&& callback = {}, uint64_t flags = 0);
|
||||
|
||||
/**
|
||||
* Returns whether or not this SwapChain currently has a FrameScheduledCallback set.
|
||||
* Returns whether this SwapChain currently has a FrameScheduledCallback set.
|
||||
*
|
||||
* @return true, if the last call to setFrameScheduledCallback set a callback
|
||||
*
|
||||
|
||||
@@ -16,13 +16,22 @@
|
||||
|
||||
#include "AtlasAllocator.h"
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/debug.h>
|
||||
#include <utils/QuadTree.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
using namespace utils;
|
||||
|
||||
static inline constexpr std::pair<uint8_t, uint8_t> unmorton(uint16_t const m) noexcept {
|
||||
static constexpr std::pair<uint8_t, uint8_t> unmorton(uint16_t const m) noexcept {
|
||||
uint32_t r = (m | (uint32_t(m) << 15u)) & 0x55555555u;
|
||||
r = (r | (r >> 1u)) & 0x33333333u;
|
||||
r = (r | (r >> 2u)) & 0x0f0f0f0fu;
|
||||
@@ -165,8 +174,8 @@ AtlasAllocator::NodeId AtlasAllocator::allocateInLayer(size_t const maxHeight) n
|
||||
NodeId found{ -1, 0 };
|
||||
QuadTree::traverse(candidate.l, candidate.code,
|
||||
[this, n, &found](NodeId const& curr) -> QuadTree::TraversalResult {
|
||||
size_t const i = index(curr.l, curr.code);
|
||||
Node& node = mQuadTree[i];
|
||||
size_t const j = index(curr.l, curr.code);
|
||||
Node& node = mQuadTree[j];
|
||||
if (curr.l == n) {
|
||||
found = curr;
|
||||
assert_invariant(!node.hasChildren());
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <filamat/MaterialBuilder.h>
|
||||
|
||||
#include <utils/JobSystem.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <utils/JobSystem.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <geometry/TangentSpaceMesh.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Panic.h>
|
||||
#include <utils/StructureOfArrays.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <string_view>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
using namespace utils;
|
||||
using namespace std::literals;
|
||||
|
||||
@@ -65,6 +65,8 @@ set(SRCS
|
||||
src/CyclicBarrier.cpp
|
||||
src/EntityManager.cpp
|
||||
src/EntityManagerImpl.h
|
||||
src/FixedCapacityVectorBase.cpp
|
||||
src/Invocable.cpp
|
||||
src/JobSystem.cpp
|
||||
src/Log.cpp
|
||||
src/NameComponentManager.cpp
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
// NOTE: this header should not include STL headers
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@@ -32,6 +31,9 @@
|
||||
#include <string.h>
|
||||
|
||||
namespace utils {
|
||||
namespace io {
|
||||
class ostream;
|
||||
}
|
||||
|
||||
//! \privatesection
|
||||
struct hashCStrings {
|
||||
@@ -39,7 +41,7 @@ struct hashCStrings {
|
||||
typedef size_t result_type;
|
||||
result_type operator()(argument_type cstr) const noexcept {
|
||||
size_t hash = 5381;
|
||||
while (int const c = *cstr++) {
|
||||
while (int const c = static_cast<unsigned char>(*cstr++)) {
|
||||
hash = (hash * 33u) ^ size_t(c);
|
||||
}
|
||||
return hash;
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
|
||||
#include <utils/CString.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
namespace utils {
|
||||
namespace io {
|
||||
class ostream;
|
||||
}
|
||||
|
||||
/**
|
||||
* CallStack captures the current's thread call stack.
|
||||
@@ -88,23 +90,23 @@ public:
|
||||
|
||||
bool operator <(const CallStack& rhs) const;
|
||||
|
||||
inline bool operator >(const CallStack& rhs) const {
|
||||
bool operator >(const CallStack& rhs) const {
|
||||
return rhs < *this;
|
||||
}
|
||||
|
||||
inline bool operator !=(const CallStack& rhs) const {
|
||||
bool operator !=(const CallStack& rhs) const {
|
||||
return *this < rhs || rhs < *this;
|
||||
}
|
||||
|
||||
inline bool operator >=(const CallStack& rhs) const {
|
||||
bool operator >=(const CallStack& rhs) const {
|
||||
return !operator <(rhs);
|
||||
}
|
||||
|
||||
inline bool operator <=(const CallStack& rhs) const {
|
||||
bool operator <=(const CallStack& rhs) const {
|
||||
return !operator >(rhs);
|
||||
}
|
||||
|
||||
inline bool operator ==(const CallStack& rhs) const {
|
||||
bool operator ==(const CallStack& rhs) const {
|
||||
return !operator !=(rhs);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/compressed_pair.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
@@ -40,6 +40,11 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
class FixedCapacityVectorBase {
|
||||
protected:
|
||||
UTILS_NORETURN static void capacityCheckFailed(size_t capacity, size_t size);
|
||||
};
|
||||
|
||||
/**
|
||||
* FixedCapacityVector is (almost) a drop-in replacement for std::vector<> except it has a
|
||||
* fixed capacity decided at runtime. The vector storage is never reallocated unless reserve()
|
||||
@@ -56,7 +61,7 @@ namespace utils {
|
||||
* the optional value argument, e.g. FixedCapacityVector<int>(4, 0) or foo.resize(4, 0).
|
||||
*/
|
||||
template<typename T, typename A = std::allocator<T>, bool CapacityCheck = true>
|
||||
class UTILS_PUBLIC FixedCapacityVector {
|
||||
class UTILS_PUBLIC FixedCapacityVector : protected FixedCapacityVectorBase {
|
||||
public:
|
||||
using allocator_type = A;
|
||||
using value_type = T;
|
||||
@@ -266,7 +271,7 @@ public:
|
||||
mSize = 0;
|
||||
}
|
||||
|
||||
void resize(size_type count) {
|
||||
void resize(size_type const count) {
|
||||
assertCapacityForSize(count);
|
||||
if constexpr(std::is_trivially_constructible_v<value_type> &&
|
||||
std::is_trivially_destructible_v<value_type>) {
|
||||
@@ -277,12 +282,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void resize(size_type count, const_reference v) {
|
||||
void resize(size_type const count, const_reference v) {
|
||||
assertCapacityForSize(count);
|
||||
resize_non_trivial(count, v);
|
||||
}
|
||||
|
||||
void swap(FixedCapacityVector& other) {
|
||||
void swap(FixedCapacityVector& other) noexcept {
|
||||
using std::swap;
|
||||
swap(mData, other.mData);
|
||||
swap(mSize, other.mSize);
|
||||
@@ -326,16 +331,16 @@ private:
|
||||
return mCapacityAllocator.second();
|
||||
}
|
||||
|
||||
iterator assertCapacityForSize(size_type s) {
|
||||
iterator assertCapacityForSize(size_type const s) {
|
||||
if constexpr(CapacityCheck || FILAMENT_FORCE_CAPACITY_CHECK) {
|
||||
FILAMENT_CHECK_PRECONDITION(capacity() >= s)
|
||||
<< "capacity exceeded: requested size " << (unsigned long)s
|
||||
<< "u, available capacity " << (unsigned long)capacity() << "u.";
|
||||
if (UTILS_VERY_UNLIKELY(capacity() < s)) {
|
||||
capacityCheckFailed(capacity(), s);
|
||||
}
|
||||
}
|
||||
return end();
|
||||
}
|
||||
|
||||
inline void construct(iterator first, iterator last) noexcept {
|
||||
void construct(iterator const first, iterator const last) noexcept {
|
||||
// we check for triviality here so that the implementation could be non-inline
|
||||
if constexpr(!std::is_trivially_constructible_v<value_type>) {
|
||||
construct_non_trivial(first, last);
|
||||
@@ -358,7 +363,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
inline void destroy(iterator first, iterator last) noexcept {
|
||||
void destroy(iterator const first, iterator const last) noexcept {
|
||||
// we check for triviality here so that the implementation could be non-inline
|
||||
if constexpr(!std::is_trivially_destructible_v<value_type>) {
|
||||
destroy_non_trivial(first, last);
|
||||
@@ -419,7 +424,7 @@ private:
|
||||
explicit SizeTypeWrapper(TYPE value) noexcept : value(value) { }
|
||||
SizeTypeWrapper& operator=(TYPE rhs) noexcept { value = rhs; return *this; }
|
||||
SizeTypeWrapper& operator=(SizeTypeWrapper& rhs) noexcept = delete;
|
||||
operator TYPE() const noexcept { return value; }
|
||||
operator TYPE() const noexcept { return value; } // NOLINT(*-explicit-constructor)
|
||||
};
|
||||
|
||||
pointer mData{};
|
||||
|
||||
@@ -14,10 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_UTILS_INVOKABLE_H
|
||||
#define TNT_UTILS_INVOKABLE_H
|
||||
|
||||
#include <utils/ostream.h>
|
||||
#ifndef TNT_UTILS_INVOCABLE_H
|
||||
#define TNT_UTILS_INVOCABLE_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -25,6 +23,9 @@
|
||||
#include <assert.h>
|
||||
|
||||
namespace utils {
|
||||
namespace io {
|
||||
class ostream;
|
||||
}
|
||||
|
||||
/*
|
||||
* Invocable is a move-only general purpose function wrapper. Instances can
|
||||
@@ -50,11 +51,16 @@ template<typename Fn, typename R, typename... Args>
|
||||
using EnableIfFnMatchesInvocable = std::enable_if_t<true, int>;
|
||||
#endif
|
||||
|
||||
class InvocableBase {
|
||||
protected:
|
||||
static io::ostream& printInvocable(io::ostream& out, const char* name);
|
||||
};
|
||||
|
||||
template<typename Signature>
|
||||
class Invocable;
|
||||
|
||||
template<typename R, typename... Args>
|
||||
class Invocable<R(Args...)> {
|
||||
class Invocable<R(Args...)> : protected InvocableBase {
|
||||
public:
|
||||
// Creates an Invocable that does not contain a functor.
|
||||
// Will evaluate to false.
|
||||
@@ -85,7 +91,7 @@ public:
|
||||
private:
|
||||
#if !defined(NDEBUG)
|
||||
friend io::ostream& operator<<(io::ostream& out, const Invocable&) {
|
||||
return out << "Invocable<>"; // TODO: is there a way to do better here?
|
||||
return printInvocable(out, "Invocable<>"); // TODO: is there a way to do better here?
|
||||
}
|
||||
#endif
|
||||
void* mInvocable = nullptr;
|
||||
@@ -156,4 +162,4 @@ Invocable<R(Args...)>::operator bool() const noexcept {
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif // TNT_UTILS_INVOKABLE_H
|
||||
#endif // TNT_UTILS_INVOCABLE_H
|
||||
|
||||
@@ -353,7 +353,7 @@ public:
|
||||
* The TPanic<> class implements the std::exception protocol as well as the Panic
|
||||
* interface common to all exceptions thrown by the framework.
|
||||
*/
|
||||
template <typename T>
|
||||
template <typename>
|
||||
class UTILS_PUBLIC TPanic : public Panic {
|
||||
public:
|
||||
// std::exception protocol
|
||||
@@ -398,12 +398,11 @@ public:
|
||||
* @see PANIC_PRECONDITION, PANIC_POSTCONDITION, PANIC_ARITHMETIC
|
||||
* @see setMode()
|
||||
*/
|
||||
static inline void panic(
|
||||
static void panic(
|
||||
char const* function, char const* file, int line, char const* literal,
|
||||
std::string reason) UTILS_NORETURN;
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
/**
|
||||
* Creates a Panic with extra information about the error-site.
|
||||
* @param function the name of the function where the error was detected
|
||||
@@ -415,11 +414,14 @@ protected:
|
||||
TPanic(char const* function, char const* file, int line, char const* literal,
|
||||
std::string reason);
|
||||
|
||||
friend class PreconditionPanic;
|
||||
friend class PostconditionPanic;
|
||||
friend class ArithmeticPanic;
|
||||
|
||||
protected:
|
||||
~TPanic() override;
|
||||
|
||||
private:
|
||||
void buildMessage();
|
||||
|
||||
char const* const mFile = nullptr; // file where the panic happened
|
||||
char const* const mFunction = nullptr; // function where the panic happened
|
||||
int const mLine = -1; // line where the panic happened
|
||||
@@ -443,7 +445,7 @@ void panicLog(
|
||||
* ASSERT_PRECONDITION uses this Panic to report a precondition failure.
|
||||
* @see ASSERT_PRECONDITION
|
||||
*/
|
||||
class UTILS_PUBLIC PreconditionPanic : public TPanic<PreconditionPanic> {
|
||||
class UTILS_PUBLIC PreconditionPanic final : public TPanic<PreconditionPanic> {
|
||||
// Programming error, can be avoided
|
||||
// e.g.: invalid arguments
|
||||
using TPanic<PreconditionPanic>::TPanic;
|
||||
@@ -457,9 +459,9 @@ class UTILS_PUBLIC PreconditionPanic : public TPanic<PreconditionPanic> {
|
||||
* ASSERT_POSTCONDITION uses this Panic to report a postcondition failure.
|
||||
* @see ASSERT_POSTCONDITION
|
||||
*/
|
||||
class UTILS_PUBLIC PostconditionPanic : public TPanic<PostconditionPanic> {
|
||||
class UTILS_PUBLIC PostconditionPanic final : public TPanic<PostconditionPanic> {
|
||||
// Usually only detectable at runtime
|
||||
// e.g.: dead-lock would occur, arithmetic errors
|
||||
// e.g.: deadlock would occur, arithmetic errors
|
||||
using TPanic<PostconditionPanic>::TPanic;
|
||||
friend class TPanic<PostconditionPanic>;
|
||||
constexpr static auto type = "Postcondition";
|
||||
@@ -471,7 +473,7 @@ class UTILS_PUBLIC PostconditionPanic : public TPanic<PostconditionPanic> {
|
||||
* ASSERT_ARITHMETIC uses this Panic to report an arithmetic (postcondition) failure.
|
||||
* @see ASSERT_ARITHMETIC
|
||||
*/
|
||||
class UTILS_PUBLIC ArithmeticPanic : public TPanic<ArithmeticPanic> {
|
||||
class UTILS_PUBLIC ArithmeticPanic final : public TPanic<ArithmeticPanic> {
|
||||
// A common case of post-condition error
|
||||
// e.g.: underflow, overflow, internal computations errors
|
||||
using TPanic<ArithmeticPanic>::TPanic;
|
||||
@@ -519,11 +521,11 @@ public:
|
||||
|
||||
PanicStream& operator<<(const void* value) noexcept;
|
||||
|
||||
PanicStream& operator<<(const char* string) noexcept;
|
||||
PanicStream& operator<<(const unsigned char* string) noexcept;
|
||||
PanicStream& operator<<(const char* value) noexcept;
|
||||
PanicStream& operator<<(const unsigned char* value) noexcept;
|
||||
|
||||
PanicStream& operator<<(std::string const& s) noexcept;
|
||||
PanicStream& operator<<(std::string_view const& s) noexcept;
|
||||
PanicStream& operator<<(std::string const& value) noexcept;
|
||||
PanicStream& operator<<(std::string_view const& value) noexcept;
|
||||
|
||||
protected:
|
||||
io::sstream mStream;
|
||||
|
||||
@@ -19,11 +19,8 @@
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <string_view>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
/**
|
||||
@@ -41,7 +38,7 @@ public:
|
||||
using const_iterator = std::string_view::const_iterator;
|
||||
|
||||
// Constructor from string literal
|
||||
template <size_t M>
|
||||
template<unsigned int M>
|
||||
constexpr StaticString(const char (&str)[M]) noexcept : mString(str, M - 1) {} // NOLINT(*-explicit-constructor)
|
||||
|
||||
constexpr StaticString() noexcept = default;
|
||||
@@ -61,7 +58,7 @@ public:
|
||||
return mString[pos];
|
||||
}
|
||||
|
||||
constexpr const_reference at(size_type pos) const {
|
||||
constexpr const_reference at(size_type const pos) const {
|
||||
return mString[pos];
|
||||
}
|
||||
|
||||
|
||||
36
libs/utils/src/FixedCapacityVectorBase.cpp
Normal file
36
libs/utils/src/FixedCapacityVectorBase.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
void FixedCapacityVectorBase::capacityCheckFailed(size_t const capacity, size_t const size) {
|
||||
UTILS_ASSUME(capacity < size);
|
||||
FILAMENT_CHECK_PRECONDITION(capacity >= size)
|
||||
<< "capacity exceeded: requested size " << size
|
||||
<< "u, available capacity " << capacity << "u.";
|
||||
|
||||
// In practice, we will never reach this.
|
||||
abort();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
24
libs/utils/src/Invocable.cpp
Normal file
24
libs/utils/src/Invocable.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
namespace utils {
|
||||
io::ostream& InvocableBase::printInvocable(io::ostream& out, const char* name) {
|
||||
return out << name;
|
||||
}
|
||||
} // namespace utils
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "ostream_.h"
|
||||
|
||||
#include <utils/CallStack.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/ostream.h>
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
getCallback().call(panic);
|
||||
}
|
||||
|
||||
void set(Panic::PanicHandlerCallback handler, void* user) noexcept {
|
||||
void set(Panic::PanicHandlerCallback const handler, void* user) noexcept {
|
||||
std::lock_guard const lock(mLock);
|
||||
mCallBack = { handler, user };
|
||||
}
|
||||
@@ -96,7 +97,7 @@ static std::string sprintfToString(const char* format, va_list args) noexcept {
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline std::string sprintfToString(const char* format, ...) noexcept {
|
||||
static std::string sprintfToString(const char* format, ...) noexcept {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
std::string const s{ sprintfToString(format, args) };
|
||||
@@ -120,14 +121,14 @@ static std::string buildPanicString(
|
||||
|
||||
Panic::~Panic() noexcept = default;
|
||||
|
||||
void Panic::setPanicHandler(PanicHandlerCallback handler, void* user) noexcept {
|
||||
void Panic::setPanicHandler(PanicHandlerCallback const handler, void* user) noexcept {
|
||||
UserPanicHandler::get().set(handler, user);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
TPanic<T>::TPanic(const char* function, const char* file, int line, char const* literal,
|
||||
TPanic<T>::TPanic(const char* function, const char* file, int const line, char const* literal,
|
||||
std::string reason)
|
||||
: mFile(file),
|
||||
mFunction(function),
|
||||
@@ -188,13 +189,13 @@ void TPanic<T>::log() const noexcept {
|
||||
}
|
||||
|
||||
UTILS_ALWAYS_INLINE
|
||||
inline static const char* formatFile(char const* file) noexcept {
|
||||
static const char* formatFile(char const* file) noexcept {
|
||||
const char * p = std::strstr(file, "filament/");
|
||||
return p ? p : file;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void TPanic<T>::panic(char const* function, char const* file, int line, char const* literal,
|
||||
void TPanic<T>::panic(char const* function, char const* file, int const line, char const* literal,
|
||||
const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -233,7 +234,7 @@ void TPanic<T>::panic(char const* function, char const* file, int line, char con
|
||||
|
||||
namespace details {
|
||||
|
||||
void panicLog(char const* function, char const* file, int line, const char* format, ...) noexcept {
|
||||
void panicLog(char const* function, char const* file, int const line, const char* format, ...) noexcept {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
std::string const reason{ sprintfToString(format, args) };
|
||||
@@ -249,79 +250,79 @@ void panicLog(char const* function, char const* file, int line, const char* form
|
||||
PanicStream::PanicStream(
|
||||
char const* function,
|
||||
char const* file,
|
||||
int line,
|
||||
int const line,
|
||||
char const* condition) noexcept
|
||||
: mFunction(function), mFile(file), mLine(line), mLiteral(condition) {
|
||||
}
|
||||
|
||||
PanicStream::~PanicStream() = default;
|
||||
|
||||
PanicStream& PanicStream::operator<<(short value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(short const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(unsigned short value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(unsigned short const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(char value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(char const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(unsigned char value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(unsigned char const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(int value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(int const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(unsigned int value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(unsigned int const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(long value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(long const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(unsigned long value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(unsigned long const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(long long int value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(long long int const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(unsigned long long int value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(unsigned long long int const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(float value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(float const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(double value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(double const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(long double value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(long double const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanicStream& PanicStream::operator<<(bool value) noexcept {
|
||||
PanicStream& PanicStream::operator<<(bool const value) noexcept {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#define TNT_UTILS_OSTREAM__H
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <utility>
|
||||
#include <mutex>
|
||||
|
||||
namespace utils::io {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
using namespace utils;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/memalign.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <uberz/ReadableArchive.h>
|
||||
#include <uberz/WritableArchive.h>
|
||||
|
||||
Reference in New Issue
Block a user