Skip to content

Commit 77abb06

Browse files
author
Michael Fero
committed
CPP-405 - Namespace rapidjson to avoid conflicts
1 parent b200c0a commit 77abb06

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

cpp-driver/src/json.hpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
/*
22
Copyright (c) DataStax, Inc.
33
4-
This software can be used solely with DataStax Enterprise. Please consult the
5-
license at http://www.datastax.com/terms/datastax-dse-driver-license-terms
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
615
*/
716

8-
#ifndef __DSE_JSON_HPP_INCLUDED__
9-
#define __DSE_JSON_HPP_INCLUDED__
17+
#ifndef __CASS_JSON_HPP_INCLUDED__
18+
#define __CASS_JSON_HPP_INCLUDED__
1019

1120
#include "memory.hpp"
12-
21+
#define RAPIDJSON_NAMESPACE cass::rapidjson
22+
#define RAPIDJSON_NAMESPACE_BEGIN namespace cass { namespace rapidjson {
23+
#define RAPIDJSON_NAMESPACE_END } }
1324
#define RAPIDJSON_NEW(x) cass::Memory::allocate<x>
1425
#define RAPIDJSON_DELETE(x) cass::Memory::deallocate(x)
1526

@@ -36,14 +47,14 @@ class Allocator {
3647
}
3748
};
3849

39-
typedef rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<json::Allocator>, json::Allocator> Document;
40-
typedef rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<json::Allocator> > Value;
41-
typedef rapidjson::GenericStringBuffer<rapidjson::UTF8<>, json::Allocator> StringBuffer;
50+
typedef cass::rapidjson::GenericDocument<cass::rapidjson::UTF8<>, cass::rapidjson::MemoryPoolAllocator<json::Allocator>, json::Allocator> Document;
51+
typedef cass::rapidjson::GenericValue<cass::rapidjson::UTF8<>, cass::rapidjson::MemoryPoolAllocator<json::Allocator> > Value;
52+
typedef cass::rapidjson::GenericStringBuffer<cass::rapidjson::UTF8<>, json::Allocator> StringBuffer;
4253

43-
template<typename OutputStream, typename SourceEncoding = rapidjson::UTF8<>, typename TargetEncoding = rapidjson::UTF8<>, typename StackAllocator = json::Allocator, unsigned writeFlags = rapidjson::kWriteDefaultFlags>
44-
class Writer : public rapidjson::Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
54+
template<typename OutputStream, typename SourceEncoding = cass::rapidjson::UTF8<>, typename TargetEncoding = cass::rapidjson::UTF8<>, typename StackAllocator = json::Allocator, unsigned writeFlags = cass::rapidjson::kWriteDefaultFlags>
55+
class Writer : public cass::rapidjson::Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
4556
public:
46-
typedef rapidjson::Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> Type;
57+
typedef cass::rapidjson::Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> Type;
4758

4859
explicit Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = Type::kDefaultLevelDepth) :
4960
Type(os, stackAllocator, levelDepth) { }
@@ -54,4 +65,4 @@ class Writer : public rapidjson::Writer<OutputStream, SourceEncoding, TargetEnco
5465

5566
} } // namespace cass::json
5667

57-
#endif
68+
#endif // __CASS_JSON_HPP_INCLUDED__

src/graph.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ CassError dse_graph_object_add_object_n(DseGraphObject* object,
392392
return CASS_ERROR_LIB_BAD_PARAMS;
393393
}
394394
object->add_key(name, name_length);
395-
object->add_writer(value, rapidjson::kObjectType);
395+
object->add_writer(value, cass::rapidjson::kObjectType);
396396
return CASS_OK;
397397
}
398398

@@ -412,7 +412,7 @@ CassError dse_graph_object_add_array_n(DseGraphObject* object,
412412
return CASS_ERROR_LIB_BAD_PARAMS;
413413
}
414414
object->add_key(name, name_length);
415-
object->add_writer(value, rapidjson::kArrayType);
415+
object->add_writer(value, cass::rapidjson::kArrayType);
416416
return CASS_OK;
417417
}
418418

