This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Handy Object Registration Macro
  Submitted by



This is a simple little macro that can be used to perform some type of one-time, start-up operation. I usually use it to register some object with some singleton-based server object. For instance, I used this macro to register several resource objects with a general purpose resource parser. In order to make this macro more useful, you'd gonna have to tweak it to make the constructor/destructor do whatever application specific code you need to do. All static objects are guarented to be created before you get to a main/WinMain, but the order of object creation isn't. So you're gonna have to be careful what you make this macro do. In the case of the resource parser, I did a lazy creation of the singleton object, i.e. create it when you try to access it.

#define REGISTER_OBJECT(x) \
    class x##_Register \
    { \
    public: \
        x##_Register() \
        { \
            ResourceParser::Register(x##::GetTag(), x##::CreateInstance); \
        } \
        \
        ~x##_Register() \
        { \
            ResourceParser::Unregister(x##::GetTag()); \
        } \
        \
        static x##_Register object; \
    }; \
    \
    x##_Register x##_Register::object; 



The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.