Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
string_list.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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_list.h
10//! @brief Dynamic list of strings.
11
12#ifndef ROC_CORE_STRING_LIST_H_
13#define ROC_CORE_STRING_LIST_H_
14
15#include "roc_core/array.h"
16#include "roc_core/iallocator.h"
18#include "roc_core/stddefs.h"
19
20namespace roc {
21namespace core {
22
23//! Dynamic list of strings.
24class StringList : public NonCopyable<> {
25public:
26 //! Initialize empty string list.
27 explicit StringList(IAllocator& allocator);
28
29 //! Get number of elements.
30 size_t size() const;
31
32 //! Get first string.
33 //! @returns
34 //! the first string in the list or NULL if it is empty.
35 const char* front() const;
36
37 //! Get last string.
38 //! @returns
39 //! the last string in the list or NULL if it is empty.
40 const char* back() const;
41
42 //! Get next string.
43 //! @returns
44 //! the first string of the given string or NULL if it is the last string.
45 //! @remarks
46 //! @p str should be a pointer returned by front() or nextof(). These
47 //! pointers are invalidated by methods that modify the list.
48 const char* nextof(const char* str) const;
49
50 //! Clear the list.
51 void clear();
52
53 //! Append string to the list.
54 //! @remarks
55 //! Reallocates memory if necessary.
56 //! @returns
57 //! false if allocation failed.
58 bool push_back(const char* str);
59
60 //! Append string from a range to the list.
61 //! @remarks
62 //! Reallocates memory if necessary.
63 //! @returns
64 //! false if allocation failed.
65 bool push_back(const char* str_begin, const char* str_end);
66
67 //! Append string to the list if it's not in the list already.
68 //! @remarks
69 //! Reallocates memory if necessary.
70 //! @returns
71 //! false if allocation failed.
72 bool push_unique(const char* str);
73
74 //! Append string from a range to the list if it's not in the list already.
75 //! @remarks
76 //! Reallocates memory if necessary.
77 //! @returns
78 //! false if allocation failed.
79 bool push_unique(const char* str_begin, const char* str_end);
80
81private:
82 enum { MinCapacity = 128 };
83
84 bool grow_(size_t size);
85
87 const char* back_;
88 size_t size_;
89};
90
91} // namespace core
92} // namespace roc
93
94#endif // ROC_CORE_STRING_LIST_H_
Dynamic array.
Dynamic array.
Definition: array.h:38
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Dynamic list of strings.
Definition: string_list.h:24
const char * back() const
Get last string.
const char * front() const
Get first string.
void clear()
Clear the list.
bool push_unique(const char *str_begin, const char *str_end)
Append string from a range to the list if it's not in the list already.
bool push_back(const char *str_begin, const char *str_end)
Append string from a range to the list.
const char * nextof(const char *str) const
Get next string.
StringList(IAllocator &allocator)
Initialize empty string list.
bool push_unique(const char *str)
Append string to the list if it's not in the list already.
size_t size() const
Get number of elements.
bool push_back(const char *str)
Append string to the list.
Memory allocator interface.
Root namespace.
Non-copyable object.
Commonly used types and functions.