Panda3D
 All Classes Functions Variables Enumerations
buttonRegistry.h
00001 // Filename: buttonRegistry.h
00002 // Created by:  drose (01Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef BUTTONREGISTRY_H
00016 #define BUTTONREGISTRY_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "buttonHandle.h"
00021 
00022 #include "pvector.h"
00023 #include "pmap.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : ButtonRegistry
00027 // Description : The ButtonRegistry class maintains all the assigned
00028 //               ButtonHandles in a given system.  There should be only
00029 //               one ButtonRegistry class during the lifetime of the
00030 //               application.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA_PUTIL ButtonRegistry {
00033 protected:
00034   class EXPCL_PANDA_PUTIL RegistryNode {
00035   public:
00036     INLINE RegistryNode(ButtonHandle handle, ButtonHandle alias,
00037                         const string &name);
00038 
00039     ButtonHandle _handle;
00040     ButtonHandle _alias;
00041     string _name;
00042   };
00043 
00044 public:
00045   bool register_button(ButtonHandle &button_handle, const string &name,
00046                        ButtonHandle alias = ButtonHandle::none(),
00047                        char ascii_equivalent = '\0');
00048 
00049 PUBLISHED:
00050   ButtonHandle get_button(const string &name);
00051   ButtonHandle find_ascii_button(char ascii_equivalent) const;
00052 
00053   void write(ostream &out) 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   INLINE ButtonHandle get_alias(ButtonHandle button) const;
00061 
00062 private:
00063   // The ButtonRegistry class should never be constructed by user code.
00064   // There is only one in the universe, and it constructs itself!
00065   ButtonRegistry();
00066 
00067   static void init_global_pointer();
00068 
00069   RegistryNode *look_up(ButtonHandle button) const;
00070 
00071   typedef pvector<RegistryNode *> HandleRegistry;
00072   HandleRegistry _handle_registry;
00073 
00074   typedef pmap<string, RegistryNode *> NameRegistry;
00075   NameRegistry _name_registry;
00076 
00077   static ButtonRegistry *_global_pointer;
00078 };
00079 
00080 #include "buttonRegistry.I"
00081 
00082 #endif
 All Classes Functions Variables Enumerations