(svn r8815) [cpp_gui] -Codechange: Added ZeroInitBegin and ZeroInitEnd helper structures
-Window members are now initialized using new helper structures
--- a/src/helpers.hpp Sun Feb 18 19:55:35 2007 +0000
+++ b/src/helpers.hpp Mon Feb 19 20:04:27 2007 +0000
@@ -161,6 +161,27 @@
return (T)val;
}
+/**
+* Zero initialization end marker.
+* @see ZeroInitBegin for usage.
+*/
+struct ZeroInitEnd {
+};
+
+/**
+ * Zero initialization begin marker. When you need to initialize struct/class members by
+ * memset(&m_first_member, 0, ((byte*)&m_last_member) - ((byte*)&m_first_member + sizeof(m_last_member));
+ * place ZeroInitBegin before m_first_member, place ZeroInitEnd after m_last_member, call ZeroInitBegin
+ * constructor give him ZeroInitEnd& as parameter. This will clear whole area between them using memset.
+ * @see ZeroInitEnd
+ */
+struct ZeroInitBegin {
+ ZeroInitBegin(const ZeroInitEnd &end)
+ {
+ memset(this, 0, ((byte*)&end) - ((byte*)this));
+ }
+};
+
#else // __cplusplus
#define DECLARE_POSTFIX_INCREMENT(E)
--- a/src/window.cpp Sun Feb 18 19:55:35 2007 +0000
+++ b/src/window.cpp Mon Feb 19 20:04:27 2007 +0000
@@ -104,12 +104,6 @@
-BaseWindow::BaseWindow(const WindowDesc *desc, WindowNumber num)
-{
- ZeroInit();
- Create(desc, num);
-}
-
/*virtual*/ bool BaseWindow::Create(const WindowDesc *desc, WindowNumber num)
{
window_class = desc->cls;
--- a/src/window.h Sun Feb 18 19:55:35 2007 +0000
+++ b/src/window.h Mon Feb 19 20:04:27 2007 +0000
@@ -495,6 +495,8 @@
public:
static WindowList s_list;
+ ZeroInitBegin m_zero_init_area; ///< following members get cleared by constructor
+
WindowFlags flags4;
WindowClass window_class;
WindowNumber window_number;
@@ -520,18 +522,20 @@
BaseWindow *parent;
byte custom[WINDOW_CUSTOM_SIZE];
- BaseWindow(const WindowDesc *desc, WindowNumber num = 0);
+ ZeroInitEnd m_zero_init_end; ///< end of zero initialization area
+
+ BaseWindow(const WindowDesc *desc, WindowNumber num = 0)
+ : m_zero_init_area(m_zero_init_end)
+ {
+ Create(desc, num);
+ }
+
virtual bool Create(const WindowDesc *desc, WindowNumber num = 0);
static BaseWindow* Allocate(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const OldWidget *widget);
static BaseWindow* Allocate(const WindowDesc *desc, int window_number = 0);
static BaseWindow* AllocateFront(const WindowDesc *desc, int window_number = 0);
- void ZeroInit()
- {
- memset(&flags4, 0, sizeof(*this) - cpp_offsetof(BaseWindow, flags4));
- }
-
BaseWindow* FindChild() const;
void SetDirty() const;
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);