Kompex SQLite Wrapper  1.11.14
KompexSQLiteStreamRedirection.h
Go to the documentation of this file.
1 /*
2  This file is part of Kompex SQLite Wrapper.
3  Copyright (c) 2008-2015 Sven Broeske
4 
5  Kompex SQLite Wrapper is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Kompex SQLite Wrapper is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Kompex SQLite Wrapper. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef KompexSQLiteCerrRedirection_H
20 #define KompexSQLiteCerrRedirection_H
21 
22 #include <fstream>
23 #include <iostream>
25 
26 namespace Kompex
27 {
30  {
31  public:
34  {
35  pOutputFile = new std::ofstream();
36  }
38  virtual ~Redirection()
39  {
40  delete pOutputFile;
41  }
42 
43  protected:
45  std::ofstream *pOutputFile;
47  std::streambuf *mBuffer;
48 
49  private:
51  Redirection(const Redirection& r);
53  Redirection& operator=(const Redirection& r) {return *this;}
54  };
55 
58  {
59  public:
61  CerrRedirection(const std::string &filename)
62  {
63  pOutputFile->open(filename.c_str(), std::ios_base::out);
64  std::streambuf *errbuf = pOutputFile->rdbuf();
65  mBuffer = std::cerr.rdbuf();
66  std::cerr.rdbuf(errbuf);
67  };
69  virtual ~CerrRedirection()
70  {
71  std::cerr.rdbuf(mBuffer);
72  }
73 
74  private:
78  CerrRedirection& operator=(const CerrRedirection& cr) {return *this;}
79  };
80 
83  {
84  public:
86  CoutRedirection(const std::string &filename)
87  {
88  pOutputFile->open(filename.c_str(), std::ios_base::out);
89  std::streambuf *buf = pOutputFile->rdbuf();
90  mBuffer = std::cout.rdbuf();
91  std::cout.rdbuf(buf);
92  };
94  virtual ~CoutRedirection()
95  {
96  std::cerr.rdbuf(mBuffer);
97  }
98 
99  private:
103  CoutRedirection& operator=(const CoutRedirection& cr) {return *this;}
104  };
105 
106 };
107 
108 #endif // KompexSQLiteCerrRedirection_H
virtual ~CoutRedirection()
Destrctor.
Definition: KompexSQLiteStreamRedirection.h:94
virtual ~CerrRedirection()
Destrctor.
Definition: KompexSQLiteStreamRedirection.h:69
virtual ~Redirection()
Destrctor.
Definition: KompexSQLiteStreamRedirection.h:38
CoutRedirection & operator=(const CoutRedirection &cr)
Assignment operator.
Definition: KompexSQLiteStreamRedirection.h:103
CoutRedirection(const std::string &filename)
Overloaded constructor.
Definition: KompexSQLiteStreamRedirection.h:86
Redirection & operator=(const Redirection &r)
Assignment operator.
Definition: KompexSQLiteStreamRedirection.h:53
std::cout redirection.
Definition: KompexSQLiteStreamRedirection.h:82
CerrRedirection & operator=(const CerrRedirection &cr)
Assignment operator.
Definition: KompexSQLiteStreamRedirection.h:78
Base-class for std redirections.
Definition: KompexSQLiteStreamRedirection.h:29
#define _SQLiteWrapperExport
Definition: KompexSQLitePrerequisites.h:32
std::streambuf * mBuffer
Stream buffer.
Definition: KompexSQLiteStreamRedirection.h:47
CoutRedirection(const CoutRedirection &cr)
Copy constrctor.
Definition: KompexSQLiteStreamRedirection.h:101
std::ofstream * pOutputFile
File handle.
Definition: KompexSQLiteStreamRedirection.h:45
CerrRedirection(const std::string &filename)
Overloaded constructor.
Definition: KompexSQLiteStreamRedirection.h:61
Redirection()
Standard constructor.
Definition: KompexSQLiteStreamRedirection.h:33
CerrRedirection(const CerrRedirection &cr)
Copy constrctor.
Definition: KompexSQLiteStreamRedirection.h:76
Definition: KompexSQLiteBlob.h:26
std::cerr redirection.
Definition: KompexSQLiteStreamRedirection.h:57