载入中...
搜索中...
未找到
Public 类型 | Public 成员函数 | Public 属性 | 相关符号 | 所有成员列表
rapidjson::GenericStringRef< CharType > 模板结构体 参考

Reference to a constant string (not taking a copy) 更多...

`#include <document.h>`

## Public 类型
typedef CharType | Ch
| character type of the string

## Public 成员函数
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

## Public 属性
const Ch *const | s
| plain CharType pointer
const SizeType | length
| length of the string (excluding the trailing NULL terminator)

## 相关符号
(注意: 这些不是成员符号.)
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

## 详细描述

template<typename CharType>
struct rapidjson::GenericStringRef< CharType >

Reference to a constant string (not taking a copy)

模板参数

  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 分配器. 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
rapidjson::GenericValue
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
定义 fwd.h:114
rapidjson::GenericStringRef::StringRef
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
定义 document.h:344

参见
  StringRef, GenericValue::SetString

## 构造及析构函数说明

## ◆ GenericStringRef() [1/3]

template<typename CharType >
template<SizeType N>

rapidjson::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.

模板参数

  N | length of the string, automatically inferred

参数

  str | Constant character array, lifetime assumed to be longer than the use of the string in e.g. a GenericValue

后置条件
  s == str

注解
  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.

## ◆ GenericStringRef() [2/3]

template<typename CharType >

rapidjson::GenericStringRef< CharType >::GenericStringRef | ( | const CharType * | str | ) |
| inline explicit

Explicitly create string reference from `const` character pointer

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

参见
  StringRef(const CharType*)

参数

  str | Constant character pointer, lifetime assumed to be longer than the use of the string in e.g. a GenericValue

后置条件
  s == str

注解
  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.

## ◆ GenericStringRef() [3/3]

template<typename CharType >

rapidjson::GenericStringRef< CharType >::GenericStringRef | ( | const CharType * | str,
|  | SizeType | len )
| inline

Create constant string reference from pointer and length

参数

  str | constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
  len | length of the string, excluding the trailing NULL terminator

后置条件
  s == str && length == len

注解
  Constant complexity.

## 友元及相关符号说明

## ◆ 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.

模板参数

  CharType | Character type of the string

参数

  str | Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue

返回
  GenericStringRef string reference object

参见
  GenericValue::GenericValue(StringRefType), GenericValue::operator=(StringRefType), GenericValue::SetString(StringRefType), GenericValue::PushBack(StringRefType, Allocator&), GenericValue::AddMember

## ◆ 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.

模板参数

  CharType | character type of the string

参数

  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.

返回
  GenericStringRef string reference object

该结构体的文档由以下文件生成:

- include/rapidjson/document.h
- include/rapidjson/fwd.h