timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::argparse::argument_vector Struct Reference

This class exists to simplify creating argument arrays compatible with execv* routines and MPI_Comm_spawn/MPI_Comm_spawn_multiple. More...

#include "timemory/utility/argparse.hpp"

+ Collaboration diagram for tim::argparse::argument_vector:

Classes

struct  c_args
 

Public Types

using base_type = std::vector< std::string >
 
using cargs_t = c_args
 

Public Member Functions

template<typename... Args>
 argument_vector (Args &&... args)
 
 argument_vector (int &argc, char **&argv)
 
 argument_vector (int &argc, const char **&argv)
 
 argument_vector (int &argc, const char *const *&argv)
 
cargs_t get_execv (const base_type &_prepend, size_t _beg=0, size_t _end=std::numeric_limits< size_t >::max()) const
 
cargs_t get_execv (size_t _beg=0, size_t _end=std::numeric_limits< size_t >::max()) const
 

Static Public Member Functions

static void free_execv (cargs_t &itr)
 

Detailed Description

This class exists to simplify creating argument arrays compatible with execv* routines and MPI_Comm_spawn/MPI_Comm_spawn_multiple.

Definition at line 269 of file argparse.hpp.

Member Typedef Documentation

◆ base_type

using tim::argparse::argument_vector::base_type = std::vector<std::string>

Definition at line 296 of file argparse.hpp.

◆ cargs_t

Definition at line 297 of file argparse.hpp.

Constructor & Destructor Documentation

◆ argument_vector() [1/4]

template<typename... Args>
tim::argparse::argument_vector::argument_vector ( Args &&...  args)
inline

Definition at line 300 of file argparse.hpp.

301 : base_type(std::forward<Args>(args)...)
302 {}
std::vector< std::string > base_type
Definition: argparse.hpp:296

◆ argument_vector() [2/4]

TIMEMORY_UTILITY_INLINE tim::argparse::argument_vector::argument_vector ( int &  argc,
char **&  argv 
)
explicit

Definition at line 39 of file argparse.cpp.

40: base_type()
41{
42 reserve(argc);
43 for(int i = 0; i < argc; ++i)
44 push_back(argv[i]);
45}
char ** argv
Definition: config.cpp:55

References tim::argv.

◆ argument_vector() [3/4]

TIMEMORY_UTILITY_INLINE tim::argparse::argument_vector::argument_vector ( int &  argc,
const char **&  argv 
)
explicit

Definition at line 48 of file argparse.cpp.

49: base_type()
50{
51 reserve(argc);
52 for(int i = 0; i < argc; ++i)
53 push_back(argv[i]);
54}

References tim::argv.

◆ argument_vector() [4/4]

TIMEMORY_UTILITY_INLINE tim::argparse::argument_vector::argument_vector ( int &  argc,
const char *const *&  argv 
)
explicit

Definition at line 57 of file argparse.cpp.

58{
59 reserve(argc);
60 for(int i = 0; i < argc; ++i)
61 push_back(argv[i]);
62}

References tim::argv.

Member Function Documentation

◆ free_execv()

static void tim::argparse::argument_vector::free_execv ( cargs_t itr)
inlinestatic

Definition at line 314 of file argparse.hpp.

314{ itr.clear(); }

References tim::argparse::argument_vector::c_args::clear().

◆ get_execv() [1/2]

TIMEMORY_UTILITY_INLINE argument_vector::cargs_t tim::argparse::argument_vector::get_execv ( const base_type _prepend,
size_t  _beg = 0,
size_t  _end = std::numeric_limits<size_t>::max() 
) const

Definition at line 65 of file argparse.cpp.

66{
67 std::stringstream cmdss;
68 // find the end if not specified
69 _end = std::min<size_t>(size(), _end);
70 // determine the number of arguments
71 auto _argc = (_end - _beg) + _prepend.size();
72 // create the new C argument array, add an extra entry at the end which will
73 // always be a null pointer because that is how execv determines the end
74 char** _argv = new char*[_argc + 1];
75
76 // ensure all arguments are null pointers initially
77 for(size_t i = 0; i < _argc + 1; ++i)
78 _argv[i] = nullptr;
79
80 // add the prepend list
81 size_t _idx = 0;
82 for(const auto& itr : _prepend)
83 _argv[_idx++] = helpers::strdup(itr.c_str());
84
85 // copy over the arguments stored internally from the range specified
86 for(auto i = _beg; i < _end; ++i)
87 _argv[_idx++] = helpers::strdup(this->at(i).c_str());
88
89 // add check that last argument really is a nullptr
90 assert(_argv[_argc] == nullptr);
91
92 // create the command string
93 for(size_t i = 0; i < _argc; ++i)
94 cmdss << " " << _argv[i];
95 auto cmd = cmdss.str().substr(1);
96
97 // return a new (int argc, char** argv) and subtract 1 bc nullptr in last entry
98 // does not count as argc
99 return cargs_t(_argc - 1, _argv, cmd);
100}
_args at(0)
char * strdup(const char *s)
Definition: timemory_c.c:41

References tim::at(), tim::plotting::cmd, and strdup().

Referenced by get_execv().

◆ get_execv() [2/2]

TIMEMORY_UTILITY_INLINE argument_vector::cargs_t tim::argparse::argument_vector::get_execv ( size_t  _beg = 0,
size_t  _end = std::numeric_limits<size_t>::max() 
) const

Definition at line 103 of file argparse.cpp.

104{
105 return get_execv(base_type{}, _beg, _end);
106}
cargs_t get_execv(const base_type &_prepend, size_t _beg=0, size_t _end=std::numeric_limits< size_t >::max()) const
Definition: argparse.cpp:65

References get_execv().


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