@@ -556,7 +556,7 @@ CassError dse_graph_array_add_object(DseGraphArray* array,
556556
if (array->is_complete() || !value->is_complete()) {
557557
return CASS_ERROR_LIB_BAD_PARAMS;
558558
}
559-
array->add_writer(value, rapidjson::kObjectType);
559+
array->add_writer(value, cass::rapidjson::kObjectType);
560560
return CASS_OK;
561561
}
562562

@@ -565,7 +565,7 @@ CassError dse_graph_array_add_array(DseGraphArray* array,
565565
if (array->is_complete() || !value->is_complete()) {
566566
return CASS_ERROR_LIB_BAD_PARAMS;
567567
}
568-
array->add_writer(value, rapidjson::kArrayType);
568+
array->add_writer(value, cass::rapidjson::kArrayType);
569569
return CASS_OK;
570570
}
571571

@@ -610,13 +610,13 @@ const DseGraphResult* dse_graph_resultset_next(DseGraphResultSet* resultset) {
610610

611611
DseGraphResultType dse_graph_result_type(const DseGraphResult* result) {
612612
switch (result->GetType()) {
613-
case rapidjson::kNullType: return DSE_GRAPH_RESULT_TYPE_NULL;
614-
case rapidjson::kFalseType: // Intentional fallthrough
615-
case rapidjson::kTrueType: return DSE_GRAPH_RESULT_TYPE_BOOL;
616-
case rapidjson::kNumberType: return DSE_GRAPH_RESULT_TYPE_NUMBER;
617-
case rapidjson::kStringType: return DSE_GRAPH_RESULT_TYPE_STRING;
618-
case rapidjson::kObjectType: return DSE_GRAPH_RESULT_TYPE_OBJECT;
619-
case rapidjson::kArrayType: return DSE_GRAPH_RESULT_TYPE_ARRAY;
613+
case cass::rapidjson::kNullType: return DSE_GRAPH_RESULT_TYPE_NULL;
614+
case cass::rapidjson::kFalseType: // Intentional fallthrough
615+
case cass::rapidjson::kTrueType: return DSE_GRAPH_RESULT_TYPE_BOOL;
616+
case cass::rapidjson::kNumberType: return DSE_GRAPH_RESULT_TYPE_NUMBER;
617+
case cass::rapidjson::kStringType: return DSE_GRAPH_RESULT_TYPE_STRING;
618+
case cass::rapidjson::kObjectType: return DSE_GRAPH_RESULT_TYPE_OBJECT;
619+
case cass::rapidjson::kArrayType: return DSE_GRAPH_RESULT_TYPE_ARRAY;
620620
}
621621

622622
// Path should never be executed

src/graph.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ class GraphWriter : private cass::json::Writer<cass::json::StringBuffer> {
124124
void add_double(cass_double_t value) { Double(value); }
125125

126126
void add_string(const char* string, size_t length) {
127-
String(string, static_cast<rapidjson::SizeType>(length));
127+
String(string, static_cast<cass::rapidjson::SizeType>(length));
128128
}
129129

130130
void add_key(const char* key, size_t length) {
131-
Key(key, static_cast<rapidjson::SizeType>(length));
131+
Key(key, static_cast<cass::rapidjson::SizeType>(length));
132132
}
133133

134134
void add_point(cass_double_t x, cass_double_t y);
@@ -141,7 +141,7 @@ class GraphWriter : private cass::json::Writer<cass::json::StringBuffer> {
141141
String(polygon->to_wkt().c_str());
142142
}
143143

144-
void add_writer(const GraphWriter* writer, rapidjson::Type type) {
144+
void add_writer(const GraphWriter* writer, cass::rapidjson::Type type) {
145145
size_t length = writer->buffer_.GetSize();
146146
Prefix(type);
147147
memcpy(os_->Push(length), writer->buffer_.GetString(), length);

0 commit comments

Comments
 (0)