Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/typeRegistry.h

Go to the documentation of this file.
00001 // Filename: typeRegistry.h
00002 // Created by:  drose (06Aug01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef TYPEREGISTRY_H
00020 #define TYPEREGISTRY_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "typeHandle.h"
00025 #include "typeRegistryNode.h"
00026 
00027 #include "notify.h"
00028 #include "pvector.h"
00029 #include "pmap.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : TypeRegistry
00033 // Description : The TypeRegistry class maintains all the assigned
00034 //               TypeHandles in a given system.  There should be only
00035 //               one TypeRegistry class during the lifetime of the
00036 //               application.  It will be created on the local heap
00037 //               initially, and it should be migrated to shared memory
00038 //               as soon as shared memory becomes available.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDAEXPRESS TypeRegistry {
00041 public:
00042   // User code shouldn't generally need to call
00043   // TypeRegistry::register_type() or record_derivation() directly;
00044   // instead, use the register_type convenience function, defined
00045   // below.
00046   bool register_type(TypeHandle &type_handle, const string &name);
00047   TypeHandle register_dynamic_type(const string &name);
00048 
00049   void record_derivation(TypeHandle child, TypeHandle parent);
00050   void record_alternate_name(TypeHandle type, const string &name);
00051 
00052 PUBLISHED:
00053   TypeHandle find_type(const string &name) const;
00054 
00055   string get_name(TypeHandle type, TypedObject *object) const;
00056   INLINE bool is_derived_from(TypeHandle child, TypeHandle base,
00057                               TypedObject *child_object);
00058 
00059   int get_num_root_classes();
00060   TypeHandle get_root_class(int n);
00061 
00062   int get_num_parent_classes(TypeHandle child,
00063                              TypedObject *child_object) const;
00064   TypeHandle get_parent_class(TypeHandle child, int index) const;
00065 
00066   int get_num_child_classes(TypeHandle child,
00067                             TypedObject *child_object) const;
00068   TypeHandle get_child_class(TypeHandle child, int index) const;
00069 
00070   TypeHandle get_parent_towards(TypeHandle child, TypeHandle base,
00071                                 TypedObject *child_object);
00072 
00073   static void reregister_types();
00074 
00075   void write(ostream &out) const;
00076 
00077   // ptr() returns the pointer to the global TypeRegistry object.
00078   static TypeRegistry *ptr();
00079 
00080 private:
00081   // The TypeRegistry class should never be constructed by user code.
00082   // There is only one in the universe, and it constructs itself!
00083   TypeRegistry();
00084 
00085   static void init_global_pointer();
00086 
00087   // In NDEBUG mode, this is an inline function; otherwise, it's
00088   // out-of-line.
00089 #ifdef NDEBUG
00090   INLINE TypeRegistryNode *look_up(TypeHandle type, TypedObject *object) const;
00091 #else
00092   TypeRegistryNode *look_up(TypeHandle type, TypedObject *object) const;
00093 #endif
00094 
00095   INLINE void freshen_derivations();
00096   void rebuild_derivations();
00097   void write_node(ostream &out, int indent_level,
00098                   const TypeRegistryNode *node) const;
00099 
00100   typedef pvector<TypeRegistryNode *> HandleRegistry;
00101   HandleRegistry _handle_registry;
00102 
00103   typedef pmap<string, TypeRegistryNode *> NameRegistry;
00104   NameRegistry _name_registry;
00105 
00106   typedef pvector<TypeRegistryNode *> RootClasses;
00107   RootClasses _root_classes;
00108 
00109   bool _derivations_fresh;
00110 
00111   static TypeRegistry *_global_pointer;
00112 };
00113 
00114 #include "typeRegistry.I"
00115 
00116 #endif

Generated on Fri May 2 00:38:44 2003 for Panda by doxygen1.3