Pigweed
Loading...
Searching...
No Matches
pw Namespace Reference

Provides basic helpers for reading and writing UTF-8 encoded strings. More...

Classes

class  Allocator
 
class  BasicInlineDeque
 
class  BasicInlineDeque< ValueType, SizeType, containers::internal::kGenericSized >
 
class  BasicInlineDequeStorage
 
class  BasicInlineDequeStorage< ValueType, SizeType, kCapacity, false >
 
class  BasicInlineDequeStorage< ValueType, SizeType, kCapacity, true >
 
class  BasicInlineQueue
 
class  BasicInlineQueue< ValueType, SizeType, containers::internal::kGenericSized >
 
class  BasicInlineVarLenEntryQueue
 
class  BasicInlineVarLenEntryQueue< T, containers::internal::kGenericSized >
 
class  ByteBuffer
 ByteBuffers declare a buffer along with a ByteBuilder. More...
 
class  ByteBuilder
 
class  Deallocator
 Abstract interface for releasing memory. More...
 
class  InlineBasicString
 pw::InlineBasicString is a fixed-capacity version of std::basic_string. In brief: More...
 
class  InlineBasicString< T, string_impl::kGeneric >
 
class  JsonArray
 
class  JsonBuffer
 
class  JsonBuilder
 
class  JsonObject
 
class  JsonValue
 
struct  NaturallyAligned
 
class  NestedJsonArray
 
class  NestedJsonObject
 
class  NoDestructor
 
class  ScopeGuard
 
class  Status
 
class  StringBuffer
 
class  StringBuilder
 
class  UniquePtr
 

Typedefs

template<typename T >
using AlignedAtomic = std::atomic< NaturallyAligned< T > >
 
template<typename T , size_t kCapacity = containers::internal::kGenericSized>
using InlineDeque = BasicInlineDeque< T, uint16_t, kCapacity >
 
template<typename T , size_t kCapacity = containers::internal::kGenericSized>
using InlineQueue = BasicInlineQueue< T, uint16_t, kCapacity >
 
template<size_t kMaxSizeBytes = containers::internal::kGenericSized>
using InlineVarLenEntryQueue = BasicInlineVarLenEntryQueue< std::byte, kMaxSizeBytes >
 Variable-length entry queue that uses std::byte for the byte type.
 
template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize, typename Allocator = PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE>
using Function = fit::function_impl< inline_target_size, !function_internal::config::kEnableDynamicAllocation, FunctionType, Allocator >
 
template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize>
using InlineFunction = fit::inline_function< FunctionType, inline_target_size >
 
using Closure = Function< void()>
 
template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize, typename Allocator = PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE>
using Callback = fit::callback_impl< inline_target_size, !function_internal::config::kEnableDynamicAllocation, FunctionType, Allocator >
 
template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize>
using InlineCallback = fit::inline_callback< FunctionType, inline_target_size >
 Version of pw::Callback that exclusively uses inline storage.
 
template<size_t kCapacity = string_impl::kGeneric>
using InlineString = InlineBasicString< char, kCapacity >
 pw::InlineString is an alias of pw::InlineBasicString<char> and is equivalent to std::string.
 
template<size_t kCapacity = string_impl::kGeneric>
using InlineByteString = InlineBasicString< std::byte, kCapacity >
 pw::InlineByteString is an alias of pw::InlineBasicString<std::byte>. InlineByteString may be used as a simple, efficient byte container.
 

Functions

constexpr size_t countl_zero (size_t x) noexcept
 
constexpr size_t bit_width (size_t x) noexcept
 
constexpr size_t bit_ceil (size_t x) noexcept
 
class pw::Deallocator DoGetInfo (InfoType info_type, const void *ptr) override
 
template<>
StatusWithSize ToString (const async2::ReadyType &, span< char > buffer)
 
template<>
StatusWithSize ToString (const async2::PendingType &, span< char > buffer)
 
template<typename T >
StatusWithSize ToString (const async2::Poll< T > &poll, span< char > buffer)
 
template<>
StatusWithSize ToString (const async2::Poll<> &poll, span< char > buffer)
 
constexpr size_t AlignDown (size_t value, size_t alignment)
 Returns the value rounded down to the nearest multiple of alignment.
 
template<typename T >
constexpr T * AlignDown (T *value, size_t alignment)
 Returns the value rounded down to the nearest multiple of alignment.
 
constexpr size_t AlignUp (size_t value, size_t alignment)
 Returns the value rounded up to the nearest multiple of alignment.
 
template<typename T >
constexpr T * AlignUp (T *value, size_t alignment)
 Returns the value rounded up to the nearest multiple of alignment.
 
constexpr size_t Padding (size_t length, size_t alignment)
 Returns the number of padding bytes required to align the provided length.
 
ByteSpan GetAlignedSubspan (ByteSpan bytes, size_t alignment)
 
constexpr ByteBuilder::iterator operator+ (int n, ByteBuilder::iterator it)
 
template<auto method, typename T >
auto bind_member (T *instance)
 
template<typename Function >
 ScopeGuard (Function()) -> ScopeGuard< Function(*)()>
 
constexpr Status OkStatus ()
 
constexpr bool operator== (const Status &lhs, const Status &rhs)
 
