using auto_ptr
fluxgen fluxgen
2 files changed,
12 insertions(+),
10 deletions(-)
M
src/FbTk/KeyUtil.cc
→
src/FbTk/KeyUtil.cc
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: KeyUtil.cc,v 1.3 2003/10/05 07:20:16 rathnor Exp $ +// $Id: KeyUtil.cc,v 1.4 2003/10/13 19:31:56 fluxgen Exp $ #include "KeyUtil.hh" #include "App.hh"@@ -28,12 +28,12 @@ #include <string>
namespace FbTk { -KeyUtil *KeyUtil::s_keyutil = 0; +std::auto_ptr<KeyUtil> KeyUtil::s_keyutil; -KeyUtil *KeyUtil::instance() { - if (s_keyutil == 0) - s_keyutil = new KeyUtil(); - return s_keyutil; +KeyUtil &KeyUtil::instance() { + if (s_keyutil.get() == 0) + s_keyutil.reset(new KeyUtil()); + return *s_keyutil.get(); }@@ -170,7 +170,7 @@ }
} unsigned int KeyUtil::keycodeToModmask(unsigned int keycode) { - XModifierKeymap *modmap = instance()->m_modmap; + XModifierKeymap *modmap = instance().m_modmap; if (!modmap) return 0;
M
src/FbTk/KeyUtil.hh
→
src/FbTk/KeyUtil.hh
@@ -19,13 +19,15 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: KeyUtil.hh,v 1.2 2003/10/05 07:20:35 rathnor Exp $ +// $Id: KeyUtil.hh,v 1.3 2003/10/13 19:31:56 fluxgen Exp $ #ifndef FBTK_KEYUTIL_HH #define FBTK_KEYUTIL_HH #include <X11/Xlib.h> #include <X11/keysym.h> + +#include <memory> namespace FbTk {@@ -36,7 +38,7 @@ KeyUtil();
~KeyUtil(); void init(); - static KeyUtil *instance(); + static KeyUtil &instance(); /** Grab the specified key@@ -78,7 +80,7 @@ private:
void loadModmap(); XModifierKeymap *m_modmap; - static KeyUtil *s_keyutil; + static std::auto_ptr<KeyUtil> s_keyutil; }; } // end namespace FbTk