Chemical Data Processing Library C++ API - Version 1.1.1
DataWriter.hpp
Go to the documentation of this file.
1 /*
2  * DataWriter.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_BASE_DATAWRITER_HPP
30 #define CDPL_BASE_DATAWRITER_HPP
31 
32 #include <memory>
33 
34 #include "CDPL/Base/DataIOBase.hpp"
35 
36 
37 namespace CDPL
38 {
39 
40  namespace Base
41  {
42 
61  template <typename T>
62  class DataWriter : virtual public DataIOBase
63  {
64 
65  public:
69  typedef std::shared_ptr<DataWriter> SharedPointer;
70 
74  typedef T DataType;
75 
82  virtual DataWriter& write(const DataType& obj) = 0;
83 
88  virtual void close() {}
89 
103  virtual operator const void*() const = 0;
104 
117  virtual bool operator!() const = 0;
118 
119  protected:
125  DataWriter& operator=(const DataWriter& writer);
126  };
127 
136  template <typename T>
137  DataWriter<T>& operator<<(DataWriter<T>& writer, const T& obj);
138 
139  } // namespace Base
140 } // namespace CDPL
141 
142 
143 // Implementation
144 
145 template <typename T>
147 {
148  if (this == &writer)
149  return *this;
150 
151  DataIOBase::operator=(writer);
152 
153  return *this;
154 }
155 
156 // \cond DOC_IMPL_DETAILS
157 
158 template <typename T>
159 CDPL::Base::DataWriter<T>& CDPL::Base::operator<<(DataWriter<T>& writer, const T& obj)
160 {
161  return writer.write(obj);
162 }
163 
164 // \endcond
165 
166 #endif // CDPL_BASE_DATAWRITER_HPP
CDPL::Base::DataWriter::operator=
DataWriter & operator=(const DataWriter &writer)
Assignment operator.
Definition: DataWriter.hpp:146
CDPL::Base::DataIOBase
Provides infrastructure for the registration of I/O callback functions.
Definition: DataIOBase.hpp:59
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Base::DataWriter::DataType
T DataType
The type of the written data objects.
Definition: DataWriter.hpp:74
CDPL::Base::operator<<
DataWriter< T > & operator<<(DataWriter< T > &writer, const T &obj)
An output operator that outputs the data object obj by means of the Base::DataWriter instance writer.
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Base::DataWriter::write
virtual DataWriter & write(const DataType &obj)=0
Writes the data object obj.
CDPL::Base::DataWriter::SharedPointer
std::shared_ptr< DataWriter > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated DataWriter instances.
Definition: DataWriter.hpp:69
CDPL::Base::DataWriter::operator!
virtual bool operator!() const =0
Tells whether the writer is in a bad state.
DataIOBase.hpp
Definition of the class CDPL::Base::DataIOBase.
CDPL::Base::DataWriter::close
virtual void close()
Writes format dependent data (if required) to mark the end of output.
Definition: DataWriter.hpp:88
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Base::DataWriter
An interface for writing data objects of a given type to an arbitrary data sink.
Definition: DataWriter.hpp:63