Skip to content

Latest commit

 

History

History
108 lines (82 loc) · 3.97 KB

metapointerwrapper.md

File metadata and controls

108 lines (82 loc) · 3.97 KB

MetaPointerWrapper interface

Overview

MetaPointerWrapper is a meta interface to get and set pointer in pointer wrapper.
Pointer wrapper is a pointer like object that behaves similar to a pointer.
The smart pointers std::shared_ptr and std::unique_ptr are pointer wrappers.

Header

#include "metapp/interfaces/metapointerwrapper.h"

Get MetaPointerWrapper interface

We can call MetaType::getMetaPointerWrapper() to get the MetaPointerWrapper interface. If the type doesn't implement the interface, nullptr is returned.

const metapp::MetaType * metaType = metapp::getMetaType<std::shared_ptr<int> >();
const metapp::MetaPointerWrapper * metaAccessible = metaType->getMetaPointerWrapper();

Implemented built-in meta types

std::shared_ptr (tkStdSharedPtr)
std::unique_ptr (tkStdUniquePtr)

MetaPointerWrapper constructor

MetaPointerWrapper(
  Variant (*getPointer)(const Variant & pointerWrapper),
  void (*setPointer)(const Variant & pointerWrapper, const Variant & pointer)
);

All arguments are function pointers. All pointers must point to valid function.
The meaning of each functions are same as the member functions listed below.

MetaPointerWrapper member functions

The first parameter in all of the member functions is const Variant & pointerWrapper. It's the Variant which meta type implements MetaPointerWrapper, and hold the proper data such as std::shared_ptr. The member functions operate on the data.
We can treat pointerWrapper as the C++ object instance which class implements an interface called MetaPointerWrapper.
Variant pointerWrapper can be value that implements MetaPointerWrapper, or reference that refers to value that implements MetaPointerWrapper.

getPointer

Variant getPointer(const Variant & pointerWrapper);

Returns the underlying pointer. It's similar to the .get() function in std::shared_ptr and std::unique_ptr.
The returned Variant holds the pointer, and the property meta type and const-volatile information for the pointer.

setPointer

void setPointer(const Variant & pointerWrapper, const Variant & pointer);

Sets the underlying pointer. It's similar to the .reset() function in std::shared_ptr and std::unique_ptr.

Non-member utility functions

Below free functions are shortcut functions to use the member functions in MetaPointerWrapper.
Usually you should prefer the utility functions to calling MetaPointerWrapper member function directly. However, if you need to call functions on a single MetaPointerWrapper more than one times in a high performance application, you may store pointerWrapper.getMetaType()->getMetaPointerWrapper() to a local variable, then use the variable to call the member functions. This is because getMetaPointerWrapper() has slightly performance overhead (the overhead is neglect most time).

inline Variant pointerWrapperGetPointer(const Variant & pointerWrapper)
{
  return getNonReferenceMetaType(pointerWrapper)->getMetaPointerWrapper()->getPointer(pointerWrapper);
}

inline void pointerWrapperSetPointer(const Variant & pointerWrapper, const Variant & pointer)
{
  getNonReferenceMetaType(pointerWrapper)->getMetaPointerWrapper()->setPointer(pointerWrapper, pointer);
}