aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
BNWriter.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 Bayesian networks.
26  *
27  * Every classe used to read or write a BN from a file, must inherit from
28  * BNWriter or BNReader.
29  *
30  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
31  */
32 #ifndef GUM_BN_WRITER_H
33 #define GUM_BN_WRITER_H
34 
35 #include <agrum/BN/IBayesNet.h>
36 #include <agrum/agrum.h>
37 #include <iostream>
38 #include <string>
39 
40 namespace gum {
41 
42  /* =========================================================================*/
43  /* === WRITERS === */
44  /* =========================================================================*/
45  /**
46  * @class BNWriter
47  * @headerfile BNWriter.h <agrum/BN/io/BNWriter.h>
48  * @brief Pure virtual class for writting a BN to a file.
49  * @ingroup bn_io
50  *
51  * Every class used to write the content of a Bayesian network in a stream, or
52  * a file must be a subclass of BNWriter.
53  */
54  template < typename GUM_SCALAR >
55 
56  class BNWriter {
57  public:
58  /**
59  * Default constructor.
60  */
61  BNWriter();
62 
63  /**
64  * Default destructor.
65  */
66  virtual ~BNWriter();
67 
68  /**
69  * Writes a Bayesian network in the ouput stream.
70  *
71  * @param output The output stream.
72  * @param bn The Bayesian network writed in output.
73  * @throws IOError Raised if an I/O error occurs.
74  */
75  virtual void write(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn) = 0;
76 
77  /**
78  * Writes a Bayesian 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 Bayesian network.
83  * @param bn The Bayesian 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 IBayesNet< GUM_SCALAR >& bn) = 0;
87  };
88 
89 
90 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
91  extern template class BNWriter< double >;
92 #endif
93 } /* namespace gum */
94 
95 #include <agrum/BN/io/BNWriter_tpl.h>
96 
97 #endif // GUM_BN_WRITER_H