diff --git a/README.md b/README.md
index 50ea863..0bed3e5 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,16 @@
livox_ros_driver is a new ROS package, specially used to connect LiDAR products produced by Livox. The driver can be run under ubuntu 14.04/16.04/18.04 operating system with ROS environment (indigo, kinetic, melodic) installed. Tested hardware platforms that can run livox_ros_driver include: Intel x86 cpu platforms, and some ARM64 hardware platforms (such as nvida TX2 / Xavier, etc.).
+## 0. Version and Release History
+
+### 0.1 Current Version
+
+[v2.6.0](https://github.com/Livox-SDK/livox_ros_driver/releases)
+
+### 0.2 Release History
+
+[Release History](https://github.com/Livox-SDK/livox_ros_driver/releases)
+
## 1. Install dependencies
Before running livox_ros_driver, ROS and Livox-SDK must be installed.
@@ -171,14 +181,12 @@ In the "ws_livox/src/livox_ros_driver/launch" path, there are two json files, li
The parameter attributes in the above json file are described in the following table :
LiDAR configuration parameter
-
| Parameter | Type | Description | Default |
| :------------------------- | ------- | ------------------------------------------------------------ | --------------- |
| broadcast_code | String | LiDAR broadcast code, 15 characters, consisting of a 14-character length serial number plus a character-length additional code | 0TFDG3B006H2Z11 |
| enable_connect | Boolean | Whether to connect to this LiDAR
true -- Connect this LiDAR
false --Do not connect this LiDAR | false |
-| enable_fan | Boolean | Whether to automatically control the fan of this LiDAR
true -- Automatically control the fan of this LiDAR
false -- Does not automatically control the fan of this LiDAR | true |
| return_mode | Int | return mode
0 -- First single return mode
1 -- Strongest single return mode
2 -- Dual return mode | 0 |
-| coordinate | Int | Coordinate
0 -- Cartesian
1 -- Spherical | 0 |
+| coordinate | Int | Coordinate
0 -- Cartesian
1 -- Spherical | 0 |
| imu_rate | Int | Push frequency of IMU sensor data
0 -- stop push
1 -- 200 Hz
Others -- undefined, it will cause unpredictable behavior
Currently only Horizon supports this, MID serials do not support it | 0 |
| extrinsic_parameter_source | Int | Whether to enable extrinsic parameter automatic compensation
0 -- Disable automatic compensation of LiDAR external reference
1 -- Automatic compensation of LiDAR external reference | 0 |
@@ -198,7 +206,6 @@ In the "ws_livox/src/livox_ros_driver/launch" path, there are two json files, li
"lidar_config": [
{
"broadcast_code": "0TFDG3B006H2Z11",
- "enable_fan": true,
"return_mode": 0,
"imu_rate": 1
}
@@ -209,7 +216,6 @@ In the "ws_livox/src/livox_ros_driver/launch" path, there are two json files, li
The main difference between the content of Hub json configuration file and the content of the LiDAR json configuration file is that the Hub configuration item "hub_config" is added, and the related configuration content of the Hub is shown in the following table :
HUB configuration parameter
-
| Parameter | Type | Description | Default |
| -------------- | ------- | ------------------------------------------------------------ | --------------- |
| broadcast_code | String | HUB broadcast code, 15 characters, consisting of a 14-character length serial number plus a character-length additional code | 13UUG1R00400170 |
@@ -251,7 +257,6 @@ $GPRMC,190430,A,4812.3038,S,07330.7690,W,3.7,3.8,090210,13.7,E,D*26
livox_ros_driver only supports the timestamp synchronization function when connected to LiDAR. The timestamp related configuration item timesync_config is in the livox_lidar_config.json file. The detailed configuration content is shown in the table below :
Timestamp synchronization function configuration instructions
-
| Parameter | Type | Description | Default |
| ---------------- | -------- | ------------------------------------------------------------ | -------------- |
| enable_timesync | Boolean | Whether to enable the timestamp synchronization
true -- Enable timestamp synchronization
false -- Disable timestamp synchronization | false |
diff --git a/README_CN.md b/README_CN.md
index 9ece378..2099668 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -3,6 +3,16 @@
览沃ROS驱动程序是一个全新的 ROS 包,专门用于连接览沃生产的 LiDAR 产品。该驱动程序可以在安装了
ROS 环境( indigo,kinetic,melodic )的 ubuntu14.04/16.04/18.04 操作系统下运行。经测试可以运行览沃 ROS 驱动程序的硬件平台包括:intel x86 主流 cpu 平台,部分 ARM64 硬件平台(如,nvida TX2/Xavier 等)。
+## 0. 版本和发布记录
+
+### 0.1 当前版本
+
+v2.6.0
+
+### 0.2 发布记录
+
+[发布记录](https://github.com/Livox-SDK/livox_ros_driver/releases)
+
## 1. 安装依赖
运行览沃 ROS 驱动程序之前,必须安装 ROS 和 Livox-SDK。
@@ -165,7 +175,6 @@ uint8 line # laser number in lidar
{
"broadcast_code": "0TFDG3B006H2Z11",
"enable_connect": true,
- "enable_fan": true,
"return_mode": 0,
"coordinate": 0,
"imu_rate": 1,
@@ -178,12 +187,10 @@ uint8 line # laser number in lidar
上面 json 文件中各参数属性说明如下表:
LiDAR 配置参数说明
-
| 属性 | 类型 | 描述 | 默认值 |
| :------------------------- | ------ | ------------------------------------------------------------ | --------------- |
| broadcast_code | 字符串 | LiDAR 广播码,15位字符,由14位字符长度序列号加一个字符长度附加码组成 | 0TFDG3B006H2Z11 |
| enable_connect | 布尔值 | 是否连接此 LiDAR
true -- 连接此 LiDAR
false -- 禁止连接此 LiDAR | false |
-| enable_fan | 布尔值 | 是否自动控制此 LiDAR 风扇
true -- 自动控制 LiDAR 风扇
false -- 禁止自动控制此 LiDAR 风扇 | true |
| return_mode | 整型 | 回波模式
0 -- 第一个回波模式
1 -- 最强回波模式
2 -- 双回波模式 | 0 |
| coordinate | 整型 | 原始点云数据的坐标轴类型
0 -- 直角坐标系
1 -- 球坐标系 | 0 |
| imu_rate | 整型 | IMU 传感器数据的推送频率
0 -- 关闭 IMU 传感器数据推送
1 -- 以 200Hz 频率推送 IMU 传感器数据
其他值 -- 未定义,会导致不可预测的行为发生
目前只有 Horizon/Tele 支持此选项,MID 序列不支持 | 0 |
@@ -206,7 +213,6 @@ uint8 line # laser number in lidar
"lidar_config": [
{
"broadcast_code": "0TFDG3B006H2Z11",
- "enable_fan": true,
"return_mode": 0,
"imu_rate": 1
}
@@ -217,7 +223,6 @@ uint8 line # laser number in lidar
中心板 json 配置文件内容与 LiDAR 配置文件的主要区别在于,增加了中心板配置项 hub_config ,中心板相关的具体配置内容见下表:
HUB 配置参数说明
-
| 属性 | 类型 | 描述 | 默认值 |
| -------------- | ------ | ------------------------------------------------------------ | --------------- |
| broadcast_code | 字符串 | HUB 广播码,15位字符,由14位字符长度的序列号加一个字符长度的附加码组成 | 13UUG1R00400170 |
@@ -261,7 +266,6 @@ uint8 line # laser number in lidar
览沃 ROS 驱动程序只有在与 LiDAR 连接的时候才支持时间戳同步功能,时间戳相关的配置项 timesync_config 位于 livox_lidar_config.json 文件中,详细的配置内容见下表:
时间戳同步功能配置说明
-
| 属性 | 类型 | 描述 | 默认值 |
| ---------------- | ------ | ------------------------------------------------------------ | -------------- |
| enable_timesync | 布尔值 | 是否使能时间戳同步功能
true -- 使能时间戳同步功能
false -- 禁止时间戳同步功能 | false |
diff --git a/livox_ros_driver/common/FastCRC/FastCRC.h b/livox_ros_driver/common/FastCRC/FastCRC.h
index 8b6b3d5..43486fa 100644
--- a/livox_ros_driver/common/FastCRC/FastCRC.h
+++ b/livox_ros_driver/common/FastCRC/FastCRC.h
@@ -49,32 +49,32 @@
// ================= 16-BIT CRC ===================
class FastCRC16 {
-public:
+ public:
FastCRC16(uint16_t seed);
// change function name from mcrf4xx_upd to mcrf4xx
- uint16_t
- mcrf4xx_calc(const uint8_t *data,
- const uint16_t datalen); // Equivalent to _crc_ccitt_update() in
- // crc16.h from avr_libc
+ uint16_t mcrf4xx_calc(
+ const uint8_t *data,
+ const uint16_t datalen); // Equivalent to _crc_ccitt_update() in
+ // crc16.h from avr_libc
-private:
+ private:
uint16_t seed_;
};
// ================= 32-BIT CRC ===================
class FastCRC32 {
-public:
+ public:
FastCRC32(uint32_t seed);
// change function name from crc32_upd to crc32
uint32_t crc32_calc(
const uint8_t *data,
- uint16_t len); // Call for subsequent calculations with previous seed
+ uint16_t len); // Call for subsequent calculations with previous seed
-private:
+ private:
uint32_t seed_;
};
-#endif // FASTCRC_FASTCRC_H_
+#endif // FASTCRC_FASTCRC_H_
diff --git a/livox_ros_driver/common/FastCRC/FastCRCsw.cpp b/livox_ros_driver/common/FastCRC/FastCRCsw.cpp
index 1ba1e7a..a4baa21 100644
--- a/livox_ros_driver/common/FastCRC/FastCRCsw.cpp
+++ b/livox_ros_driver/common/FastCRC/FastCRCsw.cpp
@@ -55,7 +55,6 @@ FastCRC16::FastCRC16(uint16_t seed) { seed_ = seed; }
*/
uint16_t FastCRC16::mcrf4xx_calc(const uint8_t *data, uint16_t len) {
-
uint16_t crc = seed_;
while (((uintptr_t)data & 3) && len) {
@@ -90,11 +89,11 @@ FastCRC32::FastCRC32(uint32_t seed) { seed_ = seed; }
crc = (table[(crc & 0xff) + 0x300]) ^ (table[((crc >> 8) & 0xff) + 0x200]) ^ \
(table[((crc >> 16) & 0xff) + 0x100]) ^ (table[(crc >> 24) & 0xff]);
-#define crcsm_n4d(crc, data, table) \
- crc ^= data; \
- crc = (crc >> 8) ^ (table[crc & 0xff]); \
- crc = (crc >> 8) ^ (table[crc & 0xff]); \
- crc = (crc >> 8) ^ (table[crc & 0xff]); \
+#define crcsm_n4d(crc, data, table) \
+ crc ^= data; \
+ crc = (crc >> 8) ^ (table[crc & 0xff]); \
+ crc = (crc >> 8) ^ (table[crc & 0xff]); \
+ crc = (crc >> 8) ^ (table[crc & 0xff]); \
crc = (crc >> 8) ^ (table[crc & 0xff]);
/** CRC32
@@ -110,7 +109,6 @@ FastCRC32::FastCRC32(uint32_t seed) { seed_ = seed; }
#endif
uint32_t FastCRC32::crc32_calc(const uint8_t *data, uint16_t len) {
-
uint32_t crc = seed_ ^ 0xffffffff;
while (((uintptr_t)data & 3) && len) {
diff --git a/livox_ros_driver/common/comm/comm_device.h b/livox_ros_driver/common/comm/comm_device.h
index 35e5386..3d614c1 100644
--- a/livox_ros_driver/common/comm/comm_device.h
+++ b/livox_ros_driver/common/comm/comm_device.h
@@ -67,5 +67,5 @@ typedef struct {
} config;
} CommDevConfig;
-} // namespace livox_ros
-#endif // COMM_COMM_DEVICE_H_
+} // namespace livox_ros
+#endif // COMM_COMM_DEVICE_H_
diff --git a/livox_ros_driver/common/comm/comm_protocol.cpp b/livox_ros_driver/common/comm/comm_protocol.cpp
index e2534fe..c63fc80 100644
--- a/livox_ros_driver/common/comm/comm_protocol.cpp
+++ b/livox_ros_driver/common/comm/comm_protocol.cpp
@@ -23,9 +23,9 @@
//
#include "comm_protocol.h"
-#include
#include
#include
+#include
namespace livox_ros {
@@ -116,23 +116,23 @@ int32_t CommProtocol::ParseCommStream(CommPacket *o_pack) {
while ((GetValidDataSize() > protocol_->GetPreambleLen()) &&
(GetValidDataSize() > offset_to_read_index_)) {
switch (fsm_parse_step_) {
- case kSearchPacketPreamble: {
- FsmSearchPacketPreamble();
- break;
- }
- case kFindPacketLength: {
- FsmFindPacketLength();
- break;
- }
- case kGetPacketData: {
- ret = FsmGetPacketData(o_pack);
- break;
- }
- default: { FsmParserStateTransfer(kSearchPacketPreamble); }
+ case kSearchPacketPreamble: {
+ FsmSearchPacketPreamble();
+ break;
+ }
+ case kFindPacketLength: {
+ FsmFindPacketLength();
+ break;
+ }
+ case kGetPacketData: {
+ ret = FsmGetPacketData(o_pack);
+ break;
+ }
+ default: { FsmParserStateTransfer(kSearchPacketPreamble); }
}
/* Must exit when in the below case */
- if ((ret == kParseSuccess) || (ret == kParseNeedMoreData)) break;
+ if ((ret == kParseSuccess) || (ret == kParseNeedMoreData)) break;
}
return ret;
@@ -221,4 +221,4 @@ int32_t CommProtocol::FsmGetPacketData(CommPacket *o_pack) {
return ret;
}
-} // namespace livox_ros
+} // namespace livox_ros
diff --git a/livox_ros_driver/common/comm/comm_protocol.h b/livox_ros_driver/common/comm/comm_protocol.h
index c31bf10..bc77cb4 100644
--- a/livox_ros_driver/common/comm/comm_protocol.h
+++ b/livox_ros_driver/common/comm/comm_protocol.h
@@ -25,10 +25,10 @@
#ifndef COMM_COMM_PROTOCOL_H_
#define COMM_COMM_PROTOCOL_H_
+#include
#include "gps_protocol.h"
#include "protocol.h"
#include "sdk_protocol.h"
-#include
namespace livox_ros {
const uint32_t kCacheSize = 8192;
@@ -50,7 +50,7 @@ typedef struct {
} CommCache;
class CommProtocol {
-public:
+ public:
CommProtocol(ProtocolConfig &config);
~CommProtocol();
@@ -67,7 +67,7 @@ class CommProtocol {
void ResetParser();
-private:
+ private:
uint32_t GetCacheTailSize();
uint32_t GetValidDataSize();
void UpdateCache(void);
@@ -101,5 +101,5 @@ class CommProtocol {
}
};
-} // namespace livox_ros
-#endif // COMM_COMM_PROTOCOL_H_
+} // namespace livox_ros
+#endif // COMM_COMM_PROTOCOL_H_
diff --git a/livox_ros_driver/common/comm/gps_protocol.cpp b/livox_ros_driver/common/comm/gps_protocol.cpp
index 301f01f..a60da6e 100644
--- a/livox_ros_driver/common/comm/gps_protocol.cpp
+++ b/livox_ros_driver/common/comm/gps_protocol.cpp
@@ -49,7 +49,7 @@ int32_t GpsProtocol::ParsePacket(const uint8_t *i_buf, uint32_t i_len,
// GpsPacket *gps_packet = (GpsPacket *)i_buf;
if (i_len < GetPacketWrapperLen()) {
- return -1; // packet length error
+ return -1; // packet length error
}
memset((void *)o_packet, 0, sizeof(CommPacket));
o_packet->protocol = kGps;
@@ -114,14 +114,12 @@ uint8_t GpsProtocol::CalcGpsPacketChecksum(const uint8_t *buf,
uint8_t AscciiToHex(const uint8_t *TwoChar) {
uint8_t h = toupper(TwoChar[0]) - 0x30;
- if (h > 9)
- h -= 7;
+ if (h > 9) h -= 7;
uint8_t l = toupper(TwoChar[1]) - 0x30;
- if (l > 9)
- l -= 7;
+ if (l > 9) l -= 7;
return h * 16 + l;
}
-} // namespace livox_ros
+} // namespace livox_ros
diff --git a/livox_ros_driver/common/comm/gps_protocol.h b/livox_ros_driver/common/comm/gps_protocol.h
index e4ecdf2..804ac7f 100644
--- a/livox_ros_driver/common/comm/gps_protocol.h
+++ b/livox_ros_driver/common/comm/gps_protocol.h
@@ -25,8 +25,8 @@
#ifndef LIVOX_GPS_PROTOCOL_H_
#define LIVOX_GPS_PROTOCOL_H_
-#include "protocol.h"
#include
+#include "protocol.h"
namespace livox_ros {
@@ -47,7 +47,7 @@ typedef struct {
uint8_t AscciiToHex(const uint8_t *TwoChar);
class GpsProtocol : public Protocol {
-public:
+ public:
GpsProtocol();
~GpsProtocol() = default;
@@ -69,11 +69,11 @@ class GpsProtocol : public Protocol {
int32_t CheckPacket(const uint8_t *buf) override;
-private:
+ private:
uint32_t found_length_;
uint8_t CalcGpsPacketChecksum(const uint8_t *buf, uint32_t length);
};
-} // namespace livox_ros
-#endif // LIVOX_GPS_PROTOCOL_H_
+} // namespace livox_ros
+#endif // LIVOX_GPS_PROTOCOL_H_
diff --git a/livox_ros_driver/common/comm/protocol.h b/livox_ros_driver/common/comm/protocol.h
index a86df81..5d50281 100644
--- a/livox_ros_driver/common/comm/protocol.h
+++ b/livox_ros_driver/common/comm/protocol.h
@@ -60,9 +60,6 @@ typedef struct CommPacket {
uint8_t *data;
uint16_t data_len;
uint32_t padding;
- // RequestPackCb *ack_request_cb;
- // uint32_t retry_times;
- // uint32_t timeout;
} CommPacket;
/** SDK Protocol info config */
@@ -72,9 +69,7 @@ typedef struct {
} SdkProtocolConfig;
/** NAME-0183 Protocol info config for gps */
-typedef struct {
- void *data;
-} GpsProtocolConfig;
+typedef struct { void *data; } GpsProtocolConfig;
typedef struct {
uint8_t type;
@@ -85,7 +80,7 @@ typedef struct {
} ProtocolConfig;
class Protocol {
-public:
+ public:
virtual ~Protocol() = default;
virtual int32_t ParsePacket(const uint8_t *i_buf, uint32_t i_len,
@@ -107,5 +102,5 @@ class Protocol {
virtual int32_t CheckPacket(const uint8_t *buf) = 0;
};
-} // namespace livox_ros
-#endif // COMM_PROTOCOL_H_
+} // namespace livox_ros
+#endif // COMM_PROTOCOL_H_
diff --git a/livox_ros_driver/common/comm/sdk_protocol.cpp b/livox_ros_driver/common/comm/sdk_protocol.cpp
index c507142..4356326 100644
--- a/livox_ros_driver/common/comm/sdk_protocol.cpp
+++ b/livox_ros_driver/common/comm/sdk_protocol.cpp
@@ -29,8 +29,8 @@
namespace livox_ros {
const uint8_t kSdkProtocolSof = 0xAA;
-const uint32_t kSdkPacketCrcSize = 4; // crc32
-const uint32_t kSdkPacketPreambleCrcSize = 2; // crc16
+const uint32_t kSdkPacketCrcSize = 4; // crc32
+const uint32_t kSdkPacketPreambleCrcSize = 2; // crc16
SdkProtocol::SdkProtocol(uint16_t seed16, uint32_t seed32)
: crc16_(seed16), crc32_(seed32) {}
@@ -77,7 +77,7 @@ int32_t SdkProtocol::ParsePacket(const uint8_t *i_buf, uint32_t i_len,
SdkPacket *sdk_packet = (SdkPacket *)i_buf;
if (i_len < GetPacketWrapperLen()) {
- return -1; // packet lenth error
+ return -1; // packet lenth error
}
memset((void *)o_packet, 0, sizeof(CommPacket));
@@ -131,4 +131,4 @@ int32_t SdkProtocol::CheckPacket(const uint8_t *buf) {
return -1;
}
}
-} // namespace livox_ros
+} // namespace livox_ros
diff --git a/livox_ros_driver/common/comm/sdk_protocol.h b/livox_ros_driver/common/comm/sdk_protocol.h
index e587b89..5808e07 100644
--- a/livox_ros_driver/common/comm/sdk_protocol.h
+++ b/livox_ros_driver/common/comm/sdk_protocol.h
@@ -25,9 +25,9 @@
#ifndef LIVOX_SDK_PROTOCOL_H_
#define LIVOX_SDK_PROTOCOL_H_
+#include
#include "FastCRC/FastCRC.h"
#include "protocol.h"
-#include
namespace livox_ros {
typedef enum { kSdkVerNone, kSdkVer0, kSdkVer1 } SdkVersion;
@@ -58,7 +58,7 @@ typedef struct {
#pragma pack()
class SdkProtocol : public Protocol {
-public:
+ public:
SdkProtocol(uint16_t seed16, uint32_t seed32);
~SdkProtocol() = default;
@@ -78,9 +78,9 @@ class SdkProtocol : public Protocol {
int32_t CheckPacket(const uint8_t *buf) override;
-private:
+ private:
FastCRC16 crc16_;
FastCRC32 crc32_;
};
-} // namespace livox_ros
-#endif // LIVOX_SDK_PROTOCOL_H_
+} // namespace livox_ros
+#endif // LIVOX_SDK_PROTOCOL_H_
diff --git a/livox_ros_driver/common/rapidjson/allocators.h b/livox_ros_driver/common/rapidjson/allocators.h
index 53f7018..03010d5 100644
--- a/livox_ros_driver/common/rapidjson/allocators.h
+++ b/livox_ros_driver/common/rapidjson/allocators.h
@@ -78,13 +78,13 @@ allocator may not book-keep this, explicitly pass to it can save memory.)
\note implements Allocator concept
*/
class CrtAllocator {
-public:
+ public:
static const bool kNeedFree = true;
void *Malloc(size_t size) {
- if (size) // behavior of malloc(0) is implementation defined.
+ if (size) // behavior of malloc(0) is implementation defined.
return std::malloc(size);
else
- return NULL; // standardize to returning NULL.
+ return NULL; // standardize to returning NULL.
}
void *Realloc(void *originalPtr, size_t originalSize, size_t newSize) {
(void)originalSize;
@@ -118,11 +118,12 @@ class CrtAllocator {
\tparam BaseAllocator the allocator type for allocating memory chunks.
Default is CrtAllocator. \note implements Allocator concept
*/
-template class MemoryPoolAllocator {
-public:
+template
+class MemoryPoolAllocator {
+ public:
static const bool kNeedFree =
- false; //!< Tell users that no need to call Free() with this allocator.
- //!< (concept Allocator)
+ false; //!< Tell users that no need to call Free() with this allocator.
+ //!< (concept Allocator)
//! Constructor with chunkSize.
/*! \param chunkSize The size of memory chunk. The default is
@@ -131,8 +132,11 @@ template class MemoryPoolAllocator {
*/
MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity,
BaseAllocator *baseAllocator = 0)
- : chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0),
- baseAllocator_(baseAllocator), ownBaseAllocator_(0) {}
+ : chunkHead_(0),
+ chunk_capacity_(chunkSize),
+ userBuffer_(0),
+ baseAllocator_(baseAllocator),
+ ownBaseAllocator_(0) {}
//! Constructor with user-supplied buffer.
/*! The user buffer will be used firstly. When it is full, memory pool
@@ -149,8 +153,11 @@ template class MemoryPoolAllocator {
MemoryPoolAllocator(void *buffer, size_t size,
size_t chunkSize = kDefaultChunkCapacity,
BaseAllocator *baseAllocator = 0)
- : chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer),
- baseAllocator_(baseAllocator), ownBaseAllocator_(0) {
+ : chunkHead_(0),
+ chunk_capacity_(chunkSize),
+ userBuffer_(buffer),
+ baseAllocator_(baseAllocator),
+ ownBaseAllocator_(0) {
RAPIDJSON_ASSERT(buffer != 0);
RAPIDJSON_ASSERT(size > sizeof(ChunkHeader));
chunkHead_ = reinterpret_cast(buffer);
@@ -175,7 +182,7 @@ template class MemoryPoolAllocator {
chunkHead_ = next;
}
if (chunkHead_ && chunkHead_ == userBuffer_)
- chunkHead_->size = 0; // Clear user buffer
+ chunkHead_->size = 0; // Clear user buffer
}
//! Computes the total capacity of allocated memory chunks.
@@ -193,15 +200,13 @@ template class MemoryPoolAllocator {
*/
size_t Size() const {
size_t size = 0;
- for (ChunkHeader *c = chunkHead_; c != 0; c = c->next)
- size += c->size;
+ for (ChunkHeader *c = chunkHead_; c != 0; c = c->next) size += c->size;
return size;
}
//! Allocates a memory block. (concept Allocator)
void *Malloc(size_t size) {
- if (!size)
- return NULL;
+ if (!size) return NULL;
size = RAPIDJSON_ALIGN(size);
if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
@@ -216,24 +221,22 @@ template class MemoryPoolAllocator {
//! Resizes a memory block (concept Allocator)
void *Realloc(void *originalPtr, size_t originalSize, size_t newSize) {
- if (originalPtr == 0)
- return Malloc(newSize);
+ if (originalPtr == 0) return Malloc(newSize);
- if (newSize == 0)
- return NULL;
+ if (newSize == 0) return NULL;
originalSize = RAPIDJSON_ALIGN(originalSize);
newSize = RAPIDJSON_ALIGN(newSize);
// Do not shrink if new size is smaller than original
- if (originalSize >= newSize)
- return originalPtr;
+ if (originalSize >= newSize) return originalPtr;
// Simply expand it if it is the last allocation and there is sufficient
// space
- if (originalPtr == reinterpret_cast(chunkHead_) +
- RAPIDJSON_ALIGN(sizeof(ChunkHeader)) +
- chunkHead_->size - originalSize) {
+ if (originalPtr ==
+ reinterpret_cast(chunkHead_) +
+ RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size -
+ originalSize) {
size_t increment = static_cast(newSize - originalSize);
if (chunkHead_->size + increment <= chunkHead_->capacity) {
chunkHead_->size += increment;
@@ -243,17 +246,16 @@ template class MemoryPoolAllocator {
// Realloc process: allocate and copy memory, do not free original buffer.
if (void *newBuffer = Malloc(newSize)) {
- if (originalSize)
- std::memcpy(newBuffer, originalPtr, originalSize);
+ if (originalSize) std::memcpy(newBuffer, originalPtr, originalSize);
return newBuffer;
} else
return NULL;
}
//! Frees a memory block (concept Allocator)
- static void Free(void *ptr) { (void)ptr; } // Do nothing
+ static void Free(void *ptr) { (void)ptr; } // Do nothing
-private:
+ private:
//! Copy constructor is not permitted.
MemoryPoolAllocator(const MemoryPoolAllocator &rhs) /* = delete */;
//! Copy assignment operator is not permitted.
@@ -279,28 +281,28 @@ template class MemoryPoolAllocator {
}
static const int kDefaultChunkCapacity =
- RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity.
+ RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity.
//! Chunk header for perpending to each chunk.
/*! Chunks are stored as a singly linked list.
*/
struct ChunkHeader {
- size_t capacity; //!< Capacity of the chunk in bytes (excluding the header
- //!< itself).
- size_t size; //!< Current size of allocated memory in bytes.
- ChunkHeader *next; //!< Next chunk in the linked list.
+ size_t capacity; //!< Capacity of the chunk in bytes (excluding the header
+ //!< itself).
+ size_t size; //!< Current size of allocated memory in bytes.
+ ChunkHeader *next; //!< Next chunk in the linked list.
};
- ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head
- //!< chunk serves allocation.
- size_t chunk_capacity_; //!< The minimum capacity of chunk when they are
- //!< allocated.
- void *userBuffer_; //!< User supplied buffer.
+ ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head
+ //!< chunk serves allocation.
+ size_t chunk_capacity_; //!< The minimum capacity of chunk when they are
+ //!< allocated.
+ void *userBuffer_; //!< User supplied buffer.
BaseAllocator
- *baseAllocator_; //!< base allocator for allocating memory chunks.
- BaseAllocator *ownBaseAllocator_; //!< base allocator created by this object.
+ *baseAllocator_; //!< base allocator for allocating memory chunks.
+ BaseAllocator *ownBaseAllocator_; //!< base allocator created by this object.
};
RAPIDJSON_NAMESPACE_END
-#endif // RAPIDJSON_ENCODINGS_H_
+#endif // RAPIDJSON_ENCODINGS_H_
diff --git a/livox_ros_driver/common/rapidjson/cursorstreamwrapper.h b/livox_ros_driver/common/rapidjson/cursorstreamwrapper.h
index cb8ea9c..045ddb8 100644
--- a/livox_ros_driver/common/rapidjson/cursorstreamwrapper.h
+++ b/livox_ros_driver/common/rapidjson/cursorstreamwrapper.h
@@ -28,8 +28,8 @@ RAPIDJSON_DIAG_OFF(effc++)
#if defined(_MSC_VER) && _MSC_VER <= 1800
RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4702) // unreachable code
-RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
+RAPIDJSON_DIAG_OFF(4702) // unreachable code
+RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
#endif
RAPIDJSON_NAMESPACE_BEGIN
@@ -40,7 +40,7 @@ RAPIDJSON_NAMESPACE_BEGIN
*/
template >
class CursorStreamWrapper : public GenericStreamWrapper {
-public:
+ public:
typedef typename Encoding::Ch Ch;
CursorStreamWrapper(InputStream &is)
@@ -63,9 +63,9 @@ class CursorStreamWrapper : public GenericStreamWrapper {
//! Get the error column number, if error exists.
size_t GetColumn() const { return col_; }
-private:
- size_t line_; //!< Current Line
- size_t col_; //!< Current Column
+ private:
+ size_t line_; //!< Current Line
+ size_t col_; //!< Current Column
};
#if defined(_MSC_VER) && _MSC_VER <= 1800
@@ -78,4 +78,4 @@ RAPIDJSON_DIAG_POP
RAPIDJSON_NAMESPACE_END
-#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_
+#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_
diff --git a/livox_ros_driver/common/rapidjson/document.h b/livox_ros_driver/common/rapidjson/document.h
index d7c3840..27addb7 100644
--- a/livox_ros_driver/common/rapidjson/document.h
+++ b/livox_ros_driver/common/rapidjson/document.h
@@ -21,13 +21,13 @@
/*! \file document.h */
+#include
+#include // placement new
#include "encodedstream.h"
#include "internal/meta.h"
#include "internal/strfunc.h"
#include "memorystream.h"
#include "reader.h"
-#include
-#include // placement new
RAPIDJSON_DIAG_PUSH
#ifdef __clang__
@@ -35,27 +35,28 @@ RAPIDJSON_DIAG_OFF(padded)
RAPIDJSON_DIAG_OFF(switch - enum)
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
#elif defined(_MSC_VER)
-RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
+RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
RAPIDJSON_DIAG_OFF(
- 4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
+ 4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
#endif
#ifdef __GNUC__
RAPIDJSON_DIAG_OFF(effc++)
-#endif // __GNUC__
+#endif // __GNUC__
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
-#include // std::random_access_iterator_tag
+#include // std::random_access_iterator_tag
#endif
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
-#include // std::move
+#include // std::move
#endif
RAPIDJSON_NAMESPACE_BEGIN
// Forward declaration.
-template class GenericValue;
+template
+class GenericValue;
template
class GenericDocument;
@@ -67,10 +68,12 @@ class GenericDocument;
that so it moved as a namespace scope struct.
https://code.google.com/p/rapidjson/issues/detail?id=64
*/
-template class GenericMember {
-public:
- GenericValue name; //!< name of member (must be a string)
- GenericValue value; //!< value of member.
+template
+class GenericMember {
+ public:
+ GenericValue
+ name; //!< name of member (must be a string)
+ GenericValue value; //!< value of member.
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Move constructor in C++11
@@ -103,7 +106,7 @@ template class GenericMember {
a.value.Swap(b.value);
}
-private:
+ private:
//! Copy constructor is not permitted.
GenericMember(const GenericMember &rhs);
};
@@ -137,14 +140,14 @@ template class GenericMember {
*/
template
class GenericMemberIterator {
-
friend class GenericValue;
- template friend class GenericMemberIterator;
+ template
+ friend class GenericMemberIterator;
typedef GenericMember PlainType;
typedef typename internal::MaybeAddConst::Type ValueType;
-public:
+ public:
//! Iterator type itself
typedef GenericMemberIterator Iterator;
//! Constant iterator type
@@ -256,14 +259,14 @@ class GenericMemberIterator {
return ptr_ - that.ptr_;
}
-private:
+ private:
//! Internal constructor from plain pointer
explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
- Pointer ptr_; //!< raw pointer
+ Pointer ptr_; //!< raw pointer
};
-#else // RAPIDJSON_NOMEMBERITERATORCLASS
+#else // RAPIDJSON_NOMEMBERITERATORCLASS
// class-based member iterator implementation disabled, use plain pointers
@@ -283,7 +286,7 @@ class GenericMemberIterator {
typedef const GenericMember *Iterator;
};
-#endif // RAPIDJSON_NOMEMBERITERATORCLASS
+#endif // RAPIDJSON_NOMEMBERITERATORCLASS
///////////////////////////////////////////////////////////////////////////////
// GenericStringRef
@@ -315,72 +318,73 @@ class GenericMemberIterator {
\see StringRef, GenericValue::SetString
*/
-template struct GenericStringRef {
- typedef CharType Ch; //!< character type of the string
-
- //! Create string reference from \c const character array
-#ifndef __clang__ // -Wdocumentation
- /*!
- This constructor implicitly creates a constant string reference from
- a \c const character array. It has better performance than
- \ref StringRef(const CharType*) by inferring the string \ref length
- from the array length, and also supports strings containing null
- characters.
-
- \tparam N length of the string, automatically inferred
-
- \param str Constant character array, lifetime assumed to be longer
- than the use of the string in e.g. a GenericValue
-
- \post \ref s == str
-
- \note Constant complexity.
- \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
- \c snprintf are excluded from consideration.
- In such cases, the referenced string should be \b copied to the
- GenericValue instead.
- */
+template
+struct GenericStringRef {
+ typedef CharType Ch; //!< character type of the string
+
+//! Create string reference from \c const character array
+#ifndef __clang__ // -Wdocumentation
+ /*!
+ This constructor implicitly creates a constant string reference from
+ a \c const character array. It has better performance than
+ \ref StringRef(const CharType*) by inferring the string \ref length
+ from the array length, and also supports strings containing null
+ characters.
+
+ \tparam N length of the string, automatically inferred
+
+ \param str Constant character array, lifetime assumed to be longer
+ than the use of the string in e.g. a GenericValue
+
+ \post \ref s == str
+
+ \note Constant complexity.
+ \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
+ \c snprintf are excluded from consideration.
+ In such cases, the referenced string should be \b copied to the
+ GenericValue instead.
+ */
#endif
template
GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
: s(str),
length(N - 1) {}
- //! Explicitly create string reference from \c const character pointer
-#ifndef __clang__ // -Wdocumentation
- /*!
- This constructor can be used to \b explicitly create a reference to
- a constant string pointer.
-
- \see StringRef(const CharType*)
-
- \param str Constant character pointer, lifetime assumed to be longer
- than the use of the string in e.g. a GenericValue
-
- \post \ref 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
- \c snprintf are excluded from consideration.
- In such cases, the referenced string should be \b copied to the
- GenericValue instead.
- */
+//! Explicitly create string reference from \c const character pointer
+#ifndef __clang__ // -Wdocumentation
+ /*!
+ This constructor can be used to \b explicitly create a reference to
+ a constant string pointer.
+
+ \see StringRef(const CharType*)
+
+ \param str Constant character pointer, lifetime assumed to be longer
+ than the use of the string in e.g. a GenericValue
+
+ \post \ref 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
+ \c snprintf are excluded from consideration.
+ In such cases, the referenced string should be \b copied to the
+ GenericValue instead.
+ */
#endif
explicit GenericStringRef(const CharType *str)
: s(str), length(NotNullStrLen(str)) {}
- //! Create constant string reference from pointer and length
-#ifndef __clang__ // -Wdocumentation
- /*! \param str constant string, lifetime assumed to be longer than the use of
- the string in e.g. a GenericValue \param len length of the string,
- excluding the trailing NULL terminator
+//! Create constant string reference from pointer and length
+#ifndef __clang__ // -Wdocumentation
+/*! \param str constant string, lifetime assumed to be longer than the use of
+ the string in e.g. a GenericValue \param len length of the string,
+ excluding the trailing NULL terminator
- \post \ref s == str && \ref length == len
- \note Constant complexity.
- */
+ \post \ref s == str && \ref length == len
+ \note Constant complexity.
+ */
#endif
GenericStringRef(const CharType *str, SizeType len)
: s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) {
@@ -393,11 +397,11 @@ template struct GenericStringRef {
//! implicit conversion to plain CharType pointer
operator const Ch *() const { return s; }
- const Ch *const s; //!< plain CharType pointer
- const SizeType
- length; //!< length of the string (excluding the trailing NULL terminator)
+ const Ch *const s; //!< plain CharType pointer
+ const SizeType length; //!< length of the string (excluding the trailing NULL
+ //!terminator)
-private:
+ private:
SizeType NotNullStrLen(const CharType *str) {
RAPIDJSON_ASSERT(str != 0);
return internal::StrLen(str);
@@ -407,7 +411,8 @@ template struct GenericStringRef {
static const Ch emptyString[];
//! Disallow construction from non-const array
- template GenericStringRef(CharType (&str)[N]) /* = delete */;
+ template
+ GenericStringRef(CharType (&str)[N]) /* = delete */;
//! Copy assignment operator not permitted - immutable type
GenericStringRef &operator=(const GenericStringRef &rhs) /* = delete */;
};
@@ -470,8 +475,8 @@ inline GenericStringRef StringRef(const CharType *str,
preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
*/
template
-inline GenericStringRef
-StringRef(const std::basic_string &str) {
+inline GenericStringRef StringRef(
+ const std::basic_string &str) {
return GenericStringRef(str.data(), SizeType(str.size()));
}
#endif
@@ -493,18 +498,21 @@ struct IsGenericValueImpl::Type,
// helper to match arbitrary GenericValue instantiations, including derived
// classes
-template struct IsGenericValue : IsGenericValueImpl::Type {};
+template
+struct IsGenericValue : IsGenericValueImpl::Type {};
-} // namespace internal
+} // namespace internal
///////////////////////////////////////////////////////////////////////////////
// TypeHelper
namespace internal {
-template struct TypeHelper {};
+template
+struct TypeHelper {};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsBool(); }
static bool Get(const ValueType &v) { return v.GetBool(); }
static ValueType &Set(ValueType &v, bool data) { return v.SetBool(data); }
@@ -514,7 +522,8 @@ template struct TypeHelper {
}
};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsInt(); }
static int Get(const ValueType &v) { return v.GetInt(); }
static ValueType &Set(ValueType &v, int data) { return v.SetInt(data); }
@@ -524,7 +533,8 @@ template struct TypeHelper {
}
};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsUint(); }
static unsigned Get(const ValueType &v) { return v.GetUint(); }
static ValueType &Set(ValueType &v, unsigned data) { return v.SetUint(data); }
@@ -536,7 +546,8 @@ template struct TypeHelper {
#ifdef _MSC_VER
RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int));
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsInt(); }
static long Get(const ValueType &v) { return v.GetInt(); }
static ValueType &Set(ValueType &v, long data) { return v.SetInt(data); }
@@ -547,7 +558,8 @@ template struct TypeHelper {
};
RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned));
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsUint(); }
static unsigned long Get(const ValueType &v) { return v.GetUint(); }
static ValueType &Set(ValueType &v, unsigned long data) {
@@ -560,7 +572,8 @@ template struct TypeHelper {
};
#endif
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsInt64(); }
static int64_t Get(const ValueType &v) { return v.GetInt64(); }
static ValueType &Set(ValueType &v, int64_t data) { return v.SetInt64(data); }
@@ -570,7 +583,8 @@ template struct TypeHelper {
}
};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsUint64(); }
static uint64_t Get(const ValueType &v) { return v.GetUint64(); }
static ValueType &Set(ValueType &v, uint64_t data) {
@@ -582,7 +596,8 @@ template struct TypeHelper {
}
};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsDouble(); }
static double Get(const ValueType &v) { return v.GetDouble(); }
static ValueType &Set(ValueType &v, double data) { return v.SetDouble(data); }
@@ -592,7 +607,8 @@ template struct TypeHelper {
}
};
-template struct TypeHelper {
+template
+struct TypeHelper {
static bool Is(const ValueType &v) { return v.IsFloat(); }
static float Get(const ValueType &v) { return v.GetFloat(); }
static ValueType &Set(ValueType &v, float data) { return v.SetFloat(data); }
@@ -669,11 +685,13 @@ struct TypeHelper {
static ObjectType Get(const ValueType &v) { return v.GetObject(); }
};
-} // namespace internal
+} // namespace internal
// Forward declarations
-template class GenericArray;
-template class GenericObject;
+template
+class GenericArray;
+template
+class GenericObject;
///////////////////////////////////////////////////////////////////////////////
// GenericValue
@@ -691,25 +709,25 @@ template class GenericObject;
*/
template >
class GenericValue {
-public:
+ public:
//! Name-value pair in an object.
typedef GenericMember Member;
typedef Encoding EncodingType; //!< Encoding type from template parameter.
typedef Allocator AllocatorType; //!< Allocator type from template parameter.
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
+ typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
typedef GenericStringRef
- StringRefType; //!< Reference to a constant string
+ StringRefType; //!< Reference to a constant string
typedef typename GenericMemberIterator::Iterator
- MemberIterator; //!< Member iterator for iterating in object.
+ MemberIterator; //!< Member iterator for iterating in object.
typedef typename GenericMemberIterator::Iterator
- ConstMemberIterator; //!< Constant member iterator for iterating in
- //!< object.
+ ConstMemberIterator; //!< Constant member iterator for iterating in
+ //!< object.
typedef GenericValue
- *ValueIterator; //!< Value iterator for iterating in array.
+ *ValueIterator; //!< Value iterator for iterating in array.
typedef const GenericValue
- *ConstValueIterator; //!< Constant value iterator for iterating in array.
+ *ConstValueIterator; //!< Constant value iterator for iterating in array.
typedef GenericValue
- ValueType; //!< Value type of itself.
+ ValueType; //!< Value type of itself.
typedef GenericArray Array;
typedef GenericArray ConstArray;
typedef GenericObject Object;
@@ -724,11 +742,11 @@ class GenericValue {
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Move constructor in C++11
GenericValue(GenericValue &&rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
- rhs.data_.f.flags = kNullFlag; // give up contents
+ rhs.data_.f.flags = kNullFlag; // give up contents
}
#endif
-private:
+ private:
//! Copy constructor is not permitted.
GenericValue(const GenericValue &rhs);
@@ -739,11 +757,11 @@ class GenericValue {
//! Move assignment from a GenericDocument is not permitted.
template
- GenericValue &
- operator=(GenericDocument &&rhs);
+ GenericValue &operator=(
+ GenericDocument &&rhs);
#endif
-public:
+ public:
//! Constructor with JSON value type.
/*! This creates a Value of specified type with default content.
\param type Type of the value.
@@ -757,8 +775,7 @@ class GenericValue {
data_.f.flags = defaultFlags[type];
// Use ShortString to store empty string.
- if (type == kStringType)
- data_.ss.SetLength(0);
+ if (type == kStringType) data_.ss.SetLength(0);
}
//! Explicit copy constructor (with allocator)
@@ -774,59 +791,60 @@ class GenericValue {
GenericValue(const GenericValue &rhs,
Allocator &allocator, bool copyConstStrings = false) {
switch (rhs.GetType()) {
- case kObjectType: {
- SizeType count = rhs.data_.o.size;
- Member *lm =
- reinterpret_cast(allocator.Malloc(count * sizeof(Member)));
- const typename GenericValue::Member *rm =
- rhs.GetMembersPointer();
- for (SizeType i = 0; i < count; i++) {
- new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
- new (&lm[i].value)
- GenericValue(rm[i].value, allocator, copyConstStrings);
- }
- data_.f.flags = kObjectFlag;
- data_.o.size = data_.o.capacity = count;
- SetMembersPointer(lm);
- } break;
- case kArrayType: {
- SizeType count = rhs.data_.a.size;
- GenericValue *le = reinterpret_cast(
- allocator.Malloc(count * sizeof(GenericValue)));
- const GenericValue *re =
- rhs.GetElementsPointer();
- for (SizeType i = 0; i < count; i++)
- new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
- data_.f.flags = kArrayFlag;
- data_.a.size = data_.a.capacity = count;
- SetElementsPointer(le);
- } break;
- case kStringType:
- if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
+ case kObjectType: {
+ SizeType count = rhs.data_.o.size;
+ Member *lm = reinterpret_cast(
+ allocator.Malloc(count * sizeof(Member)));
+ const typename GenericValue::Member *rm =
+ rhs.GetMembersPointer();
+ for (SizeType i = 0; i < count; i++) {
+ new (&lm[i].name)
+ GenericValue(rm[i].name, allocator, copyConstStrings);
+ new (&lm[i].value)
+ GenericValue(rm[i].value, allocator, copyConstStrings);
+ }
+ data_.f.flags = kObjectFlag;
+ data_.o.size = data_.o.capacity = count;
+ SetMembersPointer(lm);
+ } break;
+ case kArrayType: {
+ SizeType count = rhs.data_.a.size;
+ GenericValue *le = reinterpret_cast(
+ allocator.Malloc(count * sizeof(GenericValue)));
+ const GenericValue *re =
+ rhs.GetElementsPointer();
+ for (SizeType i = 0; i < count; i++)
+ new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
+ data_.f.flags = kArrayFlag;
+ data_.a.size = data_.a.capacity = count;
+ SetElementsPointer(le);
+ } break;
+ case kStringType:
+ if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
+ data_.f.flags = rhs.data_.f.flags;
+ data_ = *reinterpret_cast(&rhs.data_);
+ } else
+ SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()),
+ allocator);
+ break;
+ default:
data_.f.flags = rhs.data_.f.flags;
data_ = *reinterpret_cast(&rhs.data_);
- } else
- SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()),
- allocator);
- break;
- default:
- data_.f.flags = rhs.data_.f.flags;
- data_ = *reinterpret_cast(&rhs.data_);
- break;
+ break;
}
}
- //! Constructor for boolean value.
- /*! \param b Boolean value
- \note This constructor is limited to \em real boolean values and rejects
- implicitly converted types like arbitrary pointers. Use an explicit
- cast to \c bool, if you want to construct a boolean JSON value in such
- cases.
- */
-#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
+//! Constructor for boolean value.
+/*! \param b Boolean value
+ \note This constructor is limited to \em real boolean values and rejects
+ implicitly converted types like arbitrary pointers. Use an explicit
+ cast to \c bool, if you want to construct a boolean JSON value in such
+ cases.
+ */
+#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
template
explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame)))
- RAPIDJSON_NOEXCEPT // See #472
+ RAPIDJSON_NOEXCEPT // See #472
#else
explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
#endif
@@ -951,27 +969,27 @@ class GenericValue {
/*! Need to destruct elements of array, members of object, or copy-string.
*/
~GenericValue() {
- if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
+ if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
switch (data_.f.flags) {
- case kArrayFlag: {
- GenericValue *e = GetElementsPointer();
- for (GenericValue *v = e; v != e + data_.a.size; ++v)
- v->~GenericValue();
- Allocator::Free(e);
- } break;
-
- case kObjectFlag:
- for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
- m->~Member();
- Allocator::Free(GetMembersPointer());
- break;
-
- case kCopyStringFlag:
- Allocator::Free(const_cast(GetStringPointer()));
- break;
-
- default:
- break; // Do nothing for other types.
+ case kArrayFlag: {
+ GenericValue *e = GetElementsPointer();
+ for (GenericValue *v = e; v != e + data_.a.size; ++v)
+ v->~GenericValue();
+ Allocator::Free(e);
+ } break;
+
+ case kObjectFlag:
+ for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
+ m->~Member();
+ Allocator::Free(GetMembersPointer());
+ break;
+
+ case kCopyStringFlag:
+ Allocator::Free(const_cast(GetStringPointer()));
+ break;
+
+ default:
+ break; // Do nothing for other types.
}
}
}
@@ -1091,44 +1109,40 @@ class GenericValue {
template
bool operator==(const GenericValue &rhs) const {
typedef GenericValue RhsType;
- if (GetType() != rhs.GetType())
- return false;
+ if (GetType() != rhs.GetType()) return false;
switch (GetType()) {
- case kObjectType: // Warning: O(n^2) inner-loop
- if (data_.o.size != rhs.data_.o.size)
- return false;
- for (ConstMemberIterator lhsMemberItr = MemberBegin();
- lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
- typename RhsType::ConstMemberIterator rhsMemberItr =
- rhs.FindMember(lhsMemberItr->name);
- if (rhsMemberItr == rhs.MemberEnd() ||
- lhsMemberItr->value != rhsMemberItr->value)
- return false;
- }
- return true;
-
- case kArrayType:
- if (data_.a.size != rhs.data_.a.size)
- return false;
- for (SizeType i = 0; i < data_.a.size; i++)
- if ((*this)[i] != rhs[i])
- return false;
- return true;
-
- case kStringType:
- return StringEqual(rhs);
+ case kObjectType: // Warning: O(n^2) inner-loop
+ if (data_.o.size != rhs.data_.o.size) return false;
+ for (ConstMemberIterator lhsMemberItr = MemberBegin();
+ lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
+ typename RhsType::ConstMemberIterator rhsMemberItr =
+ rhs.FindMember(lhsMemberItr->name);
+ if (rhsMemberItr == rhs.MemberEnd() ||
+ lhsMemberItr->value != rhsMemberItr->value)
+ return false;
+ }
+ return true;
+
+ case kArrayType:
+ if (data_.a.size != rhs.data_.a.size) return false;
+ for (SizeType i = 0; i < data_.a.size; i++)
+ if ((*this)[i] != rhs[i]) return false;
+ return true;
+
+ case kStringType:
+ return StringEqual(rhs);
+
+ case kNumberType:
+ if (IsDouble() || rhs.IsDouble()) {
+ double a = GetDouble(); // May convert from integer to double.
+ double b = rhs.GetDouble(); // Ditto
+ return a >= b && a <= b; // Prevent -Wfloat-equal
+ } else
+ return data_.n.u64 == rhs.data_.n.u64;
- case kNumberType:
- if (IsDouble() || rhs.IsDouble()) {
- double a = GetDouble(); // May convert from integer to double.
- double b = rhs.GetDouble(); // Ditto
- return a >= b && a <= b; // Prevent -Wfloat-equal
- } else
- return data_.n.u64 == rhs.data_.n.u64;
-
- default:
- return true;
+ default:
+ return true;
}
}
@@ -1218,8 +1232,7 @@ class GenericValue {
// Checks whether a number can be losslessly converted to a double.
bool IsLosslessDouble() const {
- if (!IsNumber())
- return false;
+ if (!IsNumber()) return false;
if (IsUint64()) {
uint64_t u = GetUint64();
volatile double d = static_cast(u);
@@ -1236,26 +1249,24 @@ class GenericValue {
(d < static_cast((std::numeric_limits::max)())) &&
(i == static_cast(d));
}
- return true; // double, int, uint are always lossless
+ return true; // double, int, uint are always lossless
}
// Checks whether a number is a float (possible lossy).
bool IsFloat() const {
- if ((data_.f.flags & kDoubleFlag) == 0)
- return false;
+ if ((data_.f.flags & kDoubleFlag) == 0) return false;
double d = GetDouble();
return d >= -3.4028234e38 && d <= 3.4028234e38;
}
// Checks whether a number can be losslessly converted to a float.
bool IsLosslessFloat() const {
- if (!IsNumber())
- return false;
+ if (!IsNumber()) return false;
double a = GetDouble();
if (a < static_cast(-(std::numeric_limits::max)()) ||
a > static_cast((std::numeric_limits::max)()))
return false;
double b = static_cast(static_cast(a));
- return a >= b && a <= b; // Prevent -Wfloat-equal
+ return a >= b && a <= b; // Prevent -Wfloat-equal
}
//@}
@@ -1355,13 +1366,13 @@ class GenericValue {
\note Linear time complexity.
*/
template
- GenericValue &
- operator[](const GenericValue &name) {
+ GenericValue &operator[](
+ const GenericValue &name) {
MemberIterator member = FindMember(name);
if (member != MemberEnd())
return member->value;
else {
- RAPIDJSON_ASSERT(false); // see above note
+ RAPIDJSON_ASSERT(false); // see above note
// This will generate -Wexit-time-destructors in clang
// static GenericValue NullValue;
@@ -1373,8 +1384,8 @@ class GenericValue {
}
}
template
- const GenericValue &
- operator[](const GenericValue &name) const {
+ const GenericValue &operator[](
+ const GenericValue &name) const {
return const_cast(*this)[name];
}
@@ -1505,19 +1516,18 @@ class GenericValue {
\note Linear time complexity.
*/
template
- MemberIterator
- FindMember(const GenericValue &name) {
+ MemberIterator FindMember(
+ const GenericValue &name) {
RAPIDJSON_ASSERT(IsObject());
RAPIDJSON_ASSERT(name.IsString());
MemberIterator member = MemberBegin();
for (; member != MemberEnd(); ++member)
- if (name.StringEqual(member->name))
- break;
+ if (name.StringEqual(member->name)) break;
return member;
}
template
- ConstMemberIterator
- FindMember(const GenericValue &name) const {
+ ConstMemberIterator FindMember(
+ const GenericValue &name) const {
return const_cast(*this).FindMember(name);
}
@@ -1642,7 +1652,7 @@ class GenericValue {
GenericValue n(name);
return AddMember(n, value, allocator);
}
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
+#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Add a member (name-value pair) to the object.
/*! \param name A constant string reference as name of member.
@@ -1707,8 +1717,7 @@ class GenericValue {
*/
void RemoveAllMembers() {
RAPIDJSON_ASSERT(IsObject());
- for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
- m->~Member();
+ for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) m->~Member();
data_.o.size = 0;
}
@@ -1757,9 +1766,9 @@ class GenericValue {
MemberIterator last(GetMembersPointer() + (data_.o.size - 1));
if (data_.o.size > 1 && m != last)
- *m = *last; // Move the last one to this place
+ *m = *last; // Move the last one to this place
else
- m->~Member(); // Only one left, just destroy
+ m->~Member(); // Only one left, just destroy
--data_.o.size;
return m;
}
@@ -1796,8 +1805,7 @@ class GenericValue {
RAPIDJSON_ASSERT(last <= MemberEnd());
MemberIterator pos = MemberBegin() + (first - MemberBegin());
- for (MemberIterator itr = pos; itr != last; ++itr)
- itr->~Member();
+ for (MemberIterator itr = pos; itr != last; ++itr) itr->~Member();
std::memmove(static_cast(&*pos), &*last,
static_cast(MemberEnd() - last) * sizeof(Member));
data_.o.size -= static_cast(last - first);
@@ -1877,8 +1885,7 @@ class GenericValue {
void Clear() {
RAPIDJSON_ASSERT(IsArray());
GenericValue *e = GetElementsPointer();
- for (GenericValue *v = e; v != e + data_.a.size; ++v)
- v->~GenericValue();
+ for (GenericValue *v = e; v != e + data_.a.size; ++v) v->~GenericValue();
data_.a.size = 0;
}
@@ -1961,7 +1968,7 @@ class GenericValue {
GenericValue &PushBack(GenericValue &&value, Allocator &allocator) {
return PushBack(value, allocator);
}
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
+#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Append a constant string reference at the end of the array.
/*! \param value Constant string reference to be appended.
@@ -2040,8 +2047,7 @@ class GenericValue {
RAPIDJSON_ASSERT(first <= last);
RAPIDJSON_ASSERT(last <= End());
ValueIterator pos = Begin() + (first - Begin());
- for (ValueIterator itr = pos; itr != last; ++itr)
- itr->~GenericValue();
+ for (ValueIterator itr = pos; itr != last; ++itr) itr->~GenericValue();
std::memmove(static_cast(pos), last,
static_cast(End() - last) * sizeof(GenericValue));
data_.a.size -= static_cast(last - first);
@@ -2086,17 +2092,16 @@ class GenericValue {
double GetDouble() const {
RAPIDJSON_ASSERT(IsNumber());
if ((data_.f.flags & kDoubleFlag) != 0)
- return data_.n.d; // exact type, no conversion.
- if ((data_.f.flags & kIntFlag) != 0)
- return data_.n.i.i; // int -> double
+ return data_.n.d; // exact type, no conversion.
+ if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
if ((data_.f.flags & kUintFlag) != 0)
- return data_.n.u.u; // unsigned -> double
+ return data_.n.u.u; // unsigned -> double
if ((data_.f.flags & kInt64Flag) != 0)
return static_cast(
- data_.n.i64); // int64_t -> double (may lose precision)
+ data_.n.i64); // int64_t -> double (may lose precision)
RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast(
- data_.n.u64); // uint64_t -> double (may lose precision)
+ data_.n.u64); // uint64_t -> double (may lose precision)
}
//! Get the value as float type.
@@ -2243,19 +2248,23 @@ class GenericValue {
\tparam T Either \c bool, \c int, \c unsigned, \c int64_t, \c uint64_t, \c
double, \c float, \c const \c char*, \c std::basic_string
*/
- template bool Is() const {
+ template
+ bool Is() const {
return internal::TypeHelper::Is(*this);
}
- template T Get() const {
+ template
+ T Get() const {
return internal::TypeHelper::Get(*this);
}
- template T Get() {
+ template
+ T Get() {
return internal::TypeHelper::Get(*this);
}
- template ValueType &Set(const T &data) {
+ template
+ ValueType &Set(const T &data) {
return internal::TypeHelper::Set(*this, data);
}
@@ -2273,60 +2282,59 @@ class GenericValue {
GenericDocument, which is also a Handler. \tparam Handler type of handler.
\param handler An object implementing concept Handler.
*/
- template bool Accept(Handler &handler) const {
+ template
+ bool Accept(Handler &handler) const {
switch (GetType()) {
- case kNullType:
- return handler.Null();
- case kFalseType:
- return handler.Bool(false);
- case kTrueType:
- return handler.Bool(true);
-
- case kObjectType:
- if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
- return false;
- for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
- RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of
- // name by MemberIterator.
- if (RAPIDJSON_UNLIKELY(
- !handler.Key(m->name.GetString(), m->name.GetStringLength(),
- (m->name.data_.f.flags & kCopyFlag) != 0)))
- return false;
- if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler)))
- return false;
- }
- return handler.EndObject(data_.o.size);
-
- case kArrayType:
- if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
- return false;
- for (const GenericValue *v = Begin(); v != End(); ++v)
- if (RAPIDJSON_UNLIKELY(!v->Accept(handler)))
- return false;
- return handler.EndArray(data_.a.size);
-
- case kStringType:
- return handler.String(GetString(), GetStringLength(),
- (data_.f.flags & kCopyFlag) != 0);
-
- default:
- RAPIDJSON_ASSERT(GetType() == kNumberType);
- if (IsDouble())
- return handler.Double(data_.n.d);
- else if (IsInt())
- return handler.Int(data_.n.i.i);
- else if (IsUint())
- return handler.Uint(data_.n.u.u);
- else if (IsInt64())
- return handler.Int64(data_.n.i64);
- else
- return handler.Uint64(data_.n.u64);
+ case kNullType:
+ return handler.Null();
+ case kFalseType:
+ return handler.Bool(false);
+ case kTrueType:
+ return handler.Bool(true);
+
+ case kObjectType:
+ if (RAPIDJSON_UNLIKELY(!handler.StartObject())) return false;
+ for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
+ RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of
+ // name by MemberIterator.
+ if (RAPIDJSON_UNLIKELY(
+ !handler.Key(m->name.GetString(), m->name.GetStringLength(),
+ (m->name.data_.f.flags & kCopyFlag) != 0)))
+ return false;
+ if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler))) return false;
+ }
+ return handler.EndObject(data_.o.size);
+
+ case kArrayType:
+ if (RAPIDJSON_UNLIKELY(!handler.StartArray())) return false;
+ for (const GenericValue *v = Begin(); v != End(); ++v)
+ if (RAPIDJSON_UNLIKELY(!v->Accept(handler))) return false;
+ return handler.EndArray(data_.a.size);
+
+ case kStringType:
+ return handler.String(GetString(), GetStringLength(),
+ (data_.f.flags & kCopyFlag) != 0);
+
+ default:
+ RAPIDJSON_ASSERT(GetType() == kNumberType);
+ if (IsDouble())
+ return handler.Double(data_.n.d);
+ else if (IsInt())
+ return handler.Int(data_.n.i.i);
+ else if (IsUint())
+ return handler.Uint(data_.n.u.u);
+ else if (IsInt64())
+ return handler.Int64(data_.n.i64);
+ else
+ return handler.Uint64(data_.n.u64);
}
}
-private:
- template friend class GenericValue;
- template friend class GenericDocument;
+ private:
+ template
+ friend class GenericValue;
+ template
+ friend class GenericDocument;
enum {
kBoolFlag = 0x0008,
@@ -2367,21 +2375,21 @@ class GenericValue {
struct Flag {
#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
char payload[sizeof(SizeType) * 2 +
- 6]; // 2 x SizeType + lower 48-bit pointer
+ 6]; // 2 x SizeType + lower 48-bit pointer
#elif RAPIDJSON_64BIT
- char payload[sizeof(SizeType) * 2 + sizeof(void *) + 6]; // 6 padding bytes
+ char payload[sizeof(SizeType) * 2 + sizeof(void *) + 6]; // 6 padding bytes
#else
- char payload[sizeof(SizeType) * 2 + sizeof(void *) +
- 2]; // 2 padding bytes
+ char payload[sizeof(SizeType) * 2 + sizeof(void *) +
+ 2]; // 2 padding bytes
#endif
uint16_t flags;
};
struct String {
SizeType length;
- SizeType hashcode; //!< reserved
+ SizeType hashcode; //!< reserved
const Ch *str;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
// implementation detail: ShortString can represent zero-terminated strings up
// to MaxSize chars (excluding the terminating zero) and store a value to
@@ -2408,8 +2416,8 @@ class GenericValue {
inline SizeType GetLength() const {
return static_cast(MaxSize - str[LenPos]);
}
- }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16
- // bytes in 64-bit mode
+ }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16
+ // bytes in 64-bit mode
// By using proper binary layout, retrieval of different integer types do not
// need conversions.
@@ -2436,19 +2444,19 @@ class GenericValue {
int64_t i64;
uint64_t u64;
double d;
- }; // 8 bytes
+ }; // 8 bytes
struct ObjectData {
SizeType size;
SizeType capacity;
Member *members;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
struct ArrayData {
SizeType size;
SizeType capacity;
GenericValue *elements;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
union Data {
String s;
@@ -2457,8 +2465,8 @@ class GenericValue {
ObjectData o;
ArrayData a;
Flag f;
- }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit
- // with RAPIDJSON_48BITPOINTER_OPTIMIZATION
+ }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit
+ // with RAPIDJSON_48BITPOINTER_OPTIMIZATION
RAPIDJSON_FORCEINLINE const Ch *GetStringPointer() const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str);
@@ -2469,8 +2477,8 @@ class GenericValue {
RAPIDJSON_FORCEINLINE GenericValue *GetElementsPointer() const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements);
}
- RAPIDJSON_FORCEINLINE GenericValue *
- SetElementsPointer(GenericValue *elements) {
+ RAPIDJSON_FORCEINLINE GenericValue *SetElementsPointer(
+ GenericValue *elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements);
}
RAPIDJSON_FORCEINLINE Member *GetMembersPointer() const {
@@ -2555,7 +2563,7 @@ class GenericValue {
const Ch *const str2 = rhs.GetString();
if (str1 == str2) {
return true;
- } // fast path for constant string
+ } // fast path for constant string
return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
}
@@ -2583,11 +2591,11 @@ typedef GenericValue> Value;
template ,
typename StackAllocator = CrtAllocator>
class GenericDocument : public GenericValue {
-public:
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
+ public:
+ typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
typedef GenericValue
- ValueType; //!< Value type of the document.
- typedef Allocator AllocatorType; //!< Allocator type from template parameter.
+ ValueType; //!< Value type of the document.
+ typedef Allocator AllocatorType; //!< Allocator type from template parameter.
//! Constructor
/*! Creates an empty document of specified type.
@@ -2600,11 +2608,12 @@ class GenericDocument : public GenericValue {
explicit GenericDocument(Type type, Allocator *allocator = 0,
size_t stackCapacity = kDefaultStackCapacity,
StackAllocator *stackAllocator = 0)
- : GenericValue(type), allocator_(allocator),
- ownAllocator_(0), stack_(stackAllocator, stackCapacity),
+ : GenericValue(type),
+ allocator_(allocator),
+ ownAllocator_(0),
+ stack_(stackAllocator, stackCapacity),
parseResult_() {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
+ if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
}
//! Constructor
@@ -2617,17 +2626,18 @@ class GenericDocument : public GenericValue {
GenericDocument(Allocator *allocator = 0,
size_t stackCapacity = kDefaultStackCapacity,
StackAllocator *stackAllocator = 0)
- : allocator_(allocator), ownAllocator_(0),
- stack_(stackAllocator, stackCapacity), parseResult_() {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
+ : allocator_(allocator),
+ ownAllocator_(0),
+ stack_(stackAllocator, stackCapacity),
+ parseResult_() {
+ if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Move constructor in C++11
GenericDocument(GenericDocument &&rhs) RAPIDJSON_NOEXCEPT
: ValueType(std::forward(
- rhs)), // explicit cast to avoid prohibited move from Document
+ rhs)), // explicit cast to avoid prohibited move from Document
allocator_(rhs.allocator_),
ownAllocator_(rhs.ownAllocator_),
stack_(std::move(rhs.stack_)),
@@ -2702,13 +2712,14 @@ class GenericDocument : public GenericValue {
\param g Generator functor which sends SAX events to the parameter.
\return The document itself for fluent API.
*/
- template GenericDocument &Populate(Generator &g) {
+ template
+ GenericDocument &Populate(Generator &g) {
ClearStackOnExit scope(*this);
if (g(*this)) {
RAPIDJSON_ASSERT(stack_.GetSize() ==
- sizeof(ValueType)); // Got one and only one root object
+ sizeof(ValueType)); // Got one and only one root object
ValueType::operator=(*stack_.template Pop(
- 1)); // Move value from stack to document
+ 1)); // Move value from stack to document
}
return *this;
}
@@ -2731,9 +2742,9 @@ class GenericDocument : public GenericValue {
parseResult_ = reader.template Parse(is, *this);
if (parseResult_) {
RAPIDJSON_ASSERT(stack_.GetSize() ==
- sizeof(ValueType)); // Got one and only one root object
+ sizeof(ValueType)); // Got one and only one root object
ValueType::operator=(*stack_.template Pop(
- 1)); // Move value from stack to document
+ 1)); // Move value from stack to document
}
return *this;
}
@@ -2768,7 +2779,8 @@ class GenericDocument : public GenericValue {
\param str Mutable zero-terminated string to be parsed.
\return The document itself for fluent API.
*/
- template GenericDocument &ParseInsitu(Ch *str) {
+ template
+ GenericDocument &ParseInsitu(Ch *str) {
GenericInsituStringStream s(str);
return ParseStream(s);
}
@@ -2802,7 +2814,8 @@ class GenericDocument : public GenericValue {
kParseInsituFlag). \param str Read-only zero-terminated string to be
parsed.
*/
- template GenericDocument &Parse(const Ch *str) {
+ template
+ GenericDocument &Parse(const Ch *str) {
return Parse(str);
}
@@ -2835,8 +2848,8 @@ class GenericDocument : public GenericValue {
#if RAPIDJSON_HAS_STDSTRING
template
- GenericDocument &
- Parse(const std::basic_string &str) {
+ GenericDocument &Parse(
+ const std::basic_string &str) {
// c_str() is constant complexity according to standard. Should be faster
// than Parse(const char*, size_t)
return Parse(str.c_str());
@@ -2850,7 +2863,7 @@ class GenericDocument : public GenericValue {
GenericDocument &Parse(const std::basic_string &str) {
return Parse(str);
}
-#endif // RAPIDJSON_HAS_STDSTRING
+#endif // RAPIDJSON_HAS_STDSTRING
//!@}
@@ -2866,17 +2879,17 @@ class GenericDocument : public GenericValue {
//! Get the position of last parsing error in input, 0 otherwise.
size_t GetErrorOffset() const { return parseResult_.Offset(); }
- //! Implicit conversion to get the last parse result
-#ifndef __clang // -Wdocumentation
- /*! \return \ref ParseResult of the last parse operation
-
- \code
- Document doc;
- ParseResult ok = doc.Parse(json);
- if (!ok)
- printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()),
- ok.Offset()); \endcode
- */
+//! Implicit conversion to get the last parse result
+#ifndef __clang // -Wdocumentation
+/*! \return \ref ParseResult of the last parse operation
+
+ \code
+ Document doc;
+ ParseResult ok = doc.Parse(json);
+ if (!ok)
+ printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()),
+ ok.Offset()); \endcode
+ */
#endif
operator ParseResult() const { return parseResult_; }
//!@}
@@ -2890,13 +2903,13 @@ class GenericDocument : public GenericValue {
//! Get the capacity of stack in bytes.
size_t GetStackCapacity() const { return stack_.GetCapacity(); }
-private:
+ private:
// clear stack on any exit from ParseStream, e.g. due to exception
struct ClearStackOnExit {
explicit ClearStackOnExit(GenericDocument &d) : d_(d) {}
~ClearStackOnExit() { d_.ClearStack(); }
- private:
+ private:
ClearStackOnExit(const ClearStackOnExit &);
ClearStackOnExit &operator=(const ClearStackOnExit &);
GenericDocument &d_;
@@ -2905,9 +2918,10 @@ class GenericDocument : public GenericValue {
// callers of the following private Handler functions
// template friend class GenericReader; // for
// parsing
- template friend class GenericValue; // for deep copying
+ template