增加AutoSCL.cpp测试程序,除展示SourceCodeLocation外,也演示了__VA_OPT__与__VA_ARGS__组合使用. 是NewObject/NewComponent等宏的重要基础
This commit is contained in:
parent
39ae49171e
commit
8ba86a5b1b
@ -27,6 +27,7 @@ endmacro()
|
||||
|
||||
####################################################################################################
|
||||
cm_example_project("Debug" DebugObject debug/DebugObject.cpp)
|
||||
cm_example_project("Debug" AutoSCL debug/AutoSCL.cpp)
|
||||
|
||||
####################################################################################################
|
||||
cm_example_project("DataType/RAM" RuntimeAssetManagerTest datatype/ram/RuntimeAssetManagerTest.cpp
|
||||
|
49
debug/AutoSCL.cpp
Normal file
49
debug/AutoSCL.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
#include<hgl/SourceCodeLocation.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace hgl;
|
||||
|
||||
void out(const string &name,const SourceCodeLocation &scl)
|
||||
{
|
||||
cout<<name<<": "<<scl.file<<" ("<<scl.line<<"): \""<<scl.func<<'"'<<endl;
|
||||
}
|
||||
|
||||
class TestObject
|
||||
{
|
||||
string name;
|
||||
SourceCodeLocation scl;
|
||||
|
||||
public:
|
||||
|
||||
TestObject(const SourceCodeLocation &_scl,const string &n)
|
||||
{
|
||||
name=n;
|
||||
scl=_scl;
|
||||
}
|
||||
|
||||
void out()
|
||||
{
|
||||
::out(name,scl);
|
||||
}
|
||||
};
|
||||
|
||||
#define NewObject(class_name,...) new class_name(HGL_SCL_HERE __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
SourceCodeLocation scl=HGL_SCL_HERE;
|
||||
|
||||
out("C++",scl);
|
||||
|
||||
TestObject to(HGL_SCL_HERE,"TO1");
|
||||
|
||||
to.out();
|
||||
|
||||
auto to2=NewObject(TestObject,"NEW");
|
||||
|
||||
to2->out();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user