Debian Codegraph @

avogadro/qtplugins/openbabel/obfileformat.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTPLUGINS_OBFILEFORMAT_H
7 #define AVOGADRO_QTPLUGINS_OBFILEFORMAT_H
8
9 #include <avogadro/io/fileformat.h>
10
11 #include <avogadro/io/cjsonformat.h>
12 #include <avogadro/io/cmlformat.h>
13 #include <avogadro/io/pdbformat.h>
14
15 namespace Avogadro {
16 namespace QtPlugins {
17
18 /**
19 * @brief The OBFileFormat class implements the FileFormat API for using an
20 * OBProcess for file IO.
21 */
22 class OBFileFormat : public Avogadro::Io::FileFormat
23 {
24 public:
25 OBFileFormat(const std::string& name_, const std::string& identifier_,
26 const std::string& description_,
27 const std::string& specificationUrl_,
28 const std::vector<std::string> fileExtensions_,
29 const std::vector<std::string> mimeTypes_,
30 const std::string& defaultFormat_, bool fileOnly_ = false);
31 ~OBFileFormat() override;
32
33 Operations supportedOperations() const override
34 {
35 return m_rwFlags | File | (m_fileOnly ? None : Stream | String);
36 }
37
38 bool read(std::istream& in, Core::Molecule& molecule) override;
39 bool write(std::ostream& out, const Core::Molecule& molecule) override;
40
41 void clear() override;
42
43 FileFormat* newInstance() const override;
44
45 std::string description() const override { return m_description; }
46 std::string identifier() const override { return m_identifier; }
47 std::string name() const override { return m_name; }
48 std::string specificationUrl() const override { return m_specificationUrl; }
49
50 std::vector<std::string> fileExtensions() const override
51 {
52 return m_fileExtensions;
53 }
54 std::vector<std::string> mimeTypes() const override { return m_mimeTypes; }
55
56 /**
57 * Set whether this format supports read and/or write operations.
58 */
59 void setReadWriteFlags(Operations ops) { m_rwFlags = ops & ReadWrite; }
60
61 /** Whether or not the format supports files only. This is needed for
62 * multifile formats. */
63 void setFileOnly(bool f) { m_fileOnly = f; }
64 bool fileOnly() const { return m_fileOnly; }
65 /** @} */
66
67 class ProcessListener;
68
69 private:
70 Operations m_rwFlags;
71 std::string m_description;
72 std::vector<std::string> m_fileExtensions;
73 std::vector<std::string> m_mimeTypes;
74 std::string m_identifier;
75 std::string m_name;
76 std::string m_specificationUrl;
77 std::string m_defaultFormat;
78 bool m_fileOnly;
79
80 // internal format objects for interchange with obabel
81 Io::CjsonFormat m_cjsonFormat;
82 Io::CmlFormat m_cmlFormat;
83 Io::PdbFormat m_pdbFormat;
84 };
85
86 } // namespace QtPlugins
87 } // namespace Avogadro
88
89 #endif // AVOGADRO_QTPLUGINS_OBFILEFORMAT_H