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