Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
string_buffer.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/string_buffer.h
10
//! @brief String buffer.
11
12
#ifndef ROC_CORE_STRING_BUFFER_H_
13
#define ROC_CORE_STRING_BUFFER_H_
14
15
#include "
roc_core/array.h
"
16
#include "
roc_core/attributes.h
"
17
#include "
roc_core/iarena.h
"
18
#include "
roc_core/noncopyable.h
"
19
#include "
roc_core/panic.h
"
20
21
namespace
roc
{
22
namespace
core
{
23
24
//! String buffer.
25
//!
26
//! Dynamic array storing zero-terminated string. Works on top of Array,
27
//! but guarantees that the string is always zero-terminated.
28
//!
29
//! @tparam EmbeddedCapacity is the same as for Array.
30
class
StringBuffer
:
public
NonCopyable<> {
31
public
:
32
//! Initialize empty buffer.
33
explicit
StringBuffer
(
IArena
& arena);
34
35
//! Check if buffer is empty.
36
bool
is_empty
()
const
;
37
38
//! Get string length, excluding terminating zero.
39
size_t
len
()
const
;
40
41
//! Get zero-terminated string.
42
const
char
*
c_str
()
const
;
43
44
//! Set buffer to empty string.
45
void
clear
();
46
47
//! Copy given string into buffer.
48
//! @p str should be zero-terminated.
49
//! @returns
50
//! false if allocation failed.
51
ROC_ATTR_NODISCARD
bool
assign
(
const
char
* str);
52
53
//! Copy given range into buffer.
54
//! Buffer will be automatically zero-terminated.
55
//! @returns
56
//! false if allocation failed.
57
ROC_ATTR_NODISCARD
bool
assign
(
const
char
* str_begin,
const
char
* str_end);
58
59
//! Extend buffer by requested number of characters.
60
//! @remarks
61
//! Characters are appended to the buffer and filled with zeros.
62
//! It's the caller responsibility to fill them.
63
//! @returns
64
//! NULL if allocation failed.
65
ROC_ATTR_NODISCARD
char
*
extend
(
size_t
n_chars);
66
67
//! Grow capacity to be able to hold desired number of characters.
68
//! Capacity is increased linearly.
69
//! @returns
70
//! false if allocation failed.
71
ROC_ATTR_NODISCARD
bool
grow
(
size_t
desired_len);
72
73
//! Grow capacity to be able to hold desired number of characters.
74
//! Capacity is increased exponentially.
75
//! @returns
76
//! false if allocation failed.
77
ROC_ATTR_NODISCARD
bool
grow_exp
(
size_t
desired_len);
78
79
private
:
80
Array<char, 32>
data_;
81
};
82
83
}
// namespace core
84
}
// namespace roc
85
86
#endif
// ROC_CORE_STRING_BUFFER_H_
array.h
Dynamic array.
attributes.h
Compiler attributes.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::Array
Dynamic array.
Definition
array.h:40
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::StringBuffer::grow_exp
ROC_ATTR_NODISCARD bool grow_exp(size_t desired_len)
Grow capacity to be able to hold desired number of characters. Capacity is increased exponentially.
roc::core::StringBuffer::len
size_t len() const
Get string length, excluding terminating zero.
roc::core::StringBuffer::assign
ROC_ATTR_NODISCARD bool assign(const char *str)
Copy given string into buffer. str should be zero-terminated.
roc::core::StringBuffer::clear
void clear()
Set buffer to empty string.
roc::core::StringBuffer::is_empty
bool is_empty() const
Check if buffer is empty.
roc::core::StringBuffer::grow
ROC_ATTR_NODISCARD bool grow(size_t desired_len)
Grow capacity to be able to hold desired number of characters. Capacity is increased linearly.
roc::core::StringBuffer::assign
ROC_ATTR_NODISCARD bool assign(const char *str_begin, const char *str_end)
Copy given range into buffer. Buffer will be automatically zero-terminated.
roc::core::StringBuffer::StringBuffer
StringBuffer(IArena &arena)
Initialize empty buffer.
roc::core::StringBuffer::c_str
const char * c_str() const
Get zero-terminated string.
roc::core::StringBuffer::extend
ROC_ATTR_NODISCARD char * extend(size_t n_chars)
Extend buffer by requested number of characters.
iarena.h
Memory arena interface.
roc::core
General-purpose building blocks and platform abstraction layer.
roc
Root namespace.
noncopyable.h
Non-copyable object.
panic.h
Panic.
roc_core
string_buffer.h
Generated by
1.17.0