Changeset 151:348ae4187df0 in rrlib_util


Ignore:
Timestamp:
02.09.2016 17:32:30 (3 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Children:
152:52dd54e2592a, 158:b9ff329accda
Phase:
public
Message:

Improves tMangedConstCharPointer ((1) bugfix when handling non-copied empty strings; (2) adds OwnsBuffer() method)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tManagedConstCharPointer.cpp

    r148 r151  
    7777    size_t string_length = strlen(pointer); 
    7878    char* temp = new char[string_length + 2]; 
    79     temp[0] = 0; 
     79    temp[0] = cOWNS_BUFFER_MARKER; 
    8080    memcpy(temp + 1, pointer, string_length + 1); 
    8181    this->pointer = temp; 
  • tManagedConstCharPointer.h

    r148 r151  
    8080class tManagedConstCharPointer : public rrlib::util::tNoncopyable 
    8181{ 
     82  /*! Character that marks string copies to be deleted */ 
     83  static const char cOWNS_BUFFER_MARKER = 1; 
    8284 
    8385//---------------------------------------------------------------------- 
     
    111113  ~tManagedConstCharPointer() 
    112114  { 
    113     if (pointer && pointer[0] == 0) 
     115    if (OwnsBuffer()) 
    114116    { 
    115117      delete[] pointer; 
     
    122124  const char* Get() const 
    123125  { 
    124     return pointer ? (pointer[0] ? pointer : (pointer + 1)) : nullptr; 
     126    return OwnsBuffer() ? (pointer + 1) : pointer; 
     127  } 
     128 
     129  /*! 
     130   * \return Does this smart pointer own the buffer it points to? 
     131   */ 
     132  bool OwnsBuffer() const 
     133  { 
     134    return pointer ? pointer[0] == cOWNS_BUFFER_MARKER : false; 
    125135  } 
    126136 
     
    130140private: 
    131141 
    132   /*! Wrapped pointer; for string copies to be deleted a 0 is prepended */ 
     142  /*! Wrapped pointer; for string copies to be deleted a cOWNS_BUFFER_MARKER is prepended */ 
    133143  const char* pointer; 
    134144 
Note: See TracChangeset for help on using the changeset viewer.