// Filename: nodeTransition.I
// Created by:  drose (20Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH NodeTransition::
NodeTransition() {
  _priority = 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Copy Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH NodeTransition::
NodeTransition(const NodeTransition &copy) :
  TypedWritableReferenceCount(copy),
  _priority(copy._priority)
{
  // We specifically do *not* copy the _arcs list.
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Copy Assignment Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH void NodeTransition::
operator = (const NodeTransition &copy) {
  TypedWritableReferenceCount::operator = (copy);
  _priority = copy._priority;
  // We specifically do *not* copy the _arcs list.
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Equality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator == (const NodeTransition &other) const {
  return compare_to(other) == 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Inequality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator != (const NodeTransition &other) const {
  return compare_to(other) != 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Inequality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator < (const NodeTransition &other) const {
  return compare_to(other) < 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Inequality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator <= (const NodeTransition &other) const {
  return compare_to(other) <= 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Inequality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator > (const NodeTransition &other) const {
  return compare_to(other) > 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::Inequality Operator
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
INLINE_GRAPH bool NodeTransition::
operator >= (const NodeTransition &other) const {
  return compare_to(other) >= 0;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::generate_hash
//       Access: Public
//  Description: Adds the transition to the indicated hash generator.
////////////////////////////////////////////////////////////////////
INLINE_GRAPH void NodeTransition::
generate_hash(GraphHashGenerator &hash) const {
  hash.add_int(get_handle().get_index());
  internal_generate_hash(hash);
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::set_priority
//       Access: Public
//  Description: Changes the priority associated with this transition.
//               The transition will always override transitions with
//               a lower priority.
////////////////////////////////////////////////////////////////////
INLINE_GRAPH void NodeTransition::
set_priority(int priority) {
  _priority = priority;
  state_changed();
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::get_priority
//       Access: Public
//  Description: Returns the priority associated with this transition.
////////////////////////////////////////////////////////////////////
INLINE_GRAPH int NodeTransition::
get_priority() const {
  return _priority;
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::add_to_arc
//       Access: Protected
//  Description: Intended to be called only by the arc's
//               set_transition() method to indicate that the
//               transition has been assigned to the arc.  Further
//               state changes on the transition will now notify the
//               arc.
////////////////////////////////////////////////////////////////////
INLINE_GRAPH void NodeTransition::
added_to_arc(NodeRelation *arc) {
  bool inserted = _arcs.insert(arc).second;
  nassertv(inserted);
}

////////////////////////////////////////////////////////////////////
//     Function: NodeTransition::add_to_arc
//       Access: Protected
//  Description: Intended to be called by the arc's
//               set_transition() or clear_transition() method (or by
//               the arc's destructor) to indicate that the transition
//               is no longer assigned to the arc.  Further state
//               changes on the transition will *not* notify the arc.
////////////////////////////////////////////////////////////////////
INLINE_GRAPH void NodeTransition::
removed_from_arc(NodeRelation *arc) {
  size_t num_erased = _arcs.erase(arc);
  nassertv(num_erased == 1);
}

INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransition &ntb) {
  ntb.output(out);
  return out;
}
