Chemical Data Processing Library C++ API - Version 1.1.1
DataReader.hpp
Go to the documentation of this file.
1 /*
2  * DataReader.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_DATAREADER_HPP
30 #define CDPL_BASE_DATAREADER_HPP
31 
32 #include <cstddef>
33 #include <memory>
34 
35 #include "CDPL/Base/DataIOBase.hpp"
36 
37 
38 namespace CDPL
39 {
40 
41  namespace Base
42  {
43 
71  template <typename T>
72  class DataReader : virtual public DataIOBase
73  {
74 
75  public:
79  typedef T DataType;
80 
84  typedef std::shared_ptr<DataReader> SharedPointer;
85 
98  virtual DataReader& read(DataType& obj, bool overwrite = true) = 0;
99 
114  virtual DataReader& read(std::size_t idx, DataType& obj, bool overwrite = true) = 0;
115 
124  virtual DataReader& skip() = 0;
125 
131  virtual bool hasMoreData() = 0;
132 
137  virtual std::size_t getRecordIndex() const = 0;
138 
145  virtual void setRecordIndex(std::size_t idx) = 0;
146 
152  virtual std::size_t getNumRecords() = 0;
153 
167  virtual operator const void*() const = 0;
168 
181  virtual bool operator!() const = 0;
182 
187  virtual void close() {}
188 
189  protected:
195  DataReader& operator=(const DataReader& reader);
196  };
197 
206  template <typename T>
208 
209  } // namespace Base
210 } // namespace CDPL
211 
212 
213 // Implementation
214 
215 template <typename T>
217 {
218  if (this == &reader)
219  return *this;
220 
221  DataIOBase::operator=(reader);
222 
223  return *this;
224 }
225 
226 // \cond DOC_IMPL_DETAILS
227 
228 template <typename T>
230 {
231  return reader.read(obj);
232 }
233 
234 // \endcond
235 
236 #endif // CDPL_BASE_DATAREADER_HPP
CDPL::Base::DataReader::read
virtual DataReader & read(DataType &obj, bool overwrite=true)=0
Reads the data record at the current record index and stores the read data in obj.
CDPL::Base::operator>>
DataReader< T > & operator>>(DataReader< T > &reader, T &obj)
An input operator that reads the next data record by means of the Base::DataReader instance reader in...
CDPL::Base::DataReader::DataType
T DataType
The type of the read data objects.
Definition: DataReader.hpp:79
CDPL::Base::DataReader::operator=
DataReader & operator=(const DataReader &reader)
Assignment operator.
Definition: DataReader.hpp:216
CDPL::Base::DataReader::operator!
virtual bool operator!() const =0
Tells whether the reader is in a bad state.
CDPL::Base::DataReader::getRecordIndex
virtual std::size_t getRecordIndex() const =0
Returns the index of the current data record.
CDPL::Base::DataReader::setRecordIndex
virtual void setRecordIndex(std::size_t idx)=0
Sets the index of the current data record to idx.
CDPL::Base::DataIOBase
Provides infrastructure for the registration of I/O callback functions.
Definition: DataIOBase.hpp:59
CDPL::Base::DataReader::hasMoreData
virtual bool hasMoreData()=0
Tells if there are any data records left to read.
CDPL::Base::DataReader
An interface for reading data objects of a given type from an arbitrary data source.
Definition: DataReader.hpp:73
CDPL::Base::DataReader::skip
virtual DataReader & skip()=0
Skips the data record at the current record index.
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Base::DataReader::SharedPointer
std::shared_ptr< DataReader > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated DataReader instances.
Definition: DataReader.hpp:84
DataIOBase.hpp
Definition of the class CDPL::Base::DataIOBase.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Base::DataReader::read
virtual DataReader & read(std::size_t idx, DataType &obj, bool overwrite=true)=0
Reads the data record at index idx and stores the read data in obj.
CDPL::Base::DataReader::getNumRecords
virtual std::size_t getNumRecords()=0
Returns the total number of available data records.
CDPL::Base::DataReader::close
virtual void close()
Performs a reader specific shutdown operation (if required).
Definition: DataReader.hpp:187