source: trunk/IPs/systemC/processor/Morpheo/Behavioural/src/Stat_binary_tree_valid.cpp @ 88

Last change on this file since 88 was 88, checked in by rosiere, 15 years ago

Almost complete design
with Test and test platform

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifdef STATISTICS
2#include "Behavioural/include/Stat_binary_tree.h"
3
4namespace morpheo {
5namespace behavioural {
6
7  bool Stat_binary_tree::valid (void)
8  {
9    if (_data_type == NONE)
10      return false;
11
12    if ((_data_type == VARIABLE) or
13        (_data_type == CONSTANT))
14      return ((_left  == NULL) and
15              (_right == NULL) );
16   
17    if (_data_type == OPERATOR_UNARY)
18      return ((_right == NULL) and
19              (_left  != NULL) and
20              (_left->valid()));
21
22    if (_data_type == OPERATOR_BINARY)
23      return ((_left  != NULL ) and
24              (_left ->valid()) and
25              (_right != NULL ) and
26              (_right->valid()));
27
28    return false;
29  }
30
31  void Stat_binary_tree::print (uint32_t depth)
32  {
33    std::string tab = std::string(depth,'\t');
34    std::string sep = " ";
35    if (_data_type == NONE)
36      {
37        std::cout << tab << "<node> NONE (error)" << std::endl;
38
39        if (_left  != NULL)
40          _left ->print(depth+1);
41        if (_right != NULL)
42          _right->print(depth+1);
43      }
44
45    if ((_data_type == VARIABLE) or
46        (_data_type == CONSTANT))
47      {
48        std::cout << tab << "<leaf>"
49                  << " "
50                  << ((_left   == NULL)?"left  == NULL        ":"left  != NULL (error)")
51                  << " "
52                  << ((_right  == NULL)?"right == NULL        ":"right != NULL (error)")
53                  << std::endl;
54
55        if (_left  != NULL)
56          _left ->print(depth+1);
57        if (_right != NULL)
58          _right->print(depth+1);
59      }
60   
61    if (_data_type == OPERATOR_UNARY)
62      {
63        std::cout << tab << "<unary>"
64                  << " "
65                  << ((_left   == NULL)?"left  == NULL (error)":"left  != NULL        ")
66                  << " "
67                  << ((_right  == NULL)?"right == NULL        ":"right != NULL (error)")
68                  << std::endl;
69       
70        if (_left  != NULL)
71          _left ->print(depth+1);
72        if (_right != NULL)
73          _right->print(depth+1);
74      }
75
76    if (_data_type == OPERATOR_BINARY)
77      {
78        std::cout << tab << "<binary>"
79                  << " "
80                  << ((_left   == NULL)?"left  == NULL (error)":"left  != NULL        ")
81                  << " "
82                  << ((_right  == NULL)?"right == NULL (error)":"right != NULL        ")
83                  << std::endl;
84
85        if (_left  != NULL)
86          _left ->print(depth+1);
87        if (_right != NULL)
88          _right->print(depth+1);
89      }
90  }
91
92};
93};
94#endif
Note: See TracBrowser for help on using the repository browser.