// Filename: dataGraphTraverser.h
// Created by:  drose (05Feb01)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////

#ifndef DATAGRAPHTRAVERSER_H
#define DATAGRAPHTRAVERSER_H

#include "pandabase.h"

#include "allTransitionsWrapper.h"

class Node;

////////////////////////////////////////////////////////////////////
//       Class : DataGraphTraverser
// Description : This class manages the traversal of the data graph,
//               so that all data transitions generated by nodes in the
//               graph are transmitted to nodes below them.
//
//               A bit of logic is employed to ensure that if a node
//               is assigned to two parents, the data from both
//               parents is merged before passing it to the child.
//
//               This class need not be exported from PANDA.DLL.
////////////////////////////////////////////////////////////////////
class DataGraphTraverser {
public:
  INLINE DataGraphTraverser();

  INLINE void traverse(Node *node);
  INLINE void traverse_below(Node *node, const AllTransitionsWrapper &data);

private:
  class SavedState {
  public:
    AllTransitionsWrapper _data;
    bool _has_spam_mode;
    int _num_parents_so_far;
  };

  void r_traverse(Node *node, AllTransitionsWrapper &data, bool has_spam_mode);
  void r_traverse_below(Node *node, AllTransitionsWrapper &data, bool has_spam_mode);
  void save(Node *node, const AllTransitionsWrapper &data, bool has_spam_mode,
            int num_parents);
  void resume(Node *node, SavedState &state);
  void resume_all();

  typedef pmap<Node *, SavedState> States;
  States _saved_states;
};

#include "dataGraphTraverser.I"

#endif
