#pragma once #include "../../common/compat.hpp" namespace sprawl { template class MemberAccessor { public: typedef KeyType key_type; struct arg_type {}; MemberAccessor(ValueType& value) : m_value(&value) { // } inline KeyType const Key() const { return (m_value->*function)(); } inline ValueType& Value() { return *m_value; } inline ValueType const& Value() const { return *m_value; } private: ValueType* m_value; }; template class ConstMemberAccessor { public: typedef KeyType key_type; struct arg_type {}; ConstMemberAccessor(ValueType& value) : m_value(&value) { // } inline KeyType const Key() const { return (m_value->*function)(); } inline ValueType& Value() { return *m_value; } inline ValueType const& Value() const { return *m_value; } private: ValueType* m_value; }; template class PtrMemberAccessor { public: typedef KeyType key_type; struct arg_type {}; PtrMemberAccessor(PointerType& value) : m_value(&value) { // } inline KeyType const Key() const { return ((*(*m_value)).*function)(); } inline PointerType& Value() { return *m_value; } inline PointerType const& Value() const { return *m_value; } private: PointerType* m_value; }; template class PtrConstMemberAccessor { public: typedef KeyType key_type; struct arg_type {}; PtrConstMemberAccessor(PointerType& value) : m_value(&value) { // } inline KeyType const Key() const { return ((*m_value).*function)(); } inline PointerType& Value() { return *m_value; } inline PointerType const& Value() const { return *m_value; } private: PointerType* m_value; }; template class FunctionAccessor { public: typedef KeyType key_type; struct arg_type {}; FunctionAccessor(ValueType& value) : m_value(&value) { // } inline KeyType const Key() const { return (*function)(m_value); } inline ValueType& Value() { return *m_value; } inline ValueType const& Value() const { return *m_value; } private: ValueType* m_value; }; template class PtrFunctionAccessor { public: typedef KeyType key_type; struct arg_type {}; PtrFunctionAccessor(PointerType& value) : m_value(&value) { // } inline KeyType const Key() const { return (*function)(&(*(*m_value))); } inline PointerType& Value() { return *m_value; } inline PointerType const& Value() const { return *m_value; } private: mutable PointerType* m_value; }; template class KeyAccessor { public: typedef KeyType key_type; typedef KeyType arg_type; KeyAccessor(ValueType& value, KeyType const& key) : m_key(key) , m_value(&value) { // } inline KeyType const& Key() const { return m_key; } inline ValueType& Value() { return *m_value; } inline ValueType const& Value() const { return *m_value; } private: KeyType m_key; ValueType* m_value; }; template class SelfAccessor { public: typedef ValueType key_type; struct arg_type {}; SelfAccessor(ValueType& value) : m_value(&value) { // } inline ValueType const& Key() const { return *m_value; } inline ValueType& Value() { return *m_value; } inline ValueType const& Value() const { return *m_value; } private: ValueType* m_value; }; class NullAccessor { public: typedef void* key_type; struct arg_type {}; inline void* Key() { return nullptr; } }; }