LLVM  6.0.0svn
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::PointerUnion< PT1, PT2 > Class Template Reference

A discriminated union of two pointer types, with the discriminator in the low bit of the pointer. More...

#include "llvm/ADT/PointerUnion.h"

Inheritance diagram for llvm::PointerUnion< PT1, PT2 >:
Inheritance graph
[legend]

Public Types

using ValTy = PointerIntPair< void *, 1, bool, PointerUnionUIntTraits< PT1, PT2 > >
 

Public Member Functions

 PointerUnion ()=default
 
 PointerUnion (PT1 V)
 
 PointerUnion (PT2 V)
 
bool isNull () const
 Test if the pointer held in the union is null, regardless of which type it is. More...
 
 operator bool () const
 
template<typename T >
int is () const
 Test if the Union currently holds the type matching T. More...
 
template<typename T >
T get () const
 Returns the value of the specified pointer type. More...
 
template<typename T >
T dyn_cast () const
 Returns the current pointer if it is of the specified pointer type, otherwises returns null. More...
 
PT1 constgetAddrOfPtr1 () const
 If the union is set to the first pointer type get an address pointing to it. More...
 
PT1 * getAddrOfPtr1 ()
 If the union is set to the first pointer type get an address pointing to it. More...
 
const PointerUnionoperator= (std::nullptr_t)
 Assignment from nullptr which just clears the union. More...
 
const PointerUnionoperator= (const PT1 &RHS)
 Assignment operators - Allow assigning into this union from either pointer type, setting the discriminator to remember what it came from. More...
 
const PointerUnionoperator= (const PT2 &RHS)
 
void * getOpaqueValue () const
 

Static Public Member Functions

static PointerUnion getFromOpaqueValue (void *VP)
 

Detailed Description

template<typename PT1, typename PT2>
class llvm::PointerUnion< PT1, PT2 >

A discriminated union of two pointer types, with the discriminator in the low bit of the pointer.

This implementation is extremely efficient in space due to leveraging the low bits of the pointer, while exposing a natural and type-safe API.

Common use patterns would be something like this: PointerUnion<int*, float*> P; P = (int*)0; printf("%d %d", P.is<int*>(), P.is<float*>()); // prints "1 0" X = P.get<int*>(); // ok. Y = P.get<float*>(); // runtime assertion failure. Z = P.get<double*>(); // compile time failure. P = (float*)0; Y = P.get<float*>(); // ok. X = P.get<int*>(); // runtime assertion failure.

Definition at line 87 of file PointerUnion.h.

Member Typedef Documentation

◆ ValTy

template<typename PT1, typename PT2>
using llvm::PointerUnion< PT1, PT2 >::ValTy = PointerIntPair<void *, 1, bool, PointerUnionUIntTraits<PT1, PT2> >

Definition at line 90 of file PointerUnion.h.

Constructor & Destructor Documentation

◆ PointerUnion() [1/3]

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion ( )
default

◆ PointerUnion() [2/3]

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion ( PT1  V)
inline

Definition at line 105 of file PointerUnion.h.

◆ PointerUnion() [3/3]

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion ( PT2  V)
inline

Definition at line 108 of file PointerUnion.h.

Member Function Documentation

◆ dyn_cast()

template<typename PT1, typename PT2>
template<typename T >
T llvm::PointerUnion< PT1, PT2 >::dyn_cast ( ) const
inline

◆ get()

template<typename PT1, typename PT2>
template<typename T >
T llvm::PointerUnion< PT1, PT2 >::get ( ) const
inline

◆ getAddrOfPtr1() [1/2]

template<typename PT1, typename PT2>
PT1 const* llvm::PointerUnion< PT1, PT2 >::getAddrOfPtr1 ( ) const
inline

◆ getAddrOfPtr1() [2/2]

template<typename PT1, typename PT2>
PT1* llvm::PointerUnion< PT1, PT2 >::getAddrOfPtr1 ( )
inline

If the union is set to the first pointer type get an address pointing to it.

Definition at line 156 of file PointerUnion.h.

◆ getFromOpaqueValue()

template<typename PT1, typename PT2>
static PointerUnion llvm::PointerUnion< PT1, PT2 >::getFromOpaqueValue ( void *  VP)
inlinestatic

◆ getOpaqueValue()

template<typename PT1, typename PT2>
void* llvm::PointerUnion< PT1, PT2 >::getOpaqueValue ( ) const
inline

◆ is()

template<typename PT1, typename PT2>
template<typename T >
int llvm::PointerUnion< PT1, PT2 >::is ( ) const
inline

◆ isNull()

template<typename PT1, typename PT2>
bool llvm::PointerUnion< PT1, PT2 >::isNull ( ) const
inline

◆ operator bool()

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::operator bool ( ) const
inlineexplicit

Definition at line 120 of file PointerUnion.h.

◆ operator=() [1/3]

template<typename PT1, typename PT2>
const PointerUnion& llvm::PointerUnion< PT1, PT2 >::operator= ( std::nullptr_t  )
inline

Assignment from nullptr which just clears the union.

Definition at line 166 of file PointerUnion.h.

◆ operator=() [2/3]

template<typename PT1, typename PT2>
const PointerUnion& llvm::PointerUnion< PT1, PT2 >::operator= ( const PT1 &  RHS)
inline

Assignment operators - Allow assigning into this union from either pointer type, setting the discriminator to remember what it came from.

Definition at line 173 of file PointerUnion.h.

◆ operator=() [3/3]

template<typename PT1, typename PT2>
const PointerUnion& llvm::PointerUnion< PT1, PT2 >::operator= ( const PT2 &  RHS)
inline

Definition at line 178 of file PointerUnion.h.


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