rj_schema 0.2.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
  3. data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
  4. data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
  5. data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
  6. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +118 -0
  7. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +5 -5
  8. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
  9. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +17 -12
  10. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
  11. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
  12. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
  13. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
  14. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +1 -1
  15. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
  16. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +1 -1
  17. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
  18. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +4 -4
  19. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +1 -1
  20. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
  21. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
  22. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
  23. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
  24. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
  25. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +1 -1
  26. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +1 -1
  27. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +1 -1
  28. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
  29. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
  30. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -1
  31. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
  32. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
  33. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
  34. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1 -1
  35. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
  36. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +17 -1
  37. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
  38. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +311 -159
  39. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
  40. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
  41. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +3 -3
  42. data/ext/rj_schema/rapidjson/readme.md +3 -3
  43. data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
  44. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
  45. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
  46. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +1 -1
  47. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
  48. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +1 -1
  49. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +1 -0
  50. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +1 -1
  51. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
  52. data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
  53. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +1 -1
  54. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +1 -1
  55. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
  56. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
  57. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
  58. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +1 -1
  59. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
  60. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +1 -1
  61. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +1 -1
  62. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
  63. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
  64. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
  65. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +33 -1
  66. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
  67. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +4 -1
  68. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +1 -1
  69. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +593 -78
  70. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
  71. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
  72. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +1 -1
  73. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
  74. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
  75. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +1 -1
  76. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1 -1
  77. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
  78. data/ext/rj_schema/rj_schema.cpp +160 -16
  79. data/lib/rj_schema.rb +1 -1
  80. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88e56e46d71123b9fc6cba7e8c6caabdf2ea8aac2ec611ddf24d9a782be1ae04
4
- data.tar.gz: 2d89ed4179653ae26025d704066cfb44e987bb0c779773d871dc8f8e8a91e1ef
3
+ metadata.gz: eaf776a94bc82ea6f7ed041927c3ade57e7e74fd7a8f01db87ae1252eaac6a30
4
+ data.tar.gz: df73cdfcf503d76b70a311e64d1edf95893ce9c521ac0e3154dc27be2533d435
5
5
  SHA512:
