Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

nsTPromiseFlatString_CharT Class Reference

#include <nsTPromiseFlatString.h>

Inheritance diagram for nsTPromiseFlatString_CharT:

nsTString_CharT nsTSubstring_CharT nsTAString_CharT

List of all members.


Detailed Description

NOTE:

Try to avoid flat strings. |PromiseFlat[C]String| will help you as a last resort, and this may be necessary when dealing with legacy or OS calls, but in general, requiring a null-terminated array of characters kills many of the performance wins the string classes offer. Write your own code to use |nsA[C]String&|s for parameters. Write your string proccessing algorithms to exploit iterators. If you do this, you will benefit from being able to chain operations without copying or allocating and your code will be significantly more efficient. Remember, a function that takes an |const nsA[C]String&| can always be passed a raw character pointer by wrapping it (for free) in a |nsDependent[C]String|. But a function that takes a character pointer always has the potential to force allocation and copying.

How to use it:

A |nsPromiseFlat[C]String| doesn't necessarily own the characters it promises. You must never use it to promise characters out of a string with a shorter lifespan. The typical use will be something like this:

SomeOSFunction( PromiseFlatCString(aCString).get() ); // GOOD

Here's a BAD use:

const char* buffer = PromiseFlatCString(aCString).get(); SomeOSFunction(buffer); // BAD!! |buffer| is a dangling pointer

The only way to make one is with the function |PromiseFlat[C]String|, which produce a |const| instance. ``What if I need to keep a promise around for a little while?'' you might ask. In that case, you can keep a reference, like so

const nsPromiseFlatString& flat = PromiseFlatString(aString); // this reference holds the anonymous temporary alive, but remember, // it must _still_ have a lifetime shorter than that of |aString|

SomeOSFunction(flat.get()); SomeOtherOSFunction(flat.get());

How does it work?

A |nsPromiseFlat[C]String| is just a wrapper for another string. If you apply it to a string that happens to be flat, your promise is just a dependent reference to the string's data. If you apply it to a non-flat string, then a temporary flat string is created for you, by allocating and copying. In the event that you end up assigning the result into a sharing string (e.g., |nsTString|), the right thing happens.

Definition at line 94 of file nsTPromiseFlatString.h.


Public Types

enum  {
  F_NONE = 0, F_TERMINATED = 1 << 0, F_VOIDED = 1 << 1, F_SHARED = 1 << 2,
  F_OWNED = 1 << 3, F_FIXED = 1 << 4, F_CLASS_FIXED = 1 << 16
}
typedef nsTAString_CharT abstract_string_type
typedef char_type * char_iterator
typedef nsCharTraits< char_type > char_traits
typedef CharT char_type
typedef nsTStringComparator_CharT comparator_type
typedef const char_type * const_char_iterator
typedef nsReadingIterator
< char_type > 
const_iterator
typedef
char_traits::incompatible_char_type 
incompatible_char_type
typedef PRUint32 index_type
typedef nsWritingIterator
< char_type > 
iterator
typedef nsTObsoleteAString_CharT obsolete_string_type
typedef nsTPromiseFlatString_CharT self_type
typedef PRUint32 size_type
typedef nsTString_CharT string_type
typedef nsTSubstringTuple_CharT substring_tuple_type
typedef nsTSubstring_CharT substring_type

Public Member Functions

