WPILibC++  unspecified
json_serializer.h
1 /*----------------------------------------------------------------------------*/
2 /* Modifications Copyright (c) FIRST 2017. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 /*
8  __ _____ _____ _____
9  __| | __| | | | JSON for Modern C++
10 | | |__ | | | | | | version 2.1.1
11 |_____|_____|_____|_|___| https://github.com/nlohmann/json
12 
13 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 Copyright (c) 2013-2017 Niels Lohmann <http://nlohmann.me>.
15 
16 Permission is hereby granted, free of charge, to any person obtaining a copy
17 of this software and associated documentation files (the "Software"), to deal
18 in the Software without restriction, including without limitation the rights
19 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 copies of the Software, and to permit persons to whom the Software is
21 furnished to do so, subject to the following conditions:
22 
23 The above copyright notice and this permission notice shall be included in all
24 copies or substantial portions of the Software.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 SOFTWARE.
33 */
34 #include "support/json.h"
35 
36 #include <clocale> // lconv, localeconv
37 #include <locale> // locale
38 
39 #include "llvm/raw_ostream.h"
40 
41 namespace wpi {
42 
47 {
48  public:
49  serializer(const serializer&) = delete;
50  serializer& operator=(const serializer&) = delete;
51 
57  : o(s), loc(std::localeconv()),
58  thousands_sep(!loc->thousands_sep ? '\0' : loc->thousands_sep[0]),
59  decimal_point(!loc->decimal_point ? '\0' : loc->decimal_point[0])
60  {}
61 
79  void dump(const json& val,
80  const bool pretty_print,
81  const unsigned int indent_step,
82  const unsigned int current_indent = 0);
83 
96  void dump_escaped(llvm::StringRef s) const;
97 
106  void dump_float(double x);
107 
108  private:
111 
113  const std::lconv* loc = nullptr;
115  const char thousands_sep = '\0';
117  const char decimal_point = '\0';
118 };
119 
120 } // namespace wpi
void dump(const json &val, const bool pretty_print, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition: json_serializer.cpp:44
Definition: json.cpp:1170
void dump_float(double x)
dump a floating-point number
Definition: json_serializer.cpp:325
serializer(llvm::raw_ostream &s)
Definition: json_serializer.h:56
Definition: SocketError.cpp:18
void dump_escaped(llvm::StringRef s) const
dump escaped string
Definition: json_serializer.cpp:224
wrapper around the serialization functions
Definition: json_serializer.h:46
a class to store JSON values
Definition: json.h:1201
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42