mirror of
https://github.com/steveicarus/iverilog.git
synced 2026-08-22 05:47:31 +02:00
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:
committed by
Stephen Williams
parent
a5ca9ea8be
commit
a8fae6bbf7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user