aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
MNWriter.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Definition of abstract classes for file output manipulation
25  * of Markov Networks.
26  *
27  * Every class used to read or write a MN from a file, must inherit from
28  * MNWriter or MNReader.
29  *
30  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
31  */
32 #ifndef GUM_MN_WRITER_H
33 #define GUM_MN_WRITER_H
34 
35 #include <agrum/MN/IMarkovNet.h>
36 #include <agrum/agrum.h>
37 #include <iostream>
38 #include <string>
39 
40 namespace gum {
41 
42  /* =========================================================================*/
43  /* === WRITERS === */
44  /* =========================================================================*/
45  /**
46  * @class MNWriter
47  * @headerfile MNWriter.h <agrum/MN/io/MNWriter.h>
48  * @brief Pure virtual class for writting a MN to a file.
49  * @ingroup mn_io
50  *
51  * Every class used to write the content of a Markov Network in a stream, or
52  * a file must be a subclass of MNWriter.
53  */
54  template < typename GUM_SCALAR >
55 
56  class MNWriter {
57  public:
58  /**
59  * Default constructor.
60  */
61  MNWriter();
62 
63  /**
64  * Default destructor.
65  */
66  virtual ~MNWriter();
67 
68  /**
69  * Writes a Markov Network in the ouput stream.
70  *
71  * @param output The output stream.
72  * @param MN The Markov Network writed in output.
73  * @throws IOError Raised if an I/O error occurs.
74  */
75  virtual void write(std::ostream& output, const IMarkovNet< GUM_SCALAR >& MN) = 0;
76 
77  /**
78  * Writes a Markov Network in the file referenced by filePath.
79  * If the file doesn't exists, it is created.
80  * If the file exists, it's content will be erased.
81  *
82  * @param filePath The path to the file used to write the Markov Network.
83  * @param MN The Markov Network writen in the file.
84  * @throw IOError Raised if an I/O error occurs.
85  */
86  virtual void write(const std::string& filePath, const IMarkovNet< GUM_SCALAR >& MN) = 0;
87  };
88 
89 
90 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
91  extern template class MNWriter< double >;
92 #endif
93 } /* namespace gum */
94 
95 #include <agrum/MN/io/MNWriter_tpl.h>
96 
97 #endif // GUM_%N_WRITER_H