From 426593162ee4b22443dfca428083047ca1e39ac7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 8 May 2005 10:28:19 +0000 Subject: * ATermMap needs an assignment operator, otherwise we are screwed. --- src/libexpr/nixexpr.cc | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 2c49ecd05100..5c67b74ca6c6 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -7,6 +7,7 @@ ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct) + : table(0) { this->maxLoadPct = maxLoadPct; table = ATtableCreate(initialSize, maxLoadPct); @@ -16,6 +17,36 @@ ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct) ATermMap::ATermMap(const ATermMap & map) : table(0) +{ + copy(map); +} + + +ATermMap::~ATermMap() +{ + free(); +} + + +ATermMap & ATermMap::operator = (const ATermMap & map) +{ + if (this == &map) return *this; + free(); + copy(map); + return *this; +} + + +void ATermMap::free() +{ + if (table) { + ATtableDestroy(table); + table = 0; + } +} + + +void ATermMap::copy(const ATermMap & map) { ATermList keys = map.keys(); @@ -28,12 +59,6 @@ ATermMap::ATermMap(const ATermMap & map) } -ATermMap::~ATermMap() -{ - if (table) ATtableDestroy(table); -} - - void ATermMap::set(ATerm key, ATerm value) { return ATtablePut(table, key, value); -- cgit 1.4.1