DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ostreamwrapper.h Source File

ostreamwrapper.h

00001 // Tencent is pleased to support the open source community by making RapidJSON available.
00002 // 
00003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
00004 //
00005 // Licensed under the MIT License (the "License"); you may not use this file except
00006 // in compliance with the License. You may obtain a copy of the License at
00007 //
00008 // http://opensource.org/licenses/MIT
00009 //
00010 // Unless required by applicable law or agreed to in writing, software distributed 
00011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
00012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 
00013 // specific language governing permissions and limitations under the License.
00014 
00015 #ifndef RAPIDJSON_OSTREAMWRAPPER_H_
00016 #define RAPIDJSON_OSTREAMWRAPPER_H_
00017 
00018 #include "stream.h"
00019 #include <iosfwd>
00020 
00021 #ifdef __clang__
00022 RAPIDJSON_DIAG_PUSH
00023 RAPIDJSON_DIAG_OFF(padded)
00024 #endif
00025 
00026 RAPIDJSON_NAMESPACE_BEGIN
00027 
00028 //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept.
00029 /*!
00030     The classes can be wrapped including but not limited to:
00031 
00032     - \c std::ostringstream
00033     - \c std::stringstream
00034     - \c std::wpstringstream
00035     - \c std::wstringstream
00036     - \c std::ifstream
00037     - \c std::fstream
00038     - \c std::wofstream
00039     - \c std::wfstream
00040 
00041     \tparam StreamType Class derived from \c std::basic_ostream.
00042 */
00043    
00044 template <typename StreamType>
00045 class BasicOStreamWrapper {
00046 public:
00047     typedef typename StreamType::char_type Ch;
00048     BasicOStreamWrapper(StreamType& stream) : stream_(stream) {}
00049 
00050     void Put(Ch c) {
00051         stream_.put(c);
00052     }
00053 
00054     void Flush() {
00055         stream_.flush();
00056     }
00057 
00058     // Not implemented
00059     char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
00060     char Take() { RAPIDJSON_ASSERT(false); return 0; }
00061     size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
00062     char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
00063     size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
00064 
00065 private:
00066     BasicOStreamWrapper(const BasicOStreamWrapper&);
00067     BasicOStreamWrapper& operator=(const BasicOStreamWrapper&);
00068 
00069     StreamType& stream_;
00070 };
00071 
00072 typedef BasicOStreamWrapper<std::ostream> OStreamWrapper;
00073 typedef BasicOStreamWrapper<std::wostream> WOStreamWrapper;
00074 
00075 #ifdef __clang__
00076 RAPIDJSON_DIAG_POP
00077 #endif
00078 
00079 RAPIDJSON_NAMESPACE_END
00080 
00081 #endif // RAPIDJSON_OSTREAMWRAPPER_H_