Chemical Data Processing Library C++ API - Version 1.1.1
CompressedDataWriter.hpp
Go to the documentation of this file.
1 /*
2  * CompressedDataWriter.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_UTIL_COMPRESSEDDATAWRITER_HPP
30 #define CDPL_UTIL_COMPRESSEDDATAWRITER_HPP
31 
32 #include <iosfwd>
33 #include <functional>
34 
35 #include "CDPL/Base/DataWriter.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Util
43  {
44 
48  template <typename WriterImpl, typename CompStream, typename DataType = typename WriterImpl::DataType>
49  class CompressedDataWriter : public Base::DataWriter<DataType>
50  {
51 
52  public:
53  CompressedDataWriter(std::iostream& ios);
54 
55  CompressedDataWriter& write(const DataType& obj);
56 
57  void close();
58 
59  operator const void*() const;
60 
61  bool operator!() const;
62 
63  private:
64  CompStream stream;
65  WriterImpl writer;
66  };
67  } // namespace Util
68 } // namespace CDPL
69 
70 
71 // Implementation
72 
73 template <typename WriterImpl, typename DecompStream, typename DataType>
75  stream(ios), writer(stream)
76 {
77  writer.setParent(this);
78  writer.registerIOCallback(std::bind(&Base::DataIOBase::invokeIOCallbacks, this, std::placeholders::_2));
79 }
80 
81 template <typename WriterImpl, typename DecompStream, typename DataType>
84 {
85  writer.write(obj);
86 
87  return *this;
88 }
89 
90 template <typename WriterImpl, typename DecompStream, typename DataType>
92 {
93  writer.close();
94  stream.close();
95 }
96 
97 template <typename WriterImpl, typename DecompStream, typename DataType>
99 {
100  return writer.operator const void*();
101 }
102 
103 template <typename WriterImpl, typename DecompStream, typename DataType>
105 {
106  return writer.operator!();
107 }
108 
109 #endif // CDPL_UTIL_COMPRESSEDDATAWRITER_HPP
CDPL::Util::CompressedDataWriter
CompressedDataWriter.
Definition: CompressedDataWriter.hpp:50
CDPL::Util::CompressedDataWriter::write
CompressedDataWriter & write(const DataType &obj)
Definition: CompressedDataWriter.hpp:83
DataWriter.hpp
Definition of the class CDPL::Base::DataWriter.
CDPL::Base::DataIOBase::invokeIOCallbacks
void invokeIOCallbacks(double progress) const
Invokes all registered I/O callback functions with the argument *this.
CDPL::Util::CompressedDataWriter::close
void close()
Writes format dependent data (if required) to mark the end of output.
Definition: CompressedDataWriter.hpp:91
CDPL::Util::CompressedDataWriter::operator!
bool operator!() const
Definition: CompressedDataWriter.hpp:104
CDPL::Util::CompressedDataWriter::CompressedDataWriter
CompressedDataWriter(std::iostream &ios)
Definition: CompressedDataWriter.hpp:74
CDPL::Base::DataWriter< typename WriterImpl::DataType >::DataType
typename WriterImpl::DataType DataType
The type of the written data objects.
Definition: DataWriter.hpp:74
CDPL
The namespace of the Chemical Data Processing Library.
CompressionStreams.hpp
Provides I/O-streams capable of performing compression and decompression.
CDPL::Base::DataWriter
An interface for writing data objects of a given type to an arbitrary data sink.
Definition: DataWriter.hpp:63