util/string.h: add 'Const_byte_range_ptr'

The new 'Const_byte_range_ptr' type is suitable as argument type that
refers to a read-only byte buffer, e.g., the source buffer of a write
operation.
This commit is contained in:
Norman Feske 2023-02-09 11:26:57 +01:00 committed by Christian Helmuth
parent 73f7f8aef6
commit 07e3e09652

View File

@ -18,12 +18,14 @@
#include <base/stdint.h>
#include <base/output.h>
#include <util/misc_math.h>
#include <util/noncopyable.h>
#include <cpu/string.h>
namespace Genode {
class Number_of_bytes;
class Byte_range_ptr;
class Const_byte_range_ptr;
class Cstring;
template <Genode::size_t> class String;
}
@ -69,21 +71,37 @@ class Genode::Number_of_bytes
/**
* Data structure for describing a byte buffer
* Data structure for describing a mutable byte buffer
*
* The type is intended to be used as 'Byte_range_ptr const &' argument.
* It is deliberately non-copyable.
*/
struct Genode::Byte_range_ptr
struct Genode::Byte_range_ptr : Noncopyable
{
char * const start;
size_t const num_bytes;
struct {
char * const start;
size_t const num_bytes;
};
Byte_range_ptr(char *start, size_t num_bytes)
: start(start), num_bytes(num_bytes) { }
};
/**
* Data structure for describing a constant byte buffer
*/
struct Genode::Const_byte_range_ptr : Noncopyable
{
struct {
char const * const start;
size_t const num_bytes;
};
Const_byte_range_ptr(char const *start, size_t num_bytes)
: start(start), num_bytes(num_bytes) { }
};
/***********************
** Utility functions **
***********************/