Templatious
 All Classes Functions Pages
Public Member Functions | Protected Member Functions | List of all members
templatious::VirtualPack Struct Referenceabstract

#include <VirtualPack.hpp>

Inheritance diagram for templatious::VirtualPack:
templatious::VirtualPackImpl< coreBitmask, T >

Public Member Functions

virtual int size () const =0
 
virtual const std::type_index & typeAt (int i) const =0
 
virtual bool constAt (int i) const =0
 
virtual int useCount () const =0
 
template<class... Args>
bool matchesSignature () const
 
template<class... Args, class F >
void callFunction (F &&f)
 
template<class... Args, class F >
void callFunction (F &&f) const
 
template<class... Args, class F >
bool tryCallFunction (F &&f)
 
template<class... Args, class F >
bool tryCallFunction (F &&f) const
 
size_t getHash () const
 

Protected Member Functions

 VirtualPack (size_t hash)
 
virtual void dumpAddresses (void **arr) const =0
 
virtual void dumpMetaInfo (PackMetaInfo &out) const =0
 
virtual std::mutex * mutexPtr () const =0
 
virtual void invokeCallback () const =0
 

Detailed Description

The main purpose of this class is to encapsulate any kind of values into tuple form that can be passed around at runtime and used. Uses std::type_index to differentiate the classes. Stores everything by copy.

Member Function Documentation

template<class... Args, class F >
void templatious::VirtualPack::callFunction ( F &&  f)
inline

Call function for this pack with specified signature. If specified signature doesn't match this pack throws an exception.

Parameters
[in]fFunction to call if signature matches.
[in]ArgsSignature arguments. If signature matches these are what will be expanded into function.

Example:

auto p = SF::vpack<int,long>(1,2);
// signature has to match exactly
// for call to succeed (with exception
// that const can bind to non const)
p.callFunction<const int,long>(
[](const int& a,long b) {
std::cout << "Call succeeded!" << std::endl;
}
);
// prints out:
// Call succeeded!
template<class... Args, class F >
void templatious::VirtualPack::callFunction ( F &&  f) const
inline

Call function for this pack with specified signature. If specified signature doesn't match this pack throws an exception.

Parameters
[in]fFunction to call if signature matches.
[in]ArgsSignature arguments. If signature matches these are what will be expanded into function.

Example:

auto p = SF::vpack<int,long>(1,2);
// signature has to match exactly
// for call to succeed (with exception
// that const can bind to non const)
p.callFunction<const int,long>(
[](const int& a,long b) {
std::cout << "Call succeeded!" << std::endl;
}
);
// prints out:
// Call succeeded!
virtual bool templatious::VirtualPack::constAt ( int  i) const
pure virtual

Check if nth element is const in the pack.

Parameters
[in]iWhich element to check.

Implemented in templatious::VirtualPackImpl< coreBitmask, T >.

size_t templatious::VirtualPack::getHash ( ) const
inline

Get hash of this pack.

template<class... Args>
bool templatious::VirtualPack::matchesSignature ( ) const
inline

Check if the specified signature matches this pack.

Parameters
[in]Argssignature to check. Has to contain raw types without references. Const qualifiers allowed.

Example:

auto p = SF::vpack<const int,long>(1,2);
bool aMatch = p.matchesSignature<int,long>();
bool bMatch = p.matchesSignature<const int,long>();
bool cMatch = p.matchesSignature<const int,const long>();
bool dMatch = p.matchesSignature<const int>();
bool eMatch = p.matchesSignature<char>();
assert( !aMatch );
assert( bMatch );
assert( cMatch );
assert( !dMatch );
assert( !eMatch );
virtual int templatious::VirtualPack::size ( ) const
pure virtual

Return size of the pack in elements.

Implemented in templatious::VirtualPackImpl< coreBitmask, T >.

template<class... Args, class F >
bool templatious::VirtualPack::tryCallFunction ( F &&  f)
inline

Try to call function for this pack with specified signature. If specified signature doesn't match this pack returned value is false, if the call succeeds returns true.

Parameters
[in]fFunction to call if signature matches.
[in]ArgsSignature arguments. If signature matches these are what will be expanded into function.

Example:

auto p = SF::vpack<int,long>(1,2);
// signature has to match exactly
// for call to succeed (with exception
// that const can bind to non const)
bool matched = p.tryCallFunction<const int,long>(
[](const int& a,long b) {
std::cout << "Call succeeded!" << std::endl;
}
);
// prints out:
// Call succeeded!
assert( matched );
template<class... Args, class F >
bool templatious::VirtualPack::tryCallFunction ( F &&  f) const
inline

Try to call function for this pack with specified signature. If specified signature doesn't match this pack returned value is false, if the call succeeds returns true.

Parameters
[in]fFunction to call if signature matches.
[in]ArgsSignature arguments. If signature matches these are what will be expanded into function.

Example:

auto p = SF::vpack<int,long>(1,2);
// signature has to match exactly
// for call to succeed (with exception
// that const can bind to non const)
bool matched = p.tryCallFunction<const int,long>(
[](const int& a,long b) {
std::cout << "Call succeeded!" << std::endl;
}
);
// prints out:
// Call succeeded!
assert( matched );
virtual const std::type_index& templatious::VirtualPack::typeAt ( int  i) const
pure virtual

Return std::type_index of nth element in the pack.

Parameters
[in]iWhich element to check.

Implemented in templatious::VirtualPackImpl< coreBitmask, T >.

virtual int templatious::VirtualPack::useCount ( ) const
pure virtual

Check how many times this pack was used when expanding into function.

Implemented in templatious::VirtualPackImpl< coreBitmask, T >.


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