Remove ClassTraits.h (#235)

This commit is contained in:
An Tao 2019-09-07 21:00:51 +08:00 committed by GitHub
parent 195bc5299e
commit 5d3fda57a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 56 deletions

View File

@ -394,7 +394,6 @@ set(ORM_HEADERS
install(FILES ${ORM_HEADERS} DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/orm)
set(DROGON_UTIL_HEADERS
lib/inc/drogon/utils/ClassTraits.h
lib/inc/drogon/utils/FunctionTraits.h
lib/inc/drogon/utils/Utilities.h
lib/inc/drogon/utils/any.h

View File

@ -14,7 +14,6 @@
#pragma once
#include <drogon/utils/ClassTraits.h>
#include <trantor/utils/Logger.h>
#include <functional>
#include <memory>
@ -22,6 +21,8 @@
#include <thread>
#include <unordered_map>
#include <vector>
#include <type_traits>
#include <cstdlib>
#include <cxxabi.h>
#include <stdio.h>
@ -73,7 +74,7 @@ class DrClassMap
template <typename T>
static std::shared_ptr<T> getSingleInstance()
{
static_assert(internal::IsSubClass<T, DrObjectBase>::value,
static_assert(std::is_base_of<DrObjectBase, T>::value,
"T must be a sub-class of DrObjectBase");
return std::dynamic_pointer_cast<T>(
getSingleInstance(T::classTypeName()));

View File

@ -23,7 +23,6 @@
#include <drogon/MultiPart.h>
#include <drogon/NotFound.h>
#include <drogon/drogon_callbacks.h>
#include <drogon/utils/ClassTraits.h>
#include <drogon/utils/Utilities.h>
#include <drogon/plugins/Plugin.h>
#include <drogon/HttpRequest.h>
@ -427,11 +426,10 @@ class HttpAppFramework : public trantor::NonCopyable
template <typename T>
HttpAppFramework &registerController(const std::shared_ptr<T> &ctrlPtr)
{
static_assert(
internal::IsSubClass<T, HttpControllerBase>::value ||
internal::IsSubClass<T, HttpSimpleControllerBase>::value ||
internal::IsSubClass<T, WebSocketControllerBase>::value,
"Error! Only controller objects can be registered here");
static_assert((std::is_base_of<HttpControllerBase, T>::value ||
std::is_base_of<HttpSimpleControllerBase, T>::value ||
std::is_base_of<WebSocketControllerBase, T>::value),
"Error! Only controller objects can be registered here");
static_assert(!T::isAutoCreation,
"Controllers created and initialized "
"automatically by drogon cannot be "
@ -448,7 +446,7 @@ class HttpAppFramework : public trantor::NonCopyable
template <typename T>
HttpAppFramework &registerFilter(const std::shared_ptr<T> &filterPtr)
{
static_assert(internal::IsSubClass<T, HttpFilterBase>::value,
static_assert(std::is_base_of<HttpFilterBase, T>::value,
"Error! Only fitler objects can be registered here");
static_assert(!T::isAutoCreation,
"Filters created and initialized "

View File

@ -1,43 +0,0 @@
/**
*
* ClassTraits.h
* An Tao
*
* Copyright 2018, An Tao. All rights reserved.
* https://github.com/an-tao/drogon
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Drogon
*
*/
#pragma once
#include <type_traits>
namespace drogon
{
namespace internal
{
/// This template is used to check whether S is a subclass of B.
template <typename S, typename B>
struct IsSubClass
{
typedef
typename std::remove_cv<typename std::remove_reference<S>::type>::type
SubType;
typedef
typename std::remove_cv<typename std::remove_reference<B>::type>::type
BaseType;
static char test(void *)
{
return 0;
}
static int test(BaseType *)
{
return 0;
}
static const bool value = (sizeof(test((SubType *)nullptr)) == sizeof(int));
};
} // namespace internal
} // namespace drogon

View File

@ -15,7 +15,6 @@
#pragma once
#include <drogon/DrObject.h>
#include <drogon/utils/ClassTraits.h>
#include <functional>
#include <memory>
#include <tuple>
@ -54,7 +53,7 @@ struct FunctionTraits<ReturnType (ClassType::*)(Arguments...) const>
{
static const bool isClassFunction = true;
static const bool isDrObjectClass =
IsSubClass<ClassType, DrObject<ClassType>>::value;
std::is_base_of<DrObject<ClassType>, ClassType>::value;
typedef ClassType class_type;
static const std::string name()
{
@ -69,7 +68,7 @@ struct FunctionTraits<ReturnType (ClassType::*)(Arguments...)>
{
static const bool isClassFunction = true;
static const bool isDrObjectClass =
IsSubClass<ClassType, DrObject<ClassType>>::value;
std::is_base_of<DrObject<ClassType>, ClassType>::value;
typedef ClassType class_type;
static const std::string name()
{