Scopira  20080306
objflowloader.h
1 
2 /*
3  * Copyright (c) 2002-2004 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_TOOL_OBJFLOWLOADER_H__
15 #define __INCLUDED_SCOPIRA_TOOL_OBJFLOWLOADER_H__
16 
17 #include <typeinfo>
18 #include <string>
19 
20 #include <scopira/tool/object.h>
21 #include <scopira/tool/iterator.h>
22 #include <scopira/tool/export.h>
23 
24 namespace scopira
25 {
26  namespace tool
27  {
28  class objflowloader;
29 
30  // forward decls
31  class object;
32 
33  // utility template function for the static loader functions
34  // the add_type methods often need
35  template <class T> object* objloadfunc_g(void) { return new T(); }
36 
37  template <class T> class register_flow;
38  }
39 }
40 
55 {
56  public:
58 
59  protected:
60  class impl_t;
62 
63  static objflowloader* dm_loader; // the static loader to use
64 
65  public:
67  typedef object* (*loadfunc_t)(void);
68 
69  public:
70 
80  SCOPIRA_EXPORT static objflowloader* instance(void);
81 
91  SCOPIRA_EXPORT objflowloader(void);
92 
94  SCOPIRA_EXPORT ~objflowloader();
95 
98  SCOPIRA_EXPORT void add_type(const std::type_info& id, const std::string& name, loadfunc_t loader);
99 
101  SCOPIRA_EXPORT void add_type(const std::type_info& id, const char * name, loadfunc_t loader);
102 
104  SCOPIRA_EXPORT const std::string& get_name(const std::type_info &id) const;
105 
107  SCOPIRA_EXPORT bool has_typeinfo(const std::type_info &id) const;
109  SCOPIRA_EXPORT bool has_typeinfo(const std::string &name) const;
111  SCOPIRA_EXPORT const std::type_info& get_typeinfo(const std::string &name) const;
112 
114  SCOPIRA_EXPORT object* load_object(const std::type_info& id) const;
115 
126  SCOPIRA_EXPORT void set_note(const std::type_info &id, scopira::tool::object *o);
128  SCOPIRA_EXPORT scopira::tool::object * get_note(const std::type_info &id) const;
129 
134  SCOPIRA_EXPORT note_iterator get_note_iterator(void);
135 };
136 
137 namespace scopira
138 {
139  namespace tool
140  {
141  SCOPIRA_EXPORT void flow_reg_imp(const std::type_info& id, const char * name, scopira::tool::objflowloader::loadfunc_t loader);
142  }
143 }
144 
155 template <class T>
157 {
158  public:
160  register_flow(const char *fullname) {
161  scopira::tool::flow_reg_imp(typeid(T), (fullname), scopira::tool::objloadfunc_g<T>);
162  }
164  register_flow(const char *fullname, int dummy) {
165  scopira::tool::flow_reg_imp(typeid(T), (fullname), 0);
166  }
167 };
168 
169 #endif
170 
171 
void add_type(const std::type_info &id, const std::string &name, loadfunc_t loader)
Definition: archiveflow.h:20
const std::type_info & get_typeinfo(const std::string &name) const
gets the typeid, based on the unique name, the name must exist
const std::string & get_name(const std::type_info &id) const
gets the name, based on typeid
Definition: object.h:71
static objflowloader * instance(void)
bool has_typeinfo(const std::type_info &id) const
do i have this type?
Definition: iterator.h:26
register_flow(const char *fullname)
ctor, yes, just plain char *
Definition: objflowloader.h:160
Definition: objflowloader.h:37
Definition: objflowloader.h:54
void set_note(const std::type_info &id, scopira::tool::object *o)
object *(* loadfunc_t)(void)
a loader function type
Definition: objflowloader.h:67
register_flow(const char *fullname, int dummy)
version that has a NULL loader
Definition: objflowloader.h:164
note_iterator get_note_iterator(void)
object * load_object(const std::type_info &id) const
invokes a loader, null on fail
scopira::tool::object * get_note(const std::type_info &id) const
gets the optional note object for the given name, might return null for none