Loading...
Searching...
No Matches
CStringList Class Reference

An adapter for copying a list of C++ strings into a list of C-style strings for passing to C code that expects argc/argv parameters. More...

#include <CStringList.H>

Public Member Functions

 CStringList (const CStringList &)=delete
 No copy construct.
void operator= (const CStringList &)=delete
 No copy assignment.
constexpr CStringList () noexcept
 Default construct, adding content later (via reset).
 CStringList (std::initializer_list< const char *const > input)
 Copy construct from a list of C-strings.
template<class StringType>
 CStringList (const UList< StringType > &input)
 Copy construct from a list of strings.
 CStringList (const UList< std::string_view > &input)
 Copy construct from a list of string_views.
 CStringList (const std::vector< std::string_view > &input)
 Copy construct from a list of string_views.
 CStringList (const SubStrings &input)
 Copy construct from a list of sub-string references.
 ~CStringList ()
 Destructor. Invokes clear() to free memory.
bool empty () const noexcept
 True if the size (ie, argc) is zero.
int size () const noexcept
 Return the number of C-strings (ie, argc).
std::string_view view () const
 The flattened character content, with interspersed nul-chars.
const char * cdata_bytes () const noexcept
 The flattened character content, with interspersed nul-chars.
size_t size_bytes () const noexcept
 Overall length of the flattened character (data) content including interspersed nul-chars but not the trailing nul-char.
const char * data () const noexcept
 Same as cdata_bytes().
size_t length () const noexcept
 Same as size_bytes().
const char * get (int i) const
 Return string element at the given index. No bounds checking.
char ** strings () const noexcept
 Return the list of C-strings (ie, argv).
char ** strings (int start) const
 Return the sublist of C-strings (ie, argv) starting at the specified offset.
void clear ()
 Clear contents and free memory.
int reset (std::initializer_list< const char *const > input)
 Copy the input list of C-strings.
template<class StringType>
int reset (const UList< StringType > &input)
 Copy the input list of strings.
int reset (const SubStrings &input)
 Copy the input list of strings.
const char * operator[] (int i) const
 Return element at the given index. No bounds checking.

Static Public Member Functions

static int count (const char *const argv[])
 Count the number of parameters until the first nullptr.
template<class StringType = std::string>
static List< StringType > asList (int argc, const char *const argv[])
 Create a list from argc/argv parameters.
template<class StringType = std::string>
static List< StringType > asList (const char *const argv[])
 Create a list from a nullptr-terminated list of argv parameters.

Detailed Description

An adapter for copying a list of C++ strings into a list of C-style strings for passing to C code that expects argc/argv parameters.

In addition to providing a C-compatible list of C-strings, the string lists are flattened into a single string of data that can be also be passed en mass.

Example use:

wordList myStrings; ...
CStringList cstr(myStrings);
// pass as argc, argv:
someMain(cstr.size(), cstr.strings());
// access the raw characters:
os.write(cstr.data(), cstr.length());
OBJstream os(runTime.globalPath()/outputName)
List< word > wordList
List of word.
Definition fileName.H:60

Definition at line 67 of file CStringList.H.

Constructor & Destructor Documentation

◆ CStringList() [1/7]

CStringList ( const CStringList & )
delete

No copy construct.

References CStringList().

