1 /** 2 * 3 * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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 #ifndef DSLWRITER_H 23 #define DSLWRITER_H 24 25 #include <fstream> 26 #include <iostream> 27 #include <sstream> 28 #include <string> 29 30 #include <agrum/BN/io/BNWriter.h> 31 #include <agrum/agrum.h> 32 33 namespace gum { 34 35 /** 36 * @class DSLWriter 37 * @headerfile DSLWriter.h <agrum/BN/io/DSL/DSLWriter.h> 38 * @ingroup bn_io 39 * @brief Writes a IBayesNet in the DSL format. 40 * 41 * This class servers to write the content of a Bayesian network in 42 * the DSL format. See 43 * http://www.cs.cmu.edu/~fgcozman/Research/InterchangeFormat/Old/xmlDSL02.html 44 * for information on this format. 45 * 46 */ 47 template < typename GUM_SCALAR > 48 class DSLWriter: public BNWriter< GUM_SCALAR > { 49 public: 50 // ========================================================================== 51 /// @name Constructor & destructor 52 // ========================================================================== 53 /// @{ 54 55 /** 56 * Default constructor. 57 */ 58 DSLWriter(); 59 60 /** 61 * Destructor. 62 */ 63 ~DSLWriter(); 64 65 /// @} 66 67 /** 68 * Writes a Bayesian network in the output stream using the DSL format. 69 * 70 * @param output The output stream. 71 * @param bn The Bayesian network writen in output. 72 * @throws IOError Raised if and I/O error occurs. 73 */ 74 void write(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn) final; 75 76 /** 77 * Writes a Bayesian network in the referenced file using the DSL format. 78 * If the files doesn't exists, it is created. 79 * 80 * @param filePath The path to the file used to write the Bayesian network. 81 * @param bn The Bayesian network writed in the file. 82 * @throws IOError Raised if and I/O error occurs. 83 */ 84 void write(const std::string& filePath, const IBayesNet< GUM_SCALAR >& bn) final; 85 86 private: 87 // Returns a bloc defining a variable in the DSL format. 88 std::string _variableBloc_(const IBayesNet< GUM_SCALAR >& bn, const DiscreteVariable& var); 89 }; 90 91 92 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 93 extern template class gum::DSLWriter< double >; 94 #endif 95 96 } /* namespace gum */ 97 98 #include "DSLWriter_tpl.h" 99 100 #endif // DSLWRITER_H 101