Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Référence du modèle de la structure GenericStringRef< CharType >

Reference to a constant string (not taking a copy) Plus de détails...

#include <arcane/utils/internal/json/rapidjson/document.h>

+ Graphe de collaboration de GenericStringRef< CharType >:

Types publics

typedef CharType Ch
 character type of the string
 

Fonctions membres publiques

template<SizeType N>
 GenericStringRef (const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
 Create string reference from const character array.
 
 GenericStringRef (const CharType *str)
 Explicitly create string reference from const character pointer.
 
 GenericStringRef (const CharType *str, SizeType len)
 Create constant string reference from pointer and length.
 
 GenericStringRef (const GenericStringRef &rhs)
 
 operator const Ch * () const
 implicit conversion to plain CharType pointer
 

Attributs publics

const Ch *const s
 plain CharType pointer
 
const SizeType length
 length of the string (excluding the trailing NULL terminator)
 

Fonctions membres privées

SizeType NotNullStrLen (const CharType *str)
 
template<SizeType N>
 GenericStringRef (CharType(&str)[N])
 Disallow construction from non-const array.
 
GenericStringRefoperator= (const GenericStringRef &rhs)
 Copy assignment operator not permitted - immutable type.
 

Attributs privés statiques

static const Ch emptyString [] = { CharType() }
 Empty string - used when passing in a NULL pointer.
 

Fonctions associées

(Notez que ce ne sont pas des fonctions membres)

template<typename CharType >
GenericStringRef< CharType > StringRef (const CharType *str)
 Mark a character pointer as constant string.
 
template<typename CharType >
GenericStringRef< CharType > StringRef (const CharType *str, size_t length)
 Mark a character pointer as constant string.
 

Description détaillée

template<typename CharType>
struct GenericStringRef< CharType >

Reference to a constant string (not taking a copy)

Paramètres du template
CharTypecharacter 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

Value v("foo"); // ok, no need to copy & calculate length
const char foo[] = "foo";
v.SetString(foo); // ok
const char* bar = foo;
// Value x(bar); // not ok, can't rely on bar's lifetime
Value x(StringRef(bar)); // lifetime explicitly guaranteed by user
Value y(StringRef(bar, 3)); // ok, explicitly pass length
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition document.h:609
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:395
Voir également
StringRef, GenericValue::SetString

Définition à la ligne 287 du fichier document.h.

Documentation des définitions de type membres

◆ Ch

template<typename CharType >
typedef CharType GenericStringRef< CharType >::Ch

character type of the string

Définition à la ligne 288 du fichier document.h.

Documentation des constructeurs et destructeur

◆ GenericStringRef() [1/4]

template<typename CharType >
template<SizeType N>
GenericStringRef< CharType >::GenericStringRef ( const CharType(&)  str[N])
inline

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
Nlength of the string, automatically inferred
Paramètres
strConstant 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 316 du fichier document.h.

◆ GenericStringRef() [2/4]

template<typename CharType >
GenericStringRef< CharType >::GenericStringRef ( const CharType *  str)
inlineexplicit

Explicitly create string reference from const character pointer.

This constructor can be used to explicitly create a reference to a constant string pointer.

Voir également
StringRef(const CharType*)
Paramètres
strConstant character pointer, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
Postcondition
s == str
Note
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 340 du fichier document.h.

◆ GenericStringRef() [3/4]

template<typename CharType >
GenericStringRef< CharType >::GenericStringRef ( const CharType *  str,
SizeType  len 
)
inline

Create constant string reference from pointer and length.

Paramètres
strconstant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
lenlength of the string, excluding the trailing NULL terminator
Postcondition
s == str && length == len
Note
Constant complexity.

Définition à la ligne 352 du fichier document.h.

Références RAPIDJSON_ASSERT.

◆ GenericStringRef() [4/4]

template<typename CharType >
GenericStringRef< CharType >::GenericStringRef ( const GenericStringRef< CharType > &  rhs)
inline

Définition à la ligne 355 du fichier document.h.

Documentation des fonctions membres

◆ NotNullStrLen()

template<typename CharType >
SizeType GenericStringRef< CharType >::NotNullStrLen ( const CharType *  str)
inlineprivate

Définition à la ligne 364 du fichier document.h.

◆ operator const Ch *()

template<typename CharType >
GenericStringRef< CharType >::operator const Ch * ( ) const
inline

implicit conversion to plain CharType pointer

Définition à la ligne 358 du fichier document.h.

Références GenericStringRef< CharType >::s.

Documentation des fonctions amies et associées

◆ StringRef() [1/2]

template<typename CharType >
GenericStringRef< CharType > StringRef ( const CharType *  str)
related

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
CharTypeCharacter type of the string
Paramètres
strConstant 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 395 du fichier document.h.

◆ StringRef() [2/2]

template<typename CharType >
GenericStringRef< CharType > StringRef ( const CharType *  str,
size_t  length 
)
related

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
CharTypecharacter type of the string
Paramètres
strConstant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
lengthThe length of source string.
Renvoie
GenericStringRef string reference object

Définition à la ligne 415 du fichier document.h.

Références SizeType.

Documentation des données membres

◆ emptyString

template<typename CharType >
const CharType GenericStringRef< CharType >::emptyString = { CharType() }
staticprivate

Empty string - used when passing in a NULL pointer.

Définition à la ligne 370 du fichier document.h.

◆ length

template<typename CharType >
const SizeType GenericStringRef< CharType >::length

length of the string (excluding the trailing NULL terminator)

Définition à la ligne 361 du fichier document.h.

Référencé par GenericValue< Encoding, Allocator >::SetStringRaw().

◆ s

template<typename CharType >
const Ch* const GenericStringRef< CharType >::s

plain CharType pointer

Définition à la ligne 360 du fichier document.h.

Référencé par GenericStringRef< CharType >::operator const Ch *().


La documentation de cette structure a été générée à partir du fichier suivant :