OmniSciDB  2e3a973ef4
Parser::TrackedPtr< T > Class Template Reference

#include <TrackedPtr.h>

Public Member Functions

 TrackedPtr (const TrackedPtr &)=delete
 
TrackedPtroperator= (const TrackedPtr &)=delete
 
T * release ()
 
T * get ()
 

Static Public Member Functions

template<typename... Args>
static TrackedPtr< T > * make (std::vector< std::unique_ptr< TrackedPtr< T >>> &tracked_ptrs, Args &&... args)
 
static TrackedPtr< T > * makeEmpty ()
 

Private Member Functions

 TrackedPtr ()
 
 TrackedPtr (Node *node)
 
 TrackedPtr (const std::string &str)
 
 TrackedPtr (const char *str, size_t len)
 

Private Attributes

std::unique_ptr< T > value_
 
bool is_empty_
 
bool is_released_
 

Detailed Description

template<typename T>
class Parser::TrackedPtr< T >

Class used to ensure ownership of string or Node objects that are dynamically allocated within the parser.

Template Parameters
T- std::string or Node type

Definition at line 30 of file TrackedPtr.h.

Constructor & Destructor Documentation

◆ TrackedPtr() [1/5]

template<typename T>
Parser::TrackedPtr< T >::TrackedPtr ( const TrackedPtr< T > &  )
delete

◆ TrackedPtr() [2/5]

template<typename T>
Parser::TrackedPtr< T >::TrackedPtr ( )
inlineprivate

Definition at line 92 of file TrackedPtr.h.

92 : is_empty_(true), is_released_(false){};

◆ TrackedPtr() [3/5]

template<typename T>
Parser::TrackedPtr< T >::TrackedPtr ( Node node)
inlineprivate

Definition at line 94 of file TrackedPtr.h.

95  : value_(std::unique_ptr<Node>(node)), is_empty_(false), is_released_(false) {}
std::unique_ptr< T > value_
Definition: TrackedPtr.h:88

◆ TrackedPtr() [4/5]

template<typename T>
Parser::TrackedPtr< T >::TrackedPtr ( const std::string &  str)
inlineprivate

Definition at line 97 of file TrackedPtr.h.

98  : value_(std::make_unique<std::string>(str))
99  , is_empty_(false)
100  , is_released_(false) {}
std::unique_ptr< T > value_
Definition: TrackedPtr.h:88

◆ TrackedPtr() [5/5]

template<typename T>
Parser::TrackedPtr< T >::TrackedPtr ( const char *  str,
size_t  len 
)
inlineprivate

Definition at line 102 of file TrackedPtr.h.

103  : value_(std::make_unique<std::string>(str, len))
104  , is_empty_(false)
105  , is_released_(false) {}
std::unique_ptr< T > value_
Definition: TrackedPtr.h:88

Member Function Documentation

◆ get()

template<typename T>
T* Parser::TrackedPtr< T >::get ( )
inline

Returns a pointer to contained string or Node value.

Definition at line 54 of file TrackedPtr.h.

References Parser::TrackedPtr< T >::is_empty_, and Parser::TrackedPtr< T >::value_.

Referenced by Parser::TrackedPtr< T >::make().

54  {
55  if (is_empty_) {
56  return nullptr;
57  }
58  return value_.get();
59  }
std::unique_ptr< T > value_
Definition: TrackedPtr.h:88
+ Here is the caller graph for this function:

◆ make()

template<typename T>
template<typename... Args>
static TrackedPtr<T>* Parser::TrackedPtr< T >::make ( std::vector< std::unique_ptr< TrackedPtr< T >>> &  tracked_ptrs,
Args &&...  args 
)
inlinestatic

Creates an instance of a TrackedPtr and returns a pointer to created instance.

Parameters
tracked_ptrs- TrackedPtr unique pointer vector, which takes ownership of dynamically allocated objects.
args- Arguments to be used when creating contained string or Node values.
Returns
- pointer to created TrackedPtr

Definition at line 70 of file TrackedPtr.h.

References run_benchmark_import::args, and Parser::TrackedPtr< T >::get().

71  {
72  std::unique_ptr<TrackedPtr<T>> tracked_ptr{
73  new TrackedPtr<T>(std::forward<Args>(args)...)};
74  const auto& ptr = tracked_ptrs.emplace_back(std::move(tracked_ptr));
75  return ptr.get();
76  }
+ Here is the call graph for this function:

◆ makeEmpty()

template<typename T>
static TrackedPtr<T>* Parser::TrackedPtr< T >::makeEmpty ( )
inlinestatic

Returns a pointer to a TrackedPtr instance that represents an empty TrackedPtr.

Definition at line 81 of file TrackedPtr.h.

81  {
82  static std::unique_ptr<TrackedPtr<T>> empty_tracked_ptr_ =
83  std::unique_ptr<TrackedPtr<T>>(new TrackedPtr<T>());
84  return empty_tracked_ptr_.get();
85  }

◆ operator=()

template<typename T>
TrackedPtr& Parser::TrackedPtr< T >::operator= ( const TrackedPtr< T > &  )
delete

◆ release()

template<typename T>
T* Parser::TrackedPtr< T >::release ( )
inline

Releases ownership of contained string or Node value and returns a pointer to contained value.

Definition at line 42 of file TrackedPtr.h.

References CHECK, Parser::TrackedPtr< T >::is_empty_, Parser::TrackedPtr< T >::is_released_, and Parser::TrackedPtr< T >::value_.

42  {
43  if (is_empty_) {
44  return nullptr;
45  }
47  is_released_ = true;
48  return value_.release();
49  }
std::unique_ptr< T > value_
Definition: TrackedPtr.h:88
#define CHECK(condition)
Definition: Logger.h:197

Member Data Documentation

◆ is_empty_

template<typename T>
bool Parser::TrackedPtr< T >::is_empty_
private

◆ is_released_

template<typename T>
bool Parser::TrackedPtr< T >::is_released_
private

◆ value_

template<typename T>
std::unique_ptr<T> Parser::TrackedPtr< T >::value_
private

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