Scopira 20080306

objflowloader.h

00001 
00002 /*
00003  *  Copyright (c) 2002-2004    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013  
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_OBJFLOWLOADER_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_OBJFLOWLOADER_H__
00016 
00017 #include <typeinfo>
00018 #include <string>
00019 
00020 #include <scopira/tool/object.h>
00021 #include <scopira/tool/iterator.h>
00022 #include <scopira/tool/export.h>
00023 
00024 namespace scopira
00025 {
00026   namespace tool
00027   {
00028     class objflowloader;
00029 
00030     // forward decls
00031     class object;
00032 
00033     // utility template function for the static loader functions
00034     // the add_type methods often need
00035     template <class T> object* objloadfunc_g(void) { return new T(); }
00036 
00037     template <class T> class register_flow;
00038   }
00039 }
00040 
00054 class scopira::tool::objflowloader : public scopira::tool::object
00055 {
00056   public:
00057     typedef scopira::tool::iterator_g<object*> note_iterator;
00058 
00059   protected:
00060     class impl_t;
00061     scopira::tool::count_ptr<impl_t> dm_imp;
00062   
00063     static objflowloader* dm_loader;     // the static loader to use  
00064 
00065   public:
00067     typedef object* (*loadfunc_t)(void);
00068 
00069   public:
00070     
00080     SCOPIRA_EXPORT static objflowloader* instance(void);
00081   
00091     SCOPIRA_EXPORT objflowloader(void);
00092     
00094     SCOPIRA_EXPORT ~objflowloader();
00095     
00098     SCOPIRA_EXPORT void add_type(const std::type_info& id, const std::string& name, loadfunc_t loader);
00099 
00101     SCOPIRA_EXPORT void add_type(const std::type_info& id, const char * name, loadfunc_t loader);
00102     
00104     SCOPIRA_EXPORT const std::string& get_name(const std::type_info &id) const;
00105     
00107     SCOPIRA_EXPORT bool has_typeinfo(const std::type_info &id) const;
00109     SCOPIRA_EXPORT bool has_typeinfo(const std::string &name) const;
00111     SCOPIRA_EXPORT const std::type_info& get_typeinfo(const std::string &name) const;
00112 
00114     SCOPIRA_EXPORT object* load_object(const std::type_info& id) const;
00115 
00126     SCOPIRA_EXPORT void set_note(const std::type_info &id, scopira::tool::object *o);
00128     SCOPIRA_EXPORT scopira::tool::object * get_note(const std::type_info &id) const;
00129 
00134     SCOPIRA_EXPORT note_iterator get_note_iterator(void);
00135 };
00136 
00137 namespace scopira
00138 {
00139   namespace tool
00140   {
00141     SCOPIRA_EXPORT void flow_reg_imp(const std::type_info& id, const char * name, scopira::tool::objflowloader::loadfunc_t loader);
00142   }
00143 }
00144 
00155 template <class T>
00156 class scopira::tool::register_flow
00157 {
00158   public:
00160     register_flow(const char *fullname) {
00161       scopira::tool::flow_reg_imp(typeid(T), (fullname), scopira::tool::objloadfunc_g<T>);
00162     }
00164     register_flow(const char *fullname, int dummy) {
00165       scopira::tool::flow_reg_imp(typeid(T), (fullname), 0);
00166     }
00167 };
00168 
00169 #endif
00170 
00171