mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
general cleaning of the code (particularly IO)
This commit is contained in:
parent
ce6469cdd7
commit
eaa89657ee
@ -5,7 +5,7 @@ AC_PREREQ([2.64])
|
|||||||
AC_INIT([LatAnalyze],[3.0alpha1],[antonin.portelli@me.com],[latan])
|
AC_INIT([LatAnalyze],[3.0alpha1],[antonin.portelli@me.com],[latan])
|
||||||
AC_CONFIG_AUX_DIR([.buildutils])
|
AC_CONFIG_AUX_DIR([.buildutils])
|
||||||
AC_CONFIG_SRCDIR([latan/Global.cpp])
|
AC_CONFIG_SRCDIR([latan/Global.cpp])
|
||||||
AC_CONFIG_SRCDIR([examples/ex_test.cpp])
|
AC_CONFIG_SRCDIR([examples/exMathInterpreter.cpp])
|
||||||
AC_CONFIG_MACRO_DIR([.buildutils/m4])
|
AC_CONFIG_MACRO_DIR([.buildutils/m4])
|
||||||
AM_INIT_AUTOMAKE([-Wall -Werror])
|
AM_INIT_AUTOMAKE([-Wall -Werror])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
62
latan/Io.cpp
62
latan/Io.cpp
@ -4,9 +4,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Latan;
|
using namespace Latan;
|
||||||
|
|
||||||
// ASCII data format Bison/Flex parser declaration
|
|
||||||
int _ioAscii_parse(AsciiParserState* state);
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* File implementation *
|
* File implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
@ -17,7 +14,7 @@ File::File(void)
|
|||||||
, data_()
|
, data_()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
File::File(const string name, const unsigned int mode)
|
File::File(const string &name, const unsigned int mode)
|
||||||
: name_(name)
|
: name_(name)
|
||||||
, mode_(mode)
|
, mode_(mode)
|
||||||
, data_()
|
, data_()
|
||||||
@ -25,7 +22,9 @@ File::File(const string name, const unsigned int mode)
|
|||||||
|
|
||||||
// destructor //////////////////////////////////////////////////////////////////
|
// destructor //////////////////////////////////////////////////////////////////
|
||||||
File::~File(void)
|
File::~File(void)
|
||||||
{}
|
{
|
||||||
|
deleteData();
|
||||||
|
}
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
string File::getName(void) const
|
string File::getName(void) const
|
||||||
@ -54,15 +53,15 @@ void File::deleteData(void)
|
|||||||
* AsciiParserState implementation *
|
* AsciiParserState implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
AsciiParserState::AsciiParserState(istream* stream, string* name,
|
AsciiFile::AsciiParserState::AsciiParserState(istream* stream, string* name,
|
||||||
IoDataTable* data)
|
IoDataTable* data)
|
||||||
: ParserState<IoDataTable>(stream, name, data)
|
: ParserState<IoDataTable>(stream, name, data)
|
||||||
{
|
{
|
||||||
initScanner();
|
initScanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor //////////////////////////////////////////////////////////////////
|
// destructor //////////////////////////////////////////////////////////////////
|
||||||
AsciiParserState::~AsciiParserState(void)
|
AsciiFile::AsciiParserState::~AsciiParserState(void)
|
||||||
{
|
{
|
||||||
destroyScanner();
|
destroyScanner();
|
||||||
}
|
}
|
||||||
@ -77,7 +76,7 @@ AsciiFile::AsciiFile(void)
|
|||||||
, state_(NULL)
|
, state_(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
AsciiFile::AsciiFile(const string name, const unsigned int mode)
|
AsciiFile::AsciiFile(const string &name, const unsigned int mode)
|
||||||
{
|
{
|
||||||
openAscii(name, mode);
|
openAscii(name, mode);
|
||||||
}
|
}
|
||||||
@ -85,7 +84,7 @@ AsciiFile::AsciiFile(const string name, const unsigned int mode)
|
|||||||
// destructor //////////////////////////////////////////////////////////////////
|
// destructor //////////////////////////////////////////////////////////////////
|
||||||
AsciiFile::~AsciiFile(void)
|
AsciiFile::~AsciiFile(void)
|
||||||
{
|
{
|
||||||
clear();
|
closeAscii();
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests ///////////////////////////////////////////////////////////////////////
|
// tests ///////////////////////////////////////////////////////////////////////
|
||||||
@ -97,10 +96,11 @@ bool AsciiFile::isOpen() const
|
|||||||
// IO //////////////////////////////////////////////////////////////////////////
|
// IO //////////////////////////////////////////////////////////////////////////
|
||||||
void AsciiFile::close(void)
|
void AsciiFile::close(void)
|
||||||
{
|
{
|
||||||
clear();
|
closeAscii();
|
||||||
|
deleteData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsciiFile::open(const string name, const unsigned int mode)
|
void AsciiFile::open(const string &name, const unsigned int mode)
|
||||||
{
|
{
|
||||||
if (isOpen())
|
if (isOpen())
|
||||||
{
|
{
|
||||||
@ -114,19 +114,12 @@ void AsciiFile::save(void)
|
|||||||
LATAN_ERROR(Implementation, "saving Ascii files not implemented yet");
|
LATAN_ERROR(Implementation, "saving Ascii files not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsciiFile::saveAs(const string name __dumb)
|
void AsciiFile::saveAs(const string &name __dumb)
|
||||||
{
|
{
|
||||||
LATAN_ERROR(Implementation, "saving Ascii files not implemented yet");
|
LATAN_ERROR(Implementation, "saving Ascii files not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal functions //////////////////////////////////////////////////////////
|
void AsciiFile::openAscii(const string &name, const unsigned int mode)
|
||||||
void AsciiFile::clear()
|
|
||||||
{
|
|
||||||
deleteData();
|
|
||||||
closeAscii();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsciiFile::openAscii(const string name, const unsigned int mode)
|
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
{
|
{
|
||||||
@ -161,6 +154,33 @@ void AsciiFile::closeAscii(void)
|
|||||||
isParsed_ = false;
|
isParsed_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AsciiFile::load(const string &name __dumb)
|
||||||
|
{
|
||||||
|
if ((mode_ & FileMode::read)&&(isOpen()))
|
||||||
|
{
|
||||||
|
if (!isParsed_)
|
||||||
|
{
|
||||||
|
parse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isOpen())
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Io, "file '" + name_ + "' is not opened in read mode");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Io, "file not opened");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parser //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Bison/Flex parser declaration
|
||||||
|
int _ioAscii_parse(AsciiFile::AsciiParserState* state);
|
||||||
|
|
||||||
void AsciiFile::parse()
|
void AsciiFile::parse()
|
||||||
{
|
{
|
||||||
_ioAscii_parse(state_);
|
_ioAscii_parse(state_);
|
||||||
|
113
latan/Io.hpp
113
latan/Io.hpp
@ -36,24 +36,28 @@ public:
|
|||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
File(void);
|
File(void);
|
||||||
File(const std::string name, const unsigned int mode);
|
File(const std::string &name, const unsigned int mode);
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~File(void);
|
virtual ~File(void);
|
||||||
// access
|
// access
|
||||||
std::string getName(void) const;
|
std::string getName(void) const;
|
||||||
unsigned int getMode(void) const;
|
unsigned int getMode(void) const;
|
||||||
|
template <typename IoT>
|
||||||
|
const IoT& read(const std::string &name);
|
||||||
// tests
|
// tests
|
||||||
virtual bool isOpen(void) const = 0;
|
virtual bool isOpen(void) const = 0;
|
||||||
// Io
|
// IO
|
||||||
virtual void close(void) = 0;
|
virtual void close(void) = 0;
|
||||||
virtual void open(const std::string name, const unsigned int mode) = 0;
|
virtual void open(const std::string &name, const unsigned int mode) = 0;
|
||||||
virtual void save(void) = 0;
|
virtual void save(void) = 0;
|
||||||
virtual void saveAs(const std::string name) = 0;
|
virtual void saveAs(const std::string &name) = 0;
|
||||||
protected:
|
protected:
|
||||||
// data access
|
// data access
|
||||||
void deleteData(void);
|
void deleteData(void);
|
||||||
template <typename IoT>
|
template <typename IoT>
|
||||||
const IoT& getData(const std::string dataName);
|
const IoT& getData(const std::string &name) const;
|
||||||
|
// IO
|
||||||
|
virtual void load(const std::string &name) = 0;
|
||||||
protected:
|
protected:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
unsigned int mode_;
|
unsigned int mode_;
|
||||||
@ -62,60 +66,69 @@ protected:
|
|||||||
|
|
||||||
// Template implementations
|
// Template implementations
|
||||||
template <typename IoT>
|
template <typename IoT>
|
||||||
const IoT& File::getData(const std::string dataName)
|
const IoT& File::read(const std::string &name)
|
||||||
{
|
{
|
||||||
if (keyExists(dataName, data_))
|
load(name);
|
||||||
|
|
||||||
|
return getData<IoT>(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IoT>
|
||||||
|
const IoT& File::getData(const std::string &name) const
|
||||||
|
{
|
||||||
|
IoDataTable::const_iterator i = data_.find(name);
|
||||||
|
|
||||||
|
if (i != data_.end())
|
||||||
{
|
{
|
||||||
return dynamic_cast<const IoT&>(*(data_[dataName]));
|
return dynamic_cast<const IoT&>(*(i->second));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LATAN_ERROR(Range, "no data with name '" + dataName + "'");
|
LATAN_ERROR(Definition, "no data with name '" + name + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* ASCII datafile class *
|
* ASCII datafile class *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
class AsciiParserState: public ParserState<IoDataTable>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
explicit AsciiParserState(std::istream* stream, std::string* name,\
|
|
||||||
IoDataTable* data);
|
|
||||||
// destructor
|
|
||||||
virtual ~AsciiParserState(void);
|
|
||||||
// public members
|
|
||||||
std::stack<DMat> dMatBuf;
|
|
||||||
std::stack<double> doubleBuf;
|
|
||||||
private:
|
|
||||||
// allocation/deallocation functions defined in IoAsciiLexer.lpp
|
|
||||||
virtual void initScanner(void);
|
|
||||||
virtual void destroyScanner(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
class AsciiFile: public File
|
class AsciiFile: public File
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
class AsciiParserState: public ParserState<IoDataTable>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
explicit AsciiParserState(std::istream* stream, std::string* name,\
|
||||||
|
IoDataTable* data);
|
||||||
|
// destructor
|
||||||
|
virtual ~AsciiParserState(void);
|
||||||
|
// public members
|
||||||
|
std::stack<DMat> dMatBuf;
|
||||||
|
std::stack<double> doubleBuf;
|
||||||
|
private:
|
||||||
|
// allocation/deallocation functions defined in IoAsciiLexer.lpp
|
||||||
|
virtual void initScanner(void);
|
||||||
|
virtual void destroyScanner(void);
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
AsciiFile(void);
|
AsciiFile(void);
|
||||||
AsciiFile(const std::string name, const unsigned int mode);
|
AsciiFile(const std::string &name, const unsigned int mode);
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~AsciiFile(void);
|
virtual ~AsciiFile(void);
|
||||||
// access
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT& read(const std::string name);
|
|
||||||
// tests
|
// tests
|
||||||
virtual bool isOpen(void) const;
|
virtual bool isOpen(void) const;
|
||||||
// Io
|
// IO
|
||||||
virtual void close(void);
|
virtual void close(void);
|
||||||
virtual void open(const std::string name, const unsigned int mode);
|
virtual void open(const std::string &name, const unsigned int mode);
|
||||||
virtual void save(void);
|
virtual void save(void);
|
||||||
virtual void saveAs(const std::string name);
|
virtual void saveAs(const std::string &name);
|
||||||
private:
|
private:
|
||||||
void clear(void);
|
// IO
|
||||||
void openAscii(const std::string name, const unsigned int mode);
|
void openAscii(const std::string &name, const unsigned int mode);
|
||||||
void closeAscii(void);
|
void closeAscii(void);
|
||||||
|
virtual void load(const std::string &name);
|
||||||
|
// parser
|
||||||
void parse(void);
|
void parse(void);
|
||||||
private:
|
private:
|
||||||
std::fstream fileStream_;
|
std::fstream fileStream_;
|
||||||
@ -123,32 +136,6 @@ private:
|
|||||||
AsciiParserState* state_;
|
AsciiParserState* state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Template implementations
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT& AsciiFile::read(const std::string dataName)
|
|
||||||
{
|
|
||||||
if ((mode_ & FileMode::read)&&(isOpen()))
|
|
||||||
{
|
|
||||||
if (!isParsed_)
|
|
||||||
{
|
|
||||||
parse();
|
|
||||||
}
|
|
||||||
|
|
||||||
return getData<IoT>(dataName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isOpen())
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io,"file '" + name_ + "' is not opened in read mode");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io,"file not opened");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LATAN_END_CPPDECL
|
LATAN_END_CPPDECL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Latan;
|
using namespace Latan;
|
||||||
|
|
||||||
#define YY_EXTRA_TYPE AsciiParserState*
|
#define YY_EXTRA_TYPE AsciiFile::AsciiParserState*
|
||||||
#define YY_USER_ACTION \
|
#define YY_USER_ACTION \
|
||||||
yylloc->first_line = yylloc->last_line = yylineno;\
|
yylloc->first_line = yylloc->last_line = yylineno;\
|
||||||
yylloc->first_column = yylloc->last_column + 1;\
|
yylloc->first_column = yylloc->last_column + 1;\
|
||||||
@ -62,13 +62,13 @@ BLANK [ \t]
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
void AsciiParserState::initScanner()
|
void AsciiFile::AsciiParserState::initScanner()
|
||||||
{
|
{
|
||||||
yylex_init(&scanner);
|
yylex_init(&scanner);
|
||||||
yyset_extra(this, scanner);
|
yyset_extra(this, scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsciiParserState::destroyScanner()
|
void AsciiFile::AsciiParserState::destroyScanner()
|
||||||
{
|
{
|
||||||
yylex_destroy(scanner);
|
yylex_destroy(scanner);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
%locations
|
%locations
|
||||||
%defines
|
%defines
|
||||||
%error-verbose
|
%error-verbose
|
||||||
%parse-param { Latan::AsciiParserState* state }
|
%parse-param { Latan::AsciiFile::AsciiParserState* state }
|
||||||
%initial-action {yylloc.last_column = 0;}
|
%initial-action {yylloc.last_column = 0;}
|
||||||
%lex-param { void* scanner }
|
%lex-param { void* scanner }
|
||||||
|
|
||||||
@ -38,7 +38,8 @@
|
|||||||
%{
|
%{
|
||||||
int _ioAscii_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
|
int _ioAscii_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
|
||||||
|
|
||||||
void _ioAscii_error(YYLTYPE* locp, AsciiParserState* state, const char* err)
|
void _ioAscii_error(YYLTYPE* locp, AsciiFile::AsciiParserState* state,
|
||||||
|
const char* err)
|
||||||
{
|
{
|
||||||
stringstream buf;
|
stringstream buf;
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ public:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
virtual ~IoObject(void) = 0;
|
virtual ~IoObject(void) {};
|
||||||
virtual unsigned int getType(void) = 0;
|
virtual unsigned int getType(void) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
LATAN_END_CPPDECL
|
LATAN_END_CPPDECL
|
||||||
|
@ -20,7 +20,7 @@ DMat::DMat(const unsigned int nRow, const unsigned int nCol)
|
|||||||
: DMatBase(nRow,nCol)
|
: DMatBase(nRow,nCol)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unsigned int DMat::getType(void)
|
unsigned int DMat::getType(void) const
|
||||||
{
|
{
|
||||||
return IoType::dMat;
|
return IoType::dMat;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ public:
|
|||||||
DMat(const DMat& M);
|
DMat(const DMat& M);
|
||||||
DMat(const unsigned int nRow, const unsigned int nCol);
|
DMat(const unsigned int nRow, const unsigned int nCol);
|
||||||
// IO
|
// IO
|
||||||
virtual unsigned int getType(void);
|
virtual unsigned int getType(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
LATAN_END_CPPDECL
|
LATAN_END_CPPDECL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <latan/Global.hpp>
|
#include <latan/Global.hpp>
|
||||||
#include <latan/Function.hpp>
|
#include <latan/Function.hpp>
|
||||||
#include <latan/MathCompiler.hpp>
|
#include <latan/MathInterpreter.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
LATAN_BEGIN_CPPDECL
|
LATAN_BEGIN_CPPDECL
|
||||||
@ -70,4 +70,4 @@ namespace STDMATH_NAMESPACE
|
|||||||
|
|
||||||
LATAN_END_CPPDECL
|
LATAN_END_CPPDECL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,4 +43,4 @@ ParserState<DataObj>::~ParserState(void)
|
|||||||
|
|
||||||
LATAN_END_CPPDECL
|
LATAN_END_CPPDECL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user