Chemical Data Processing Library C++ API - Version 1.1.1
Base/DataFormat.hpp
Go to the documentation of this file.
1 /*
2  * DataFormat.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_DATAFORMAT_HPP
30 #define CDPL_BASE_DATAFORMAT_HPP
31 
32 #include <cstddef>
33 #include <string>
34 #include <vector>
35 
36 #include "CDPL/Base/APIPrefix.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Base
43  {
44 
49  {
50 
51  typedef std::vector<std::string> FileExtensionList;
52 
53  public:
58  typedef FileExtensionList::const_iterator ConstFileExtensionIterator;
59 
64  typedef FileExtensionList::iterator FileExtensionIterator;
65 
76  template <typename Iter>
77  DataFormat(const std::string& name, const std::string& descr, const std::string& mime_type,
78  Iter file_ext_begin, Iter file_ext_end, bool multi_rec):
79  name(name),
80  description(descr), mimeType(mime_type), fileExtensions(file_ext_begin, file_ext_end),
81  multiRecordFormat(multi_rec)
82  {}
83 
90  multiRecordFormat(false) {}
91 
96  const std::string& getDescription() const;
97 
102  void setDescription(const std::string& descr);
103 
108  const std::string& getName() const;
109 
114  void setName(const std::string& name);
115 
120  const std::string& getMimeType() const;
121 
126  void setMimeType(const std::string& mime_type);
127 
132  std::size_t getNumFileExtensions() const;
133 
139 
145 
151 
157 
163 
169 
175 
181 
186  DataFormat& addFileExtension(const std::string& file_ext);
187 
194  const std::string& getFileExtension(std::size_t idx) const;
195 
202  void setFileExtension(std::size_t idx, const std::string& file_ext);
203 
209  void removeFileExtension(std::size_t idx);
210 
217 
222 
227  bool isMultiRecordFormat() const;
228 
234  void setMultiRecordFormat(bool multi_rec);
235 
242  bool matchesName(const std::string& name) const;
243 
250  bool matchesMimeType(const std::string& mime_type) const;
251 
258  bool matchesFileExtension(const std::string& file_ext) const;
259 
265  bool operator==(const DataFormat& fmt) const;
266 
276  bool operator!=(const DataFormat& fmt) const;
277 
278  private:
279  std::string name;
280  std::string description;
281  std::string mimeType;
282  FileExtensionList fileExtensions;
283  bool multiRecordFormat;
284  };
285  } // namespace Base
286 } // namespace CDPL
287 
288 #endif // CDPL_BASE_DATAFORMAT_HPP
CDPL::Base::DataFormat::setMimeType
void setMimeType(const std::string &mime_type)
Sets the mime-type of the data format.
CDPL::Base::DataFormat::matchesMimeType
bool matchesMimeType(const std::string &mime_type) const
Tells whether the mime-type of this data format matches the mime-type specified by mime_type.
CDPL::Base::DataFormat::addFileExtension
DataFormat & addFileExtension(const std::string &file_ext)
Adds file_ext to the current list of file extensions.
CDPL::Base::DataFormat::getMimeType
const std::string & getMimeType() const
Returns the mime-type of the data format.
CDPL::Base::DataFormat
Provides meta-information about a particular data storage format.
Definition: Base/DataFormat.hpp:49
CDPL::Base::DataFormat::DataFormat
DataFormat(const std::string &name, const std::string &descr, const std::string &mime_type, Iter file_ext_begin, Iter file_ext_end, bool multi_rec)
Constructs and initializes a DataFormat object with the given attributes.
Definition: Base/DataFormat.hpp:77
CDPL::Base::DataFormat::operator==
bool operator==(const DataFormat &fmt) const
Equality comparison operator.
CDPL_BASE_API
#define CDPL_BASE_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Base::DataFormat::ConstFileExtensionIterator
FileExtensionList::const_iterator ConstFileExtensionIterator
A constant random access iterator used to iterate over the list of file extensions.
Definition: Base/DataFormat.hpp:58
CDPL::Base::DataFormat::isMultiRecordFormat
bool isMultiRecordFormat() const
Tells whether or not the data format supports the storage of multiple data records.
CDPL::Base::DataFormat::getDescription
const std::string & getDescription() const
Returns the description of the data format.
CDPL::Base::DataFormat::DataFormat
DataFormat()
Default constructor.
Definition: Base/DataFormat.hpp:89
CDPL::Base::DataFormat::getFileExtensionsBegin
ConstFileExtensionIterator getFileExtensionsBegin() const
Returns a constant iterator pointing to the beginning of the file extension list.
CDPL::Base::DataFormat::getFileExtensionsBegin
FileExtensionIterator getFileExtensionsBegin()
Returns a mutable iterator pointing to the beginning of the file extension list.
CDPL::Base::DataFormat::matchesFileExtension
bool matchesFileExtension(const std::string &file_ext) const
Tells whether file_ext is contained in the list of file extensions.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_BASE_API.
CDPL::Base::DataFormat::getFileExtensionsEnd
FileExtensionIterator getFileExtensionsEnd()
Returns a mutable iterator pointing to the end of the file extension list.
CDPL::Base::DataFormat::end
ConstFileExtensionIterator end() const
Returns a constant iterator pointing to the end of the file extension list.
CDPL::Base::DataFormat::removeFileExtension
FileExtensionIterator removeFileExtension(const FileExtensionIterator &it)
Removes the file extension list entry pointed to by the iterator it.
CDPL::Base::DataFormat::end
FileExtensionIterator end()
Returns a mutable iterator pointing to the end of the file extension list.
CDPL::Base::DataFormat::begin
FileExtensionIterator begin()
Returns a mutable iterator pointing to the beginning of the file extension list.
CDPL::Base::DataFormat::setName
void setName(const std::string &name)
Sets the short-name of the data format.
CDPL::Base::DataFormat::clearFileExtensions
void clearFileExtensions()
Clears the file extension list.
CDPL::Base::DataFormat::getFileExtensionsEnd
ConstFileExtensionIterator getFileExtensionsEnd() const
Returns a constant iterator pointing to the end of the file extension list.
CDPL::Base::DataFormat::matchesName
bool matchesName(const std::string &name) const
Tells whether the name of this data format matches the name specified by name.
CDPL::Base::DataFormat::operator!=
bool operator!=(const DataFormat &fmt) const
Inequality comparison operator.
CDPL::Base::DataFormat::getName
const std::string & getName() const
Returns the short-name of the data format.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Base::DataFormat::FileExtensionIterator
FileExtensionList::iterator FileExtensionIterator
A mutable random access iterator used to iterate over the list of file extensions.
Definition: Base/DataFormat.hpp:64
CDPL::Base::DataFormat::getNumFileExtensions
std::size_t getNumFileExtensions() const
Returns the number of registered file extensions.
CDPL::Base::DataFormat::removeFileExtension
void removeFileExtension(std::size_t idx)
Removes the file extension list entry at index idx.
CDPL::Base::DataFormat::begin
ConstFileExtensionIterator begin() const
Returns a constant iterator pointing to the beginning of the file extension list.
CDPL::Base::DataFormat::setMultiRecordFormat
void setMultiRecordFormat(bool multi_rec)
Specifies whether or not the data format supports the storage of multiple data records.
CDPL::Base::DataFormat::setFileExtension
void setFileExtension(std::size_t idx, const std::string &file_ext)
Sets the file extension list entry at index idx to file_ext.
CDPL::Base::DataFormat::setDescription
void setDescription(const std::string &descr)
Sets the description of the data format.
CDPL::Base::DataFormat::getFileExtension
const std::string & getFileExtension(std::size_t idx) const
Returns the file extension list entry at index idx.