6
- metadata.gz: c662fd5652dfc176b7da0543769ed894e756106488e1843cf7dd084cda0fafa335d243afcaa4348120c311a5f64cb67b4dd06e09001c5a37540b500e9356d4df
7
- data.tar.gz: 55e3d48f9ee2cf718273a04381c1955bc16d6bc4bfb1bf12f4ff0f0eab0074c223bd302091e85f450f82734d581534dd3b0737789a5ce5d889b8ca724d8be358
6
+ metadata.gz: 13da02db7af7782178b92b1970c006de03bc45d65c96c90cc87b8aa3b90e0a673dac67bfc3e22a1f4d85ae26e1f8c7a6f951b3fe44239bb2d8149f290a18a585
7
+ data.tar.gz: 8c05a82b990647d6c8010fb121c45c4e4e9b7e35dac3a8a4b48f997597180ffd31095ff5e558ae3f15eb4cfd2c5077bdd459536299e20153127d9f74508cfc4e
@@ -0,0 +1,139 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "version": {
5
+ "$ref": "#/definitions/decimal_type"
6
+ },
7
+ "address": {
8
+ "$ref": "#/definitions/address_type"
9
+ },
10
+ "phones": {
11
+ "type": "array",
12
+ "minItems": 1,
13
+ "maxItems": 2,
14
+ "uniqueItems": true,
15
+ "items": {
16
+ "$ref": "#/definitions/phone_type"
17
+ }
18
+ },
19
+ "names": {
20
+ "type": "array",
21
+ "items": [
22
+ { "type": "string" },
23
+ { "type": "string" }
24
+ ],
25
+ "additionalItems": false
26
+ },
27
+ "extra": {
28
+ "type": "object",
29
+ "patternProperties": {
30
+ "^S_": { "type": "string" }
31
+ }
32
+ },
33
+ "gender": {
34
+ "type": "string",
35
+ "enum": ["M", "F"]
36
+ }
37
+ },
38
+ "additionalProperties": false,
39
+ "dependencies": {
40
+ "address": [ "version" ],
41
+ "names": {
42
+ "properties": {
43
+ "version": { "$ref": "#/definitions/decimal_type" }
44
+ },
45
+ "required": ["version"]
46
+ }
47
+ },
48
+ "definitions": {
49
+ "address_type": {
50
+ "type": "object",
51
+ "properties": {
52
+ "number": {
53
+ "$ref": "#/definitions/positiveInt_type"
54
+ },
55
+ "street1": {
56
+ "type": "string"
57
+ },
58
+ "street2": {
59
+ "type": ["string", "null"]
60
+ },
61
+ "street3": {
62
+ "not": { "type": ["boolean", "number", ",integer", "object", "null"] }
63
+ },
64
+ "city": {
65
+ "type": "string",
66
+ "maxLength": 10,
67
+ "minLength": 4
68
+ },
69
+ "area": {
70
+ "oneOf": [
71
+ { "$ref": "#/definitions/county_type" },
72
+ { "$ref": "#/definitions/province_type" }
73
+ ]
74
+ },
75
+ "country": {
76
+ "allOf": [
77
+ { "$ref": "#/definitions/country_type" }
78
+ ]
79
+ },
80
+ "postcode": {
81
+ "anyOf": [
82
+ { "type": "string", "pattern": "^[A-Z]{2}[0-9]{1,2} [0-9][A-Z]{2}$" },
83
+ { "type": "string", "pattern": "^[0-9]{5}$" }
84
+ ]
85
+ }
86
+ },
87
+ "minProperties": 7,
88
+ "required": [
89
+ "number",
90
+ "street1",
91
+ "city"
92
+ ]
93
+ },
94
+ "country_type": {
95
+ "type": "string",
96
+ "enum": ["UK", "Canada"]
97
+ },
98
+ "county_type": {
99
+ "type": "string",
100
+ "enum": ["Sussex", "Surrey", "Kent"]
101
+ },
102
+ "province_type": {
103
+ "type": "string",
104
+ "enum": ["Quebec", "BC", "Alberta"]
105
+ },
106
+ "date_type": {
107
+ "pattern": "^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)?$",
108
+ "type": "string"
109
+ },
110
+ "positiveInt_type": {
111
+ "minimum": 0,
112
+ "exclusiveMinimum": true,
113
+ "maximum": 100,
114
+ "exclusiveMaximum": true,
115
+ "type": "integer"
116
+ },
117
+ "decimal_type": {
118
+ "multipleOf": 1.0,
119
+ "type": "number"
120
+ },
121
+ "time_type": {
122
+ "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?$",
123
+ "type": "string"
124
+ },
125
+ "unsignedInt_type": {
126
+ "type": "integer",
127
+ "minimum": 0,
128
+ "maximum": 99999
129
+ },
130
+ "phone_type": {
131
+ "pattern": "^[0-9]*-[0-9]*",
132
+ "type": "string"
133
+ },
134
+ "url_type": {
135
+ "pattern": "^\\S*$",
136
+ "type": "string"
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "allOf": [
3
+ {
4
+ "$ref": "http://localhost:1234/address.json#"
5
+ }
6
+ ]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "anyOf": [
3
+ {
4
+ "$ref": "http://localhost:1234/address.json#"
5
+ }
6
+ ]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "oneOf": [
3
+ {
4
+ "$ref": "http://localhost:1234/address.json#"
5
+ }
6
+ ]
7
+ }
@@ -7,9 +7,124 @@
7
7
  #include "rapidjson/schema.h"
8
8
  #include "rapidjson/stringbuffer.h"
9
9
  #include "rapidjson/prettywriter.h"
10
+ #include <string>
11
+ #include <iostream>
12
+ #include <sstream>
10
13
 
11
14
  using namespace rapidjson;
12
15
 
16
+ typedef GenericValue<UTF8<>, CrtAllocator > ValueType;
17
+
18
+ // Forward ref
19
+ static void CreateErrorMessages(const ValueType& errors, size_t depth, const char* context);
20
+
21
+ // Convert GenericValue to std::string
22
+ static std::string GetString(const ValueType& val) {
23
+ std::ostringstream s;
24
+ if (val.IsString())
25
+ s << val.GetString();
26
+ else if (val.IsDouble())
27
+ s << val.GetDouble();
28
+ else if (val.IsUint())
29
+ s << val.GetUint();
30
+ else if (val.IsInt())
31
+ s << val.GetInt();
32
+ else if (val.IsUint64())
33
+ s << val.GetUint64();
34
+ else if (val.IsInt64())
35
+ s << val.GetInt64();
36
+ else if (val.IsBool() && val.GetBool())
37
+ s << "true";
38
+ else if (val.IsBool())
39
+ s << "false";
40
+ else if (val.IsFloat())
41
+ s << val.GetFloat();
42
+ return s.str();}
43
+
44
+ // Create the error message for a named error
45
+ // The error object can either be empty or contain at least member properties:
46
+ // {"errorCode": <code>, "instanceRef": "<pointer>", "schemaRef": "<pointer>" }
47
+ // Additional properties may be present for use as inserts.
48
+ // An "errors" property may be present if there are child errors.
49
+ static void HandleError(const char* errorName, const ValueType& error, size_t depth, const char* context) {
50
+ if (!error.ObjectEmpty()) {
51
+ // Get error code and look up error message text (English)
52
+ int code = error["errorCode"].GetInt();
53
+ std::string message(GetValidateError_En(static_cast<ValidateErrorCode>(code)));
54
+ // For each member property in the error, see if its name exists as an insert in the error message and if so replace with the stringified property value
55
+ // So for example - "Number '%actual' is not a multiple of the 'multipleOf' value '%expected'." - we would expect "actual" and "expected" members.
56
+ for (ValueType::ConstMemberIterator insertsItr = error.MemberBegin();
57
+ insertsItr != error.MemberEnd(); ++insertsItr) {
58
+ std::string insertName("%");
59
+ insertName += insertsItr->name.GetString(); // eg "%actual"
60
+ size_t insertPos = message.find(insertName);
61
+ if (insertPos != std::string::npos) {
62
+ std::string insertString("");
63
+ const ValueType &insert = insertsItr->value;
64
+ if (insert.IsArray()) {
65
+ // Member is an array so create comma-separated list of items for the insert string
66
+ for (ValueType::ConstValueIterator itemsItr = insert.Begin(); itemsItr != insert.End(); ++itemsItr) {
67
+ if (itemsItr != insert.Begin()) insertString += ",";
68
+ insertString += GetString(*itemsItr);
69
+ }
70
+ } else {
71
+ insertString += GetString(insert);
72
+ }
73
+ message.replace(insertPos, insertName.length(), insertString);
74
+ }
75
+ }
76
+ // Output error message, references, context
77
+ std::string indent(depth * 2, ' ');
78
+ std::cout << indent << "Error Name: " << errorName << std::endl;
79
+ std::cout << indent << "Message: " << message.c_str() << std::endl;
80
+ std::cout << indent << "Instance: " << error["instanceRef"].GetString() << std::endl;
81
+ std::cout << indent << "Schema: " << error["schemaRef"].GetString() << std::endl;
82
+ if (depth > 0) std::cout << indent << "Context: " << context << std::endl;
83
+ std::cout << std::endl;
84
+
85
+ // If child errors exist, apply the process recursively to each error structure.
86
+ // This occurs for "oneOf", "allOf", "anyOf" and "dependencies" errors, so pass the error name as context.
87
+ if (error.HasMember("errors")) {
88
+ depth++;
89
+ const ValueType &childErrors = error["errors"];
90
+ if (childErrors.IsArray()) {
91
+ // Array - each item is an error structure - example
92
+ // "anyOf": {"errorCode": ..., "errors":[{"pattern": {"errorCode\": ...\"}}, {"pattern": {"errorCode\": ...}}]
93
+ for (ValueType::ConstValueIterator errorsItr = childErrors.Begin();
94
+ errorsItr != childErrors.End(); ++errorsItr) {
95
+ CreateErrorMessages(*errorsItr, depth, errorName);
96
+ }
97
+ } else if (childErrors.IsObject()) {
98
+ // Object - each member is an error structure - example
99
+ // "dependencies": {"errorCode": ..., "errors": {"address": {"required": {"errorCode": ...}}, "name": {"required": {"errorCode": ...}}}
100
+ for (ValueType::ConstMemberIterator propsItr = childErrors.MemberBegin();
101
+ propsItr != childErrors.MemberEnd(); ++propsItr) {
102
+ CreateErrorMessages(propsItr->value, depth, errorName);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ // Create error message for all errors in an error structure
110
+ // Context is used to indicate whether the error structure has a parent 'dependencies', 'allOf', 'anyOf' or 'oneOf' error
111
+ static void CreateErrorMessages(const ValueType& errors, size_t depth = 0, const char* context = 0) {
112
+ // Each member property contains one or more errors of a given type
113
+ for (ValueType::ConstMemberIterator errorTypeItr = errors.MemberBegin(); errorTypeItr != errors.MemberEnd(); ++errorTypeItr) {
114
+ const char* errorName = errorTypeItr->name.GetString();
115
+ const ValueType& errorContent = errorTypeItr->value;
116
+ if (errorContent.IsArray()) {
117
+ // Member is an array where each item is an error - eg "type": [{"errorCode": ...}, {"errorCode": ...}]
118
+ for (ValueType::ConstValueIterator contentItr = errorContent.Begin(); contentItr != errorContent.End(); ++contentItr) {
119
+ HandleError(errorName, *contentItr, depth, context);
120
+ }
121
+ } else if (errorContent.IsObject()) {
122
+ // Member is an object which is a single error - eg "type": {"errorCode": ... }
123
+ HandleError(errorName, errorContent, depth, context);
124
+ }
125
+ }
126
+ }
127
+
13
128
  int main(int argc, char *argv[]) {
14
129
  if (argc != 2) {
15
130
  fprintf(stderr, "Usage: schemavalidator schema.json < input.json\n");
@@ -65,6 +180,8 @@ int main(int argc, char *argv[]) {
65
180
  validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
66
181
  fprintf(stderr, "Invalid schema: %s\n", sb.GetString());
67
182
  fprintf(stderr, "Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
183
+ fprintf(stderr, "Invalid code: %d\n", validator.GetInvalidSchemaCode());
184
+ fprintf(stderr, "Invalid message: %s\n", GetValidateError_En(validator.GetInvalidSchemaCode()));
68
185
  sb.Clear();
69
186
  validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
70
187
  fprintf(stderr, "Invalid document: %s\n", sb.GetString());
@@ -73,6 +190,7 @@ int main(int argc, char *argv[]) {
73
190
  PrettyWriter<StringBuffer> w(sb);
74
191
  validator.GetError().Accept(w);
75
192
  fprintf(stderr, "Error report:\n%s\n", sb.GetString());
193
+ CreateErrorMessages(validator.GetError());
76
194
  return EXIT_FAILURE;
77
195
  }
78
196
  }
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -77,19 +77,19 @@ public:
77
77
  static const bool kNeedFree = true;
78
78
  void* Malloc(size_t size) {
79
79
  if (size) // behavior of malloc(0) is implementation defined.
80
- return std::malloc(size);
80
+ return RAPIDJSON_MALLOC(size);
81
81
  else
82
82
  return NULL; // standardize to returning NULL.
83
83
  }
84
84
  void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
85
85
  (void)originalSize;
86
86
  if (newSize == 0) {
87
- std::free(originalPtr);
87
+ RAPIDJSON_FREE(originalPtr);
88
88
  return NULL;
89
89
  }
90
- return std::realloc(originalPtr, newSize);
90
+ return RAPIDJSON_REALLOC(originalPtr, newSize);
91
91
  }
92
- static void Free(void *ptr) { std::free(ptr); }
92
+ static void Free(void *ptr) { RAPIDJSON_FREE(ptr); }
93
93
  };
94
94
 
95
95
  ///////////////////////////////////////////////////////////////////////////////
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -289,12 +289,14 @@ class GenericMemberIterator;
289
289
  //! non-const GenericMemberIterator
290
290
  template <typename Encoding, typename Allocator>
291
291
  class GenericMemberIterator<false,Encoding,Allocator> {
292
+ public:
292
293
  //! use plain pointer as iterator type
293
294
  typedef GenericMember<Encoding,Allocator>* Iterator;
294
295
  };
295
296
  //! const GenericMemberIterator
296
297
  template <typename Encoding, typename Allocator>
297
298
  class GenericMemberIterator<true,Encoding,Allocator> {
299
+ public:
298
300
  //! use plain const pointer as iterator type
299
301
  typedef const GenericMember<Encoding,Allocator>* Iterator;
300
302
  };
@@ -2001,17 +2003,18 @@ private:
2001
2003
 
2002
2004
  // Initial flags of different types.
2003
2005
  kNullFlag = kNullType,
2004
- kTrueFlag = kTrueType | kBoolFlag,
2005
- kFalseFlag = kFalseType | kBoolFlag,
2006
- kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
2007
- kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
2008
- kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag,
2009
- kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag,
2010
- kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag,
2011
- kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
2012
- kConstStringFlag = kStringType | kStringFlag,
2013
- kCopyStringFlag = kStringType | kStringFlag | kCopyFlag,
2014
- kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
2006
+ // These casts are added to suppress the warning on MSVC about bitwise operations between enums of different types.
2007
+ kTrueFlag = static_cast<int>(kTrueType) | static_cast<int>(kBoolFlag),
2008
+ kFalseFlag = static_cast<int>(kFalseType) | static_cast<int>(kBoolFlag),
2009
+ kNumberIntFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag),
2010
+ kNumberUintFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag),
2011
+ kNumberInt64Flag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kInt64Flag),
2012
+ kNumberUint64Flag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kUint64Flag),
2013
+ kNumberDoubleFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kDoubleFlag),
2014
+ kNumberAnyFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag),
2015
+ kConstStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag),
2016
+ kCopyStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag | kCopyFlag),
2017
+ kShortStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag | kCopyFlag | kInlineStrFlag),
2015
2018
  kObjectFlag = kObjectType,
2016
2019
  kArrayFlag = kArrayType,
2017
2020
 
@@ -2609,6 +2612,7 @@ public:
2609
2612
  GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
2610
2613
  ~GenericArray() {}
2611
2614
 
2615
+ operator ValueType&() const { return value_; }
2612
2616
  SizeType Size() const { return value_.Size(); }
2613
2617
  SizeType Capacity() const { return value_.Capacity(); }
2614
2618
  bool Empty() const { return value_.Empty(); }
@@ -2664,6 +2668,7 @@ public:
2664
2668
  GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
2665
2669
  ~GenericObject() {}
2666
2670
 
2671
+ operator ValueType&() const { return value_; }
2667
2672
  SizeType MemberCount() const { return value_.MemberCount(); }
2668
2673
  SizeType MemberCapacity() const { return value_.MemberCapacity(); }
2669
2674
  bool ObjectEmpty() const { return value_.ObjectEmpty(); }
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at