Loading...
Searching...
No Matches
CStringListI.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29
30inline char* Foam::CStringList::stringCopy(char* dest, const char* src)
31{
32 dest = std::copy_n(src, (src ? strlen(src) : 0), dest);
33 *(dest++) = '\0';
34 return dest;
35}
36
37
38inline char* Foam::CStringList::stringCopy(char *dest, std::string_view src)
39{
40 dest = std::copy_n(src.data(), src.size(), dest);
41 *(dest++) = '\0';
42 return dest;
43}
44
45
46inline char* Foam::CStringList::stringCopy(char *dest, const std::string& src)
47{
48 dest = std::copy_n(src.data(), src.size(), dest);
49 *(dest++) = '\0';
50 return dest;
51}
52
53
54// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
55
56inline int Foam::CStringList::count(const char * const argv[])
57{
58 int n = 0;
59 if (argv)
60 {
61 while (argv[n])
62 {
63 ++n;
64 }
65 }
66 return n;
67}
68
69
70// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71
73:
74 argc_(0),
75 nbytes_(0),
76 argv_(nullptr),
77 data_(nullptr)
78{}
79
80
82(
83 std::initializer_list<const char* const> input
84)
85:
87{
88 reset(input);
89}
90
91
92template<class StringType>
96{
97 resetContent(input);
98}
99
100
104{
105 resetContent(input);
106}
107
108
110(
111 const std::vector<std::string_view>& input
112)
115{
116 resetContent(input);
117}
118
119
121:
124 resetContent(input);
125}
126
127
128// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129
132 clear();
133}
134
135
136// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138inline std::string_view Foam::CStringList::view() const
139{
140 return std::string_view(data_, nbytes_);
141}
142
143
144inline void Foam::CStringList::clear()
145{
146 argc_ = 0;
147 nbytes_ = 0;
148
149 if (data_)
150 {
151 delete[] data_;
152 data_ = nullptr;
153 }
154 if (argv_)
156 delete[] argv_;
157 argv_ = nullptr;
158 }
159}
160
161
162inline char** Foam::CStringList::strings(int start) const
163{
164 return &(argv_[start]);
165}
166
167
168// ************************************************************************* //
label n
An adapter for copying a list of C++ strings into a list of C-style strings for passing to C code tha...
Definition CStringList.H:68
~CStringList()
Destructor. Invokes clear() to free memory.
constexpr CStringList() noexcept
Default construct, adding content later (via reset).
static int count(const char *const argv[])
Count the number of parameters until the first nullptr.
char ** strings() const noexcept
Return the list of C-strings (ie, argv).
int reset(std::initializer_list< const char *const > input)
Copy the input list of C-strings.
CStringList(const CStringList &)=delete
No copy construct.
std::string_view view() const
The flattened character content, with interspersed nul-chars.
void clear()
Clear contents and free memory.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
Definition SubStrings.H:49
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
surface1 clear()
const direction noexcept
Definition scalarImpl.H:265