NS_COM void NS_FASTCALL Adopt (char_type *data, size_type length=size_type(-1))
NS_COM void NS_FASTCALL Append (char_type c)
NS_COM void NS_FASTCALL Append (const char_type *data, size_type length)
NS_COM void NS_FASTCALL Append (const char_type *data)
void Append (const abstract_string_type &readable)
void Append (const substring_tuple_type &tuple)
void Append (const self_type &str)
void Append (const char_type *data, size_type length=size_type(-1))
void Append (char_type c)
NS_COM void NS_FASTCALL AppendASCII (const char *data)
NS_COM void NS_FASTCALL AppendASCII (const char *data, size_type length)
void AppendASCII (const char *data, size_type length=size_type(-1))
template<int N>
void AppendLiteral (char(&str)[N])
template<int N>
void AppendLiteral (const char(&str)[N])
NS_COM void NS_FASTCALL Assign (char_type c)
NS_COM void NS_FASTCALL Assign (const char_type *data, size_type length)
NS_COM void NS_FASTCALL Assign (const char_type *data)
NS_COM void NS_FASTCALL Assign (const abstract_string_type &)
NS_COM void NS_FASTCALL Assign (const substring_tuple_type &)
NS_COM void NS_FASTCALL Assign (const self_type &)
NS_COM void NS_FASTCALL Assign (const char_type *data, size_type length=size_type(-1))
void Assign (char_type c)
NS_COM void NS_FASTCALL AssignASCII (const char *data, size_type length)
NS_COM void NS_FASTCALL AssignASCII (const char *data)
NS_COM void NS_FASTCALL AssignASCII (const char *data, size_type length)
template<int N>
void AssignLiteral (char(&str)[N])
template<int N>
void AssignLiteral (const char(&str)[N])
const_char_iterator & BeginReading (const_char_iterator &iter) const
const_iteratorBeginReading (const_iterator &iter) const
const_char_iterator BeginReading () const
char_iterator & BeginWriting (char_iterator &iter)
iteratorBeginWriting (iterator &iter)
char_iterator BeginWriting ()
char_type CharAt (index_type i) const
NS_COM size_type NS_FASTCALL CountChar (char_type) const
NS_COM size_type NS_FASTCALL CountChar (char_type) const
NS_COM void NS_FASTCALL Cut (index_type cutStart, size_type cutLength)
void Cut (index_type cutStart, size_type cutLength)
const char_type * Data () const
const_char_iterator & EndReading (const_char_iterator &iter) const
const_iteratorEndReading (const_iterator &iter) const
const_char_iterator EndReading () const
char_iterator & EndWriting (char_iterator &iter)
iteratorEndWriting (iterator &iter)
char_iterator EndWriting ()
NS_COM PRBool NS_FASTCALL Equals (const char_type *, const comparator_type &) const
NS_COM PRBool NS_FASTCALL Equals (const char_type *) const
NS_COM PRBool NS_FASTCALL Equals (const char_type *data, const comparator_type &comp) const
NS_COM PRBool NS_FASTCALL Equals (const char_type *data) const
NS_COM PRBool NS_FASTCALL Equals (const abstract_string_type &readable, const comparator_type &comp) const
NS_COM PRBool NS_FASTCALL Equals (const abstract_string_type &readable) const
NS_COM PRBool NS_FASTCALL Equals (const self_type &, const comparator_type &) const
NS_COM PRBool NS_FASTCALL Equals (const self_type &) const
NS_COM PRBool NS_FASTCALL EqualsASCII (const char *data, size_type len) const
NS_COM PRBool NS_FASTCALL EqualsASCII (const char *data) const
NS_COM PRBool NS_FASTCALL EqualsASCII (const char *data, size_type len) const
template<int N>
PRBool EqualsLiteral (char(&str)[N]) const
template<int N>
PRBool EqualsLiteral (const char(&str)[N]) const
NS_COM PRInt32 NS_FASTCALL FindChar (char_type, index_type offset=0) const
NS_COM PRInt32 NS_FASTCALL FindChar (char_type, index_type offset=0) const
char_type First () const
const char_type * get () const
NS_COM void NS_FASTCALL Insert (char_type c, index_type pos)
NS_COM void NS_FASTCALL Insert (const char_type *data, index_type pos, size_type length)
NS_COM void NS_FASTCALL Insert (const char_type *data, index_type pos)
NS_COM void NS_FASTCALL Insert (const substring_tuple_type &tuple, index_type pos)
NS_COM void NS_FASTCALL Insert (const self_type &readable, index_type pos)
void Insert (const abstract_string_type &readable, index_type pos)
void Insert (const substring_tuple_type &tuple, index_type pos)
void Insert (const self_type &str, index_type pos)
void Insert (const char_type *data, index_type pos, size_type length=size_type(-1))
void Insert (char_type c, index_type pos)
PRBool IsEmpty () const
PRBool IsTerminated () const
PRBool IsVoid () const
char_type Last () const
size_type Length () const
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII (const char *data, size_type len) const
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII (const char *data) const
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII (const char *data, size_type len) const
template<int N>
PRBool LowerCaseEqualsLiteral (char(&str)[N]) const
template<int N>
PRBool LowerCaseEqualsLiteral (const char(&str)[N]) const
 nsTPromiseFlatString_CharT (const substring_tuple_type &tuple)
 nsTPromiseFlatString_CharT (const abstract_string_type &readable)
 nsTPromiseFlatString_CharT (const substring_type &str)
