#include <wipal/tool/static_base.hh>
Public Types | |
typedef HIDDEN | exact_type |
Public Member Functions | |
Downcast methods | |
const exact_type & | exact () const |
exact_type & | exact () |
const exact_type * | exact_ptr () const |
exact_type * | exact_ptr () |
A static hierarchy is a class hierarchy within which each class knows its exact type thanks to specific template parameters.
E.g.
static_base<cow> : animal<cow> : mammal<cow> : cow
static_base's main role is to provide the exact() and exact_ptr() methods. These methods allow intermediate classes in the hierarchy to static_cast
themselves directly to their exact type. This is perfectly type safe.
E.g.
template <class Exact> void animal<Exact>::eat() { this->exact().eat_impl(); // Delegate eat() to Exact::eat_impl(). }
In the previous example however, one cannot subclass cow
because it has no Exact
parametter. Use the bottom class to solve this issue:
static_base<cow<bottom>> : animal<cow<bottom>> : mammal<cow<bottom>> : cow<bottom> or static_base<highland_cow<bottom>> : animal<highland_cow<bottom>> : mammal<highland_cow<bottom>> : cow<highland_cow<bottom>> : highland_cow<bottom>
In this example however, cow
must provide to mammal
either highland_cow<bottom>
either cow<bottom>
, depending on its template parameter. This is done using the get_exact trait:
template <class Bottom> struct cow: public mammal<typename get_exact< Bottom, cow<Bottom> >::return_type> { // Inherit mammal<cow<bottom>> if Bottom = bottom, // inherit mammal<Bottom>, else. // ... };
For simple cases, we provide the WP_GET_EXACT
() and WP_INHERIT
() preprocessor macros:
template <class Bottom> struct cow: WP_INHERIT(public mammal, cow<Bottom>) { typedef WP_GET_EXACT(Bottom, cow<Bottom>) exact_type; // ... };
typedef HIDDEN tool::static_base< Bottom >::exact_type |
Exact type for this template instanciation.
Reimplemented in pcapxx::descriptor< Bottom >, pcapxx::internals::frame_iterator< Descriptor, Bottom >, avs::header, phy::empty_time< Bottom >, phy::empty_header< Bottom >, phy::time< Bottom >, phy::uint64_time< Bottom >, phy::header< Bottom >, prism::time, prism::header, rtap::header, tool::iterable< Bottom >, tool::iterator< Bottom >, tool::valued_iterator< Bottom >, tool::window< InputIterator, WSize, Step, Bottom >, wifi::frame::filter::internals::non_noisy_prism_iterator< I, B, Bottom >, wifi::frame::filter::internals::uniquely_identifiable_iterator< U, I, H, B, Bottom >, wifi::time_converter< PhyHeaderType, Bottom >, phy::time< prism::time >, phy::header< rtap::header >, phy::header< prism::header >, phy::header< avs::header >, tool::iterable< internals::SI_unit< 8 > >, tool::iterable< HIDDEN >, tool::iterator< HIDDEN >, tool::valued_iterator< HIDDEN >, and wifi::time_converter< HeaderType >.
const static_base< Bottom >::exact_type & tool::static_base< Bottom >::exact | ( | ) | const [inline] |
Safely downcast to the exact type as a const reference.
Referenced by tool::iterable< Bottom >::begin(), phy::header< Bottom >::decapsulate(), tool::iterable< Bottom >::end(), phy::time< Bottom >::get(), phy::header< Bottom >::len(), phy::time< Bottom >::operator+(), phy::header< Bottom >::time_get(), and phy::header< Bottom >::time_set().
static_base< Bottom >::exact_type & tool::static_base< Bottom >::exact | ( | ) | [inline] |
Safely downcast to the exact type as a non-const reference.
const static_base< Bottom >::exact_type * tool::static_base< Bottom >::exact_ptr | ( | ) | const [inline] |
Safely downcast to the exact type as a const pointer.
Referenced by pcapxx::frame_descriptor< PCAPDescriptor >::frame_descriptor().
static_base< Bottom >::exact_type * tool::static_base< Bottom >::exact_ptr | ( | ) | [inline] |
Safely downcast to the exact type as a non-const pointer.