Skip to content

Jsoncpp aliases 2 #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/json/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#define JSON_FAIL_MESSAGE(message) \
{ \
JSONCPP_OSTRINGSTREAM oss; \
OStringStream oss; \
oss << message; \
Json::throwLogicError(oss.str()); \
abort(); \
Expand All @@ -43,7 +43,7 @@
// release builds we abort, for a core-dump or debugger.
#define JSON_FAIL_MESSAGE(message) \
{ \
JSONCPP_OSTRINGSTREAM oss; \
OStringStream oss; \
oss << message; \
assert(false && oss.str().c_str()); \
abort(); \
Expand Down
56 changes: 31 additions & 25 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
#ifndef JSON_CONFIG_H_INCLUDED
#define JSON_CONFIG_H_INCLUDED
#include <cstddef>
#include <cstdint> //typedef int64_t, uint64_t
#include <string> //typedef String
#include <cstdint>
#include <istream>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>

/// If defined, indicates that json library is embedded in CppTL library.
//# define JSON_IN_CPPTL 1
Expand Down Expand Up @@ -142,12 +147,9 @@ msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);

#if !defined(JSON_IS_AMALGAMATION)

#include "allocator.h"
#include "version.h"

#if JSONCPP_USING_SECURE_MEMORY
#include "allocator.h" //typedef Allocator
#endif

#endif // if !defined(JSON_IS_AMALGAMATION)

namespace Json {
Expand All @@ -170,24 +172,28 @@ typedef Int64 LargestInt;
typedef UInt64 LargestUInt;
#define JSON_HAS_INT64
#endif // if defined(JSON_NO_INT64)
#if JSONCPP_USING_SECURE_MEMORY
#define JSONCPP_STRING \
std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
#define JSONCPP_OSTRINGSTREAM \
std::basic_ostringstream<char, std::char_traits<char>, \
Json::SecureAllocator<char> >
#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char> >
#define JSONCPP_ISTRINGSTREAM \
std::basic_istringstream<char, std::char_traits<char>, \
Json::SecureAllocator<char> >
#define JSONCPP_ISTREAM std::istream
#else
#define JSONCPP_STRING std::string
#define JSONCPP_OSTRINGSTREAM std::ostringstream
#define JSONCPP_OSTREAM std::ostream
#define JSONCPP_ISTRINGSTREAM std::istringstream
#define JSONCPP_ISTREAM std::istream
#endif // if JSONCPP_USING_SECURE_MEMORY
} // end namespace Json

template <typename T>
using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
SecureAllocator<T>,
std::allocator<T> >::type;
using String =
std::basic_string<char, std::char_traits<char>, Allocator<char> >;
using IStringStream = std::basic_istringstream<String::value_type,
String::traits_type,
String::allocator_type>;
using OStringStream = std::basic_ostringstream<String::value_type,
String::traits_type,
String::allocator_type>;
using IStream = std::istream;
using OStream = std::ostream;
} // namespace Json

// Legacy names (formerly macros).
using JSONCPP_STRING = Json::String;
using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
using JSONCPP_ISTREAM = Json::IStream;
using JSONCPP_OSTREAM = Json::OStream;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, I intend to squash it all down to one commit.
It's separate commits just so that it's reviewable steps.
7b1e53c is huge, but it's just a big rename.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Feel free to merge right after squashing.


