DCL 3.7.4
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#ifndef __cplusplus
5#error "dcl/Object.h requires C++ Complilation"
6#endif
7
8#ifndef __DCL_CONFIG_H__
9#include <dcl/Config.h>
10#endif
11
12#ifdef __WINNT__
13 #if __DCL_PTHREAD
14 #include <pthread.h>
15 typedef pthread_t thread_t;
16 #else
17 typedef unsigned long thread_t;
18 #endif
19#else
20 #if defined(__linux__)
21 #include <bits/pthreadtypes.h>
22 #elif defined(__APPLE__)
23 #include <sys/_pthread/_pthread_types.h>
24 #else
25 #include <pthread.h>
26 #endif
27 typedef pthread_t thread_t;
28#endif
29
30#ifndef __DCL_NO_RTTI
31#include <typeinfo>
32#endif
33
34#if __DCL_HAVE_ALLOC_DEBUG && !(__DCL_DEBUG)
35#error "dcl/_Config.h incorrect"
36#endif
37
38#ifdef __DCL_DEBUG_NEW
39#error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
40#undef new
41#endif
42
43#undef __CONCAT__
44#undef __CONCAT
45
46#undef __STRING__
47
48#undef __TEXT__
49#undef __TEXT
50#undef __T
51#undef _T
52
53#define __CONCAT__(x, y) x ## y
54#define __CONCAT(x, y) __CONCAT__(x, y)
55
56#define __STRING__(expr) #expr
57
58#define __TEXT__(str) L ## str
59#define __TEXT(str) __TEXT__(str)
60#define __T(str) __TEXT__(str)
61#define _T(str) __TEXT__(str)
62
63#define __CONCAT_TEXT(str, expr) __TEXT(str) __STRING__(expr)
64
65#if 0
66// Test text-macros
67#define BB bb
68
69__CONCAT(aa, BB)
70__STRING__(aa == b)
71
72__TEXT("aa")
73__T("aa")
74
75__CONCAT_TEXT("aa", BB)
76#endif
77
78__DCL_BEGIN_NAMESPACE
79
80/*
81DCLCore classes
82
83Object;
84 Exception;
85 IOException;
86 DllException;
87 AssertError;
88 SQLException;
89 InputStream;
90 FileInputStream;
91 OutputStream;
92 ByteOutputStream;
93 XByteOutputStream;
94 FileOutputStream;
95 XFileOutputStream;
96 File;
97 StdFile;
98 Thread;
99 MThread; // Message
100 Dll;
101 SQLDriver;
102 SQLField;
103 SQLParam;
104 SQLQuery;
105 SQLConnection;
106 SQLConnectionPool;
107 HtmlTemplate;
108 IniFile;
109#ifdef __WINNT__
110 Registry;
111#endif
112 Regex;
113 Writer;
114
115String;
116Date;
117Time;
118DateTime;
119Interval;
120Int32;
121Int64;
122Single;
123Double;
124Decimal;
125
126SyncObject;
127 Mutex;
128 ThreadCond;
129*/
130
131class String;
132class Writer;
133
135{
136protected:
137 virtual ~Object();
138 Object();
139
140public:
141 virtual String toString() const;
142
143#ifdef __DCL_DEBUG
144 virtual void dump(Writer& _out) const;
145#endif
150 virtual void destroy();
151
152#if __DCL_HAVE_ALLOC_DEBUG
153 void* operator new(
154 size_t _size,
155 bool _check,
156 const char_t* _filename,
157 unsigned int _line
158 );
159
160 void* operator new[](
161 size_t _size,
162 bool _check,
163 const char_t* _filename,
164 unsigned int _line
165 );
166
167 void operator delete(
168 void* _ptr,
169 bool, // _check
170 const char_t* _filename,
171 unsigned int _line
172 ) noexcept;
173
174 void operator delete[](
175 void* _ptr,
176 bool, // _check
177 const char_t* _filename,
178 unsigned int _line
179 ) noexcept;
180
181 void* operator new(size_t);
182 void* operator new[](size_t);
183
184 void operator delete(void* _ptr) noexcept;
185 void operator delete[](void* _ptr) noexcept;
186
187 // default placement
188 void* operator new(size_t, void* _ptr) { return _ptr; }
189 void* operator new[](size_t, void* _ptr) { return _ptr; }
190 void operator delete(void*, void*) noexcept { }
191 void operator delete[](void*, void*) noexcept { }
192#endif
193
194public:
195 String className() const;
196
197#ifdef __DCL_NO_RTTI
198 struct DCLCAPI ClassInfo
199 {
200 const wchar_t* pszClassName;
201 size_t nObjectSize;
202 const ClassInfo* pBaseClassInfo;
203 };
204 static const ClassInfo __classInfo;
205
206 // 인스턴스의 클래스가 pClassInfo이거나 pClassInfo로부터 상속받은 클래스이면 true
207 bool isKindOf(const ClassInfo* pClassInfo) const;
208 // pClassInfo의 인스턴스이면 true
209 bool isInstanceOf(const ClassInfo* pClassInfo) const;
210 virtual const ClassInfo* classInfo() const;
211#else
212 bool isInstanceOf(const std::type_info& typeinfo) const;
213 virtual const std::type_info& typeInfo() const;
214#endif
215};
216
217#ifdef __DCL_NO_RTTI
218#define CLASSINFO_REF const Object::ClassInfo*
219#define CLASSINFO(class_name) (&class_name::__classInfo)
220#define DECLARE_CLASSINFO(class_name) \
221public: \
222 static const ClassInfo __classInfo; \
223 virtual const ClassInfo* classInfo() const;
224#else
225#define CLASSINFO_REF const std::type_info&
226#define CLASSINFO(class_name) (typeid(class_name))
227#define DECLARE_CLASSINFO(class_name) \
228public: \
229 virtual const std::type_info& typeInfo() const;
230#endif
231
232#ifdef __DCL_NO_RTTI
233#define IMPLEMENT_CLASSINFO(class_name, base_class_name) \
234const Object::ClassInfo class_name::__classInfo = \
235{ \
236 __DCL_NAMESPACE_STRING __S(class_name), \
237 sizeof(class class_name), \
238 &base_class_name::__classInfo \
239}; \
240const Object::ClassInfo* class_name::classInfo() const \
241{ \
242 return CLASSINFO(class_name); \
243}
244#else
245#define IMPLEMENT_CLASSINFO(class_name, base_class_name) \
246const std::type_info& class_name::typeInfo() const \
247{ \
248 return typeid(class_name); \
249}
250#endif
251
252__DCL_END_NAMESPACE
253
254#ifdef __DCL_DEBUG
255#define DCLInitialize DCLInitializeD
256#define DCLCleanup DCLCleanupD
257#endif
258
259#if __DCL_HAVE_MANUAL_INITIALIZE
268DCLCAPI int DCLInitialize();
269
280DCLCAPI void DCLCleanup();
281
282#define __DCL_INITIALIZE DCLInitialize();
283#define __DCL_CLEANUP DCLCleanup();
284#else
285#define __DCL_INITIALIZE
286#define __DCL_CLEANUP
287#endif
288
289//typedef void (* DCLCleanupCallback)(void*);
290typedef void (* DCLCleanupCallback)();
291
292#ifdef __DCL_DEBUG
302DCLCAPI __DCL_NAMESPACE Writer* DCLDebugSetGlobalReport(
303 __DCL_NAMESPACE Writer* __noclose__ _pWriter
304);
305
313DCLCAPI __DCL_NAMESPACE Writer* DCLDebugSetThreadReport(
314 thread_t _threadId,
315 __DCL_NAMESPACE Writer* __noclose__ _pWriter
316);
317
321DCLCAPI void DCLDebugAssert(
322 const char_t* _filename,
323 unsigned int _line,
324 const char_t* _expr,
325 const char_t* _message
326) __DCL_THROWS1(__DCL_NAMESPACE AssertError*);
327
331DCLCAPI void DCLDebugTrace(
332 const char_t* _filename,
333 unsigned int _line,
334 const char_t* _format,
335 ...
336);
337#endif /* __DCL_DEBUG */
338
339/*****************************************************
340 MACRO FOR ASSERT/TRACE
341*****************************************************/
342
343#undef ASSERT
344#undef ASSERT_EX
345#undef VERIFY
346
347#define ASSERT __DCL_ASSERT
348#define ASSERT_EX __DCL_ASSERT_EX
349#define VERIFY __DCL_VERIFY
350
351#undef TRACE0
352#undef TRACE1
353#undef TRACE2
354#undef TRACE3
355#undef TRACE4
356#undef TRACE5
357#undef TRACE6
358
359#define TRACE0 __DCL_TRACE0
360#define TRACE1 __DCL_TRACE1
361#define TRACE2 __DCL_TRACE2
362#define TRACE3 __DCL_TRACE3
363#define TRACE4 __DCL_TRACE4
364#define TRACE5 __DCL_TRACE5
365#define TRACE6 __DCL_TRACE6
366
367#ifdef __DCL_DEBUG
368
369#define __DCL_ASSERT(expr) \
370 (expr) ? (void) 0 : DCLDebugAssert(__THIS_FILE__, __LINE__, __T(#expr), NULL)
371
372#define __DCL_ASSERT_EX(expr, msg) \
373 (expr) ? (void) 0 : DCLDebugAssert(__THIS_FILE__, __LINE__, __T(#expr), msg)
374
375#define __DCL_VERIFY(expr) __DCL_ASSERT(expr)
376
377#define __DCL_TRACE0(psz) \
378 DCLDebugTrace(__THIS_FILE__, __LINE__, psz)
379#define __DCL_TRACE1(fmt, arg1) \
380 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1)
381#define __DCL_TRACE2(fmt, arg1, arg2) \
382 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2)
383#define __DCL_TRACE3(fmt, arg1, arg2, arg3) \
384 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3)
385#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4) \
386 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3, arg4)
387#define __DCL_TRACE5(fmt, arg1, arg2, arg3, arg4, arg5) \
388 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3, arg4, arg5)
389#define __DCL_TRACE6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
390 DCLDebugTrace(__THIS_FILE__, __LINE__, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
391
392#else /* __DCL_DEBUG */
393
394#define __DCL_ASSERT(expr) ((void)0)
395#define __DCL_ASSERT_EX(expr, msg) ((void)0)
396#define __DCL_VERIFY(expr) ((void)(expr))
397
398#define __DCL_TRACE0(psz)
399#define __DCL_TRACE1(fmt, arg1)
400#define __DCL_TRACE2(fmt, arg1, arg2)
401#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
402#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4)
403#define __DCL_TRACE5(fmt, arg1, arg2, arg3, arg4, arg5)
404#define __DCL_TRACE6(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
405
406#endif /* __DCL_DEBUG */
407
408#define __DCL_ASSERT_HANDLE(expr) __DCL_ASSERT(expr)
409#define __DCL_ASSERT_PARAM(expr) __DCL_ASSERT(expr)
410
411#include <new>
412
413#if __DCL_HAVE_ALLOC_DEBUG
414
415typedef enum {
416 DCL_ALLOC_DEFAULT = (short) 0, /* malloc, calloc, reallc, free */
417 DCL_ALLOC_NEW, /* new char, new int, new struct, ... */
418 DCL_ALLOC_NEW_ARRAY, /* new char[], new int[], ... */
419 DCL_ALLOC_NEW_OBJECT, /* new Object */
420 DCL_ALLOC_NEW_OBJECT_ARRAY, /* new Object[] */
421 DCL_ALLOC_DELETE, /* delete ptr */
422 DCL_ALLOC_DELETE_ARRAY, /* delete[] ptr */
423 DCL_ALLOC_DELETE_OBJECT, /* delete (Object*) */
424 DCL_ALLOC_DELETE_OBJECT_ARRAY /* delete[] (Object*) */
425} DCLAllocFunc;
426
430DCLCAPI void DCLDebugAllocEnterNear(
431 const char_t* _filename,
432 unsigned int _line
433);
434
435DCLCAPI void* DCLDebugMalloc(
436 size_t _size,
437 bool _check,
438 DCLAllocFunc _func,
439 const char_t* _filename,
440 unsigned int _line
441);
442
443DCLCAPI void DCLDebugFree(
444 void* _ptr,
445 DCLAllocFunc _func,
446 const char_t* _filename,
447 unsigned int _line
448);
449
450DCLCAPI void* DCLDebugCalloc(
451 size_t _count,
452 size_t _size,
453 bool _check,
454 const char_t* _filename,
455 unsigned int _line
456);
457
458DCLCAPI void* DCLDebugRealloc(
459 void* _ptr,
460 size_t _size,
461 bool _check,
462 const char_t* _filename,
463 unsigned int _line
464);
465
466DCLCAPI bool DCLDebugAllocIsValid(
467 const void* _ptr
468);
469
470DCLCAPI void DCLDebugAllocSetCheckFlag(
471 const void* _ptr,
472 bool _check
473);
474
478DCLCAPI bool DCLDebugAllocGetPosition(
479 const void* _ptr,
480 char_t* _filename,
481 size_t _buflen,
482 unsigned int* _line
483);
484
488DCLCAPI const void* DCLDebugGetLastAllocPosition(
489 thread_t _threadId
490);
491
492typedef enum {
493 DCL_ALLOC_DUMP_ALL = 0,
494 DCL_ALLOC_DUMP_INTERNAL,
495 DCL_ALLOC_DUMP_USER
496} DCLAllocLeakDumpLevel;
497
498/*
499uThreadId가 할당한 _startPosition에서 최근까지의 메모리 누출 보고
500return : 성공하면 메모리 누출 항목의 갯수 >= 0, 실패(-1) 출력을 위한 버퍼할당 오류
501*/
502DCLCAPI size_t DCLDebugDumpThreadMemoryLeak(
503 thread_t _threadId,
504 const void* _startPosition,
505 DCLAllocLeakDumpLevel _level,
506 __DCL_NAMESPACE Writer* _writer
507);
508
509/*
510프로세스가 할당한 전체 메모리 누출 보고
511return : 성공하면 메모리 누출 항목의 갯수 >= 0, 실패(-1) 출력을 위한 버퍼할당 오류
512*/
513DCLCAPI size_t DCLDebugDumpGlobalMemoryLeak(
514 DCLAllocLeakDumpLevel _level,
515 __DCL_NAMESPACE Writer* _writer
516);
517
518/*****************************************************
519 NEW/DELETE FOR ALLOC DEBUG
520*****************************************************/
521
522// Global new/delete Operator Overload
523DCLCAPI void* operator new(
524 size_t _size,
525 bool _check,
526 const char_t* _filename,
527 unsigned int _line
528);
529
530DCLCAPI void* operator new[](
531 size_t _size,
532 bool _check,
533 const char_t* _filename,
534 unsigned int _line
535);
536
537DCLCAPI void operator delete(
538 void* _ptr,
539 bool _check,
540 const char_t* _filename,
541 unsigned int _line
542) noexcept;
543
544DCLCAPI void operator delete[](
545 void* _ptr,
546 bool _check,
547 const char_t* _filename,
548 unsigned int _line
549) noexcept;
550
551#define __DCL_TRACE_INTNAL_ 0
552
553#ifdef __WINNT__
554
555#if __DCL_TRACE_INTNAL_
556 #include <stdio.h>
557 #define __DCL_TRACE_INTNAL_DELETE_FN__ \
558 fprintf(stderr, "%s:%d __delete__ %p\n", __FILE__, __LINE__, _ptr);
559 #define __DCL_TRACE_INTNAL_NEW_A__ \
560 fprintf(stderr, "%s:%d new[] %zd %p\n", __FILE__, __LINE__, _size, r);
561 #define __DCL_TRACE_INTNAL_DELETE_A__ \
562 fprintf(stderr, "%s:%d delete[] %p\n", __FILE__, __LINE__, _ptr);
563 #define __DCL_TRACE_INTNAL_NEW__ \
564 fprintf(stderr, "%s:%d new %zd %p\n", __FILE__, __LINE__, _size, r);
565 #define __DCL_TRACE_INTNAL_DELETE__ \
566 fprintf(stderr, "%s:%d delete %p\n", __FILE__, __LINE__, _ptr);
567#else
568 #define __DCL_TRACE_INTNAL_DELETE_FN__
569 #define __DCL_TRACE_INTNAL_NEW_A__
570 #define __DCL_TRACE_INTNAL_DELETE_A__
571 #define __DCL_TRACE_INTNAL_NEW__
572 #define __DCL_TRACE_INTNAL_DELETE__
573#endif
574 // MSC에서 다음 4개의 new, delete는 dllexport, dllimport 할 수 없다.
575 #ifdef __WINNT_GCC__
576 // MinGW g++에서는 overrided delete가 호출되지 않는다.
577 template<typename TYPE>
578 void __delete__(TYPE* _ptr, const char_t* _filename, unsigned int _line) {
579 _ptr->~TYPE();
580 __DCL_TRACE_INTNAL_DELETE_FN__
581 DCLDebugFree(_ptr, DCL_ALLOC_DELETE, _filename, _line);
582 }
583
584 void* operator new[](size_t _size);
585 void operator delete[](void* _ptr) noexcept;
586
587 #define __WINNT_NEW_DELETE_OVERRIDE \
588 void* operator new[](size_t _size)\
589 {\
590 void* r = DCLDebugMalloc(\
591 _size == 0 ? 1 : _size, true, DCL_ALLOC_NEW_ARRAY, NULL, 0\
592 );\
593 __DCL_TRACE_INTNAL_NEW_A__\
594 return r;\
595 }\
596 void operator delete[](void* _ptr) noexcept\
597 {\
598 __DCL_TRACE_INTNAL_DELETE_A__\
599 DCLDebugFree(_ptr, DCL_ALLOC_DELETE_ARRAY, NULL, 0);\
600 }
601 #else // __WINNT_GCC__
602 void* operator new(size_t _size);
603 void operator delete(void* _ptr) noexcept;
604 void* operator new[](size_t _size);
605 void operator delete[](void* _ptr) noexcept;
606
607 #define __WINNT_NEW_DELETE_OVERRIDE\
608 void* operator new(size_t _size)\
609 {\
610 void* r = DCLDebugMalloc(\
611 _size == 0 ? 1 : _size, true, DCL_ALLOC_NEW, NULL, 0\
612 );\
613 __DCL_TRACE_INTNAL_NEW__\
614 return r;\
615 }\
616 void operator delete(void* _ptr) noexcept\
617 {\
618 __DCL_TRACE_INTNAL_DELETE__\
619 DCLDebugFree(_ptr, DCL_ALLOC_DELETE, NULL, 0);\
620 }\
621 void* operator new[](size_t _size)\
622 {\
623 void* r = DCLDebugMalloc(\
624 _size == 0 ? 1 : _size, true, DCL_ALLOC_NEW_ARRAY, NULL, 0\
625 );\
626 __DCL_TRACE_INTNAL_NEW_A__\
627 return r;\
628 }\
629 void operator delete[](void* _ptr) noexcept\
630 {\
631 __DCL_TRACE_INTNAL_DELETE_A__\
632 DCLDebugFree(_ptr, DCL_ALLOC_DELETE_ARRAY, NULL, 0);\
633 }
634 #endif // __WINNT_GCC__
635#else // __WINNT__
636 // MinGW clang++ 및 UNIX g++, clang++에서 DSO 구현이 사용가능하다.
637 // GCC에서 delete를 inline으로 하면 컴파일러가 제공하는 delete가 호출된다.
638 DCLCAPI void* operator new(size_t _size);
639 DCLCAPI void* operator new[](size_t _size);
640 DCLCAPI void operator delete(void* _ptr) noexcept;
641 DCLCAPI void operator delete[](void* _ptr) noexcept;
642#endif
643
644// for default placement
645//#if __GNUC__ >=3 || _MSC_VER >= 1200
646/*
647inline void* operator new(size_t, void* _ptr){ return _ptr; }
648inline void* operator new[](size_t, void* _ptr) { return _ptr; }
649inline void operator delete(void*, void*) { }
650inline void operator delete[](void*, void*) { }
651*/
652//#else
653//#include <new>
654//#endif
655
656//#else /* __DCL_HAVE_ALLOC_DEBUG */
657//#include <new>
658
659#endif /* __DCL_HAVE_ALLOC_DEBUG */
660
661/*****************************************************
662 MACRO FOR ALLOC DEBUG
663*****************************************************/
664
665#if __DCL_HAVE_ALLOC_DEBUG
666
667#define __DCL_ALLOC_INTERNAL false
668#define __DCL_ALLOC_USER true
669#define __DCL_ALLOC_LEVEL __DCL_ALLOC_USER
670
671#define __DCL_DEBUG_NEW \
672 new(__DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
673#define __DCL_DEBUG_MALLOC(size) \
674 DCLDebugMalloc(size, __DCL_ALLOC_LEVEL, DCL_ALLOC_DEFAULT, __THIS_FILE__, __LINE__)
675#define __DCL_DEBUG_CALLOC(count, size) \
676 DCLDebugCalloc(count, size, __DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
677#define __DCL_DEBUG_REALLOC(ptr, size) \
678 DCLDebugRealloc(ptr, size, __DCL_ALLOC_LEVEL, __THIS_FILE__, __LINE__)
679#define __DCL_DEBUG_FREE(ptr) \
680 DCLDebugFree(ptr, DCL_ALLOC_DEFAULT, __THIS_FILE__, __LINE__)
681
682#ifdef __WINNT_GCC__
683 #define __DCL_DEBUG_DELETE(_p) __delete__(_p, __THIS_FILE__, __LINE__)
684 // #define delete(_p) __DCL_DEBUG_DELETE(_p)
685#endif
686
687#define new __DCL_DEBUG_NEW
688#define malloc(size) __DCL_DEBUG_MALLOC(size)
689#define calloc(count, size) __DCL_DEBUG_CALLOC(count, size)
690#define realloc(ptr, size) __DCL_DEBUG_REALLOC(ptr, size)
691#define free(ptr) __DCL_DEBUG_FREE(ptr)
692
693/* macro disable
694#undef new
695#undef malloc
696#undef calloc
697#undef realloc
698#undef free
699*/
700
701#endif // __DCL_HAVE_ALLOC_DEBUG
702
703#ifdef __DCL_HAVE_ALLOC_DEBUG
704#define __DCL_DEBUG_ALLOC_ENTER DCLDebugAllocEnterNear(__THIS_FILE__, __LINE__)
705#define __DCL_DEBUG_ALLOC_LEAVE DCLDebugAllocEnterNear(NULL, 0)
706#else
707#define __DCL_DEBUG_ALLOC_ENTER
708#define __DCL_DEBUG_ALLOC_LEAVE
709#endif
710
711#if 0
712#undef __THIS_FILE__
713#define __THIS_FILE__ __T(__FILE__)
714#endif
715
716#endif // __DCL_OBJECT_H__
#define DCLCAPI
Definition Config.h:95
wchar_t char_t
Definition Config.h:247
#define __noclose__
Definition Config.h:331
#define __DCL_THROWS1(e)
Definition Config.h:152
#define __CONCAT_TEXT(str, expr)
Definition Object.h:63
#define __CONCAT(x, y)
Definition Object.h:54
#define __STRING__(expr)
Definition Object.h:56
#define __T(str)
Definition Object.h:60
pthread_t thread_t
Definition Object.h:27
#define __TEXT(str)
Definition Object.h:59
void(* DCLCleanupCallback)()
Definition Object.h:290
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