bpp-seq3  3.0.0
AbstractOSequence.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_IO_ABSTRACTOSEQUENCE_H
6 #define BPP_SEQ_IO_ABSTRACTOSEQUENCE_H
7 
8 
9 #include "../Alphabet/Alphabet.h"
10 #include "../Container/VectorSequenceContainer.h"
11 #include "../ProbabilisticSequence.h"
12 #include "OSequence.h"
13 
14 // From the STL:
15 #include <string>
16 #include <fstream>
17 
18 namespace bpp
19 {
24  public virtual OSequence
25 {
26 public:
28  virtual ~AbstractOSequence() {}
29 
30 public:
36  void writeSequences(std::ostream& output, const SequenceContainerInterface& sc) const override = 0;
37 
38  void writeSequences(const std::string& path, const SequenceContainerInterface& sc, bool overwrite = true) const override
39  {
40  // Open file in specified mode
41  std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
42  writeSequences(output, sc);
43  output.close();
44  }
46 };
47 
55  public virtual AbstractOSequence,
56  // in case for Diamond inheritance
57  public virtual OAlignment
58 {
59 public:
61  virtual ~AbstractOSequence2() {}
62 
63 public:
73  void writeAlignment(std::ostream& output, const SiteContainerInterface& sc) const override
74  {
75  writeSequences(output, sc);
76  }
77 
78  void writeAlignment(const std::string& path, const SiteContainerInterface& sc, bool overwrite = true) const override
79  {
80  writeSequences(path, sc, overwrite);
81  }
83 };
84 
89  public virtual OProbabilisticSequence
90 {
91 public:
94 
95 public:
101  void writeSequences(std::ostream& output, const ProbabilisticSequenceContainerInterface& psc) const override = 0;
102 
103  void writeSequences(const std::string& path, const ProbabilisticSequenceContainerInterface& psc, bool overwrite = true) const override
104  {
105  // Open file in specified mode
106  std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
107  writeSequences(output, psc);
108  output.close();
109  }
110 
112 };
113 
122  public virtual OProbabilisticAlignment
123 {
124 public:
127 
128 public:
142  void writeAlignment(std::ostream& output, const ProbabilisticSiteContainerInterface& sc) const override
143  {
144  writeSequences(output, sc);
145  }
146 
147  void writeAlignment(const std::string& path, const ProbabilisticSiteContainerInterface& sc, bool overwrite = true) const override
148  {
149  writeSequences(path, sc, overwrite);
150  }
151 
153 };
154 } // end of namespace bpp.
155 #endif // BPP_SEQ_IO_ABSTRACTOSEQUENCE_H
Partial implementation of the OProbabilisticAlignment interface.
void writeAlignment(std::ostream &output, const ProbabilisticSiteContainerInterface &sc) const override
Write a container to a stream.
void writeAlignment(const std::string &path, const ProbabilisticSiteContainerInterface &sc, bool overwrite=true) const override
Write a container to a file.
Partial implementation of the OProbabilisticSequence interface.
void writeSequences(std::ostream &output, const ProbabilisticSequenceContainerInterface &psc) const override=0
Write a container to a stream.
void writeSequences(const std::string &path, const ProbabilisticSequenceContainerInterface &psc, bool overwrite=true) const override
Write a container to a file.
Partial implementation of the OAlignment interface.
void writeAlignment(const std::string &path, const SiteContainerInterface &sc, bool overwrite=true) const override
Write a container to a file.
void writeAlignment(std::ostream &output, const SiteContainerInterface &sc) const override
Write a container to a stream.
Partial implementation of the OSequence interface.
void writeSequences(const std::string &path, const SequenceContainerInterface &sc, bool overwrite=true) const override
Write a container to a file.
void writeSequences(std::ostream &output, const SequenceContainerInterface &sc) const override=0
Write a container to a stream.
The OAlignment interface.
Definition: OSequence.h:58
The OProbabilisticAlignment interface.
Definition: OSequence.h:127
The OProbabilisticSequence interface.
Definition: OSequence.h:94
The OSequence interface.
Definition: OSequence.h:23
The SequenceContainer interface.
This alphabet is used to deal NumericAlphabet.