The performance testing code is not written by me! So no questions about it to me please (http://stackoverflow.com/questions/795827/testing-the-performance-of-a-c-app https://stackoverflow.com/questions/795827/testing-the-performance-of-a-c-app).
The performance testing code is not written by me! So no questions about it to me please (http://stackoverflow.com/questions/795827/testing-the-performance-of-a-c-app).
The performance testing code is not written by me! So no questions about it to me please (https://stackoverflow.com/questions/795827/testing-the-performance-of-a-c-app).
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void*& pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void*void*& pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void*& pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void*& pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void* pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void*& pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void*& pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void*& pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void*& pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void*void*& pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void* pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void*void*& pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void* pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void* pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void* pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H
#ifndef ANY_H
#define ANY_H
#include <typeinfo>
namespace mango
{
namespace exception
{
class bad_cast
{};
}
namespace detail
{
template <class T> void killContent(void* target);
template <class T> void reproduceAny(void* target, void*& pool);
}
class Any
{
public:
Any()
: m_Content(new int), m_ContentType(const_cast<std::type_info*>(&typeid(int))), kill(&detail::killContent<int>), reproduceAnyContent(&detail::reproduceAny<int>)
{}
~Any()
{
if (nullptr != m_Content)
{
kill(m_Content);
}
}
template<class T>
operator T&()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
template<class T>
Any(const T& value)
: m_Content(new T(value)), m_ContentType(const_cast<std::type_info*>(&typeid(T))), kill(&detail::killContent<T>), reproduceAnyContent(&detail::reproduceAny<T>)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
}
Any(const Any& C)
: m_Content(nullptr), m_ContentType(nullptr), kill(nullptr), reproduceAnyContent(nullptr)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(C.m_Content, m_Content);
kill = C.kill;
reproduceAnyContent = C.reproduceAnyContent;
m_ContentType = C.m_ContentType;
}
template<class T>
T& operator = (const T& value)
{
if (nullptr == m_Content)
{
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
m_ContentType = const_cast<std::type_info*>(&typeid(T));
if (nullptr != m_Content)
{
kill(m_Content);
}
m_Content = new T(value);
kill = &detail::killContent<T>;
reproduceAnyContent = &detail::reproduceAny<T>;
}
else
{
*static_cast<T*>(m_Content) = value;
}
return *static_cast<T*>(m_Content);
}
Any& operator = (const Any& value)
{
if (nullptr != m_Content)
{
kill(m_Content);
}
reproduceAnyContent(value.m_Content, m_Content);
kill = value.kill;
reproduceAnyContent = value.reproduceAnyContent;
m_ContentType = value.m_ContentType;
return *this;
}
template<class T>
T& get()
{
if (const_cast<std::type_info*>(&typeid(T)) != m_ContentType)
{
throw exception::bad_cast_any();
}
return *static_cast<T*>(m_Content);
}
private:
void* m_Content;
std::type_info* m_ContentType;
void(*kill)(void* target);
void(*reproduceAnyContent)(void* target, void* pool);
};
template<class T>
T any_get(Any& any)
{
return any.get<T>();
}
template<class from, class to>
to any_cast(Any& any)
{
return static_cast<to>(static_cast<from>(any));
}
namespace detail
{
template <class T>
void killContent(void* target)
{
delete static_cast<T*>(target);
}
template <class T>
void reproduceAny(void* target, void*& pool)
{
pool = new T(*static_cast<T*>(target));
}
}
}
#endif //Any_H