| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
1 |
// Tencent is pleased to support the open source community by making RapidJSON available. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
2 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
3 |
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
4 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
5 |
// Licensed under the MIT License (the "License"); you may not use this file except |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
6 |
// in compliance with the License. You may obtain a copy of the License at |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
7 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
8 |
// http://opensource.org/licenses/MIT |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
9 |
// |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
10 |
// Unless required by applicable law or agreed to in writing, software distributed |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
11 |
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
12 |
// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
13 |
// specific language governing permissions and limitations under the License. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
14 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
15 |
#ifndef CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
16 |
#define CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
17 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
18 |
#include "stream.h" |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
19 |
#include <iosfwd> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
20 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
21 |
#ifdef __clang__ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
22 |
CEREAL_RAPIDJSON_DIAG_PUSH |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
23 |
CEREAL_RAPIDJSON_DIAG_OFF(padded) |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
24 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
25 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
26 |
CEREAL_RAPIDJSON_NAMESPACE_BEGIN |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
27 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
28 |
//! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
29 |
/*! |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
30 |
The classes can be wrapped including but not limited to: |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
31 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
32 |
- \c std::ostringstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
33 |
- \c std::stringstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
34 |
- \c std::wpstringstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
35 |
- \c std::wstringstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
36 |
- \c std::ifstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
37 |
- \c std::fstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
38 |
- \c std::wofstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
39 |
- \c std::wfstream |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
40 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
41 |
\tparam StreamType Class derived from \c std::basic_ostream. |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
42 |
*/ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
43 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
44 |
template <typename StreamType> |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
45 |
class BasicOStreamWrapper { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
46 |
public: |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
47 |
typedef typename StreamType::char_type Ch; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
48 |
BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
49 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
50 |
void Put(Ch c) { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
51 |
stream_.put(c); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
52 |
} |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
53 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
54 |
void Flush() { |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
55 |
stream_.flush(); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
56 |
} |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
57 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
58 |
// Not implemented |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
59 |
char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
60 |
char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
61 |
size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
62 |
char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
63 |
size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
64 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
65 |
private: |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
66 |
BasicOStreamWrapper(const BasicOStreamWrapper&); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
67 |
BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
68 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
69 |
StreamType& stream_; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
70 |
}; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
71 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
72 |
typedef BasicOStreamWrapper<std::ostream> OStreamWrapper; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
73 |
typedef BasicOStreamWrapper<std::wostream> WOStreamWrapper; |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
74 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
75 |
#ifdef __clang__ |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
76 |
CEREAL_RAPIDJSON_DIAG_POP |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
77 |
#endif |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
78 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
79 |
CEREAL_RAPIDJSON_NAMESPACE_END |
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
80 |
|
| 6c5f2c01 |
sago007 |
2017-03-15 17:56 |
81 |
#endif // CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ |
|
|
1970-01-01 00:00 |
82 |
|