Nektar++
Public Member Functions | Private Attributes | List of all members
CppCommandLine Struct Reference

Helper structure to construct C++ command line argc and argv variables from a Python list. More...

#include <NekPyConfig.hpp>

Public Member Functions

 CppCommandLine (py::list &py_argv)
 Constructor. More...
 
 ~CppCommandLine ()
 Destructor. More...
 
char ** GetArgv ()
 Returns the constructed argv. More...
 
int GetArgc ()
 Returns the constructed argc. More...
 

Private Attributes

char ** m_argv = nullptr
 Pointers for strings argv. More...
 
int m_argc = 0
 Number of arguments argc. More...
 
std::vector< char > m_buf
 Buffer for storage of the argument strings. More...
 

Detailed Description

Helper structure to construct C++ command line argc and argv variables from a Python list.

Definition at line 88 of file NekPyConfig.hpp.

Constructor & Destructor Documentation

◆ CppCommandLine()

CppCommandLine::CppCommandLine ( py::list &  py_argv)
inline

Constructor.

Parameters
py_argvList of command line arguments from Python.

Definition at line 95 of file NekPyConfig.hpp.

95 : m_argc(py::len(py_argv))
96 {
97 int i = 0;
98 size_t bufSize = 0;
99 char *p;
100
101 m_argv = new char *[m_argc + 1];
102
103 // Create argc, argv to give to the session reader. Note that this needs
104 // to be a contiguous block in memory, otherwise MPI (specifically
105 // OpenMPI) will likely segfault.
106 for (i = 0; i < m_argc; ++i)
107 {
108 std::string tmp = py::cast<std::string>(py_argv[i]);
109 bufSize += tmp.size() + 1;
110 }
111
112 m_buf.resize(bufSize);
113 for (i = 0, p = &m_buf[0]; i < m_argc; ++i)
114 {
115 std::string tmp = py::cast<std::string>(py_argv[i]);
116 std::copy(tmp.begin(), tmp.end(), p);
117 p[tmp.size()] = '\0';
118 m_argv[i] = p;
119 p += tmp.size() + 1;
120 }
121
122 m_argv[m_argc] = nullptr;
123 }
def copy(self)
Definition: pycml.py:2663
int m_argc
Number of arguments argc.
std::vector< char > m_buf
Buffer for storage of the argument strings.
char ** m_argv
Pointers for strings argv.

References CellMLToNektar.pycml::copy(), m_argc, m_argv, m_buf, and CellMLToNektar.cellml_metadata::p.

◆ ~CppCommandLine()

CppCommandLine::~CppCommandLine ( )
inline

Destructor.

Definition at line 128 of file NekPyConfig.hpp.

129 {
130 if (m_argv == nullptr)
131 {
132 return;
133 }
134
135 delete m_argv;
136 }

References m_argv.

Member Function Documentation

◆ GetArgc()

int CppCommandLine::GetArgc ( )
inline

Returns the constructed argc.

Definition at line 149 of file NekPyConfig.hpp.

150 {
151 return m_argc;
152 }

References m_argc.

Referenced by Field_Init(), NewPartition(), and SessionReader_CreateInstance().

◆ GetArgv()

char ** CppCommandLine::GetArgv ( )
inline

Returns the constructed argv.

Definition at line 141 of file NekPyConfig.hpp.

142 {
143 return m_argv;
144 }

References m_argv.

Referenced by Field_Init(), NewPartition(), and SessionReader_CreateInstance().

Member Data Documentation

◆ m_argc

int CppCommandLine::m_argc = 0
private

Number of arguments argc.

Definition at line 158 of file NekPyConfig.hpp.

Referenced by CppCommandLine(), and GetArgc().

◆ m_argv

char** CppCommandLine::m_argv = nullptr
private

Pointers for strings argv.

Definition at line 156 of file NekPyConfig.hpp.

Referenced by CppCommandLine(), GetArgv(), and ~CppCommandLine().

◆ m_buf

std::vector<char> CppCommandLine::m_buf
private

Buffer for storage of the argument strings.

Definition at line 160 of file NekPyConfig.hpp.

Referenced by CppCommandLine().