Commit c39cda9b authored by Laurent Belcour's avatar Laurent Belcour

Refactoring the way function are saved.

parent e653d2d8
......@@ -213,3 +213,8 @@ class vec : public std::vector<double>
} ;
#define NOT_IMPLEMENTED() \
std::cerr << "<<ERROR>> not implemented " << __FILE__ \
<< ":" << __LINE__ << std::endl; \
throw
......@@ -41,7 +41,30 @@ class function
//! be used to differenciate the type of export.
//!
//! \see rational_function.cpp for an example
virtual void save(const std::string& filename, const arguments& args) const = 0 ;
virtual void save(const std::string& filename, const arguments& args) const
{
if(args.is_defined("export"))
{
if(args["export"].compare("c++") == 0)
{
std::cout << "<<INFO>> will export in C++ format" << std::endl;
save_cpp(filename, args);
}
else if(args["export"].compare("matlab") == 0)
{
std::cout << "<<INFO>> will export in matlab format" << std::endl;
save_matlab(filename, args);
}
else
{
std::cerr << "<<ERROR>> the export format is unknown" << std::endl ;
}
}
else
{
save(filename) ;
}
}
//! Provide the dimension of the input space of the function
virtual int dimX() const { return _nX ; }
......@@ -87,8 +110,37 @@ class function
_in_param = new_param;
}
protected: // function
//! \brief Standard saving function.
virtual void save(const std::string& filename) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the rational function as a gnuplot file. It requires
//! the data object to output the function at the input location only.
virtual void save_gnuplot(const std::string& filename, const data* d,
const arguments& args) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the rational function using a C++ function formating.
virtual void save_cpp(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the rational function using a C++ function formating.
virtual void save_matlab(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
protected: //data
protected: // data
// Dimension of the function & domain of definition.
int _nX, _nY ;
......
......@@ -348,31 +348,6 @@ void rational_function::load(const std::string& filename)
}
*/
}
void rational_function::save(const std::string& filename, const arguments& args) const
{
if(args.is_defined("export"))
{
if(args["export"].compare("c++") == 0)
{
std::cout << "<<INFO>> will export in C++ format" << std::endl;
save_cpp(filename, args);
}
else if(args["export"].compare("matlab") == 0)
{
std::cout << "<<INFO>> will export in matlab format" << std::endl;
save_matlab(filename, args);
}
else
{
std::cerr << "<<ERROR>> the export format is unknown" << std::endl ;
}
}
else
{
std::cout << "<<INFO>> will export the rational coefficients" << std::endl;
save_rational_function(filename) ;
}
}
//! \todo it should handle parametrization
void rational_function::save_matlab(const std::string& filename, const arguments& args) const
......@@ -587,7 +562,7 @@ void rational_function::save_gnuplot(const std::string& filename, const data* d,
file.close();
}
void rational_function::save_rational_function(const std::string& filename) const
void rational_function::save(const std::string& filename) const
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
file << "#DIM " << _nX << " " << _nY << std::endl ;
......
......@@ -51,22 +51,23 @@ class rational_function : public QObject, public function
// STL stream ouput
friend std::ostream& operator<< (std::ostream& out, const rational_function& r) ;
//! \brief Save the rational function to the rational format (see \ref formating).
void save_rational_function(const std::string& filename) const ;
//! \brief Output the rational function as a gnuplot file. It requires
//! the data object to output the function at the input location only.
void save_gnuplot(const std::string& filename, const data* d, const arguments& args) const ;
//! \brief Output the rational function using a C++ function formating.
void save_cpp(const std::string& filename, const arguments& args) const ;
//! \brief Output the rational function using a C++ function formating.
void save_matlab(const std::string& filename, const arguments& args) const ;
protected: // functions
//! Convert a 1D index into a vector of degree for a
//! multinomial coeffcient. The resulting vector v should
//! be used as prod_k x[k]^v[k] for the monomial basis
std::vector<int> index2degree(int i) const ;
//! \brief Save the rational function to the rational format (see \ref formating).
void save(const std::string& filename) const ;
//! \brief Output the rational function as a gnuplot file. It requires
//! the data object to output the function at the input location only.
void save_gnuplot(const std::string& filename, const data* d, const arguments& args) const ;
//! \brief Output the rational function using a C++ function formating.
void save_cpp(const std::string& filename, const arguments& args) const ;
//! \brief Output the rational function using a C++ function formating.
void save_matlab(const std::string& filename, const arguments& args) const ;
protected: // data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment