Commit 9ead819f authored by Ludovic Courtès's avatar Ludovic Courtès

data: Move the guts of the 'save' method to 'save_data_as_text'.

parent a0ef97e8
......@@ -4,7 +4,8 @@ import sys
Import('env', 'ALTA_LIBS')
# Library sources
sources = ['common.cpp',
sources = ['common.cpp',
'data.cpp',
'function.cpp',
'params.cpp',
'plugins_manager.cpp',
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014, 2015 Inria
This file is part of ALTA.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <iostream>
#include "data.h"
static void save_data_as_text(std::ostream& out, const data &data)
{
out << "#DIM " << data.dimX() << " " << data.dimY() << std::endl;
out << "#PARAM_IN " << params::get_name(data.input_parametrization()) << std::endl;
out << "#PARAM_OUT " << params::get_name(data.output_parametrization()) << std::endl;
for(int i=0; i < data.size(); ++i)
{
vec x = data.get(i);
for(int j=0; j< data.dimX() + data.dimY(); ++j)
{
out << x[j] << "\t";
}
out << std::endl;
}
}
void data::save(const std::string& filename) const
{
std::ofstream file;
file.exceptions(std::ios_base::failbit);
file.open(filename.c_str(), std::ios_base::trunc);
file.exceptions(std::ios_base::goodbit);
save_data_as_text(file, *this);
file.close();
}
......@@ -51,23 +51,7 @@ class data : public parametrized
virtual void load(const std::string& filename, const arguments& args) = 0 ;
// Save the data to a file
virtual void save(const std::string& filename) const
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
file << "#DIM " << _nX << " " << _nY << std::endl;
file << "#PARAM_IN " << params::get_name(input_parametrization()) << std::endl;
file << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl;
for(int i=0; i<size(); ++i)
{
vec x = this->get(i);
for(int j=0; j<_nX+_nY; ++j)
{
file << x[j] << "\t";
}
file << std::endl;
}
file.close();
}
virtual void save(const std::string& filename) const;
// Acces to data
virtual vec get(int i) const = 0 ;
......@@ -189,3 +173,5 @@ class data_params : public data
std::vector<vec> _data;
};
/* -*- c++ -*- */
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