aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/detail/NullBuff.hpp
blob: baf9e1b5841d1091416a11cd21377923aaf0cc6f (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;
   };

   typedef basic_onullstream<char> onullstream;
   typedef basic_onullstream<wchar_t> wonullstream;

   inline onullstream cnull;
   inline onullstream wcnull;
}