00001 00002 #ifndef _SUIFLINK_SUIFCOUNTER_H_ 00003 #define _SUIFLINK_SUIFCOUNTER_H_ 00004 00009 #include "common/suif_map.h" 00010 #include "common/suif_vector.h" 00011 #include "iokernel/meta_class.h" 00012 #include "suifkernel/suif_object.h" 00013 #include "suifkernel/suif_env.h" 00014 #include "suifkernel/all_walker.h" 00015 #include <iostream.h> 00016 00017 class NodeCounter; 00018 00022 class NodeCounter { 00023 private: 00024 const MetaClass * const _meta_class; 00025 NodeCounter *_parent; 00026 suif_vector<NodeCounter*> _children; 00027 unsigned _direct_count; 00028 void set_parent(NodeCounter*); 00029 public: 00030 NodeCounter(const MetaClass*); 00031 ~NodeCounter(void); 00032 MetaClass* get_meta_class(void) const; 00033 unsigned get_direct_count(void) const; 00034 unsigned get_indirect_count(void) const; 00035 void add_child(NodeCounter*); 00036 unsigned get_child_count(void) const; 00037 NodeCounter* get_nth_child(unsigned) const; 00038 unsigned add_direct_count(void); 00039 }; 00040 00041 00042 00049 class SuifCounter : public AllWalker { 00050 private: 00051 NodeCounter *_root_counter; 00052 suif_map<const MetaClass*, NodeCounter*> _NodeCounter_map; 00053 bool make_ancestors(NodeCounter*); 00054 NodeCounter *add_node_counter(const MetaClass*); 00055 00056 public: 00058 SuifCounter(SuifEnv*); 00059 00063 Walker::ApplyStatus operator()(SuifObject*); 00064 00067 void count(SuifObject* obj); 00068 00071 NodeCounter* get_node_counter(const MetaClass* mc); 00072 00075 ostream& print_result(ostream&) const; 00076 00077 }; 00078 00079 00080 #endif // _SUIFLINK_SUIFCOUNTER_H_ 00081