[vdr] Re: cString operator= with same buffer
Klaus Schmidinger
Klaus.Schmidinger at cadsoft.de
Sat Nov 26 15:14:21 CET 2005
Holger Brunn wrote:
>>Is this the complete patch now? I still suggest adding a copy ctor (which
>>should word like operator= without freeing)..
>
>
> The copy constructor is added with the patch from an older posting
> (vdr-cstring-copyctor.diff).
Just to make sure I'm not missing anything, here's
what I've adopted now:
--- tools.h 2005/11/05 10:54:39 1.83
+++ tools.h 2005/11/26 14:03:47
@@ -75,6 +75,7 @@
char *s;
public:
cString(const char *S = NULL, bool TakePointer = false);
+ cString(const cString &String);
virtual ~cString();
operator const char * () const { return s; } // for use in (const char *) context
const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)
--- tools.c 2005/11/04 16:33:18 1.103
+++ tools.c 2005/11/26 14:12:31
@@ -527,6 +527,11 @@
s = TakePointer ? (char *)S : S ? strdup(S) : NULL;
}
+cString::cString(const cString &String)
+{
+ s = String.s ? strdup(String.s) : NULL;
+}
+
cString::~cString()
{
free(s);
@@ -534,6 +539,8 @@
cString &cString::operator=(const cString &String)
{
+ if (this == &String)
+ return *this;
free(s);
s = String.s ? strdup(String.s) : NULL;
return *this;
Klaus
More information about the vdr
mailing list