--- parser3/src/include/pa_hash.h 2002/02/08 07:27:44 1.53 +++ parser3/src/include/pa_hash.h 2003/01/22 15:39:07 1.58.2.1 @@ -1,16 +1,16 @@ /** @file Parser: hash class decl. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: pa_hash.h,v 1.53 2002/02/08 07:27:44 paf Exp $ + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_HASH_H #define PA_HASH_H +static const char* IDENT_HASH_H="$Date: 2003/01/22 15:39:07 $"; + #include "pa_pool.h" #include "pa_types.h" #include "pa_string.h" @@ -23,7 +23,7 @@ get returning 0 means there were no such. "put value 0" means "remove" */ -class Hash : public Pooled { +class Hash: public PA_Object { public: typedef String Key; ///< hash Key type. longing for templates @@ -40,11 +40,11 @@ public: public: - Hash(Pool& apool) : Pooled(apool) { + Hash() { construct_new(); } - Hash(const Hash& source) : Pooled(source.pool()){ + Hash(const Hash& source) { construct_copy(source); } @@ -140,7 +140,7 @@ private: Val *value; Pair *link; - void *operator new(size_t allocated, Pool& apool); + void *operator new(size_t size); Pair(uint acode, const Key& akey, Val *avalue, Pair *alink) : code(acode), @@ -160,5 +160,21 @@ private: //disabled Hash& operator = (const Hash&) { return *this; } }; +/// Auto-object used for temporarily substituting/removing hash values +class Temp_hash_value { + Hash& fhash; + const Hash::Key& fname; + Hash::Val *saved_value; +public: + Temp_hash_value(Hash& ahash, const Hash::Key& aname, Hash::Val *avalue) : + fhash(ahash), + fname(aname), + saved_value(ahash.get(aname)) { + fhash.put(aname, avalue); + } + ~Temp_hash_value() { + fhash.put(fname, saved_value); + } +}; #endif