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-2017 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 std::string& src)
31{
32 // Like string::copy() but without extra checks
33 const size_t len = src.length();
34 for (size_t i = 0; i < len; ++i)
35 {
36 *dest = src[i];
37 ++dest;
38 }
39 *(dest++) = '\0';
40
41 return dest;
42}
43
44
45// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
46
47inline int Foam::CStringList::count(const char * const argv[])
48{
49 int n = 0;
50 if (argv)
51 {
52 while (argv[n])
53 {
54 ++n;
55 }
56 }
57 return n;
58}
59
60
61// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62
64:
65 argc_(0),
66 nbytes_(0),
67 argv_(nullptr),
68 data_(nullptr)
69{}
70
71
72template<class StringType>
74:
76{
77 reset(input);
78}
79
80
81template<class StringType>
83:
85{
86 reset(input);
87}
88
89
90// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
91
93{
94 clear();
95}
96
97
98// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99
101{
102 argc_ = 0;
103 nbytes_ = 0;
104
105 if (data_)
106 {
107 delete[] data_;
108 data_ = nullptr;
109 }
110 if (argv_)
111 {
112 delete[] argv_;
113 argv_ = nullptr;
114 }
115}
116
117
119{
120 return !argc_;
121}
122
123
125{
126 return argc_;
127}
128
129
131{
132 return argv_;
133}
134
135
136inline char** Foam::CStringList::strings(int start) const
137{
138 return &(argv_[start]);
139}
140
141
142template<class StringType>
144{
145 return resetContent(input);
146}
147
148
149template<class StringType>
151{
152 return resetContent(input);
153}
154
155
156// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
157
158inline const char* Foam::CStringList::get(int i) const
159{
160 return argv_[i];
161}
162
163
164inline const char* Foam::CStringList::operator[](int i) const
165{
166 return argv_[i];
167}
168
169
170// ************************************************************************* //
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:70
~CStringList()
Destructor. Invokes clear() to free memory.
Definition: CStringListI.H:92
int size() const noexcept
Return the number of C-strings (ie, argc)
Definition: CStringListI.H:124
const char * operator[](int i) const
Return element at the given index. No bounds checking.
Definition: CStringListI.H:164
constexpr CStringList() noexcept
Default construct, adding content later (via reset).
Definition: CStringListI.H:63
bool empty() const noexcept
True if the size (ie, argc) is zero.
Definition: CStringListI.H:118
char ** strings() const noexcept
Return the list of C-strings (ie, argv)
Definition: CStringListI.H:130
int reset(const UList< StringType > &input)
Copy the input list of strings.
Definition: CStringListI.H:143
void clear()
Clear contents and free memory.
Definition: CStringListI.H:100
unsigned int get() const
Get value as unsigned, no range-checking.
Definition: PackedListI.H:302
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
Definition: SubStrings.H:54
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:94
void reset()
Reset to defaults.
label count() const
patchWriters clear()
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
const direction noexcept
Definition: Scalar.H:223