NEURON
neuron::unique_cstr Class Reference

A RAII wrapper for C-style strings. More...

#include <unique_cstr.hpp>

Public Member Functions

 unique_cstr ()=default
 
 unique_cstr (const unique_cstr &)=delete
 
 unique_cstr (unique_cstr &&other) noexcept
 
unique_cstroperator= (const unique_cstr &)=delete
 
unique_cstroperator= (unique_cstr &&other) noexcept
 
 unique_cstr (char *cstr)
 
 ~unique_cstr ()
 
char * release ()
 Releases ownership of the string. More...
 
char * c_str () const
 
bool is_valid () const
 

Private Attributes

char * str_ = nullptr
 

Detailed Description

A RAII wrapper for C-style strings.

The string must be null-terminated and allocated with malloc. The lifetime of the string is bound to the life time of the unique_cstr. Certain patterns in NRN require passing on ownership, this is achieved using .release(), which returns the contained C-string and makes this object invalid.

Definition at line 18 of file unique_cstr.hpp.

Constructor & Destructor Documentation

◆ unique_cstr() [1/4]

neuron::unique_cstr::unique_cstr ( )
default

◆ unique_cstr() [2/4]

neuron::unique_cstr::unique_cstr ( const unique_cstr )
delete

◆ unique_cstr() [3/4]

neuron::unique_cstr::unique_cstr ( unique_cstr &&  other)
inlinenoexcept

Definition at line 22 of file unique_cstr.hpp.

◆ unique_cstr() [4/4]

neuron::unique_cstr::unique_cstr ( char *  cstr)
inlineexplicit

Definition at line 33 of file unique_cstr.hpp.

◆ ~unique_cstr()

neuron::unique_cstr::~unique_cstr ( )
inline

Definition at line 36 of file unique_cstr.hpp.

Member Function Documentation

◆ c_str()

char* neuron::unique_cstr::c_str ( ) const
inline

Definition at line 48 of file unique_cstr.hpp.

◆ is_valid()

bool neuron::unique_cstr::is_valid ( ) const
inline

Definition at line 51 of file unique_cstr.hpp.

◆ operator=() [1/2]

unique_cstr& neuron::unique_cstr::operator= ( const unique_cstr )
delete

◆ operator=() [2/2]

unique_cstr& neuron::unique_cstr::operator= ( unique_cstr &&  other)
inlinenoexcept

Definition at line 27 of file unique_cstr.hpp.

◆ release()

char* neuron::unique_cstr::release ( )
inline

Releases ownership of the string.

Returns the string and makes this object invalid.

Definition at line 44 of file unique_cstr.hpp.

Member Data Documentation

◆ str_

char* neuron::unique_cstr::str_ = nullptr
private

Definition at line 56 of file unique_cstr.hpp.


The documentation for this class was generated from the following file: