Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ACE_Auto_String_Free::operator bool #2263

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ACE/ace/SString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions ACE/ace/SString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
12 changes: 9 additions & 3 deletions ACE/ace/SString.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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
{
Expand All @@ -284,7 +290,7 @@ ACE_INLINE char*
ACE_Auto_String_Free::release ()
{
char* p = this->p_;
this->p_ = 0;
this->p_ = nullptr;
return p;
}

Expand Down
13 changes: 13 additions & 0 deletions ACE/tests/SString_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ int testConstIterator()
return 0;
}

int testAutoStringFree()
{
char* s = ACE_OS::strdup("Hello, World");
const ACE_Auto_String_Free s1(s);
if (!s1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("ACE_Auto_String_Free is nullptr")),
1);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test when it is nullptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test with a ACE_Auto_String_Free which is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return 0;
}


int
run_main (int, ACE_TCHAR *[])
Expand Down Expand Up @@ -425,6 +437,7 @@ run_main (int, ACE_TCHAR *[])
int err = testConcatenation ();
err += testIterator ();
err += testConstIterator ();
err += testAutoStringFree ();

ACE_END_TEST;
return err;
Expand Down