/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef BehTree_h
#define BehTree_h

#include <stdlib.h>
#include "../headers/CircBufPacket.h"
#include "../headers/FileSystem.h"

class BehTree {

 public:
  enum val_type { T_BOOL,T_INT };

  struct TreeNode{

    //leaf node if num_children = 0
    int num_children;
    TreeNode** children;
    
    //only valid for decision nodes    
    char* attr_name;      //descriptive name of what we split on (used in printing the tree)
    int value_type;       //T_BOOL or T_INT
    int *int_attr_value;  //points to the int variable that we test
    bool *bool_attr_value;//points to the bool variable that we test

    //only valid for leaf nodes
    char* beh_seq;   //the BehaviorSequence name we want to run
    int num_failures;//number of failed terminations of this BehaviorSequence
    int num_successes;//number of successful terminations of this BehaviorSequence
  };
  
  TreeNode *root;
  
  
  BehTree();  
  ~BehTree();

  TreeNode* addDecisionNode(char* name, int num_vals, int *value_ptr);
  TreeNode* addDecisionNode(char* name, int num_vals, bool *value_ptr);
  TreeNode* addLeafNode(char* beh_seq);

  void print();

 private:
  void recursivePrint(int indent_level,TreeNode *node);

};

#endif