#endif // JSON_CONFIG_H_INCLUDED
42 changes: 19 additions & 23 deletions include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JSON_API Reader {
struct StructuredError {
ptrdiff_t offset_start;
ptrdiff_t offset_limit;
JSONCPP_STRING message;
String message;
};

/** \brief Constructs a Reader allowing all features
Expand Down Expand Up @@ -103,7 +103,7 @@ class JSON_API Reader {

/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);
bool parse(IStream& is, Value& root, bool collectComments = true);

/** \brief Returns a user friendly string that list errors in the parsed
* document.
Expand All @@ -115,7 +115,7 @@ class JSON_API Reader {
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
*/
JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
JSONCPP_STRING getFormatedErrorMessages() const;
String getFormatedErrorMessages() const;

/** \brief Returns a user friendly string that list errors in the parsed
* document.
Expand All @@ -125,7 +125,7 @@ class JSON_API Reader {
* occurred
* during parsing.
*/
JSONCPP_STRING getFormattedErrorMessages() const;
String getFormattedErrorMessages() const;

/** \brief Returns a vector of structured erros encounted while parsing.
* \return A (possibly empty) vector of StructuredError objects. Currently
Expand All @@ -142,7 +142,7 @@ class JSON_API Reader {
* \return \c true if the error was successfully added, \c false if the
* Value offset exceeds the document size.
*/
bool pushError(const Value& value, const JSONCPP_STRING& message);
bool pushError(const Value& value, const String& message);

/** \brief Add a semantic error message with extra context.
* \param value JSON Value location associated with the error
Expand All @@ -151,9 +151,7 @@ class JSON_API Reader {
* \return \c true if the error was successfully added, \c false if either
* Value offset exceeds the document size.
*/
bool pushError(const Value& value,
const JSONCPP_STRING& message,
const Value& extra);
bool pushError(const Value& value, const String& message, const Value& extra);

/** \brief Return whether there are any errors.
* \return \c true if there are no errors to report \c false if
Expand Down Expand Up @@ -189,7 +187,7 @@ class JSON_API Reader {
class ErrorInfo {
public:
Token token_;
JSONCPP_STRING message_;
String message_;
Location extra_;
};

Expand All @@ -209,7 +207,7 @@ class JSON_API Reader {
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeString(Token& token);
bool decodeString(Token& token, JSONCPP_STRING& decoded);
bool decodeString(Token& token, String& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeUnicodeCodePoint(Token& token,
Expand All @@ -220,35 +218,33 @@ class JSON_API Reader {
Location& current,
Location end,
unsigned int& unicode);
bool addError(const JSONCPP_STRING& message,
Token& token,
Location extra = nullptr);
bool addError(const String& message, Token& token, Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const JSONCPP_STRING& message,
bool addErrorAndRecover(const String& message,
Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
Value& currentValue();
Char getNextChar();
void
getLocationLineAndColumn(Location location, int& line, int& column) const;
JSONCPP_STRING getLocationLineAndColumn(Location location) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);

static bool containsNewLine(Location begin, Location end);
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
static String normalizeEOL(Location begin, Location end);

typedef std::stack<Value*> Nodes;
Nodes nodes_;
Errors errors_;
JSONCPP_STRING document_;
String document_;
Location begin_{};
Location end_{};
Location current_{};
Location lastValueEnd_{};
Value* lastValue_{};
JSONCPP_STRING commentsBefore_;
String commentsBefore_;
Features features_;
bool collectComments_{};
}; // Reader
Expand Down Expand Up @@ -279,7 +275,7 @@ class JSON_API CharReader {
virtual bool parse(char const* beginDoc,
char const* endDoc,
Value* root,
JSONCPP_STRING* errs) = 0;
String* errs) = 0;

class JSON_API Factory {
public:
Expand All @@ -299,7 +295,7 @@ class JSON_API CharReader {
CharReaderBuilder builder;
builder["collectComments"] = false;
Value value;
JSONCPP_STRING errs;
String errs;
bool ok = parseFromStream(builder, std::cin, &value, &errs);
\endcode
*/
Expand Down Expand Up @@ -359,7 +355,7 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {

/** A simple way to update a specific setting.
*/
Value& operator[](const JSONCPP_STRING& key);
Value& operator[](const String& key);

/** Called by ctor, but you can use this to reset settings_.
* \pre 'settings' != NULL (but Json::null is fine)
Expand All @@ -380,7 +376,7 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
* is convenient.
*/
bool JSON_API parseFromStream(CharReader::Factory const&,
JSONCPP_ISTREAM&,
IStream&,
Value* root,
std::string* errs);

Expand Down Expand Up @@ -408,7 +404,7 @@ bool JSON_API parseFromStream(CharReader::Factory const&,
\throw std::exception on parse error.
\see Json::operator<<()
*/
JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
JSON_API IStream& operator>>(IStream&, Value&);

} // namespace Json

Expand Down
Loading