DCL 4.0
Loading...
Searching...
No Matches
Object.h
Go to the documentation of this file.
1#ifndef __DCL_OBJECT_H__
2#define __DCL_OBJECT_H__ 20050517
3
4//#include <stdio.h>
5
6#ifndef __cplusplus
7#error "dcl/Object.h requires C++ Complilation"
8#endif
9
10#ifndef __DCL_CONFIG_H__
11#include <dcl/Config.h>
12#endif
13
14#ifndef __DCL_NO_RTTI
15#include <typeinfo>
16#endif
17
18#if __DCL_HAVE_ALLOC_DEBUG && !(__DCL_DEBUG)
19#error "dcl/_Config.h incorrect"
20#endif
21
22#ifdef __DCL_DEBUG_NEW
23#error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
24#undef new
25#endif
26
27#undef __CONCAT__
28#undef __CONCAT
29
30#undef __STRING__
31
32#undef __TEXT__
33#undef __TEXT
34#undef __T
35#undef _T
36
37#define __CONCAT__(x, y) x##y
38#define __CONCAT(x, y) __CONCAT__(x, y)
39
40#define __STRING__(expr) #expr
41
42#define __TEXT__(str) L##str
43#define __TEXT(str) __TEXT__(str)
44#define __T(str) __TEXT__(str)
45#define _T(str) __TEXT__(str)
46
47#define __CONCAT_TEXT(str, expr) __TEXT(str) __STRING__(expr)
48
49#if 0
50// Test text-macros
51#define BB bb
52
53__CONCAT(aa, BB)
54__STRING__(aa == b)
55
56__TEXT("aa")
57__T("aa")
58
59__CONCAT_TEXT("aa", BB)
60#endif
61
62__DCL_BEGIN_NAMESPACE
63
64/*
65DCLCore classes
66
67Object;
68 Exception;
69 IOException;
70 DllException;
71 AssertError;
72 SQLException;
73 InputStream;
74 FileInputStream;
75 OutputStream;
76 ByteOutputStream;
77 XByteOutputStream;
78 FileOutputStream;
79 XFileOutputStream;
80 File;
81 StdFile;
82 Thread;
83 MThread; // Message
84 Dll;
85 SQLDriver;
86 SQLField;
87 SQLParam;
88 SQLQuery;
89 SQLConnection;
90 SQLConnectionPool;
91 HtmlTemplate;
92#if __DCL_WINDOWS
93 WinRegistry;
94#endif
95 IniFile;
96 Regex;
97
98String;
99Date;
100Time;
101DateTime;
102Interval;
103Int32;
104Int64;
105Single;
106Double;
107Decimal;
108
109SyncObject;
110 Mutex;
111 ThreadCond;
112*/
113
114class String;
115class Writer;
116
118{
119protected:
120 virtual ~Object();
121 Object();
122
123public:
124 virtual String toString() const;
125
126#if __DCL_DEBUG
127 virtual void dump(Writer& out) const;
128#endif
133 virtual void destroy();
134
135#if __DCL_HAVE_ALLOC_DEBUG
136 void* operator new(
137 size_t _size,
138 bool _check,
139 const char_t* _filename,
140 unsigned int _line
141 );
142
143 void* operator new[](
144 size_t _size,
145 bool _check,
146 const char_t* _filename,
147 unsigned int _line
148 );
149
150 void operator delete(
151 void* _ptr,
152 bool, // _check
153 const char_t* _filename,
154 unsigned int _line
155 );
156
157 void operator delete[](
158 void* _ptr,
159 bool, // _check
160 const char_t* _filename,
161 unsigned int _line
162 );
163
164 void* operator new(size_t);
165 void* operator new[](size_t);
166
167 void operator delete(void* _ptr);
168 void operator delete[](void* _ptr);
169
170 // default placement
171 void* operator new(size_t, void* _ptr){ return _ptr; }
172 void* operator new[](size_t, void* _ptr) { return _ptr; }
173 void operator delete(void*, void*) { }
174 void operator delete[](void*, void*) { }
175#endif
176
177public:
178 String className() const;
179
180#ifdef __DCL_NO_RTTI
181 struct DCLCAPI ClassInfo
182 {
183 const wchar_t* pszClassName;
184 size_t nObjectSize;
185 const ClassInfo* pBaseClassInfo;
186 };
187 static const ClassInfo m_classInfo;
188
189 // 인스턴스의 클래스가 pClassInfo이거나 pClassInfo로부터 상속받은 클래스이면 true
190 bool isKindOf(const ClassInfo* pClassInfo) const;
191 // pClassInfo의 인스턴스이면 true
192 bool isInstanceOf(const ClassInfo* pClassInfo) const;
193 virtual const ClassInfo* classInfo() const;
194#else
195 bool isInstanceOf(const std::type_info& typeinfo) const;
196 virtual const std::type_info& typeInfo() const;
197#endif
198};
199
200#ifdef __DCL_NO_RTTI
201#define CLASSINFO_REF const Object::ClassInfo*
202#define CLASSINFO(class_name) (&class_name::m_classInfo)
203#define DECLARE_CLASSINFO(class_name) \
204public: \
205 static const ClassInfo m_classInfo; \
206 virtual const ClassInfo* classInfo() const;
207#else
208#define CLASSINFO_REF const std::type_info&
209#define CLASSINFO(class_name) (typeid(class_name))
210#define DECLARE_CLASSINFO(class_name) \
211public: \
212 virtual const std::type_info& typeInfo() const;
213#endif
214
215#ifdef __DCL_NO_RTTI
216#define IMPLEMENT_CLASSINFO(class_name, base_class_name) \
217const Object::ClassInfo class_name::m_classInfo = \
218{ \
219 __DCL_NAMESPACE_STRING __S(class_name), \
220 sizeof(class class_name), \
221 &base_class_name::m_classInfo \
222}; \
223const Object::ClassInfo* class_name::classInfo() const \
224{ \
225 return CLASSINFO(class_name); \
226}
227#else
228#define IMPLEMENT_CLASSINFO(class_name, base_class_name) \
229const std::type_info& class_name::typeInfo() const \
230{ \
231 return typeid(class_name); \
232}
233#endif
234
235__DCL_END_NAMESPACE
236
237#if __DCL_DEBUG
238#define DCLInitialize DCLInitializeD
239#define DCLCleanup DCLCleanupD
240#endif
241
242#if __DCL_HAVE_MANUAL_INITIALIZE
251DCLCAPI int DCLInitialize();
252
263DCLCAPI void DCLCleanup();
264
265#define __DCL_INITIALIZE DCLInitialize();
266#define __DCL_CLEANUP DCLCleanup();
267#else
268#define __DCL_INITIALIZE
269#define __DCL_CLEANUP
270#endif
271
272//typedef void (* DCLCleanupCallback)(void*);
273typedef void (* DCLCleanupCallback)();
274
275
276#if __DCL_DEBUG
286DCLCAPI __DCL_NAMESPACE Writer* DCLDebugSetGlobalReport(
287 __DCL_NAMESPACE Writer* __noclose__ _pWriter
288 );
289
297DCLCAPI __DCL_NAMESPACE Writer* DCLDebugSetThreadReport(
298 unsigned long uThreadId,
299 __DCL_NAMESPACE Writer* __noclose__ _pWriter
300 );
301
305DCLCAPI void DCLDebugAssert(
306 const char_t* _filename,
307 unsigned int _line,
308 const char_t* _expr,
309 const char_t* _message
310 ) __DCL_THROWS1(__DCL_NAMESPACE AssertError*);
311
315DCLCAPI void DCLDebugTrace(
316 const char_t* _filename,
317 unsigned int _line,
318 const char_t* _format,
319 ...
320 );
321#endif /* __DCL_DEBUG */
322
323
324/*****************************************************
325 MACRO FOR ASSERT/TRACE
326*****************************************************/
327
328#undef ASSERT
329#undef ASSERT_EX
330#undef VERIFY
331
332#define ASSERT __DCL_ASSERT
333#define ASSERT_EX __DCL_ASSERT_EX
334#define VERIFY __DCL_VERIFY
335
336#undef TRACE0
337#undef TRACE1
338#undef TRACE2
339#undef TRACE3
340#undef TRACE4
341
342#define TRACE0 __DCL_TRACE0
343#define TRACE1 __DCL_TRACE1
344#define TRACE2 __DCL_TRACE2
345#define TRACE3 __DCL_TRACE3
346#define TRACE4 __DCL_TRACE4
347
348#if __DCL_DEBUG
349
350#define __DCL_ASSERT(expr) \
351 (expr) ? (void) 0 : DCLDebugAssert(__THIS_FILE__, __LINE__, __T(#expr), NULL)
352
353#define __DCL_ASSERT_EX(expr, msg) \
354 (expr) ? (void) 0 : DCLDebugAssert(__THIS_FILE__, __LINE__, __T(#expr), msg)
355
356#define __DCL_VERIFY(expr) __DCL_ASSERT(expr)
357
358#define __DCL_TRACE0(psz) \
359 DCLDebugTrace(__THIS_FILE__, __LINE__, psz)
360#define __DCL_TRACE1(fmt, arg1) \
361 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1)
362#define __DCL_TRACE2(fmt, arg1, arg2) \
363 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2)
364#define __DCL_TRACE3(fmt, arg1, arg2, arg3) \
365 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3)
366#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4) \
367 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3, arg4)
368
369#else /* __DCL_DEBUG */
370
371#define __DCL_ASSERT(expr) ((void)0)
372#define __DCL_ASSERT_EX(expr, msg) ((void)0)
373#define __DCL_VERIFY(expr) ((void)(expr))
374
375#define __DCL_TRACE0(psz)
376#define __DCL_TRACE1(fmt, arg1)
377#define __DCL_TRACE2(fmt, arg1, arg2)
378#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
379#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4)
380
381#endif /* __DCL_DEBUG */
382
383#define __DCL_ASSERT_HANDLE(expr) __DCL_ASSERT(expr)
384#define __DCL_ASSERT_PARAM(expr) __DCL_ASSERT(expr)
385
386#include <new>
387
388#if __DCL_HAVE_ALLOC_DEBUG
389
390typedef enum {
391 DCL_ALLOC_DEFAULT, /* malloc, calloc, reallc, free */
392 DCL_ALLOC_NEW, /* new char, new int, new struct, ... */
393 DCL_ALLOC_NEW_ARRAY, /* new char[], new int[], ... */
394 DCL_ALLOC_NEW_OBJECT, /* new Object */
395 DCL_ALLOC_NEW_OBJECT_ARRAY, /* new Object[] */
396 DCL_ALLOC_DELETE, /* delete ptr */
397 DCL_ALLOC_DELETE_ARRAY, /* delete[] ptr */
398 DCL_ALLOC_DELETE_OBJECT, /* delete (Object*) */
399 DCL_ALLOC_DELETE_OBJECT_ARRAY /* delete[] (Object*) */
400} DCLAllocFunction;
401
405DCLCAPI void DCLDebugAllocEnterNear(
406 const char_t* _filename,
407 unsigned int _line
408 );
409
410DCLCAPI void* DCLDebugMalloc(
411 size_t _size,
412 bool _check,
413 DCLAllocFunction allocFunction,
414 const char_t* _filename,
415 unsigned int _line
416 );
417
418DCLCAPI void DCLDebugFree(
419 void* _ptr,
420 DCLAllocFunction allocFunction,
421 const char_t* _filename,
422 unsigned int _line
423 );
424
425DCLCAPI void* DCLDebugCalloc(
426 size_t _count,
427 size_t _size,
428 bool _check,
429 const char_t* _filename,
430 unsigned int _line
431 );
432
433DCLCAPI void* DCLDebugRealloc(
434 void* _ptr,
435 size_t _newsize,
436 bool _check,
437 const char_t* _filename,
438 unsigned int _line
439 );
440
441DCLCAPI bool DCLDebugAllocIsValid(
442 const void* _ptr
443 );
444
445DCLCAPI void DCLDebugAllocSetCheckFlag(
446 const void* _ptr,
447 bool _check
448 );
449
453DCLCAPI bool DCLDebugAllocGetPosition(
454 const void* _ptr,
455 char_t* _pfilename,
456 size_t _count,
457 unsigned int* _pline
458 );
459
463DCLCAPI const void* DCLDebugGetLastAllocPosition(
464 unsigned long uThreadId
465 );
466
467typedef enum {
468 DCL_ALLOC_DUMP_ALL = 0,
469 DCL_ALLOC_DUMP_INTERNAL,
470 DCL_ALLOC_DUMP_USER
471} DCLAllocLeakDumpLevel;
472
473/*
474uThreadId가 할당한 pvStartPosition에서 최근까지의 메모리 누출 보고
475return : 성공하면 메모리 누출 항목의 갯수 >= 0, 실패(-1) 출력을 위한 버퍼할당 오류
476*/
477DCLCAPI size_t DCLDebugDumpThreadMemoryLeak(
478 unsigned long uThreadId,
479 const void* pvStartPosition,
480 DCLAllocLeakDumpLevel level,
481 __DCL_NAMESPACE Writer* pWriter
482 );
483
484/*
485프로세스가 할당한 전체 메모리 누출 보고
486return : 성공하면 메모리 누출 항목의 갯수 >= 0, 실패(-1) 출력을 위한 버퍼할당 오류
487*/
488DCLCAPI size_t DCLDebugDumpGlobalMemoryLeak(
489 DCLAllocLeakDumpLevel level,
490 __DCL_NAMESPACE Writer* pWriter
491 );
492
493/*****************************************************
494 NEW/DELETE FOR ALLOC DEBUG
495*****************************************************/
496
497// Global new/delete Operator Overload
498DCLCAPI void* operator new(
499 size_t _size,
500 bool _check,
501 const char_t* _filename,
502 unsigned int _line
503 );
504
505DCLCAPI void* operator new[](
506 size_t _size,
507 bool _check,
508 const char_t* _filename,
509 unsigned int _line
510 );
511
512DCLCAPI void operator delete(
513 void* _ptr,
514 bool _check,
515 const char_t* _filename,
516 unsigned int _line
517 );
518
519DCLCAPI void operator delete[](
520 void* _ptr,
521 bool _check,
522 const char_t* _filename,
523 unsigned int _line
524 );
525
526// 원칙적으로 위 연산자를 사용하는 구현과, 아래의 그렇지 않은 구현이
527// 같은 프로세스에서 사용할 수 없다.
528#if __DCL_WINDOWS
529// MinGW gcc, clang 포함하여,
530// VC++의 기본 new/delete 연산자는 dllexport로 컴파일 될 수 없다.
531
532#undef __THIS_FILE__
533static const char_t __szObject_h[] = __T("dcl/Object.h");
534#define __THIS_FILE__ __szObject_h
535
536#ifdef _MSC_VER
537#pragma warning(push)
538#pragma warning(disable:4595)
539#endif
540inline void* operator new(size_t _size)
541{
542 void* r = DCLDebugMalloc(
543 _size == 0 ? 1 : _size,
544 true,
545 DCL_ALLOC_NEW,
546 NULL,
547 0
548 );
549 //fprintf(stderr, "%s:%d[%zd][%p]\n", __FILE__, __LINE__, _size, r);
550 return r;
551}
552
553inline void* operator new[](size_t _size)
554{
555 void* r = DCLDebugMalloc(
556 _size == 0 ? 1 : _size,
557 true,
558 DCL_ALLOC_NEW_ARRAY,
559 NULL,
560 0
561 );
562 //fprintf(stderr, "%s:%d[%zd][%p]\n", __FILE__, __LINE__, _size, r);
563 return r;
564}
565
566inline void operator delete(void* _ptr)
567{
568 //fprintf(stderr, "%s:%d[%p]\n", __FILE__, __LINE__, _ptr);
569 DCLDebugFree(_ptr, DCL_ALLOC_DELETE, NULL, 0);
570}
571
572inline void operator delete[](void* _ptr)
573{
574 //fprintf(stderr, "%s:%d[%p]\n", __FILE__, __LINE__, _ptr);
575 DCLDebugFree(_ptr, DCL_ALLOC_DELETE_ARRAY, NULL, 0);
576}
577#ifdef _MSC_VER
578#pragma warning(pop)
579#endif
580#else
581// GCC에서 delete를 inline으로 하면 컴파일러가 제공하는 delete가 호출된다.
582DCLCAPI void* operator new(size_t _size);
583DCLCAPI void* operator new[](size_t _size);
584DCLCAPI void operator delete(void* _ptr);
585DCLCAPI void operator delete[](void* _ptr);
586#endif
587
588// for default placement
589//#if __GNUC__ >=3 || _MSC_VER >= 1200
590/*
591inline void* operator new(size_t, void* _ptr){ return _ptr; }
592inline void* operator new[](size_t, void* _ptr) { return _ptr; }
593inline void operator delete(void*, void*) { }
594inline void operator delete[](void*, void*) { }
595*/
596//#else
597//#include <new>
598//#endif
599
600//#else /* __DCL_HAVE_ALLOC_DEBUG */
601//#include <new>
602
603#endif /* __DCL_HAVE_ALLOC_DEBUG */
604
605/*****************************************************
606 MACRO FOR ALLOC DEBUG
607*****************************************************/
608
609#if __DCL_HAVE_ALLOC_DEBUG
610
611#define __DCL_ALLOC_INTERNAL false
612#define __DCL_ALLOC_USER true
613#define __DCL_ALLOC_LEVEL __DCL_ALLOC_USER
614
615#define __DCL_DEBUG_NEW \
616 new(__DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
617#define __DCL_DEBUG_MALLOC(size) \
618 DCLDebugMalloc(size, __DCL_ALLOC_LEVEL, DCL_ALLOC_DEFAULT, __THIS_FILE__, __LINE__)
619#define __DCL_DEBUG_CALLOC(count, size) \
620 DCLDebugCalloc(count, size, __DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
621#define __DCL_DEBUG_REALLOC(ptr, size) \
622 DCLDebugRealloc(ptr, size, __DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
623#define __DCL_DEBUG_FREE(ptr) \
624 DCLDebugFree(ptr, DCL_ALLOC_DEFAULT, __THIS_FILE__, __LINE__)
625
626#define new __DCL_DEBUG_NEW
627#define malloc(size) __DCL_DEBUG_MALLOC(size)
628#define calloc(count, size) __DCL_DEBUG_CALLOC(count, size)
629#define realloc(ptr, size) __DCL_DEBUG_REALLOC(ptr, size)
630#define free(ptr) __DCL_DEBUG_FREE(ptr)
631
632/* macro disable
633#undef new
634#undef malloc
635#undef calloc
636#undef realloc
637#undef free
638*/
639
640#endif // __DCL_HAVE_ALLOC_DEBUG
641
642#ifdef __DCL_HAVE_ALLOC_DEBUG
643#define __DCL_DEBUG_ALLOC_ENTER DCLDebugAllocEnterNear(__THIS_FILE__, __LINE__)
644#define __DCL_DEBUG_ALLOC_LEAVE DCLDebugAllocEnterNear(NULL, 0)
645#else
646#define __DCL_DEBUG_ALLOC_ENTER
647#define __DCL_DEBUG_ALLOC_LEAVE
648#endif
649
650#undef __THIS_FILE__
651#define __THIS_FILE__ __T(__FILE__)
652
653#endif // __DCL_OBJECT_H__
#define NULL
Definition Config.h:340
#define DCLCAPI
Definition Config.h:100
wchar_t char_t
Definition Config.h:275
#define __noclose__
Definition Config.h:360
#define __DCL_THROWS1(e)
Definition Config.h:167
#define __CONCAT_TEXT(str, expr)
Definition Object.h:47
#define __CONCAT(x, y)
Definition Object.h:38
#define __STRING__(expr)
Definition Object.h:40
#define __T(str)
Definition Object.h:44
#define __TEXT(str)
Definition Object.h:43
void(* DCLCleanupCallback)()
Definition Object.h:273
ByteString r
Object()
Definition Object.cpp:183
virtual const std::type_info & typeInfo() const
Definition Object.cpp:126
virtual String toString() const
Definition Object.cpp:187
virtual void destroy()
Definition Object.cpp:192
bool isInstanceOf(const std::type_info &typeinfo) const
Definition Object.cpp:168
String className() const
Definition Object.cpp:163