self_typeoperator+= (char_type c)
self_typeoperator+= (const char_type *data)
self_typeoperator+= (const abstract_string_type &readable)
self_typeoperator+= (const substring_tuple_type &tuple)
self_typeoperator+= (const self_type &str)
self_typeoperator+= (const char_type *data)
self_typeoperator+= (char_type c)
char_type operator[] (index_type i) const
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const substring_tuple_type &readable)
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const self_type &readable)
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const abstract_string_type &readable)
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const substring_tuple_type &tuple)
void Replace (index_type cutStart, size_type cutLength, const self_type &str)
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const char_type *data, size_type length=size_type(-1))
void Replace (index_type cutStart, size_type cutLength, char_type c)
NS_COM void NS_FASTCALL ReplaceASCII (index_type cutStart, size_type cutLength, const char *data, size_type length=size_type(-1))
NS_COM void NS_FASTCALL SetCapacity (size_type)
NS_COM void NS_FASTCALL SetCapacity (size_type capacity)
NS_COM void NS_FASTCALL SetIsVoid (PRBool)
NS_COM void NS_FASTCALL SetLength (size_type)
NS_COM void NS_FASTCALL SetLength (size_type)
void Truncate (size_type aNewLength=0)
void Truncate (size_type newLength=0)

Protected Member Functions

obsolete_string_typeAsObsoleteString ()
const obsolete_string_typeAsObsoleteString () const
substring_typeAsSubstring ()
const substring_typeAsSubstring () const
size_type NS_FASTCALL Capacity () const
NS_COM void NS_FASTCALL EnsureMutable ()
void NS_FASTCALL Finalize ()
NS_COM size_type NS_FASTCALL GetReadableBuffer (const char_type **data) const
NS_COM size_type NS_FASTCALL GetWritableBuffer (char_type **data)
PRBool NS_FASTCALL IsDependentOn (const char_type *start, const char_type *end) const
PRBool IsDependentOn (const char_type *start, const char_type *end) const
PRBool NS_FASTCALL MutatePrep (size_type capacity, char_type **old_data, PRUint32 *old_flags)
void NS_FASTCALL ReplacePrep (index_type cutStart, size_type cutLength, size_type newLength)
void SetDataFlags (PRUint32 dataFlags)
const substring_type NS_FASTCALL ToSubstring () const

Protected Attributes

char_type * mData
PRUint32 mFlags
size_type mLength
const void * mVTable

Private Member Functions

NS_COM void Init (const abstract_string_type &)
NS_COM void Init (const substring_type &)
void operator= (const self_type &)

Friends

class nsTAString_CharT
class nsTDependentSubstring_CharT
class nsTObsoleteAStringThunk_CharT
class nsTPromiseFlatString_CharT
class nsTSubstring_CharT
class nsTSubstringTuple_CharT

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index