Scopira 20080306

register.h

00001 
00002 /*
00003  *  Copyright (c) 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_CORE_REGISTER_H__
00015 #define __INCLUDED_SCOPIRA_CORE_REGISTER_H__
00016 
00017 #include <scopira/tool/objflowloader.h>
00018 
00019 namespace scopira
00020 {
00021   namespace core
00022   {
00036     enum
00037     {
00038       vg_primary =      0x0001,       // not used, but i might sometime
00039       vg_noui_c =       0x0002,       // doesnt actually have a UI component (and doesnt decent from coreui::widget, etc)
00040       vg_windowui_c =   0x0004,       // has a gui, and always wants to be in its own window (having this and vg_noui_c)
00041 
00042       vg_needs_project_c = 0x0100,    // a view that requires the model to have a project and be clicked from the project tree manager
00043       vg_needs_copyfunc_c = 0x0200,   // a view that requires the model have a registered copy ctor/func
00044 
00045       vg_show_c =       0x00FF,       // lower 16 are shown by default
00046       vg_hide_c =       0xFF00,       // default that are hidden (just to be complete)
00047     };
00048 
00049     // another mapping of the above
00050     enum
00051     {
00052       no_uimode_c = vg_noui_c,
00053       default_uimode_c = 0,
00054       windowonly_uimode_c = vg_windowui_c,
00055     };
00056 
00058     class interface_model_type { };
00060     class copyable_model_type { };
00061 
00062     typedef scopira::tool::object* (*copyfunc_t)(const scopira::tool::object*);
00063     template <class T> scopira::tool::object* objcopyfunc_g(const scopira::tool::object *srco) { return new T(*dynamic_cast<const T*>(srco)); }
00064 
00065     class mi_set;
00066 
00067     template <class T> class register_flow;
00068     template <class T> class register_object;
00069     template <class T> class register_model;
00070     template <class T> class register_view;
00071     //class register_task;
00072 
00074     SCOPIRA_EXPORT void flow_reg_imp(const std::type_info& id, const char * name, scopira::tool::objflowloader::loadfunc_t loader);
00076     SCOPIRA_EXPORT void link_object_parent_imp(const std::type_info &id, const char *parent_name);
00078     SCOPIRA_EXPORT void link_object_parent_imp(const std::type_info &id, const char **parents);
00080     SCOPIRA_EXPORT void link_object_copyfunc(const std::type_info &id, copyfunc_t cf);
00082     SCOPIRA_EXPORT void link_model_imp(const std::type_info &id, bool linktomodeltype);
00084     SCOPIRA_EXPORT void link_view_imp(const std::type_info &id, const char *model_type, const char *menu_name, int vgmask);
00085     class objecttype;
00087     SCOPIRA_EXPORT void build_objecttype_tree(scopira::tool::count_ptr<scopira::core::objecttype> &out);
00088 
00090     extern SCOPIRA_EXPORT const char *object_type_c;
00092     extern SCOPIRA_EXPORT const char *model_type_c;
00094     extern SCOPIRA_EXPORT const char *project_type_c;
00096     extern SCOPIRA_EXPORT const char *view_type_c;
00097   }
00098 }
00099 
00100 // Lots of C-array stuff for efficincy when making static objects
00101 // all resolves to std::strings for storage, though
00102 
00109 class scopira::core::mi_set
00110 {
00111   public:
00112     const char * pm_parents[4];
00113 
00114   public:
00115     // ctors
00116 
00117     mi_set(const char *parent0)
00118       { pm_parents[0] = parent0; pm_parents[1] = 0; }
00119     mi_set(const char *parent0, const char *parent1)
00120       { pm_parents[0] = parent0; pm_parents[1] = parent1; pm_parents[2] = 0; }
00121     mi_set(const char *parent0, const char *parent1, const char *parent2)
00122       { pm_parents[0] = parent0; pm_parents[1] = parent1; pm_parents[2] = parent2; pm_parents[3] = 0; }
00123 };
00124 
00132 template <class T>
00133 class scopira::core::register_flow
00134 {
00135   public:
00137     register_flow(const char *fullname) {
00138       scopira::core::flow_reg_imp(typeid(T), (fullname), scopira::tool::objloadfunc_g<T>);
00139     }
00141     register_flow(const char *fullname, int dummy) {
00142       scopira::core::flow_reg_imp(typeid(T), (fullname), 0);
00143     }
00144 };
00145 
00151 template <class T>
00152 class scopira::core::register_object : public scopira::core::register_flow<T>
00153 {
00154   private:
00155     typedef scopira::core::register_flow<T> parent_type;
00156   public:
00158     register_object(const char *fullname, const char *parent_name = 0)
00159       : parent_type(fullname)
00160       { link_object_parent_imp(typeid(T), parent_name); }
00162     register_object(const char *fullname, mi_set s)
00163       : parent_type(fullname)
00164       { link_object_parent_imp(typeid(T), s.pm_parents); }
00167     register_object(const char *fullname, const char *parent_name, int dummy)
00168       : parent_type(fullname, dummy)
00169       { link_object_parent_imp(typeid(T), parent_name); }
00170 
00171     // a pure conat char ** one can be made too, if need be
00172 };
00173 
00184 template <class T>
00185 class scopira::core::register_model : public scopira::core::register_flow<T>
00186 {
00187   private:
00188     typedef scopira::core::register_flow<T> parent_type;
00189   public:
00191     register_model(const char *fullname, const char *parent_name = 0)
00192       : parent_type(fullname)
00193       { link_model_imp(typeid(T), !parent_name); link_object_parent_imp(typeid(T), parent_name); }
00195     register_model(const char *fullname, const char *parent_name, copyable_model_type dummyinstance)
00196       : parent_type(fullname)
00197       { link_model_imp(typeid(T), !parent_name); link_object_parent_imp(typeid(T), parent_name);
00198         link_object_copyfunc(typeid(T), objcopyfunc_g<T>); }
00200     register_model(const char *fullname, mi_set s)
00201       : parent_type(fullname)
00202       { link_model_imp(typeid(T), false); link_object_parent_imp(typeid(T), s.pm_parents); }
00204     register_model(const char *fullname, const char *parent_name, interface_model_type dummyinstance)
00205       : parent_type(fullname, 1)
00206       { link_model_imp(typeid(T), !parent_name); link_object_parent_imp(typeid(T), parent_name); }
00207 
00208     // a pure const char ** one can be made too, if need be
00209 };
00210 
00221 template <class T>
00222 class scopira::core::register_view : public scopira::core::register_flow<T>
00223 {
00224   private:
00225     typedef scopira::core::register_flow<T> parent_type;
00226   public:
00228 
00239     register_view(const char *fullname, const char *model_type, const char *menu_name, int vgmask = default_uimode_c)
00240       : parent_type(fullname)
00241       { link_view_imp(typeid(T), model_type, menu_name, vgmask); }
00242 };
00243 
00278 #endif
00279