arsenalgear-cpp
A library containing general purpose C++ utils.
stream.hpp
Go to the documentation of this file.
1 //====================================================
2 // File data
3 //====================================================
11 //====================================================
12 // Preprocessor settings
13 //====================================================
14 #pragma once
15 #ifndef ARSENALGEAR_STREAM_HPP
16 #define ARSENALGEAR_STREAM_HPP
17 
18 //====================================================
19 // Headers
20 //====================================================
21 
22 // STD headers
23 #include <iostream>
24 #include <string>
25 
26 namespace agr
27  {
28  //====================================================
29  // Classes
30  //====================================================
31 
32  // savebuf
37  class savebuf: public std::streambuf
38  {
39  public:
40 
41  //====================================================
42  // Public methods declaration
43  //====================================================
44  savebuf( std::streambuf* sbuf );
45  std::string str() const;
46 
47  private:
48 
49  //====================================================
50  // Private methods declaration
51  //====================================================
52  int overflow( int c );
53  int sync();
54 
55  //====================================================
56  // Private attributes
57  //====================================================
58  std::streambuf* sbuf;
59  std::string save;
60  };
61 
62  //====================================================
63  // Structs
64  //====================================================
65 
66  // select_cout
72  template <class T>
73  struct select_cout
74  {
75  static std::basic_ostream<T> &cout;
76  };
77 
78  // select_cout specializations
79  template <> inline std::ostream &select_cout <char>::cout = std::cout;
80  template <> inline std::wostream &select_cout <wchar_t>::cout = std::wcout;
81 
82  // select_cin
88  template <class T>
89  struct select_cin
90  {
91  static std::basic_istream<T> &cin;
92  };
93 
94  // select_cin specializations
95  template <> inline std::istream &select_cin <char>::cin = std::cin;
96  template <> inline std::wistream &select_cin <wchar_t>::cin = std::wcin;
97  }
98 
99 #endif
Class used to store the output sent to an output stream.
Definition: stream.hpp:38
savebuf(std::streambuf *sbuf)
Construct a new savebuf object.
Definition: stream.cpp:33
std::string str() const
Method to return the string stored by the output stream.
Definition: stream.cpp:43
Definition: stream.cpp:22
Struct used to define a way to template the choice of the "std::cin" object in order to be "std::cin"...
Definition: stream.hpp:90
static std::basic_istream< T > & cin
Definition: stream.hpp:91
Struct used to define a way to template the choice of the "std::cout" object in order to be "std::cou...
Definition: stream.hpp:74
static std::basic_ostream< T > & cout
Definition: stream.hpp:75