Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1:/tmp/cvs-serv4267/include
Modified Files:
miscutil.h pointers.h strutil.h
Log Message:
Replaced BOUND_POINTER with AutoPtr
Index: miscutil.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/miscutil.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -b -u -2 -r1.21 -r1.22
--- miscutil.h 3 Oct 2003 11:05:15 -0000 1.21
+++ miscutil.h 3 Oct 2003 15:11:21 -0000 1.22
@@ -90,45 +90,4 @@
} \
-#define BOUND_POINTER(type,name) \
- class name \
- { \
- public: \
- typedef type HostType; \
- \
- name() : m_pointer(NULL) {} \
- ~name() { Destroy(); } \
- \
- void Initialize(); \
- void Initialize(HostType *pointer); \
- type *operator->() { return m_pointer; } \
- operator bool() const { return m_pointer != NULL; } \
- \
- private: \
- void Destroy(); \
- \
- type *m_pointer; \
- }
-
-#define IMPLEMENT_BOUND_POINTER_COMMON(name) \
- void name::Destroy() { delete m_pointer; } \
- \
- void name::Initialize(name::HostType *pointer) \
- { \
- ASSERT( !m_pointer ); \
- m_pointer = pointer; \
- } \
-
-#define IMPLEMENT_BOUND_POINTER_DEFAULT(name) \
- IMPLEMENT_BOUND_POINTER_COMMON(name) \
- \
- void name::Initialize() \
- { Initialize(new name::HostType); } \
-
-#define IMPLEMENT_BOUND_POINTER(name) \
- IMPLEMENT_BOUND_POINTER_COMMON(name) \
- \
- void name::Initialize() \
- { FAIL_MSG(_T("No default constructor")); } \
-
class TreeIteratorNode
Index: pointers.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/pointers.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -u -2 -r1.2 -r1.3
--- pointers.h 3 Oct 2003 13:39:46 -0000 1.2
+++ pointers.h 3 Oct 2003 15:11:21 -0000 1.3
@@ -20,8 +20,10 @@
public:
RefCounter() { NewDefault(); }
+ // Expects IncRef-ed object
RefCounter(ClassName *copy) { NewBare(copy); }
RefCounter(const RefCounter<ClassName> ©) { NewCopy(copy); }
~RefCounter() { Destroy(); }
+ // Expects object that has not been IncRef-ed yet, don't use if possible
void AttachAndIncRef(ClassName *pointer)
{
@@ -39,7 +41,6 @@
void NewDefault() { m_pointer = 0; }
void NewCopy(const RefCounter<ClassName> ©)
- { NewBare(copy.m_pointer); }
- void NewBare(ClassName *copy)
- { RefCounterIncrement(m_pointer = copy); }
+ { RefCounterIncrement(m_pointer = copy.m_pointer); }
+ void NewBare(ClassName *copy) { m_pointer = copy; }
void Destroy() { RefCounterDecrement(m_pointer); }
@@ -73,7 +74,40 @@
}
+class MObjectRC;
extern void RefCounterIncrement(MObjectRC *pointer);
extern void RefCounterDecrement(MObjectRC *pointer);
extern void RefCounterAssign(MObjectRC *target,MObjectRC *source);
+
+
+// Equivalent of auto_ptr, but with private copy constructor and assignment
+template <class ClassName>
+class AutoPtr
+{
+public:
+ AutoPtr() { NewDefault(); }
+ AutoPtr(ClassName *copy) { NewCopy(); }
+ ~AutoPtr() { Destroy(); }
+
+ void Initialize(ClassName *copy)
+ {
+ Destroy();
+ m_pointer = copy;
+ }
+
+ operator ClassName *() { return Get(); }
+ ClassName *operator->() { return Get(); }
+
+private:
+ void NewDefault() { m_pointer = 0; }
+ void NewCopy(ClassName *copy) { m_pointer = copy; }
+ void Destroy() { if( m_pointer ) delete m_pointer; }
+
+ ClassName *Get() { return m_pointer; }
+
+ ClassName *m_pointer;
+
+ AutoPtr(const AutoPtr<ClassName>& copy) {}
+ void operator=(const AutoPtr<ClassName>& copy) {}
+};
#endif // M_POINTERS_H
Index: strutil.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/strutil.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -b -u -2 -r1.65 -r1.66
--- strutil.h 2 Oct 2003 12:03:39 -0000 1.65
+++ strutil.h 3 Oct 2003 15:11:21 -0000 1.66
@@ -17,4 +17,5 @@
#include "FolderType.h" // for strutil_expandfoldername
+#include "pointers.h"
class kbStringList;
@@ -365,4 +366,5 @@
public:
DetectSignature();
+ ~DetectSignature();
bool Initialize(Profile *profile);
@@ -373,6 +375,5 @@
bool m_useRE;
// a RE to detect the start of the signature
- BOUND_POINTER(wxRegEx,RegExPointer);
- RegExPointer m_reSig;
+ AutoPtr<wxRegEx> m_reSig;
#endif
};
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates