25 Commits

Author SHA1 Message Date
Donovan Watteau 7f19a83f13 COMMON: Replace STATIC_ASSERT uses with static_assert
The current C++11 requirement means that all targets already support
static_assert().
2025-10-12 14:11:24 +03:00
Orgad Shaneh ce744add1f JANITORIAL: Fix unused variable warnings on release build 2025-05-13 22:33:16 +03:00
Le Philousophe 5e98ef6d21 COMMON: Silence cast-user-defined GCC warning
Make it explicit that we don't want to call any copy constructor but
only casting a reference type.
2025-02-16 13:30:36 +01:00
Le Philousophe d2ec868154 COMMON: Rename Conditional type
This now matches what STL does
Also add conditional_t type introduced in C++14.
2025-02-16 13:10:07 +01:00
Le Philousophe 89f632ef39 COMMON: Add add_cv, add_const, add_volatiles constructs
And migrate away from the old AddConst
2025-02-16 13:10:07 +01:00
Le Philousophe 95051b52d4 COMMON: Delete RemoveConst construct and move remove_*
We already have remove_const which has the same name as the STL
construct.
Move the STL compliant versions to type-traits.h to match STL more and
lighten util.h.
2025-02-16 13:10:07 +01:00
Le Philousophe e556f54f98 COMMON: Rename type-traits.h to type_traits.h
This now matches the STL header
2025-02-16 13:10:07 +01:00
Orgad Shaneh cf8022dd27 JANITORIAL: Use default for span ctors 2025-01-03 09:30:16 +02:00
Orgad Shaneh c9c2ffd88b JANITORIAL: Require semicolon after COMMON_SPAN_TYPEDEFS macro use 2025-01-03 09:30:16 +02:00
Donovan Watteau 8140fdfbcc COMMON: Fix MSVC C4309 enum sign warning 2022-11-29 01:37:55 +01:00
Donovan Watteau 5ebd9b8d23 BUILD: Remove/simplify GCC_ATLEAST() calls when they targeted pre-C++11 compilers
C++11 is now required, so there's no point in checking for pre-C++11
versions of GCC anymore.  Note that Clang defines __GNUC__ too, but
always reports itself as GCC-4.2.1-compatible (and, in practice, the
earliest C++11-compatible versions of Clang will also be have most
GCC 4.8 features).
2022-05-25 19:07:30 +03:00
Eugene Sandulenko abea37c9bb ALL: Update ScummVM project license to GPLv3+ 2021-12-26 18:48:43 +01:00
Walter van Niftrik d4ecbbc5d3 COMMON: Fix Span::toStream() when given index
When providing an index but no numEntries, the computed numEntries is
not adjust for index and an error is thrown
2020-08-20 23:58:37 +02:00
D G Turner 76bf6da5fa COMMON: Fix Missing Default Switch Case in Span Header
This is flagged by GCC if -Wswitch-default is enabled.
2019-12-01 00:32:48 +00:00
Colin Snover d7e5e5f995 COMMON: Take immutable reference in SpanOwner copy assignment
Thanks again to @waltervn.
2017-06-08 20:04:37 -05:00
Colin Snover 58c83dcd14 COMMON: Make SpanOwner copy assignment make a copy of the owned Span
To move data from one SpanOwner to another, use `moveFrom`.
Thanks @waltervn for pointing out the problem.
2017-06-08 10:45:55 -05:00
Colin Snover 993d83fe4b COMMON: Reduce maximum Span size to 4GiB
Until C++11 (which introduces the z and t length modifiers), there
is no consistent way to print size_t and ptrdiff_t types using
printf formatting across 32-bit, LLP64, and LP64 architectures
without using a cumbersome macro to select the appropriate length
modifier for the target architecture. Since ScummVM engines
currently need to support 32-bit targets, there is no reason at
the moment to support any larger memory sizes in Span anyway.

Span error output is also updated in this commit to reflect that
index values are unsigned.
2017-03-30 14:22:56 -05:00
Paul Gilbert 4564b84d91 COMMON: Compilation fix for Visual Studio 2015
The SpanImpl template was generating a bunch of C2248 errors that
protected fields of the SpanBase template could not be accessed
2017-03-28 18:50:58 -04:00
Colin Snover f1d9955540 COMMON: Fix calling Span::getStringAt with non-zero index 2017-02-08 12:05:14 -06:00
D G Turner 906f850a9c COMMON: Fix Variable Used Uninitialized Compiler Warning. 2017-01-15 11:46:42 +00:00
Colin Snover 3c02008262 COMMON: Fix GCC 4 shadow warnings in Span 2017-01-08 15:17:22 -06:00
Colin Snover 3cfc396ecd COMMON: Simplify Span code
Implicitly generated constructors can be used instead of explicit
constructors, which reduces the amount of necessary boilerplate.

Long lists of identical typedefs to the superclass are now defined
using a macro.

data() const now returns a pointer to data that matches the
value_type of the data, instead of forcing the data to be const.
This better matches the intent of the Span class, which provides
a view into data, rather than being a container that holds data.
2017-01-08 14:08:16 -06:00
Colin Snover b2796e65aa COMMON: Restrict use of data access helpers
The data access helpers as written are effectively little-endian
when reading from spans with value_types larger than the size of
the requested data (e.g. more than 1 byte for getting a char,
more than 2 bytes for getting a uint16, etc.). For now, restrict
use of these methods at compile time until someone actually needs
to read memory that way.
2017-01-08 13:21:10 -06:00
Colin Snover 2558b20cdd COMMON: Improve test coverage for Span and fix bugs from testing 2017-01-08 13:20:23 -06:00
Colin Snover 640f6039ca COMMON: Add Span to common library
Span is roughly modelled on the GSL span<T> type, and is intended
to replace direct access to raw pointers -- especially pointers
that are passed to functions along with a separate size
parameter. It provides low-cost bounds-checked reads and writes,
as well as convenience functions for reading common values
(integers of varying endianness, strings, etc.). While similar to
MemoryReadStream in purpose, Span is superior in cases where
memory is writable, where memory is accessed randomly rather than
sequentially, or where any invalid access should be treated as an
unrecoverable error. It should also be more efficient than a
MemoryReadStream because it is implemented using CRTP, so there is
no runtime overhead from dynamic dispatch.

NamedSpan is an extension of Span which provides enhanced
debugging information when out-of-bounds memory accesses occur.
It allows programmers to name the memory span at construction time,
and it also tracks the offsets of subspans so that the absolute
byte offset of the original memory can be provided in the error
message if an out-of-bounds access occurs.

SpanOwner is similar to ScopedPtr but has awareness of the design
of Span objects, so allows the memory pointed to by the Span object
inside the SpanOwner to be freed when the SpanOwner is freed
without requiring holding a separate pointer to the start of
memory. It also provides some copy semantics, so unlike a ScopedPtr,
SpanOwners can be held by objects in movable containers like
Common::Array -- but note that because there are no move semantics
in C++98, this means that a new, complete memory copy of the
pointed-to data will be created, rather than just a new Span
pointing to the same block of memory, when a container holding a
SpanOwner expands.
2017-01-08 13:20:23 -06:00