nixd
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
nixt::PtrPool< T > Struct Template Reference

A simple pointer pool, a vector of unique_ptrs. More...

#include <PtrPool.h>

Public Member Functions

template<class U >
U * add (std::unique_ptr< U > Node)
 Takes ownership of a node, add it to the pool.
 
template<class U >
U * record (U *Node)
 Takes ownership from a raw pointer.
 

Public Attributes

std::vector< std::unique_ptr< T > > Nodes
 

Detailed Description

template<class T>
struct nixt::PtrPool< T >

A simple pointer pool, a vector of unique_ptrs.

It is used for "owning" nodes. Other classes can use weak/raw pointers to the nodes, to avoid cyclic references.

Also in nix AST, the nodes are not owned by it's parent because in bison algorithm nodes should be copyable while performing shift-reduce. So in our implementation nodes are owned in this structure.

Definition at line 22 of file PtrPool.h.

Member Function Documentation

◆ add()

template<class T >
template<class U >
U * nixt::PtrPool< T >::add ( std::unique_ptr< U > Node)
inline

Takes ownership of a node, add it to the pool.

Definition at line 26 of file PtrPool.h.

References nixt::PtrPool< T >::Nodes.

◆ record()

template<class T >
template<class U >
U * nixt::PtrPool< T >::record ( U * Node)
inline

Takes ownership from a raw pointer.

Note
This should only be used when it is allocated by "malloc", and not owned by other objects (otherwise it will cause double free).

Definition at line 35 of file PtrPool.h.

References nixt::PtrPool< T >::Nodes.

Member Data Documentation

◆ Nodes

template<class T >
std::vector<std::unique_ptr<T> > nixt::PtrPool< T >::Nodes

Definition at line 23 of file PtrPool.h.

Referenced by nixt::PtrPool< T >::add(), and nixt::PtrPool< T >::record().


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