36#ifndef TYPE_HOLDER_H_INCLUDED
37#define TYPE_HOLDER_H_INCLUDED
40#include "memutils/common_utils/common_types.h"
41#include "memutils/common_utils/common_assert.h"
42#include "memutils/message/AssertInfo.h"
46#define GET_TYPE_ID(type) (&TypeHolder<type>::type_size)
55 typedef size_t (*id_t)();
60 bool is_type()
const {
return this->id() == GET_TYPE_ID(T); }
64 D_ASSERT2(this->is_type<T>(),
65 AssertParamLog(AssertIdTypeUnmatch, (uint32_t)this->
id(), (uint32_t)GET_TYPE_ID(T)));
70 const T& get()
const {
71 D_ASSERT2(this->is_type<T>(),
72 AssertParamLog(AssertIdTypeUnmatch, (uint32_t)this->
id(), (uint32_t)GET_TYPE_ID(T)));
77 T& get_any(
bool size_check =
true) {
79 D_ASSERT2(
sizeof(T) <= this->size(),
86 const T& get_any(
bool size_check =
true)
const {
88 D_ASSERT2(
sizeof(T) <= this->size(),
94 size_t size()
const {
return this->id()(); }
97 size_t sz = this->size();
98 const unsigned char* data = &get_any<unsigned char>();
99 printf(
"size:%u, id:%p, data: ", sz, this->
id());
100 for (
size_t i = 0; i < MIN(sz, 16); ++i) {
101 printf(
"%02x ", data[i]);
106 virtual id_t id()
const = 0;
108#ifdef USE_TYPE_HOLDER_ACTION_API
111 virtual void* action(
void*) {
return 0; }
112 virtual void* action(
void*)
const {
return 0; }
126 static size_t type_size() {
return sizeof(T); }
129 explicit TypeHolder(
const T& data) : m_held(data) {}
131 T& get() {
return m_held; }
132 const T& get()
const {
return m_held; }
138 virtual id_t id()
const {
return &type_size; }
Definition: type_holder.h:53
Definition: type_holder.h:122
Definition: AssertInfo.h:210