Browse Source

operator bool()

David Rose 17 years ago
parent
commit
5d73bc8e19
2 changed files with 13 additions and 0 deletions
  1. 11 0
      panda/src/pgraph/nodePath.I
  2. 2 0
      panda/src/pgraph/nodePath.h

+ 11 - 0
panda/src/pgraph/nodePath.I

@@ -222,6 +222,17 @@ is_empty() const {
   return (_head == (NodePathComponent *)NULL);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::operator bool
+//       Access: Published
+//  Description: Returns true if the NodePath is valid (not empty),
+//               or false if it contains no nodes.
+////////////////////////////////////////////////////////////////////
+INLINE NodePath::
+operator bool () const {
+  return !is_empty();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::is_singleton
 //       Access: Published

+ 2 - 0
panda/src/pgraph/nodePath.h

@@ -177,6 +177,8 @@ PUBLISHED:
 
   // Methods to query a NodePath's contents.
   INLINE bool is_empty() const;
+  INLINE operator bool () const;
+
   INLINE bool is_singleton(Thread *current_thread = Thread::get_current_thread()) const;
   int get_num_nodes(Thread *current_thread = Thread::get_current_thread()) const;
   PandaNode *get_node(int index, Thread *current_thread = Thread::get_current_thread()) const;