VirtualBox

Changeset 21358 in vbox for trunk/include


Ignore:
Timestamp:
Jul 7, 2009 4:19:32 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49707
Message:

IPRT: ministring crash fix + documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/ministring_cpp.h

    r21352 r21358  
    4343 *  Semantics are like in std::string, except it can do a lot less.
    4444 *
    45  *  Much of the code in here used to be in Utf8Str so that Utf8Str can now
    46  *  derive from ministring and only contain code that is COM-specific, such
    47  *  as com::Bstr conversions. Compared to the old Utf8Str though, ministring
     45 *  Much of the code in here used to be in com::Utf8Str so that com::Utf8Str
     46 *  can now derive from ministring and only contain code that is COM-specific,
     47 *  such as com::Bstr conversions. Compared to the old Utf8Str though, ministring
    4848 *  always knows the length of its member string and the size of the buffer
    4949 *  so it can use memcpy() instead of strdup().
     
    5353{
    5454public:
     55    /**
     56     * Creates an empty string that has no memory allocated.
     57     */
    5558    ministring()
    5659        : m_psz(NULL),
     
    6063    }
    6164
     65    /**
     66     * Creates a copy of another ministring. This allocates
     67     * s.length() + 1 bytes for the new instance.
     68     * @param s
     69     */
    6270    ministring(const ministring &s)
    6371    {
     
    6573    }
    6674
     75    /**
     76     * Creates a copy of another ministring. This allocates
     77     * strlen(pcsz) + 1 bytes for the new instance.
     78     * @param pcsz
     79     */
    6780    ministring(const char *pcsz)
    6881    {
     
    7083    }
    7184
     85    /**
     86     * Destructor.
     87     */
    7288    virtual ~ministring()
    7389    {
     
    7591    }
    7692
     93    /**
     94     * Returns the length of the member string. This is always cached
     95     * so calling this is cheap and requires no strlen() invocation.
     96     * @return
     97     */
    7798    size_t length() const
    7899    {
     
    81102
    82103    /**
    83      * Returns the no. of bytes allocated in the internal string buffer,
    84      * which is at least m_cbLength + 1 if m_cbLength != 0.
     104     * Returns the number of bytes allocated in the internal string buffer,
     105     * which is at least length() + 1 if length() > 0.
    85106     * @return
    86107     */
     
    93114     * Requests that the contained memory buffer have at least cb bytes allocated.
    94115     * This may expand or shrink the string's storage, but will never truncate the
    95      * contained string.
     116     * contained string. In other words, cb will be ignored if it's smaller than
     117     * length() + 1.
    96118     * @param cb new minimum size of member memory buffer
    97119     */
     
    107129    }
    108130
     131    /**
     132     * Deallocates all memory.
     133     */
    109134    inline void setNull()
    110135    {
     
    146171    }
    147172
     173    /**
     174     * Assigns a copy of pcsz to "this".
     175     * @param pcsz
     176     * @return
     177     */
    148178    ministring& operator=(const char *pcsz)
    149179    {
     
    156186    }
    157187
     188    /**
     189     * Assigns a copy of s to "this".
     190     * @param s
     191     * @return
     192     */
    158193    ministring& operator=(const ministring &s)
    159194    {
     
    166201    }
    167202
     203    /**
     204     * Appends a copy of @a that to "this".
     205     * @param that
     206     */
    168207    void append(const ministring &that)
    169208    {
     
    184223    }
    185224
     225    /**
     226     * Returns the contained string as a C-style const char* pointer.
     227     * @return
     228     */
    186229    inline const char* c_str() const
    187230    {
     
    189232    }
    190233
     234    /**
     235     * Like c_str(), for compatibility with lots of VirtualBox Main code.
     236     * @return
     237     */
    191238    inline const char* raw() const
    192239    {
     
    200247    }
    201248
     249    /**
     250     * Returns true if the member string has no length. This states nothing about
     251     * how much memory might be allocated.
     252     * @return
     253     */
    202254    bool isEmpty() const
    203255    {
     
    205257    }
    206258
     259    /**
     260     * Returns true if no memory is currently allocated.
     261     * @return
     262     */
    207263    bool isNull() const
    208264    {
     
    216272    };
    217273
     274    /**
     275     * Compares the member string to pcsz.
     276     * @param pcsz
     277     * @param cs Whether comparison should be case-sensitive.
     278     * @return
     279     */
    218280    int compare(const char *pcsz, CaseSensitivity cs = CaseSensitive) const
    219281    {
     
    265327
    266328    /**
     329     * Protected internal helper.
    267330     * copyFrom() unconditionally sets the members to a copy of the
    268331     * given other strings and makes no assumptions about previous
     
    278341    void copyFrom(const ministring &s)
    279342    {
    280         m_cbLength = s.m_cbLength;
    281         m_cbAllocated = m_cbLength + 1;
    282         m_psz = (char*)RTMemAlloc(m_cbAllocated);
    283         memcpy(m_psz, s.m_psz, m_cbAllocated);      // include 0 terminator
    284     }
    285 
    286     /**
     343        if ((m_cbLength = s.m_cbLength))
     344        {
     345            m_cbAllocated = m_cbLength + 1;
     346            m_psz = (char*)RTMemAlloc(m_cbAllocated);
     347            memcpy(m_psz, s.m_psz, m_cbAllocated);      // include 0 terminator
     348        }
     349        else
     350        {
     351            m_cbAllocated = 0;
     352            m_psz = NULL;
     353        }
     354    }
     355
     356    /**
     357     * Protected internal helper.
    287358     * See copyFrom() above.
    288359     *
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette