mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-10 12:41:35 -10:00
String processing enhancement prerequisites for the upcoming `split_str_once` PR. 1. Add overloads of some string processing functions with a length parameter, to allow processing of substrings of C-strings 2. Add overloads of gr_printf that work with string lengths 3. Add constructors to `HUD_message_data` and `line_node` 4. Rename "size" to "len" in `vm_strndup` for clarity 5. Fill in some string attribute annotations 6. Make the rest of the HUD render functions `const` 7. Removed unneeded circular #includes in code/globalincs/memory/
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdlib>
|
|
|
|
namespace memory
|
|
{
|
|
struct quiet_alloc_t { quiet_alloc_t(){} };
|
|
extern const quiet_alloc_t quiet_alloc;
|
|
|
|
void out_of_memory();
|
|
}
|
|
|
|
inline void *vm_malloc(size_t size, const memory::quiet_alloc_t &)
|
|
{ return std::malloc(size); }
|
|
|
|
inline void *vm_malloc(size_t size)
|
|
{
|
|
auto ptr = vm_malloc(size, memory::quiet_alloc);
|
|
|
|
if (ptr == NULL)
|
|
{
|
|
memory::out_of_memory();
|
|
}
|
|
|
|
return ptr;
|
|
}
|
|
|
|
inline void vm_free(void *ptr)
|
|
{ std::free(ptr); }
|
|
|
|
inline void *vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &)
|
|
{ return std::realloc(ptr, size); }
|
|
|
|
inline void *vm_realloc(void *ptr, size_t size)
|
|
{
|
|
auto ret_ptr = vm_realloc(ptr, size, memory::quiet_alloc);
|
|
|
|
if (ret_ptr == NULL)
|
|
{
|
|
memory::out_of_memory();
|
|
}
|
|
|
|
return ret_ptr;
|
|
}
|
|
|
|
// For use with unique_ptr
|
|
template <typename T>
|
|
struct VmFreeDeleter
|
|
{
|
|
void operator()(T* const p) const
|
|
{
|
|
vm_free(p);
|
|
}
|
|
};
|
|
|
|
// Managed unique pointer for data allocated using vm_malloc. Never use with data allocated with new or malloc;
|
|
// allocation and deallocation must always be performed using matching operations.
|
|
template<typename T>
|
|
using SCP_vm_unique_ptr = std::unique_ptr<T, VmFreeDeleter<T>>;
|