From 24d705b031a1925b2545a7a9db637a00a07988e0 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 29 Jul 2014 11:15:12 +0000 Subject: [PATCH] The "null" ButtonHandle and TypeHandle now evaluate to false --- dtool/src/dtoolbase/typeHandle.I | 12 +++++++++++- dtool/src/dtoolbase/typeHandle.h | 1 + panda/src/putil/buttonHandle.I | 13 ++++++++++++- panda/src/putil/buttonHandle.h | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dtool/src/dtoolbase/typeHandle.I b/dtool/src/dtoolbase/typeHandle.I index 9304fd400c..482d0996db 100644 --- a/dtool/src/dtoolbase/typeHandle.I +++ b/dtool/src/dtoolbase/typeHandle.I @@ -275,6 +275,17 @@ none() { return _none; } +//////////////////////////////////////////////////////////////////// +// Function: TypeHandle::operator bool +// Access: Published +// Description: TypeHandle::none() evaluates to false, everything +// else evaluates to true. +//////////////////////////////////////////////////////////////////// +INLINE TypeHandle:: +operator bool () const { + return (_index != 0); +} + //////////////////////////////////////////////////////////////////// // Function: get_best_parent_from_Set // Access: Published @@ -295,4 +306,3 @@ INLINE int TypeHandle::get_best_parent_from_Set(const std::set< int > &legal_va } return -1; } - diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index 5d0bfa34fb..2ca06169e3 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -146,6 +146,7 @@ PUBLISHED: INLINE int get_index() const; INLINE void output(ostream &out) const; INLINE static TypeHandle none(); + INLINE operator bool () const; private: int _index; diff --git a/panda/src/putil/buttonHandle.I b/panda/src/putil/buttonHandle.I index e692cef07e..0da0f9a782 100644 --- a/panda/src/putil/buttonHandle.I +++ b/panda/src/putil/buttonHandle.I @@ -135,7 +135,7 @@ get_index() const { //////////////////////////////////////////////////////////////////// // Function: ButtonHandle::output // Access: Published -// Description: +// Description: //////////////////////////////////////////////////////////////////// INLINE void ButtonHandle:: output(ostream &out) const { @@ -152,3 +152,14 @@ INLINE ButtonHandle ButtonHandle:: none() { return _none; } + +//////////////////////////////////////////////////////////////////// +// Function: ButtonHandle::operator bool +// Access: Published +// Description: ButtonHandle::none() evaluates to false, everything +// else evaluates to true. +//////////////////////////////////////////////////////////////////// +INLINE ButtonHandle:: +operator bool () const { + return (_index != 0); +} diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index 909458c32c..3e4a5f0e4d 100644 --- a/panda/src/putil/buttonHandle.h +++ b/panda/src/putil/buttonHandle.h @@ -51,6 +51,8 @@ PUBLISHED: INLINE void output(ostream &out) const; INLINE static ButtonHandle none(); + INLINE operator bool () const; + private: int _index; static ButtonHandle _none;