CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

CompileTimeTaglib.h

Go to the documentation of this file.
00001 #ifndef CXXSP_COMPILE_TIME_TAGLIB_H_
00002 #define CXXSP_COMPILE_TIME_TAGLIB_H_
00003 
00004 #include <map>
00005 #include <iostream>
00006 
00007 #include "Taglib.h"
00008 
00009 namespace servlet
00010 {
00011 namespace taglib
00012 {
00013 
00014 class Generator;
00015 
00016 class CompileTimeTaglib: public Taglib
00017 {
00018 public:
00019     class TagFactoryBase
00020     {
00021     public:
00022         virtual ~TagFactoryBase();
00023         virtual Generator* makeTag(const std::string&)=0;
00024     };
00025     template <class T>
00026      class TagFactory: public TagFactoryBase
00027     {
00028     public:
00029         virtual Generator* makeTag(const std::string& name)
00030         {
00031             return new T(name);
00032         }
00033     };
00034 private:
00035     typedef std::map<std::string, TagFactoryBase*> tagfactorymap_t;
00036     tagfactorymap_t m_factoryMap;
00037 public:
00038     CompileTimeTaglib(const std::string& prefix);
00039     void registerTag(const std::string& name, TagFactoryBase* factory);
00040     virtual Generator* getTag(const std::string&);
00041     virtual void releaseTag(Generator*);
00042 };
00043 
00044 } // namespace taglib
00045 } // namespace servlet
00046 
00047 #define DECLARE_COMPILE_TIME_TAGLIB(prefix) extern "C" servlet::taglib::CompileTimeTaglib* get_taglib_##prefix();
00048 
00049 #define COMPILE_TIME_TAGLIB(prefix) \
00050     extern "C" { \
00051         servlet::taglib::CompileTimeTaglib* get_taglib_##prefix() \
00052         { \
00053             static servlet::taglib::CompileTimeTaglib taglib(#prefix); \
00054             return &taglib; \
00055         } \
00056         servlet::taglib::Taglib* create_taglib_##prefix(const servlet::taglib::attribs_t&) \
00057         { \
00058             return get_taglib_##prefix();   \
00059         } \
00060     }
00061 
00069 #define EXPORT_COMPILE_TIME_TAG(prefix,name,class) \
00070     struct register_compile_time_tag_##prefix##_##name##_t \
00071     { \
00072         register_compile_time_tag_##prefix##_##name##_t() \
00073         { \
00074             static servlet::taglib::CompileTimeTaglib::TagFactory<class> factory; \
00075             get_taglib_##prefix()->registerTag(#name, &factory); \
00076         } \
00077     } register_compile_time_tag_##prefix##_##name;
00078 
00079 #endif // CXXSP_COMPILE_TIME_TAGLIB_H_
00080 /* -*- c++ -*- */

SourceForge.net Logo