constexpr bool operator!= (const Status &lhs, const Status &rhs)
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator== (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator!= (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator< (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator<= (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator> (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity, size_t kRhsCapacity>
constexpr bool operator>= (const InlineBasicString< T, kLhsCapacity > &lhs, const InlineBasicString< T, kRhsCapacity > &rhs) noexcept
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator== (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator== (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator!= (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator!= (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator< (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator< (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator<= (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator<= (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator> (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator> (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<typename T , size_t kLhsCapacity>
constexpr bool operator>= (const InlineBasicString< T, kLhsCapacity > &lhs, const T *rhs)
 
template<typename T , size_t kRhsCapacity>
constexpr bool operator>= (const T *lhs, const InlineBasicString< T, kRhsCapacity > &rhs)
 
template<size_t kBufferSize = 0u, typename... Args>
auto MakeString (Args &&... args)
 
system::AsyncCoreSystem ()
 
void SystemStart (channel::ByteReaderWriter &io_channel)
 

Detailed Description

Provides basic helpers for reading and writing UTF-8 encoded strings.

Typedef Documentation

◆ Callback

template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize, typename Allocator = PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE>
using pw::Callback = typedef fit::callback_impl< inline_target_size, !function_internal::config::kEnableDynamicAllocation, FunctionType, Allocator>

pw::Callback is identical to

embed:rst:inline :cpp:type:`pw::Function` 

except:

  1. On the first call to invoke a pw::Callback, the target function held by the pw::Callback cannot be called again.
  2. When a pw::Callback is invoked for the first time, the target function is released and destructed, along with any resources owned by that function (typically the objects captured by a lambda).

A pw::Callback in the "already called" state has the same state as a pw::Callback that has been assigned to nullptr.

◆ Function

template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize, typename Allocator = PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE>
using pw::Function = typedef fit::function_impl< inline_target_size, !function_internal::config::kEnableDynamicAllocation, FunctionType, Allocator>

pw::Function is a wrapper for an arbitrary callable object. It can be used by callback-based APIs to allow callers to provide any type of callable.

Example:

template <typename T>
bool All(const pw::Vector<T>& items,
const pw::Function<bool(const T& item)>& predicate) {
for (const T& item : items) {
if (!predicate(item)) {
return false;
}
}
return true;
}
bool ElementsArePositive(const pw::Vector<int>& items) {
return All(items, [](const int& i) { return i > 0; });
}
bool IsEven(const int& i) { return i % 2 == 0; }
bool ElementsAreEven(const pw::Vector<int>& items) {
return All(items, IsEven);
}
fit::function_impl< inline_target_size, !function_internal::config::kEnableDynamicAllocation, FunctionType, Allocator > Function
Definition: function.h:63
Template Parameters
AllocatorThe Allocator used to dynamically allocate the callable, if it exceeds inline_target_size and dynamic allocation is enabled. Its value_type is irrelevant, since it must support rebinding.

◆ InlineDeque

template<typename T , size_t kCapacity = containers::internal::kGenericSized>
using pw::InlineDeque = typedef BasicInlineDeque<T, uint16_t, kCapacity>

The InlineDeque class is similar to the STL's double ended queue (std::deque), except it is backed by a fixed-size buffer. InlineDeque's must be declared with an explicit maximum size (e.g. InlineDeque<int, 10>>) but deques can be used and referred to without the max size template parameter (e.g. InlineDeque<int>).

To allow referring to a pw::InlineDeque without an explicit maximum size, all InlineDeque classes inherit from the BasicInlineDequeStorage class, which in turn inherits from InlineDeque<T>, which stores the maximum size in a variable. This allows InlineDeques to be used without having to know their maximum size at compile time. It also keeps code size small since function implementations are shared for all maximum sizes.

◆ InlineFunction

template<typename FunctionType , std::size_t inline_target_size = function_internal::config::kInlineCallableSize>
using pw::InlineFunction = typedef fit::inline_function<FunctionType, inline_target_size>

Version of pw::Function that exclusively uses inline storage.

IMPORTANT: If pw::Function is configured to allow dynamic allocations then any attempt to convert pw::InlineFunction to pw::Function will ALWAYS allocate.

◆ InlineQueue

template<typename T , size_t kCapacity = containers::internal::kGenericSized>
using pw::InlineQueue = typedef BasicInlineQueue<T, uint16_t, kCapacity>

The InlineQueue class is similar to std::queue<T, std::deque>, except it is backed by a fixed-size buffer. InlineQueue's must be declared with an explicit maximum size (e.g. InlineQueue<int, 10>>) but deques can be used and referred to without the max size template parameter (e.g. InlineQueue<int>).

pw::InlineQueue is wrapper around pw::InlineDeque with a simplified API and push_overwrite() & emplace_overwrite() helpers.

Function Documentation

◆ bind_member()

template<auto method, typename T >
auto pw::bind_member ( T *  instance)

Returns a Callable which, when called, invokes method on instance using the arguments provided.

This is useful for binding the this argument of a callable.

pw::bind_member<&T::MethodName>(instance) is roughly equivalent to [instance](Arg arg1, ...) { instance->MethodName(arg1, ...) }, albeit with proper support for overloads and argument forwarding.

◆ GetAlignedSubspan()

ByteSpan pw::GetAlignedSubspan ( ByteSpan  bytes,
size_t  alignment 
)

Returns the largest aligned subspan of a given byte span.

The subspan will start and end on alignment boundaries.

Returns
A ByteSpan within bytes aligned to alignment, or an empty ByteSpan if alignment was not possible.

◆ OkStatus()

constexpr Status pw::OkStatus ( )
constexpr

Returns an

embed:rst:inline :c:enumerator:`OK` 

status. Equivalent to Status() or Status(PW_STATUS_OK). This function is used instead of a Status::Ok() function, which would be too similar to Status::ok().

◆ System()

system::AsyncCore & pw::System ( )
inline

Returns a reference to the global pw_system instance. pw::System() provides several features for applications: a memory allocator, an async dispatcher, and a RPC server.

◆ SystemStart()

void pw::SystemStart ( channel::ByteReaderWriter io_channel)

Starts running pw_system:async with the provided IO channel. This function never returns.