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 204 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 211 of file NekPyConfig.hpp.

211 : m_argc(py::len(py_argv))
212 {
213 int i = 0;
214 size_t bufSize = 0;
215 char *p;
216
217 m_argv = new char *[m_argc + 1];
218
219 // Create argc, argv to give to the session reader. Note that this needs
220 // to be a contiguous block in memory, otherwise MPI (specifically
221 // OpenMPI) will likely segfault.
222 for (i = 0; i < m_argc; ++i)
223 {
224 std::string tmp = py::extract<std::string>(py_argv[i]);
225 bufSize += tmp.size() + 1;
226 }
227
228 m_buf.resize(bufSize);
229 for (i = 0, p = &m_buf[0]; i < m_argc; ++i)
230 {
231 std::string tmp = py::extract<std::string>(py_argv[i]);
232 std::copy(tmp.begin(), tmp.end(), p);
233 p[tmp.size()] = '\0';
234 m_argv[i] = p;
235 p += tmp.size() + 1;
236 }
237
238 m_argv[m_argc] = nullptr;
239 }
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 244 of file NekPyConfig.hpp.

245 {
246 if (m_argv == nullptr)
247 {
248 return;
249 }
250
251 delete m_argv;
252 }

References m_argv.

Member Function Documentation

◆ GetArgc()

int CppCommandLine::GetArgc ( )
inline

Returns the constructed argc.

Definition at line 265 of file NekPyConfig.hpp.

266 {
267 return m_argc;
268 }

References m_argc.

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

◆ GetArgv()

char ** CppCommandLine::GetArgv ( )
inline

Returns the constructed argv.

Definition at line 257 of file NekPyConfig.hpp.

258 {
259 return m_argv;
260 }

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 274 of file NekPyConfig.hpp.

Referenced by CppCommandLine(), and GetArgc().

◆ m_argv

char** CppCommandLine::m_argv = nullptr
private

Pointers for strings argv.

Definition at line 272 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 276 of file NekPyConfig.hpp.

Referenced by CppCommandLine().