diff options
-rw-r--r-- | ChangeLog-99b | 9 | ||||
-rw-r--r-- | ace/SString.h | 30 | ||||
-rw-r--r-- | ace/SString.i | 66 |
3 files changed, 105 insertions, 0 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b index 0797b85cb24..25426c8a542 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -1,3 +1,12 @@ +Fri May 14 11:36:05 1999 Carlos O'Ryan <coryan@cs.wustl.edu> + + * ace/SString.h: + * ace/SString.i: + Added new class to auto destroy dynamically allocated strings, + sort of a mixing between auto_ptr and CString. Auto_Ptr_Array + was not useful because we need to free using ACE_OS::free() (and + in the future allocators). + Fri May 14 10:37:49 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> * ace/OS.i: Fixed a deadlock in cond_timedwait()/cond_broadcast(). diff --git a/ace/SString.h b/ace/SString.h index a829ec4d975..b7fe755c629 100644 --- a/ace/SString.h +++ b/ace/SString.h @@ -588,6 +588,36 @@ private: // Pointer to the next free space in delimiters_. }; +// **************************************************************** + +class ACE_Auto_String_Free +{ + // = TITLE + // Simple class to automatically de-allocate strings + // + // = DESCRIPTION + // Keeps a pointer to a string and deallocates it (using + // ACE_OS::free()) on its destructor. + // If you need to delete using "delete[]" the + // ACE_Auto_Array_Ptr<char*> is your choice. + // The class plays the same role as auto_ptr<> + // +public: + /* explicit */ ACE_Auto_String_Free (char* p = 0); + ACE_Auto_String_Free (ACE_Auto_String_Free &rhs); + ACE_Auto_String_Free& operator= (ACE_Auto_String_Free &rhs); + ~ACE_Auto_String_Free (void); + + char* operator* () const; + char operator[] (int i) const; + char* get (void) const; + char* release (void); + void reset (char* p = 0); + +private: + char* p_; +}; + #if defined (__ACE_INLINE__) #include "ace/SString.i" #endif /* __ACE_INLINE__ */ diff --git a/ace/SString.i b/ace/SString.i index 46b33d7541d..d606a464c98 100644 --- a/ace/SString.i +++ b/ace/SString.i @@ -684,3 +684,69 @@ ACE_WString::hash (void) const { return ACE::hash_pjw (this->rep_); } + +// **************************************************************** + +ACE_INLINE +ACE_Auto_String_Free::ACE_Auto_String_Free (char* p) + : p_ (p) +{ +} + +ACE_INLINE +ACE_Auto_String_Free::ACE_Auto_String_Free (ACE_Auto_String_Free& rhs) + : p_ (rhs.p_) +{ + rhs.p_ = 0; +} + +ACE_INLINE void +ACE_Auto_String_Free::reset (char* p) +{ + if (this->p_ != 0) + ACE_OS::free (this->p_); + this->p_ = p; +} + +ACE_INLINE ACE_Auto_String_Free& +ACE_Auto_String_Free::operator= (ACE_Auto_String_Free& rhs) +{ + if (this != &rhs) + { + this->reset (rhs.p_); + rhs.p_ = 0; + } + return *this; +} + +ACE_INLINE +ACE_Auto_String_Free::~ACE_Auto_String_Free (void) +{ + this->reset (0); +} + +ACE_INLINE char* +ACE_Auto_String_Free::operator* (void) const +{ + return this->p_; +} + +ACE_INLINE char +ACE_Auto_String_Free::operator[] (int i) const +{ + return this->p_[i]; +} + +ACE_INLINE char* +ACE_Auto_String_Free::get (void) const +{ + return this->p_; +} + +ACE_INLINE char* +ACE_Auto_String_Free::release (void) +{ + char* p = this->p_; + this->p_ = 0; + return p; +} |