gslcpp
Modern-C++ Wrapper for GSL
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
gsl::v_stor< T > Class Template Reference

Specialization, which is interface to storage with two key properties: (1) that size of storage is determined dynamically, at run-time, and (2) that it is owned by instance of interface. More...

#include <v-stor.hpp>

Public Member Functions

 v_stor (size_t n, alloc_type a=ALLOC)
 Allocate vector and its descriptor. More...
 
bool valid () const
 True if object's data have been validly allocated. More...
 
auto * v ()
 Reference to GSL's interface to vector. More...
 
const auto * v () const
 Reference to GSL's interface to vector. More...
 
 v_stor (v_stor &&src)
 Move on construction. More...
 
virtual ~v_stor ()
 Deallocate vector and its descriptor.
 

Protected Member Functions

void free ()
 Deallocate vector and its descriptor.
 
w_vector< T > * allocate (size_t n, alloc_type a)
 Allocate vector and its descriptor. More...
 

Protected Attributes

w_vector< T > * v_ = nullptr
 Pointer to allocated descriptor for vector.
 

Private Member Functions

 v_stor (v_stor const &)=delete
 Disable copy-construction.
 
v_storoperator= (v_stor const &)=delete
 Disable copy-assignment.
 

Detailed Description

template<typename T>
class gsl::v_stor< T >

Specialization, which is interface to storage with two key properties: (1) that size of storage is determined dynamically, at run-time, and (2) that it is owned by instance of interface.

Generic gsl::v_stor<T,S> is for storage-size S determined at compile-time.

Move-construction is provided, but move-assignment is not. Once memory is allocated for a vector, that memory and only that memory belongs to the vector until it is destroyed.

Template Parameters
TType of each element in vector.

Definition at line 68 of file v-stor.hpp.

Constructor & Destructor Documentation

◆ v_stor() [1/2]

template<typename T >
gsl::v_stor< T >::v_stor ( size_t  n,
alloc_type  a = ALLOC 
)
inline

Allocate vector and its descriptor.

Parameters
nNumber of elements in vector.
aMethod to use for allocation.

Definition at line 96 of file v-stor.hpp.

96 { v_= allocate(n, a); }

◆ v_stor() [2/2]

template<typename T >
gsl::v_stor< T >::v_stor ( v_stor< T > &&  src)
inline

Move on construction.

Constructor is not template because moving works only from other v_stor.

Parameters
srcVector to move.

Definition at line 113 of file v-stor.hpp.

113 : v_(src.v_) { src.v_= nullptr; }

Member Function Documentation

◆ allocate()

template<typename T >
w_vector<T>* gsl::v_stor< T >::allocate ( size_t  n,
alloc_type  a 
)
inlineprotected

Allocate vector and its descriptor.

Parameters
nNumber of elements in vector.
aType of allocation (simple or initialized to zero).
Returns
Pointer to vector's descriptor.

Definition at line 86 of file v-stor.hpp.

86  {
87  free();
88  if(a == ALLOC) return w_vector_alloc<T>(n);
89  return w_vector_calloc<T>(n);
90  }

◆ v() [1/2]

template<typename T >
auto* gsl::v_stor< T >::v ( )
inline

Reference to GSL's interface to vector.

Returns
Reference to GSL's interface to vector.

Definition at line 104 of file v-stor.hpp.

104 { return v_; }

◆ v() [2/2]

template<typename T >
const auto* gsl::v_stor< T >::v ( ) const
inline

Reference to GSL's interface to vector.

Returns
Reference to GSL's interface to immutable vector.

Definition at line 108 of file v-stor.hpp.

108 { return v_; }

◆ valid()

template<typename T >
bool gsl::v_stor< T >::valid ( ) const
inline

True if object's data have been validly allocated.

Returns
True if object's data have been validly allocated.

Definition at line 100 of file v-stor.hpp.

100 { return v_!= nullptr; }

The documentation for this class was generated from the following file:
gsl::v_stor< T >::free
void free()
Deallocate vector and its descriptor.
Definition: v-stor.hpp:77
gsl::v_stor< T >::allocate
w_vector< T > * allocate(size_t n, alloc_type a)
Allocate vector and its descriptor.
Definition: v-stor.hpp:86
gsl::v_stor< T >::v_
w_vector< T > * v_
Pointer to allocated descriptor for vector.
Definition: v-stor.hpp:74
gsl::ALLOC
@ ALLOC
Just allocate without initialization.
Definition: v-stor.hpp:51