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