From 5d9125f51c97190c71f2da1e51187f7836524cb5 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 6 Nov 2014 19:14:20 +0100 Subject: [PATCH 1/5] add RAPIDJSON_NAMESPACE + _BEGIN, _END --- include/rapidjson/rapidjson.h | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index d4c7f03..10b3286 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -48,6 +48,52 @@ #include // malloc(), realloc(), free(), size_t #include // memset(), memcpy(), memmove(), memcmp() +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NAMESPACE_(BEGIN|END) +/*! \def RAPIDJSON_NAMESPACE + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace + + In order to avoid symbol clashes and/or "One Definition Rule" errors + between multiple inclusions of (different versions of) RapidJSON in + a single binary, users can customize the name of the main RapidJSON + namespace. + + In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE + to a custom name (e.g. \c MyRapidJSON) is sufficient. If multiple + levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref + RAPIDJSON_NAMESPACE_END need to be defined as well: + + \code + // in some .cpp file + #define RAPIDJSON_NAMESPACE my::rapidjson + #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson { + #define RAPIDJSON_NAMESPACE_END } } + #include "rapidjson/..." + \endcode + + \see rapidjson + */ +/*! \def RAPIDJSON_NAMESPACE_BEGIN + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace (opening expression) + \see RAPIDJSON_NAMESPACE +*/ +/*! \def RAPIDJSON_NAMESPACE_END + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace (closing expression) + \see RAPIDJSON_NAMESPACE +*/ +#ifndef RAPIDJSON_NAMESPACE +#define RAPIDJSON_NAMESPACE rapidjson +#endif +#ifndef RAPIDJSON_NAMESPACE_BEGIN +#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE { +#endif +#ifndef RAPIDJSON_NAMESPACE_END +#define RAPIDJSON_NAMESPACE_END } +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_NO_INT64DEFINE From 55757ff4209bb4d3e204ce41544f716d66045a13 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 6 Nov 2014 19:14:36 +0100 Subject: [PATCH 2/5] Doxyfile: expand RapidJSON namespace macros --- build/Doxyfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/Doxyfile b/build/Doxyfile index e34a3ff..d2a03be 100644 --- a/build/Doxyfile +++ b/build/Doxyfile @@ -1993,6 +1993,8 @@ INCLUDE_FILE_PATTERNS = PREDEFINED = \ RAPIDJSON_DOXYGEN_RUNNING \ + RAPIDJSON_NAMESPACE_BEGIN="namespace rapidjson {" \ + RAPIDJSON_NAMESPACE_END="}" \ RAPIDJSON_REMOVEFPTR_(x)=x \ RAPIDJSON_ENABLEIF_RETURN(cond,returntype)="RAPIDJSON_REMOVEFPTR_ returntype" \ RAPIDJSON_DISABLEIF_RETURN(cond,returntype)="RAPIDJSON_REMOVEFPTR_ returntype" From 549dcb755d64a0f7990b5935796c1b2ef74a46e4 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 6 Nov 2014 19:24:20 +0100 Subject: [PATCH 3/5] *.h: move to namespace macros --- include/rapidjson/allocators.h | 4 ++-- include/rapidjson/document.h | 4 ++-- include/rapidjson/encodedstream.h | 4 ++-- include/rapidjson/encodings.h | 4 ++-- include/rapidjson/error/en.h | 4 ++-- include/rapidjson/error/error.h | 4 ++-- include/rapidjson/filereadstream.h | 4 ++-- include/rapidjson/filestream.h | 4 ++-- include/rapidjson/filewritestream.h | 4 ++-- include/rapidjson/internal/dtoa.h | 4 ++-- include/rapidjson/internal/itoa.h | 4 ++-- include/rapidjson/internal/meta.h | 16 ++++++++-------- include/rapidjson/internal/pow10.h | 4 ++-- include/rapidjson/internal/stack.h | 4 ++-- include/rapidjson/internal/strfunc.h | 4 ++-- include/rapidjson/memorybuffer.h | 4 ++-- include/rapidjson/memorystream.h | 4 ++-- include/rapidjson/prettywriter.h | 4 ++-- include/rapidjson/rapidjson.h | 27 +++++++++++++++------------ include/rapidjson/reader.h | 4 ++-- include/rapidjson/stringbuffer.h | 4 ++-- include/rapidjson/writer.h | 4 ++-- 22 files changed, 63 insertions(+), 60 deletions(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 0d7b664..c0a26ee 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -23,7 +23,7 @@ #include "rapidjson.h" -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // Allocator @@ -240,6 +240,6 @@ private: BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object. }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ENCODINGS_H_ diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 2b9fe63..bdea8e7 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -66,7 +66,7 @@ RAPIDJSON_DIAG_OFF(effc++) #include // std::move #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN // Forward declaration. template @@ -1899,7 +1899,7 @@ GenericValue::GenericValue(const GenericValue(1)); } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #if defined(_MSC_VER) || defined(__GNUC__) RAPIDJSON_DIAG_POP diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index 9dc00c7..c310d2e 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -28,7 +28,7 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Input byte stream wrapper with a statically bound encoding. /*! @@ -281,7 +281,7 @@ private: #undef RAPIDJSON_ENCODINGS_FUNC -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #ifdef __GNUC__ RAPIDJSON_DIAG_POP diff --git a/include/rapidjson/encodings.h b/include/rapidjson/encodings.h index 5c7da3e..6bc8aec 100644 --- a/include/rapidjson/encodings.h +++ b/include/rapidjson/encodings.h @@ -32,7 +32,7 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // Encoding @@ -621,7 +621,7 @@ struct Transcoder { } }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #if defined(__GNUC__) || defined(_MSV_VER) RAPIDJSON_DIAG_POP diff --git a/include/rapidjson/error/en.h b/include/rapidjson/error/en.h index d153e04..0171183 100644 --- a/include/rapidjson/error/en.h +++ b/include/rapidjson/error/en.h @@ -23,7 +23,7 @@ #include "error.h" -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Maps error code of parsing into error message. /*! @@ -66,6 +66,6 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro } } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ERROR_EN_H__ diff --git a/include/rapidjson/error/error.h b/include/rapidjson/error/error.h index 1466044..161ef87 100644 --- a/include/rapidjson/error/error.h +++ b/include/rapidjson/error/error.h @@ -51,7 +51,7 @@ #define RAPIDJSON_ERROR_STRING(x) x #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // ParseErrorCode @@ -145,6 +145,6 @@ private: */ typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ERROR_ERROR_H__ diff --git a/include/rapidjson/filereadstream.h b/include/rapidjson/filereadstream.h index 31c193b..ea46dac 100644 --- a/include/rapidjson/filereadstream.h +++ b/include/rapidjson/filereadstream.h @@ -24,7 +24,7 @@ #include "rapidjson.h" #include -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! File byte stream for input using fread(). /*! @@ -89,6 +89,6 @@ private: bool eof_; }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_FILESTREAM_H_ diff --git a/include/rapidjson/filestream.h b/include/rapidjson/filestream.h index 5fe0036..a4f559c 100644 --- a/include/rapidjson/filestream.h +++ b/include/rapidjson/filestream.h @@ -24,7 +24,7 @@ #include "rapidjson.h" #include -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! (Deprecated) Wrapper of C file stream for input or output. /*! @@ -68,6 +68,6 @@ private: size_t count_; }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_FILESTREAM_H_ diff --git a/include/rapidjson/filewritestream.h b/include/rapidjson/filewritestream.h index 05c5ca0..cecd700 100644 --- a/include/rapidjson/filewritestream.h +++ b/include/rapidjson/filewritestream.h @@ -24,7 +24,7 @@ #include "rapidjson.h" #include -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Wrapper of C file stream for input using fread(). /*! @@ -92,6 +92,6 @@ inline void PutN(FileWriteStream& stream, char c, size_t n) { stream.PutN(c, n); } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_FILESTREAM_H_ diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index 6ae588a..9645e9b 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -34,7 +34,7 @@ #include "itoa.h" // GetDigitsLut() -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { #ifdef __GNUC__ @@ -413,6 +413,6 @@ RAPIDJSON_DIAG_POP #endif } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_DTOA_ diff --git a/include/rapidjson/internal/itoa.h b/include/rapidjson/internal/itoa.h index 425e983..3684f07 100644 --- a/include/rapidjson/internal/itoa.h +++ b/include/rapidjson/internal/itoa.h @@ -21,7 +21,7 @@ #ifndef RAPIDJSON_ITOA_ #define RAPIDJSON_ITOA_ -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { inline const char* GetDigitsLut() { @@ -301,6 +301,6 @@ inline char* i64toa(int64_t value, char* buffer) { } } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ITOA_ diff --git a/include/rapidjson/internal/meta.h b/include/rapidjson/internal/meta.h index dbe5450..226465a 100644 --- a/include/rapidjson/internal/meta.h +++ b/include/rapidjson/internal/meta.h @@ -39,7 +39,7 @@ RAPIDJSON_DIAG_OFF(6334) #endif //@cond RAPIDJSON_INTERNAL -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching @@ -157,29 +157,29 @@ template struct RemoveSfinaeTag; template struct RemoveSfinaeTag { typedef T Type; }; #define RAPIDJSON_REMOVEFPTR_(type) \ - typename ::rapidjson::internal::RemoveSfinaeTag \ - < ::rapidjson::internal::SfinaeTag&(*) type>::Type + typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ + < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type #define RAPIDJSON_ENABLEIF(cond) \ - typename ::rapidjson::internal::EnableIf \ + typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ ::Type * = NULL #define RAPIDJSON_DISABLEIF(cond) \ - typename ::rapidjson::internal::DisableIf \ + typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ ::Type * = NULL #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ - typename ::rapidjson::internal::EnableIf \ + typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ ::Type #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ - typename ::rapidjson::internal::DisableIf \ + typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ ::Type } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END //@endcond #if defined(__GNUC__) || defined(_MSC_VER) diff --git a/include/rapidjson/internal/pow10.h b/include/rapidjson/internal/pow10.h index 72e0dac..0252edf 100644 --- a/include/rapidjson/internal/pow10.h +++ b/include/rapidjson/internal/pow10.h @@ -21,7 +21,7 @@ #ifndef RAPIDJSON_POW10_ #define RAPIDJSON_POW10_ -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { //! Computes integer powers of 10 in double (10.0^n). @@ -54,6 +54,6 @@ inline double Pow10(int n) { } } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_POW10_ diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index b7d7449..93c5f45 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -21,7 +21,7 @@ #ifndef RAPIDJSON_INTERNAL_STACK_H_ #define RAPIDJSON_INTERNAL_STACK_H_ -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { /////////////////////////////////////////////////////////////////////////////// @@ -178,6 +178,6 @@ private: }; } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_STACK_H_ diff --git a/include/rapidjson/internal/strfunc.h b/include/rapidjson/internal/strfunc.h index 80adcb6..c271dac 100644 --- a/include/rapidjson/internal/strfunc.h +++ b/include/rapidjson/internal/strfunc.h @@ -21,7 +21,7 @@ #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ #define RAPIDJSON_INTERNAL_STRFUNC_H_ -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN namespace internal { //! Custom strlen() which works on different character types. @@ -38,6 +38,6 @@ inline SizeType StrLen(const Ch* s) { } } // namespace internal -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ diff --git a/include/rapidjson/memorybuffer.h b/include/rapidjson/memorybuffer.h index ef15c46..95c68a3 100644 --- a/include/rapidjson/memorybuffer.h +++ b/include/rapidjson/memorybuffer.h @@ -24,7 +24,7 @@ #include "rapidjson.h" #include "internal/stack.h" -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Represents an in-memory output byte stream. /*! @@ -71,6 +71,6 @@ inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_MEMORYBUFFER_H_ diff --git a/include/rapidjson/memorystream.h b/include/rapidjson/memorystream.h index 6ed226e..f994a12 100644 --- a/include/rapidjson/memorystream.h +++ b/include/rapidjson/memorystream.h @@ -23,7 +23,7 @@ #include "rapidjson.h" -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Represents an in-memory input byte stream. /*! @@ -62,6 +62,6 @@ struct MemoryStream { size_t size_; //!< Size of the stream. }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_MEMORYBUFFER_H_ diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 4eac8d7..ca62bb7 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -28,7 +28,7 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Writer with indentation and spacing. /*! @@ -196,7 +196,7 @@ private: PrettyWriter& operator=(const PrettyWriter&); }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #ifdef __GNUC__ RAPIDJSON_DIAG_POP diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 10b3286..b13e0b0 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -284,20 +284,20 @@ #ifdef RAPIDJSON_DOXYGEN_RUNNING #define RAPIDJSON_NO_SIZETYPEDEFINE #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Size type (for string lengths, array sizes, etc.) /*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms, instead of using \c size_t. Users may override the SizeType by defining \ref RAPIDJSON_NO_SIZETYPEDEFINE. */ typedef unsigned SizeType; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // always import std::size_t to rapidjson namespace -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN using std::size_t; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_ASSERT @@ -321,12 +321,11 @@ using std::size_t; // Adopt from boost #ifndef RAPIDJSON_STATIC_ASSERT //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -namespace rapidjson { - +RAPIDJSON_NAMESPACE_BEGIN template struct STATIC_ASSERTION_FAILURE; template <> struct STATIC_ASSERTION_FAILURE { enum { value = 1 }; }; template struct StaticAssertTest {}; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y) #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y) @@ -344,8 +343,9 @@ template struct StaticAssertTest {}; \param x compile-time condition \hideinitializer */ -#define RAPIDJSON_STATIC_ASSERT(x) typedef ::rapidjson::StaticAssertTest<\ - sizeof(::rapidjson::STATIC_ASSERTION_FAILURE)>\ +#define RAPIDJSON_STATIC_ASSERT(x) \ + typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \ + sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE)> \ RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE #endif @@ -464,8 +464,11 @@ template struct StaticAssertTest {}; #include "allocators.h" #include "encodings.h" -//! main RapidJSON namespace -namespace rapidjson { +/*! \namespace rapidjson + \brief main RapidJSON namespace + \see RAPIDJSON_NAMESPACE +*/ +RAPIDJSON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // Stream @@ -620,6 +623,6 @@ enum Type { kNumberType = 6 //!< number }; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_RAPIDJSON_H_ diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index f41ba2f..0f1bb7e 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -116,7 +116,7 @@ RAPIDJSON_DIAG_OFF(4702) // unreachable code #include "error/error.h" // ParseErrorCode, ParseResult -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // ParseFlag @@ -1360,7 +1360,7 @@ private: //! Reader with UTF8 encoding and default allocator. typedef GenericReader, UTF8<> > Reader; -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #ifdef _MSC_VER RAPIDJSON_DIAG_POP diff --git a/include/rapidjson/stringbuffer.h b/include/rapidjson/stringbuffer.h index 55124f1..b862572 100644 --- a/include/rapidjson/stringbuffer.h +++ b/include/rapidjson/stringbuffer.h @@ -24,7 +24,7 @@ #include "rapidjson.h" #include "internal/stack.h" -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! Represents an in-memory output stream. /*! @@ -74,6 +74,6 @@ inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { std::memset(stream.stack_.Push(n), c, n * sizeof(c)); } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_STRINGBUFFER_H_ diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index fb6601e..fdade6e 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -34,7 +34,7 @@ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant #endif -namespace rapidjson { +RAPIDJSON_NAMESPACE_BEGIN //! JSON writer /*! Writer implements the concept Handler. @@ -380,7 +380,7 @@ inline bool Writer::WriteDouble(double d) { return true; } -} // namespace rapidjson +RAPIDJSON_NAMESPACE_END #ifdef _MSC_VER RAPIDJSON_DIAG_POP From 7dc9b18f549a58f10b7f85ab4c3da57eb8429fa1 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 6 Nov 2014 20:54:46 +0100 Subject: [PATCH 4/5] namespacetest.cpp: add test for separate namespace --- test/unittest/namespacetest.cpp | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/unittest/namespacetest.cpp diff --git a/test/unittest/namespacetest.cpp b/test/unittest/namespacetest.cpp new file mode 100644 index 0000000..ed74ae3 --- /dev/null +++ b/test/unittest/namespacetest.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2011 Milo Yip +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "unittest.h" + +// test another instantiation of RapidJSON in a different namespace + +#define RAPIDJSON_NAMESPACE my::rapid::json +#define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapid { namespace json { +#define RAPIDJSON_NAMESPACE_END } } } + +// include lots of RapidJSON files + +#include "rapidjson/document.h" +#include "rapidjson/writer.h" +#include "rapidjson/filereadstream.h" +#include "rapidjson/filewritestream.h" +#include "rapidjson/encodedstream.h" +#include "rapidjson/stringbuffer.h" + +static const char json[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}"; + +TEST(NamespaceTest,Using) { + using namespace RAPIDJSON_NAMESPACE; + typedef GenericDocument, CrtAllocator> DocumentType; + DocumentType doc; + + doc.Parse(json); + EXPECT_TRUE(!doc.HasParseError()); +} + +TEST(NamespaceTest,Direct) { + typedef RAPIDJSON_NAMESPACE::Document Document; + typedef RAPIDJSON_NAMESPACE::Reader Reader; + typedef RAPIDJSON_NAMESPACE::StringStream StringStream; + typedef RAPIDJSON_NAMESPACE::StringBuffer StringBuffer; + typedef RAPIDJSON_NAMESPACE::Writer WriterType; + + StringStream s(json); + StringBuffer buffer; + WriterType writer(buffer); + buffer.ShrinkToFit(); + Reader reader; + reader.Parse(s, writer); + + EXPECT_STREQ(json, buffer.GetString()); + EXPECT_EQ(sizeof(json)-1, buffer.GetSize()); + EXPECT_TRUE(writer.IsComplete()); + + Document doc; + doc.Parse(buffer.GetString()); + EXPECT_TRUE(!doc.HasParseError()); + + buffer.Clear(); + writer.Reset(buffer); + doc.Accept(writer); + EXPECT_STREQ(json, buffer.GetString()); + EXPECT_TRUE(writer.IsComplete()); +} From a0f9de61a93006b626ace773ec5a80fc0a478ebf Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 6 Nov 2014 21:11:58 +0100 Subject: [PATCH 5/5] namespacetest: add symbol check to .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 145dc73..986ca0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ before_script: script: - make -C build/gmake -f test.make config=${CONF}${BITS} - make -C build/gmake -f example.make config=${CONF}${BITS} + - if [ "$CONF" = "debug" ] && ( objdump -t -C intermediate/${CONF}/gmake/unittest/x${BITS}/namespacetest.o | grep rapidjson ) ; then echo "Symbol check failed!" ; false; fi - pushd bin - ./unittest_${CONF}_x${BITS}_gmake - valgrind --leak-check=full --error-exitcode=1 ./unittest_${CONF}_x${BITS}_gmake