使用C++20的std::source_location代替自定义的实现
This commit is contained in:
parent
fff021488c
commit
098b87d8ce
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include<hgl/platform/Platform.h>
|
|
||||||
|
|
||||||
namespace hgl
|
|
||||||
{
|
|
||||||
struct SourceCodeLocation
|
|
||||||
{
|
|
||||||
const char * file; ///<源文件
|
|
||||||
size_t line; ///<行号
|
|
||||||
const char * func; ///<函数
|
|
||||||
};
|
|
||||||
|
|
||||||
#define HGL_SOURCE_CODE_LOCATION __FILE__,__LINE__,__HGL_FUNC__
|
|
||||||
|
|
||||||
#define HGL_SCL_HERE SourceCodeLocation(HGL_SOURCE_CODE_LOCATION)
|
|
||||||
}//namespace hgl
|
|
@ -1,9 +1,8 @@
|
|||||||
#ifndef HGL_LOGINFO_INCLUDE
|
#pragma once
|
||||||
#define HGL_LOGINFO_INCLUDE
|
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
#include<source_location>
|
||||||
#include<hgl/CodePage.h>
|
#include<hgl/CodePage.h>
|
||||||
#include<hgl/SourceCodeLocation.h>
|
|
||||||
#include<hgl/log/LogLevel.h>
|
#include<hgl/log/LogLevel.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
@ -32,14 +31,22 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
#endif//HGL_SUPPORT_CHAR8_T
|
#endif//HGL_SUPPORT_CHAR8_T
|
||||||
|
|
||||||
inline void DebugLog(LogLevel ll,const U16String &str,const char *filename,int line,const char *funcname)
|
inline void DebugLog(LogLevel ll,const U16String &str,const std::source_location scl)
|
||||||
{
|
{
|
||||||
Log(ll,str+U16_TEXT(">>LogFrom(\"")+to_u16((u8char *)filename)+U16_TEXT("\", ")+U16String::numberOf(line)+U16_TEXT(" line,func:\"")+to_u16((u8char *)funcname)+U16_TEXT("\")"));
|
Log(ll,str+U16_TEXT(">>LogFrom(\"")+
|
||||||
|
to_u16((u8char *)scl.file_name())+U16_TEXT("\", (")+
|
||||||
|
U16String::numberOf(scl.line())+U16_TEXT(",")+
|
||||||
|
U16String::numberOf(scl.column())+U16_TEXT(") ,func:\"")+
|
||||||
|
to_u16((u8char *)scl.function_name())+U16_TEXT("\")"));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DebugLog(LogLevel ll,const U8String &str,const char *filename,int line,const char *funcname)
|
inline void DebugLog(LogLevel ll,const U8String &str,const std::source_location scl)
|
||||||
{
|
{
|
||||||
Log(ll,str+U8_TEXT(">>LogFrom(\"")+U8String((u8char *)filename)+U8_TEXT("\", ")+U8String::numberOf(line)+U8_TEXT(" line,func:\"")+U8String((u8char *)funcname)+U8_TEXT("\")"));
|
Log(ll,str+U8_TEXT(">>LogFrom(\"")+
|
||||||
|
U8String((u8char *)scl.file_name())+U8_TEXT("\",(")+
|
||||||
|
U8String::numberOf(scl.line())+U8_TEXT(",")+
|
||||||
|
U8String::numberOf(scl.column())+U8_TEXT(") ,func:\"")+
|
||||||
|
U8String((u8char *)scl.function_name())+U8_TEXT("\")"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_INFO(str) {Log(LogLevel::Info, str);}
|
#define LOG_INFO(str) {Log(LogLevel::Info, str);}
|
||||||
@ -47,9 +54,9 @@ namespace hgl
|
|||||||
#define LOG_PROBLEM(str) {Log(LogLevel::Warning, str);}
|
#define LOG_PROBLEM(str) {Log(LogLevel::Warning, str);}
|
||||||
#define LOG_ERROR(str) {Log(LogLevel::Error, str);}
|
#define LOG_ERROR(str) {Log(LogLevel::Error, str);}
|
||||||
|
|
||||||
#define RETURN_FALSE {DebugLog(LogLevel::Verbose,OS_TEXT("return(false)"), __FILE__,__LINE__,__HGL_FUNC__);return(false);}
|
#define RETURN_FALSE {DebugLog(LogLevel::Verbose,OS_TEXT("return(false)"), std::source_location::current());return(false);}
|
||||||
#define RETURN_ERROR(v) {DebugLog(LogLevel::Info, OS_TEXT("return error(")+OSString::numberOf(v)+OS_TEXT(")"),__FILE__,__LINE__,__HGL_FUNC__);return(v);}
|
#define RETURN_ERROR(v) {DebugLog(LogLevel::Info, OS_TEXT("return error(")+OSString::numberOf(v)+OS_TEXT(")"),std::source_location::current());return(v);}
|
||||||
#define RETURN_ERROR_NULL {DebugLog(LogLevel::Info, OS_TEXT("return error(nullptr)"), __FILE__,__LINE__,__HGL_FUNC__);return(nullptr);}
|
#define RETURN_ERROR_NULL {DebugLog(LogLevel::Info, OS_TEXT("return error(nullptr)"), std::source_location::current());return(nullptr);}
|
||||||
|
|
||||||
#define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}
|
#define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}
|
||||||
|
|
||||||
@ -58,4 +65,3 @@ namespace hgl
|
|||||||
|
|
||||||
using namespace logger;
|
using namespace logger;
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_LOGINFO_INCLUDE
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
#include<hgl/type/object/ObjectBaseInfo.h>
|
#include<hgl/type/object/ObjectBaseInfo.h>
|
||||||
#include<hgl/SourceCodeLocation.h>
|
#include<source_location>
|
||||||
|
|
||||||
#include<tsl/robin_map.h>
|
#include<tsl/robin_map.h>
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ namespace hgl
|
|||||||
#define HGL_OBJECT_CONSTRUCT(class_name) class_name(const ObjectBaseInfo &obi):Object(obi){}
|
#define HGL_OBJECT_CONSTRUCT(class_name) class_name(const ObjectBaseInfo &obi):Object(obi){}
|
||||||
#define HGL_OBJECT_CONSTRUCT_SC(class_name,super_class) class_name(const ObjectBaseInfo &obi):super_class(obi){}
|
#define HGL_OBJECT_CONSTRUCT_SC(class_name,super_class) class_name(const ObjectBaseInfo &obi):super_class(obi){}
|
||||||
|
|
||||||
template<typename T> inline T *NewObjectSCL(const SourceCodeLocation &scl)
|
template<typename T> inline T *NewObjectSCL(const std::source_location scl=std::source_location::current())
|
||||||
{
|
{
|
||||||
static size_t new_count=0;
|
static size_t new_count=0;
|
||||||
|
|
||||||
@ -104,5 +104,5 @@ namespace hgl
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NewObject(type) NewObjectSCL<type>(HGL_SCL_HERE)
|
#define NewObject(type) NewObjectSCL<type>(std::source_location::current())
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/SourceCodeLocation.h>
|
#include<source_location>
|
||||||
#include<typeinfo>
|
#include<typeinfo>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
@ -13,7 +13,7 @@ namespace hgl
|
|||||||
const std::type_info *info; ///<对象数据类型的type_info指针
|
const std::type_info *info; ///<对象数据类型的type_info指针
|
||||||
size_t unique_id; ///<唯一序列号
|
size_t unique_id; ///<唯一序列号
|
||||||
|
|
||||||
SourceCodeLocation scl;
|
std::source_location scl; ///<对象创建位置
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ObjectTypeInfo
|
struct ObjectTypeInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user