diff --git a/vhdlpp/scope.cc b/vhdlpp/scope.cc index a715e86f4..6c27d0ed9 100644 --- a/vhdlpp/scope.cc +++ b/vhdlpp/scope.cc @@ -61,18 +61,10 @@ void ScopeBase::cleanup() * objects that were defined in this scope, leaving * objects from the other scopes untouched. */ - for(map::iterator it = new_signals_.begin() - ; it != new_signals_.end(); ++it) - delete it->second; - for(map::iterator it = new_components_.begin() - ; it != new_components_.end(); ++it) - delete it->second; - for(map::iterator it = new_types_.begin() - ; it != new_types_.end(); ++it) - delete it->second; - for(map::iterator it = new_constants_.begin() - ; it != new_constants_.end(); ++it) - delete it->second; + delete_all(new_signals_); + delete_all(new_components_); + delete_all(new_types_); + delete_all(new_constants_); } const VType*ScopeBase::find_type(perm_string by_name) diff --git a/vhdlpp/scope.h b/vhdlpp/scope.h index c17f7932b..69a8de4a7 100644 --- a/vhdlpp/scope.h +++ b/vhdlpp/scope.h @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +# include # include # include # include "StringHeap.h" @@ -30,6 +31,16 @@ class Architecture; class ComponentBase; class VType; +template +struct delete_object{ + void operator()(T* item) { delete item; } +}; + +template +struct delete_pair_second{ + void operator()(pair item){ delete item.second; } +}; + class ScopeBase { public: @@ -42,6 +53,16 @@ class ScopeBase { protected: void cleanup(); + //containers' cleaning helper functions + template void delete_all(list& c) + { + for_each(c.begin(), c.end(), ::delete_object()); + } + template void delete_all(map& c) + { + for_each(c.begin(), c.end(), ::delete_pair_second()); + } + // Signal declarations... std::map old_signals_; //previous scopes std::map new_signals_; //current scope