Scopira 20080306

objecttype.h

00001 
00002 /*
00003  *  Copyright (c) 2005    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_OBJECTTYPE_H__
00015 #define __INCLUDED_SCOPIRA_CORE_OBJECTTYPE_H__
00016 
00017 #include <vector>
00018 
00019 #include <scopira/tool/object.h>
00020 #include <scopira/tool/objflowloader.h>
00021 #include <scopira/tool/iterator.h>
00022 #include <scopira/tool/export.h>
00023 #include <scopira/core/register.h>
00024 
00025 namespace scopira
00026 {
00027   namespace core
00028   {
00029     class objecttype;
00030   }
00031 }
00032 
00038 class scopira::core::objecttype : public scopira::tool::object
00039 {
00040   private:
00041     typedef std::vector<objecttype*> parents_t;
00042     typedef std::vector<scopira::tool::count_ptr<objecttype> > childs_t;      // bad english, yeah :)
00043 
00044   public:
00045     typedef scopira::tool::iterator_g<objecttype*> objecttype_iterator;
00046 
00047   private:
00048     parents_t dm_parents;
00049     childs_t dm_childs;   // parents and children
00050     std::string dm_name;    // name of the type
00051     copyfunc_t dm_copyfunc;
00052 
00053   public:
00055     SCOPIRA_EXPORT objecttype(const std::string &name, copyfunc_t cp);
00056 
00062     const std::string &get_name(void) const { return dm_name; }
00063 
00069     bool has_copyfunc(void) const { return dm_copyfunc != 0; }
00070 
00075     SCOPIRA_EXPORT void add_child(objecttype *d);
00076 
00081     SCOPIRA_EXPORT objecttype_iterator get_parent_iterator(void);
00086     SCOPIRA_EXPORT objecttype_iterator get_child_iterator(void);
00087 
00095     SCOPIRA_EXPORT objecttype * find(const std::string & _name);
00096 
00103     SCOPIRA_EXPORT bool is_base(const objecttype *d) const;
00104 
00110     SCOPIRA_EXPORT int base_depth(const objecttype *d) const;
00111 
00117     SCOPIRA_EXPORT void print_tree(int indent = 0);
00118 
00120     template <class CT>
00121       CT * load_copy(const scopira::tool::object *src) const { return dynamic_cast<CT*>(load_copy_impl(src)); }
00122 
00123   protected:
00125     SCOPIRA_EXPORT virtual void print_tree_this(int indent);
00126 
00127   private:
00128     SCOPIRA_EXPORT object * load_copy_impl(const scopira::tool::object *srco) const;
00129 };
00130 
00131 #endif
00132