-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDyncObject.h
More file actions
86 lines (69 loc) · 1.89 KB
/
DyncObject.h
File metadata and controls
86 lines (69 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef _DYNC_OBJECT_H_
#define _DYNC_OBJECT_H_
#include <iostream>
#include <assert.h>
#include <string>
#include "util/tc_autoptr.h"
#include "util/tc_thread_mutex.h"
#include "servant/Application.h"
using namespace std;
using namespace tars;
/**
* 精简版动态创建:
*
*/
//.虚类声明
#define DECLARE_CMDDYNAMIC(class_name) \
public: \
static RuntimeObject class##class_name;
//.虚类定义
#define IMPLEMENT_CMDDYNAMIC(class_name) \
RuntimeObject class_name::class##class_name = {#class_name, NULL, NULL}; \
ObjectList __initcmd_##class_name(&class_name::class##class_name);
//.实类声明
#define DECLARE_CMDDYNCREATE(class_name) \
public: \
static RuntimeObject class##class_name; \
static DyncObject* CreateObject();
//.实类定义
#define IMPLEMENT_CMDDYNCREATE(class_name) \
RuntimeObject class_name::class##class_name = { #class_name, class_name::CreateObject, NULL}; \
ObjectList __initcmd_##class_name(&class_name::class##class_name); \
DyncObject* class_name::CreateObject(void) { return new class_name; }
struct DyncObject;
/**
* 执行期对象结构
*/
struct RuntimeObject
{
const char* m_szClassName;
DyncObject* (*m_pfnCreateObject)(void);
RuntimeObject* m_pNextClass;
};
/**
* 执行期对象
*/
struct DyncObject : public tars::TC_HandleBase
, public TC_ThreadMutex
{
public:
static RuntimeObject classDyncObject;
void setName(const string& name) { sThisName = name; }
const std::string& name() const { return sThisName; }
private:
std::string sThisName;
};
typedef tars::TC_AutoPtr<DyncObject> DyncObjectPtr;
/**
* 构建执行期对象全局链
*/
struct ObjectList
{
ObjectList(RuntimeObject *pNewClass);
};
/**
* 执行期对象创建接口
*/
DyncObject* TCreateObject(const char* class_name);
/////////////////////////////////////////////////////////
#endif