diff --git a/ACE/ace/SString.cpp b/ACE/ace/SString.cpp index abd86b337cb53..40ffed47baf0c 100644 --- a/ACE/ace/SString.cpp +++ b/ACE/ace/SString.cpp @@ -21,7 +21,7 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_OSTREAM_TYPE & operator<< (ACE_OSTREAM_TYPE &os, const ACE_CString &cs) { - if (cs.fast_rep () != 0) + if (cs.fast_rep ()) os << cs.fast_rep (); return os; } @@ -59,7 +59,7 @@ ACE_NS_WString::char_rep () const return 0; else { - char *t = 0; + char *t = nullptr; #if defined (ACE_HAS_ALLOC_HOOKS) ACE_ALLOCATOR_RETURN (t, @@ -89,7 +89,7 @@ ACE_NS_WString::ushort_rep () const return 0; else { - ACE_UINT16 *t = 0; + ACE_UINT16 *t = nullptr; #if defined (ACE_HAS_ALLOC_HOOKS) ACE_ALLOCATOR_RETURN (t, diff --git a/ACE/ace/SString.h b/ACE/ace/SString.h index 1473c2dee2632..fc9210c2b083e 100644 --- a/ACE/ace/SString.h +++ b/ACE/ace/SString.h @@ -275,16 +275,17 @@ typedef ACE_CString ACE_TString; class ACE_Export ACE_Auto_String_Free { public: - explicit ACE_Auto_String_Free (char* p = 0); + explicit ACE_Auto_String_Free (char* p = nullptr); ACE_Auto_String_Free (ACE_Auto_String_Free &rhs); ACE_Auto_String_Free& operator= (ACE_Auto_String_Free &rhs); ~ACE_Auto_String_Free (); char* operator* () const; char operator[] (size_t i) const; + explicit operator bool () const; char* get () const; char* release (); - void reset (char* p = 0); + void reset (char* p = nullptr); private: char* p_; diff --git a/ACE/ace/SString.inl b/ACE/ace/SString.inl index 1757425725c9a..8a4e1695eda81 100644 --- a/ACE/ace/SString.inl +++ b/ACE/ace/SString.inl @@ -231,7 +231,7 @@ ACE_INLINE ACE_Auto_String_Free::ACE_Auto_String_Free (ACE_Auto_String_Free& rhs) : p_ (rhs.p_) { - rhs.p_ = 0; + rhs.p_ = nullptr; } ACE_INLINE void @@ -251,7 +251,7 @@ ACE_Auto_String_Free::operator= (ACE_Auto_String_Free& rhs) if (this != &rhs) { this->reset (rhs.p_); - rhs.p_ = 0; + rhs.p_ = nullptr; } return *this; } @@ -274,6 +274,12 @@ ACE_Auto_String_Free::operator[] (size_t i) const return this->p_[i]; } +ACE_INLINE +ACE_Auto_String_Free::operator bool (void) const +{ + return this->p_ != nullptr; +} + ACE_INLINE char* ACE_Auto_String_Free::get () const { @@ -284,7 +290,7 @@ ACE_INLINE char* ACE_Auto_String_Free::release () { char* p = this->p_; - this->p_ = 0; + this->p_ = nullptr; return p; } diff --git a/ACE/tests/SString_Test.cpp b/ACE/tests/SString_Test.cpp index 793bf6a5df6fe..796634306c4b1 100644 --- a/ACE/tests/SString_Test.cpp +++ b/ACE/tests/SString_Test.cpp @@ -150,6 +150,33 @@ int testConstIterator() return 0; } +int testAutoStringFree() +{ + char* s = ACE_OS::strdup("Hello, World"); + const ACE_Auto_String_Free s1(s); + if (s1) + { + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ACE_Auto_String_Free::operator bool return false")), + 1); + } + + if (!s1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("!ACE_Auto_String_Free::operator bool return true")), + 1); + + if (!**s1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ACE_Auto_String_Free is empty")), + 1); + + return 0; +} + int run_main (int, ACE_TCHAR *[]) @@ -425,6 +452,7 @@ run_main (int, ACE_TCHAR *[]) int err = testConcatenation (); err += testIterator (); err += testConstIterator (); + err += testAutoStringFree (); ACE_END_TEST; return err;