Use stl algorithms and templates in ScopeBase destructor

This patch applies a more sophisticated method for
cleaning containers in VHDL ScopeBase class.
This commit is contained in:
Pawel Szostek
2011-07-24 09:57:20 -07:00
committed by Stephen Williams
parent a5ca9ea8be
commit a8fae6bbf7
2 changed files with 25 additions and 12 deletions
+21
View File
@@ -19,6 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
# include <algorithm>
# include <list>
# include <map>
# include "StringHeap.h"
@@ -30,6 +31,16 @@ class Architecture;
class ComponentBase;
class VType;
template<typename T>
struct delete_object{
void operator()(T* item) { delete item; }
};
template<typename T>
struct delete_pair_second{
void operator()(pair<perm_string, T*> item){ delete item.second; }
};
class ScopeBase {
public:
@@ -42,6 +53,16 @@ class ScopeBase {
protected:
void cleanup();
//containers' cleaning helper functions
template<typename T> void delete_all(list<T*>& c)
{
for_each(c.begin(), c.end(), ::delete_object<T>());
}
template<typename T> void delete_all(map<perm_string, T*>& c)
{
for_each(c.begin(), c.end(), ::delete_pair_second<T>());
}
// Signal declarations...
std::map<perm_string,Signal*> old_signals_; //previous scopes
std::map<perm_string,Signal*> new_signals_; //current scope