aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/detail/NullBuff.hpp
blob: e5c6f4af256a65e9959adbdde2ee7b86e49737ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <ostream>

namespace ovdl::detail {
   template<class cT, class traits = std::char_traits<cT>>
   class basic_nullbuf : public std::basic_streambuf<cT, traits> {
      typename traits::int_type overflow(typename traits::int_type c) {
         return traits::not_eof(c); // indicate success
      }
   };

   template<class cT, class traits = std::char_traits<cT>>
   class basic_onullstream : public std::basic_ostream<cT, traits> {
   public:
      basic_onullstream() : std::basic_ios<cT, traits>(&m_sbuf),
                       std::basic_ostream<cT, traits>(&m_sbuf) {
         std::basic_ios<cT, traits>::init(&m_sbuf);
      }

   private:
      basic_nullbuf<cT, traits> m_sbuf;
   };

   using onullstream = basic_onullstream<char>;
   using wonullstream = basic_onullstream<wchar_t>;

   static inline onullstream cnull;
   static inline onullstream wcnull;
}