Changeset 52 for sources/src/module_hierarchy.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/module_hierarchy.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : module_hierarchy.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 15_12_2005 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : module_hierarchy.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 15_12_2005 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 34 34 */ 35 35 36 #include "module_hierarchy.h"37 #include "sc_module.h"38 36 #include <cassert> 39 37 #include <map> 38 #include <cstdlib> 39 #include <cstring> 40 41 #include "sc_module.h" 42 #include "module_hierarchy.h" 43 40 44 #ifdef HAVE_CONFIG_H 41 45 #include "config.h" 42 46 #endif 43 #include <cstdlib> 44 #include <cstring> 47 45 48 46 49 using namespace std; … … 48 51 namespace sc_core { 49 52 50 typedef vector<sc_object *> sc_object_list_t;51 typedef map<const sc_object *,sc_object_list_t> sc_object2sc_object_list_t;52 typedef map<const sc_object*, sc_object *>sc_object2sc_object_t;53 typedef vector<sc_object *> sc_object_list_t; 54 typedef map<const sc_object *, sc_object_list_t> sc_object2sc_object_list_t; 55 typedef map<const sc_object*, sc_object *> sc_object2sc_object_t; 53 56 54 sc_object_list_t 55 sc_object2sc_object_list_t 56 sc_object2sc_object_t 57 sc_object_list_t top_level_objects; 58 sc_object2sc_object_list_t object2childs; 59 sc_object2sc_object_t object2parent; 57 60 58 void 59 set_parent (sc_module &mod, sc_module *parent) 60 { 61 object2parent[&mod] = parent; 62 sc_object_list_t &obj_list = (parent == NULL)?top_level_objects:object2childs[parent]; 63 obj_list.push_back (&mod); 61 62 void set_parent (sc_module &mod, sc_module * parent) { 63 object2parent[&mod] = parent; 64 sc_object_list_t &obj_list = (parent == NULL) ? top_level_objects : object2childs[parent]; 65 obj_list.push_back (&mod); 64 66 } 65 67 66 void 67 add_child (sc_object &obj) 68 { 69 sc_object_list_t *obj_list; 70 if (modules_stack.empty ()) 71 { 72 obj_list = &top_level_objects; 73 } else { 74 const sc_module *parent = modules_stack.top (); 75 if (parent == NULL) 76 return; //obj_list = &top_level_objects; 68 69 void add_child (sc_object &obj) { 70 sc_object_list_t * obj_list; 71 if (modules_stack.empty ()) { 72 obj_list = &top_level_objects; 73 } 77 74 else { 78 assert(parent != &obj); 79 const sc_object *pobj = (const sc_module *) parent; 80 obj_list = &(object2childs[pobj]); 75 const sc_module * parent = modules_stack.top (); 76 if (parent == NULL) { 77 return; //obj_list = &top_level_objects; 78 } 79 else { 80 assert(parent != &obj); 81 const sc_object * pobj = (const sc_module *) parent; 82 obj_list = &(object2childs[pobj]); 83 } 81 84 } 82 } 83 obj_list->push_back (&obj); 85 obj_list->push_back (&obj); 84 86 } 85 87 86 const std::vector<sc_object*>& 87 sc_get_top_level_objects() 88 { 89 return top_level_objects; 88 89 const std::vector<sc_object *>& sc_get_top_level_objects() { 90 return top_level_objects; 90 91 } 91 92 92 const sc_object* 93 sc_find_object (const char* name) 94 { 95 sc_object2sc_object_list_t::iterator i = object2childs.begin (); 96 while (i != object2childs.end ()) 97 { 98 const sc_object *obj = i->first; 99 const char *n = obj->name (); 100 if (strcmp (name, n) == 0) 101 return obj; 102 ++i; 103 } 104 return NULL; 105 } 106 107 const std::vector<sc_object*>& 108 get_child_objects (const sc_object &obj) 109 { 110 sc_object_list_t &l = object2childs[&obj]; 111 /* 112 * If the object is not in the objects list, 113 * get_child_objects returns an empty list. 114 */ 115 return l; 93 94 const sc_object * sc_find_object(const char * name) { 95 sc_object2sc_object_list_t::iterator i = object2childs.begin (); 96 while (i != object2childs.end()) { 97 const sc_object * obj = i->first; 98 const char * n = obj->name (); 99 if (strcmp (name, n) == 0) { 100 return obj; 101 } 102 ++i; 103 } 104 return NULL; 116 105 } 117 106 118 sc_object* 119 get_parent_object (const sc_object &obj) 120 { 121 return object2parent[&obj]; 107 108 const std::vector<sc_object *>& get_child_objects(const sc_object &obj) { 109 sc_object_list_t &l = object2childs[&obj]; 110 /* 111 * If the object is not in the objects list, 112 * get_child_objects returns an empty list. 113 */ 114 return l; 115 } 116 117 118 sc_object * get_parent_object(const sc_object &obj) { 119 return object2parent[&obj]; 122 120 } 123 121 … … 125 123 126 124 125 /* 126 # Local Variables: 127 # tab-width: 4; 128 # c-basic-offset: 4; 129 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 130 # indent-tabs-mode: nil; 131 # End: 132 # 133 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 134 */ 135
Note: See TracChangeset
for help on using the changeset viewer.