Chemical Data Processing Library C++ API - Version 1.4.0
DefaultDataOutputHandler.hpp
Go to the documentation of this file.
1 /*
2  * DefaultDataOutputHandler.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_DEFAULTDATAOUTPUTHANDLER_HPP
30 #define CDPL_UTIL_DEFAULTDATAOUTPUTHANDLER_HPP
31 
34 
35 
36 namespace CDPL
37 {
38 
39  namespace Util
40  {
41 
51  template <typename WriterImpl, const Base::DataFormat& FORMAT, typename DataType = typename WriterImpl::DataType>
53  {
54 
55  public:
58 
64  {
65  return FORMAT;
66  }
67 
73  typename WriterType::SharedPointer createWriter(std::ostream& os) const
74  {
75  return typename WriterType::SharedPointer(new WriterImpl(os));
76  }
77 
84  typename WriterType::SharedPointer createWriter(const std::string& file_name, std::ios_base::openmode mode) const
85  {
86  return typename WriterType::SharedPointer(new Util::FileDataWriter<WriterImpl>(file_name, mode));
87  }
88  };
89  } // namespace Util
90 } // namespace CDPL
91 
92 #endif // CDPL_UTIL_DEFAULTDATAOUTPUTHANDLER_HPP
Definition of class CDPL::Base::DataOutputHandler.
Definition of class CDPL::Util::FileDataWriter.
Provides meta-information about a particular data storage format.
Definition: Base/DataFormat.hpp:49
Factory interface providing methods for the creation of Base::DataWriter instances handling a particu...
Definition: DataOutputHandler.hpp:54
Interface for writing data objects of a given type to an arbitrary data sink.
Definition: DataWriter.hpp:63
std::shared_ptr< DataWriter > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated DataWriter instances.
Definition: DataWriter.hpp:69
Default Base::DataOutputHandler implementation that exposes a fixed Base::DataFormat and instantiates...
Definition: DefaultDataOutputHandler.hpp:53
const Base::DataFormat & getDataFormat() const
Returns the data format advertised by this handler.
Definition: DefaultDataOutputHandler.hpp:63
WriterType::SharedPointer createWriter(const std::string &file_name, std::ios_base::openmode mode) const
Creates a writer that writes to the file file_name (opened in mode mode).
Definition: DefaultDataOutputHandler.hpp:84
WriterType::SharedPointer createWriter(std::ostream &os) const
Creates a writer that writes to the output stream os.
Definition: DefaultDataOutputHandler.hpp:73
Base::DataOutputHandler< DataType >::WriterType WriterType
Type of the Base::DataWriter specialization produced by this handler.
Definition: DefaultDataOutputHandler.hpp:57
Convenience wrapper that adapts a stream-based writer implementation WriterImpl into a file-based Bas...
Definition: FileDataWriter.hpp:55
The namespace of the Chemical Data Processing Library.