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

panda/src/putil/buttonRegistry.h

Go to the documentation of this file.
00001 // Filename: buttonRegistry.h
00002 // Created by:  drose (01Mar00)
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 BUTTONREGISTRY_H
00020 #define BUTTONREGISTRY_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "buttonHandle.h"
00025 
00026 #include "pvector.h"
00027 #include "pmap.h"
00028 #include <string>
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : ButtonRegistry
00032 // Description : The ButtonRegistry class maintains all the assigned
00033 //               ButtonHandles in a given system.  There should be only
00034 //               one ButtonRegistry class during the lifetime of the
00035 //               application.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDA ButtonRegistry {
00038 protected:
00039   class EXPCL_PANDA RegistryNode {
00040   public:
00041     INLINE RegistryNode(ButtonHandle handle, const string &name);
00042 
00043     ButtonHandle _handle;
00044     string _name;
00045   };
00046 
00047 public:
00048   bool register_button(ButtonHandle &button_handle, const string &name,
00049                        char ascii_equivalent = '\0');
00050 
00051 PUBLISHED:
00052   ButtonHandle get_button(const string &name);
00053   ButtonHandle find_ascii_button(char ascii_equivalent) const;
00054 
00055   // ptr() returns the pointer to the global ButtonRegistry object.
00056   INLINE static ButtonRegistry *ptr();
00057 
00058 public:
00059   INLINE string get_name(ButtonHandle button) const;
00060 
00061   void write(ostream &out) const;
00062 
00063 private:
00064   // The ButtonRegistry class should never be constructed by user code.
00065   // There is only one in the universe, and it constructs itself!
00066   ButtonRegistry();
00067 
00068   static void init_global_pointer();
00069 
00070   RegistryNode *look_up(ButtonHandle button) const;
00071 
00072   typedef pvector<RegistryNode *> HandleRegistry;
00073   HandleRegistry _handle_registry;
00074 
00075   typedef pmap<string, RegistryNode *> NameRegistry;
00076   NameRegistry _name_registry;
00077 
00078   static ButtonRegistry *_global_pointer;
00079 };
00080 
00081 #include "buttonRegistry.I"
00082 
00083 #endif

Generated on Fri May 2 00:43:34 2003 for Panda by doxygen1.3