Add C++ convenience methods

This commit is contained in:
Nigel Tao committed 2018-06-30 13:02:16 +10:00
1 parent 60a7b48745
commit 30cfaa5db7
20 files changed
+1444 -229

No files matched your search

+38 -13
View File
@@ -682,23 +682,13 @@ static inline uint32_t wuffs_base__rect_ie_u32__height(
// ---------------- I/O
// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length), plus
// additional indexes into that buffer, plus an opened / closed flag.
//
// A value with all fields NULL or zero is a valid, empty buffer.
typedef struct {
uint8_t* ptr; // Pointer.
size_t len; // Length.
size_t wi; // Write index. Invariant: wi <= len.
size_t ri; // Read index. Invariant: ri <= wi.
bool closed; // No further writes are expected.
} wuffs_base__io_buffer;
struct wuffs_base__io_buffer__struct;
typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
struct wuffs_base__io_buffer__struct* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
@@ -710,7 +700,7 @@ typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
struct wuffs_base__io_buffer__struct* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
@@ -718,6 +708,25 @@ typedef struct {
} private_impl;
} wuffs_base__io_writer;
// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length), plus
// additional indexes into that buffer, plus an opened / closed flag.
//
// A value with all fields NULL or zero is a valid, empty buffer.
typedef struct wuffs_base__io_buffer__struct {
uint8_t* ptr; // Pointer.
size_t len; // Length.
size_t wi; // Write index. Invariant: wi <= len.
size_t ri; // Read index. Invariant: ri <= wi.
bool closed; // No further writes are expected.
#ifdef __cplusplus
inline void compact();
inline wuffs_base__io_reader reader();
inline wuffs_base__io_writer writer();
#endif // __cplusplus
} wuffs_base__io_buffer;
// wuffs_base__io_buffer__compact moves any written but unread bytes to the
// start of the buffer.
static inline void wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {
@@ -746,6 +755,22 @@ static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
return ret;
}
#ifdef __cplusplus
inline void wuffs_base__io_buffer__struct::compact() {
wuffs_base__io_buffer__compact(this);
}
inline wuffs_base__io_reader wuffs_base__io_buffer__struct::reader() {
return wuffs_base__io_buffer__reader(this);
}
inline wuffs_base__io_writer wuffs_base__io_buffer__struct::writer() {
return wuffs_base__io_buffer__writer(this);
}
#endif // __cplusplus
// ---------------- Images
// wuffs_base__color_u32argb is an 8 bit per channel Alpha, Red, Green, Blue