Snel
A shell implementation for A.U.TH (Operating Systems Lab)
snel::ArgList Struct Reference

#include <sequencer.h>

Public Types

using type = typename std::string::value_type
 Basic data type (aka char)
 
using vtype = type *
 Vector type.
 
using vtype_ptr = vtype *
 Pointer to vector type.
 

Public Member Functions

 ~ArgList ()
 
 ArgList (const ArgList &)=default
 
 ArgList (ArgList &&)=default
 
ArgListpush_back (const std::string &item)
 A vector::push_back wrapper. More...
 
vtype front ()
 A vector::front() wrapper.
 
size_t size ()
 A vector::size() wrapper.
 
vtype_ptr data () noexcept
 return a pointer to underling data for execvp()
 
vtype_ptr operator* () noexcept
 same as data()
 

Private Attributes

std::vector< vtypeargs_ {nullptr}
 underling data for the execvp() arguments
 

Detailed Description

A vector based wrapper above execvp()'s char* argv[] interface. We use a vector for convenience and resizing capabilities. We can then use a pointer to underling data to pass to execvp() std::vector elements guaranteed to be contiguous. To quote the standard

   The elements of a vector are stored contiguously, meaning that if v is
   a vector<T, Allocator> where T is some type other than bool, then it obeys
   the identity &v[n] == &v[0] + n for all 0 <= n < v.size().

See also cppreference

Definition at line 52 of file sequencer.h.

Constructor & Destructor Documentation

◆ ~ArgList()

snel::ArgList::~ArgList ( )

destructor to free up all the allocations

Note
Using RAII for ArgList we ensure "no memory leak"

Definition at line 88 of file sequencer.cpp.

Member Function Documentation

◆ push_back()

ArgList & snel::ArgList::push_back ( const std::string &  item)

A vector::push_back wrapper.

A push_back wrapper to our underling vector. This ensures NULL terminating argument list for exec() sys-call.

Parameters
itemThe argument to push
Returns
Reference to ArgList for chaining

Definition at line 99 of file sequencer.cpp.


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