template<typename CharType>
struct GenericStringRef< CharType >
Reference to a constant string (not taking a copy)
- Paramètres du template
-
| CharType | character type of the string |
This helper class is used to automatically infer constant string references for string literals, especially from const (!) character arrays.
The main use is for creating JSON string values without copying the source string via an Allocator. This requires that the referenced string pointers have a sufficient lifetime, which exceeds the lifetime of the associated GenericValue.
Example
const char foo[] = "foo";
v.SetString(foo);
const char* bar = foo;
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
- Voir également
- StringRef, GenericValue::SetString
Définition à la ligne 347 du fichier document.h.
template<typename CharType>
Create string reference from const character array.
This constructor implicitly creates a constant string reference from a const character array. It has better performance than StringRef(const CharType*) by inferring the string length from the array length, and also supports strings containing null characters.
- Paramètres du template
-
| N | length of the string, automatically inferred |
- Paramètres
-
| str | Constant character array, lifetime assumed to be longer than the use of the string in e.g. a GenericValue |
- Postcondition
- s == str
- Note
- Constant complexity.
-
There is a hidden, private overload to disallow references to non-const character arrays to be created via this constructor. By this, e.g. function-scope arrays used to be filled via
snprintf are excluded from consideration. In such cases, the referenced string should be copied to the GenericValue instead.
Définition à la ligne 376 du fichier document.h.
template<typename CharType>
Mark a character pointer as constant string.
Mark a plain character pointer as a "string literal". This function can be used to avoid copying a character string to be referenced as a value in a JSON GenericValue object, if the string's lifetime is known to be valid long enough.
- Paramètres du template
-
| CharType | Character type of the string |
- Paramètres
-
| str | Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue |
- Renvoie
- GenericStringRef string reference object
- Voir également
- GenericValue::GenericValue(StringRefType), GenericValue::operator=(StringRefType), GenericValue::SetString(StringRefType), GenericValue::PushBack(StringRefType, Allocator&), GenericValue::AddMember
Définition à la ligne 455 du fichier document.h.
template<typename CharType>
Mark a character pointer as constant string.
Mark a plain character pointer as a "string literal". This function can be used to avoid copying a character string to be referenced as a value in a JSON GenericValue object, if the string's lifetime is known to be valid long enough.
This version has better performance with supplied length, and also supports string containing null characters.
- Paramètres du template
-
| CharType | character type of the string |
- Paramètres
-
| str | Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue |
| length | The length of source string. |
- Renvoie
- GenericStringRef string reference object
Définition à la ligne 475 du fichier document.h.