2014-02-20 23:52:45 +00:00
|
|
|
/*
|
|
|
|
* AsciiFile.hpp, part of LatAnalyze 3
|
|
|
|
*
|
2015-06-11 14:04:54 +01:00
|
|
|
* Copyright (C) 2013 - 2015 Antonin Portelli
|
2014-02-20 23:52:45 +00:00
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_AsciiFile_hpp_
|
|
|
|
#define Latan_AsciiFile_hpp_
|
|
|
|
|
2014-03-13 18:51:01 +00:00
|
|
|
#include <LatAnalyze/Global.hpp>
|
|
|
|
#include <LatAnalyze/File.hpp>
|
|
|
|
#include <LatAnalyze/Mat.hpp>
|
|
|
|
#include <LatAnalyze/MatSample.hpp>
|
2015-10-01 00:13:34 +01:00
|
|
|
#include <LatAnalyze/ParserState.hpp>
|
2014-03-13 18:51:01 +00:00
|
|
|
#include <LatAnalyze/RandGen.hpp>
|
2014-03-03 14:21:37 +00:00
|
|
|
#include <fstream>
|
2014-02-20 23:52:45 +00:00
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
BEGIN_LATAN_NAMESPACE
|
2014-02-20 23:52:45 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ASCII datafile class *
|
|
|
|
******************************************************************************/
|
|
|
|
class AsciiFile: public File
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class AsciiParserState: public ParserState<IoDataTable>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
2014-03-03 14:21:37 +00:00
|
|
|
AsciiParserState(std::istream *stream, std::string *name,
|
|
|
|
IoDataTable *data);
|
2014-02-20 23:52:45 +00:00
|
|
|
// destructor
|
|
|
|
virtual ~AsciiParserState(void);
|
|
|
|
// first element reference
|
|
|
|
bool isFirst;
|
|
|
|
std::string first;
|
|
|
|
// parsing buffers
|
|
|
|
RandGenState stateBuf;
|
|
|
|
DMatSample dMatSampleBuf;
|
|
|
|
std::queue<DMat> dMatQueue;
|
|
|
|
std::queue<double> doubleQueue;
|
|
|
|
std::queue<int> intQueue;
|
|
|
|
private:
|
|
|
|
// allocation/deallocation functions defined in IoAsciiLexer.lpp
|
|
|
|
virtual void initScanner(void);
|
|
|
|
virtual void destroyScanner(void);
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
// constructors
|
2014-03-03 14:21:37 +00:00
|
|
|
AsciiFile(void) = default;
|
2014-02-20 23:52:45 +00:00
|
|
|
AsciiFile(const std::string &name, const unsigned int mode);
|
|
|
|
// destructor
|
|
|
|
virtual ~AsciiFile(void);
|
|
|
|
// access
|
|
|
|
virtual void save(const DMat &m, const std::string &name);
|
|
|
|
virtual void save(const DMatSample &s, const std::string &name);
|
|
|
|
virtual void save(const RandGenState &state, const std::string &name);
|
2015-10-01 00:13:34 +01:00
|
|
|
// read first name
|
|
|
|
virtual std::string getFirstName(void);
|
2014-02-20 23:52:45 +00:00
|
|
|
// tests
|
|
|
|
virtual bool isOpen(void) const;
|
|
|
|
// IO
|
|
|
|
virtual void close(void);
|
|
|
|
virtual void open(const std::string &name, const unsigned int mode);
|
2015-01-28 17:15:05 +00:00
|
|
|
public:
|
|
|
|
// default ASCII precision
|
|
|
|
static const unsigned int defaultDoublePrec = 15;
|
2014-02-20 23:52:45 +00:00
|
|
|
private:
|
|
|
|
// IO
|
|
|
|
virtual std::string load(const std::string &name = "");
|
|
|
|
// parser
|
|
|
|
void parse(void);
|
|
|
|
private:
|
|
|
|
std::fstream fileStream_;
|
2014-03-03 14:21:37 +00:00
|
|
|
bool isParsed_{false};
|
|
|
|
std::unique_ptr<AsciiParserState> state_{nullptr};
|
2014-02-20 23:52:45 +00:00
|
|
|
};
|
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
END_LATAN_NAMESPACE
|
2014-02-20 23:52:45 +00:00
|
|
|
|
|
|
|
#endif // Latan_AsciiFile_hpp_
|