Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

reg_serializer.hpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // "supermacro" code for doing some registration stuff for Serializers.
00003 //
00004 // See s11n::io::register_serializer<>() for a function which does the
00005 // same thing as this supermacro (it's easier to use and doesn't
00006 // add as much back-end overhead).
00007 //
00008 // License: Public Domain
00009 // Author: stephan@s11n.net
00010 ////////////////////////////////////////////////////////////////////////
00011 // NOTE: this file does not use a conventional BLAH_H_INCLUDED guard.
00012 // Yes, that's on purpose.
00013 ////////////////////////////////////////////////////////////////////////
00014 // The s11n header files are expected to have been included by the
00015 // time this file is ever included.
00016 //
00017 // usage:
00018 // define:
00019 // SERIALIZER_TYPE serializer_class
00020 // SERIALIZER_BASE base_of_serializer (or SERIALIZER_TYPE)
00021 // SERIALIZER_MAGIC_COOKIE optional "#!/magic/cookie/string"
00022 // SERIALIZER_ALIAS optional "alias_string" for classloading
00023 //
00024 // #include <this_file>
00025 //
00026 // After each include all of these macros are unset so that they may
00027 // be immediately re-used for another registration.
00028 //
00029 // The cookie is required if s11n is to be able to load
00030 // your files transparently. An alias is convenient for s11nconvert
00031 // and such, but not required.
00032 ////////////////////////////////////////////////////////////////////////
00033 
00034 #include <stdlib.h> // abort()
00035 
00036 #define DEBUG_REG 0
00037 #if DEBUG_REG
00038 #  include <s11n.net/s11n/s11n_debuggering_macros.hpp> // CERR macro
00039 #endif
00040 
00041 
00042 #ifndef SERIALIZER_TYPE
00043 #    error "SERIALIZER_TYPE is not set. Set it to the type you want to proxy before including this file!"
00044 #endif
00045 
00046 #ifndef SERIALIZER_NAME
00047 #    error "SERIALIZER_NAME must be set to the string form of SERIALIZER_TYPE"
00048 #endif
00049 
00050 #ifndef SERIALIZER_BASE
00051 #    error "SERIALIZER_BASE must be the base-most type of SERIALIZER_TYPE (may be the same)."
00052 #endif
00053 
00054 #include <s11n.net/s11n/classload.hpp>
00055 
00056 namespace { // anonymous namespace is important for complex linking reasons.
00057 
00058 
00059 
00060 #ifndef s11n_SERIALIZER_REG_CONTEXT_DEFINED
00061 #define s11n_SERIALIZER_REG_CONTEXT_DEFINED 1
00062         ///////////////////////////////////////////////////////////////
00063         // we must not include this more than once per compilation unit
00064         ///////////////////////////////////////////////////////////////
00065         // A unique (per SERIALIZER_BASE/per compilation unit) space to assign
00066         // a bogus value for classloader registration purposes (see
00067         // the classloader docs for a full description of how this
00068         // works).
00069         template <typename Context>
00070         struct serializer_reg_context
00071         {
00072                 typedef Context context;
00073                 static bool placeholder;
00074                 static void reg()
00075                 {
00076                         CERR << "ACHTUNG: serializer_reg_context<context> >()"
00077                              << " is not specialized, which means that registration hasn't been done.\n"
00078                              << "For instructions see: " << __FILE__ << "\n";
00079                         abort();
00080                 }
00081         };
00082         template <typename Context> bool serializer_reg_context<Context>::placeholder = false;
00083 #endif
00084 // !s11n_SERIALIZER_REG_CONTEXT_DEFINED
00085 ////////////////////////////////////////////////////////////////////////////////
00086 
00087         template <>
00088         struct serializer_reg_context< SERIALIZER_TYPE >
00089         {
00090                 typedef SERIALIZER_TYPE context;
00091                 static bool placeholder;
00092                 static void reg()
00093                 {
00094                         std::string cname = SERIALIZER_NAME;
00095 #if DEBUG_REG
00096                         CERR << "\nRegistering Serializer: " << cname << "\n"
00097 #  ifdef SERIALIZER_MAGIC_COOKIE
00098                              << "cookie="<< SERIALIZER_MAGIC_COOKIE << "\n"
00099 #  endif
00100 #  ifdef SERIALIZER_ALIAS
00101                              << "alias="<< SERIALIZER_ALIAS << "\n"
00102 #  endif
00103                                 ; // CERR
00104 #endif // DEBUG_REG
00105 
00106 #ifdef SERIALIZER_ABSTRACT
00107                         ::s11n::cl::classloader_register_abstract< SERIALIZER_BASE >( cname );
00108 #  undef SERIALIZER_ABSTRACT
00109 #else
00110                         ::s11n::cl::classloader_register< SERIALIZER_BASE, SERIALIZER_TYPE >( cname );
00111 #endif
00112 #ifdef SERIALIZER_MAGIC_COOKIE
00113                         ::s11n::cl::classloader_alias< SERIALIZER_BASE >( SERIALIZER_MAGIC_COOKIE, cname );
00114 #  undef SERIALIZER_MAGIC_COOKIE
00115 #endif
00116 #ifdef SERIALIZER_ALIAS
00117                         ::s11n::cl::classloader_alias< SERIALIZER_BASE >( SERIALIZER_ALIAS, cname );
00118 #  undef SERIALIZER_ALIAS
00119 #endif
00120                 }
00121         };
00122 
00123         bool serializer_reg_context< SERIALIZER_TYPE >::placeholder = (
00124                                                                        serializer_reg_context< SERIALIZER_TYPE >::reg()
00125                                                                        ,
00126                                                                        true
00127                                                                        );
00128 
00129 } // anon namespace 
00130 
00131 ////////////////////////////////////////////////////////////////////////////////
00132 // end proxy code for [SERIALIZER]
00133 ////////////////////////////////////////////////////////////////////////////////
00134 #undef SERIALIZER_TYPE
00135 #undef SERIALIZER_NAME
00136 #undef DEBUG_REG

Generated on Sun Dec 25 20:26:11 2005 for libs11n-1.2.3 by  doxygen 1.4.4