Referenced by CStringList(), CStringList(), CStringList(), CStringList(), CStringList(), CStringList(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CStringList() [2/7]

CStringList ( )
inlineconstexprnoexcept

Default construct, adding content later (via reset).

Definition at line 65 of file CStringListI.H.

References Foam::noexcept.

◆ CStringList() [3/7]

CStringList ( std::initializer_list< const char *const > input)
inlineexplicit

Copy construct from a list of C-strings.

Copies the input characters.

Definition at line 74 of file CStringListI.H.

References CStringList(), and reset().

Here is the call graph for this function:

◆ CStringList() [4/7]

template<class StringType>
CStringList ( const UList< StringType > & input)
inlineexplicit

Copy construct from a list of strings.

Copies the input characters.

Definition at line 86 of file CStringListI.H.

References CStringList().

Here is the call graph for this function:

◆ CStringList() [5/7]

CStringList ( const UList< std::string_view > & input)
inlineexplicit

Copy construct from a list of string_views.

Copies the input characters.

Definition at line 94 of file CStringListI.H.

References CStringList().

Here is the call graph for this function:

◆ CStringList() [6/7]

CStringList ( const std::vector< std::string_view > & input)
inlineexplicit

Copy construct from a list of string_views.

Copies the input characters.

Definition at line 102 of file CStringListI.H.

References CStringList().

Here is the call graph for this function:

◆ CStringList() [7/7]

CStringList ( const SubStrings & input)
inlineexplicit

Copy construct from a list of sub-string references.

Copies the input characters.

Definition at line 113 of file CStringListI.H.

References CStringList().

Here is the call graph for this function:

◆ ~CStringList()

~CStringList ( )
inline

Destructor. Invokes clear() to free memory.

Definition at line 123 of file CStringListI.H.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ operator=()

void operator= ( const CStringList & )
delete

No copy assignment.

References count(), CStringList(), and Foam::noexcept.

Here is the call graph for this function:

◆ count()

int count ( const char *const argv[])
inlinestatic

Count the number of parameters until the first nullptr.

Return 0 if argv is nullptr.

Definition at line 49 of file CStringListI.H.

References n.

Referenced by operator=().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

True if the size (ie, argc) is zero.

Definition at line 213 of file CStringList.H.

References empty(), and Foam::noexcept.

Referenced by empty(), and Foam::system().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

int size ( ) const
inlinenoexcept

Return the number of C-strings (ie, argc).

Definition at line 218 of file CStringList.H.

References Foam::noexcept.

◆ view()

std::string_view view ( ) const
inline

The flattened character content, with interspersed nul-chars.

Definition at line 131 of file CStringListI.H.

◆ cdata_bytes()

const char * cdata_bytes ( ) const
inlinenoexcept

The flattened character content, with interspersed nul-chars.

Definition at line 228 of file CStringList.H.

References Foam::noexcept.

◆ size_bytes()

size_t size_bytes ( ) const
inlinenoexcept

Overall length of the flattened character (data) content including interspersed nul-chars but not the trailing nul-char.

Definition at line 234 of file CStringList.H.

References Foam::noexcept.

◆ data()

const char * data ( ) const
inlinenoexcept

Same as cdata_bytes().

Definition at line 239 of file CStringList.H.

References Foam::noexcept.

◆ length()

size_t length ( ) const
inlinenoexcept

Same as size_bytes().

Definition at line 244 of file CStringList.H.

References Foam::noexcept.

◆ get()

const char * get ( int i) const
inline

Return string element at the given index. No bounds checking.

Definition at line 249 of file CStringList.H.

◆ strings() [1/2]

char ** strings ( ) const
inlinenoexcept

Return the list of C-strings (ie, argv).

The position at argc is a nullptr

Definition at line 256 of file CStringList.H.

References Foam::noexcept.

Referenced by Foam::system().

Here is the caller graph for this function:

◆ strings() [2/2]

char ** strings ( int start) const
inline

Return the sublist of C-strings (ie, argv) starting at the specified offset.

Parameters
startthe offset, must be less than argc

Definition at line 155 of file CStringListI.H.

◆ clear()

void clear ( )
inline

Clear contents and free memory.

Definition at line 137 of file CStringListI.H.

◆ reset() [1/3]

int reset ( std::initializer_list< const char *const > input)

Copy the input list of C-strings.

Returns
number of arguments (argc)

Referenced by CStringList().

Here is the caller graph for this function:

◆ reset() [2/3]

template<class StringType>
int reset ( const UList< StringType > & input)
inline

Copy the input list of strings.

Returns
number of arguments (argc)

Definition at line 287 of file CStringList.H.

◆ reset() [3/3]

int reset ( const SubStrings & input)
inline

Copy the input list of strings.

Returns
number of arguments (argc)

Definition at line 297 of file CStringList.H.

◆ asList() [1/2]

template<class StringType = std::string>
List< StringType > asList ( int argc,
const char *const argv[] )
static

Create a list from argc/argv parameters.

A null pointer for argv is permissible when argc is zero.

◆ asList() [2/2]

template<class StringType = std::string>
List< StringType > asList ( const char *const argv[])
inlinestatic

Create a list from a nullptr-terminated list of argv parameters.

Using a nullptr for argv is permissible.

◆ operator[]()

const char * operator[] ( int i) const
inline

Return element at the given index. No bounds checking.

Definition at line 327 of file CStringList.H.


The documentation for this class was generated from the following files: