Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:03

0001 // Tencent is pleased to support the open source community by making RapidJSON available.
0002 // 
0003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
0004 //
0005 // Licensed under the MIT License (the "License"); you may not use this file except
0006 // in compliance with the License. You may obtain a copy of the License at
0007 //
0008 // http://opensource.org/licenses/MIT
0009 //
0010 // Unless required by applicable law or agreed to in writing, software distributed 
0011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
0012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 
0013 // specific language governing permissions and limitations under the License.
0014 
0015 #ifndef RAPIDJSON_OSTREAMWRAPPER_H_
0016 #define RAPIDJSON_OSTREAMWRAPPER_H_
0017 
0018 #include "stream.h"
0019 #include <iosfwd>
0020 
0021 #ifdef __clang__
0022 RAPIDJSON_DIAG_PUSH
0023 RAPIDJSON_DIAG_OFF(padded)
0024 #endif
0025 
0026 RAPIDJSON_NAMESPACE_BEGIN
0027 
0028 //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept.
0029 /*!
0030     The classes can be wrapped including but not limited to:
0031 
0032     - \c std::ostringstream
0033     - \c std::stringstream
0034     - \c std::wpstringstream
0035     - \c std::wstringstream
0036     - \c std::ifstream
0037     - \c std::fstream
0038     - \c std::wofstream
0039     - \c std::wfstream
0040 
0041     \tparam StreamType Class derived from \c std::basic_ostream.
0042 */
0043    
0044 template <typename StreamType>
0045 class BasicOStreamWrapper {
0046 public:
0047     typedef typename StreamType::char_type Ch;
0048     BasicOStreamWrapper(StreamType& stream) : stream_(stream) {}
0049 
0050     void Put(Ch c) {
0051         stream_.put(c);
0052     }
0053 
0054     void Flush() {
0055         stream_.flush();
0056     }
0057 
0058     // Not implemented
0059     char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
0060     char Take() { RAPIDJSON_ASSERT(false); return 0; }
0061     size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
0062     char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
0063     size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
0064 
0065 private:
0066     BasicOStreamWrapper(const BasicOStreamWrapper&);
0067     BasicOStreamWrapper& operator=(const BasicOStreamWrapper&);
0068 
0069     StreamType& stream_;
0070 };
0071 
0072 typedef BasicOStreamWrapper<std::ostream> OStreamWrapper;
0073 typedef BasicOStreamWrapper<std::wostream> WOStreamWrapper;
0074 
0075 #ifdef __clang__
0076 RAPIDJSON_DIAG_POP
0077 #endif
0078 
0079 RAPIDJSON_NAMESPACE_END
0080 
0081 #endif // RAPIDJSON_OSTREAMWRAPPER_H_