mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-11-04 08:04:32 +00:00 
			
		
		
		
	general cleaning of the code (particularly IO)
This commit is contained in:
		@@ -5,7 +5,7 @@ AC_PREREQ([2.64])
 | 
			
		||||
AC_INIT([LatAnalyze],[3.0alpha1],[antonin.portelli@me.com],[latan])
 | 
			
		||||
AC_CONFIG_AUX_DIR([.buildutils])
 | 
			
		||||
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])
 | 
			
		||||
AM_INIT_AUTOMAKE([-Wall -Werror])
 | 
			
		||||
AM_SILENT_RULES([yes])
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										62
									
								
								latan/Io.cpp
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								latan/Io.cpp
									
									
									
									
									
								
							@@ -4,9 +4,6 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace Latan;
 | 
			
		||||
 | 
			
		||||
// ASCII data format Bison/Flex parser declaration
 | 
			
		||||
int _ioAscii_parse(AsciiParserState* state);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                          File implementation                               *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
@@ -17,7 +14,7 @@ File::File(void)
 | 
			
		||||
, data_()
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
File::File(const string name, const unsigned int mode)
 | 
			
		||||
File::File(const string &name, const unsigned int mode)
 | 
			
		||||
: name_(name)
 | 
			
		||||
, mode_(mode)
 | 
			
		||||
, data_()
 | 
			
		||||
@@ -25,7 +22,9 @@ File::File(const string name, const unsigned int mode)
 | 
			
		||||
 | 
			
		||||
// destructor //////////////////////////////////////////////////////////////////
 | 
			
		||||
File::~File(void)
 | 
			
		||||
{}
 | 
			
		||||
{
 | 
			
		||||
    deleteData();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
string File::getName(void) const
 | 
			
		||||
@@ -54,15 +53,15 @@ void File::deleteData(void)
 | 
			
		||||
 *                     AsciiParserState implementation                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
AsciiParserState::AsciiParserState(istream* stream, string* name,
 | 
			
		||||
                                   IoDataTable* data)
 | 
			
		||||
AsciiFile::AsciiParserState::AsciiParserState(istream* stream, string* name,
 | 
			
		||||
                                              IoDataTable* data)
 | 
			
		||||
: ParserState<IoDataTable>(stream, name, data)
 | 
			
		||||
{
 | 
			
		||||
    initScanner();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// destructor //////////////////////////////////////////////////////////////////
 | 
			
		||||
AsciiParserState::~AsciiParserState(void)
 | 
			
		||||
AsciiFile::AsciiParserState::~AsciiParserState(void)
 | 
			
		||||
{
 | 
			
		||||
    destroyScanner();
 | 
			
		||||
}
 | 
			
		||||
@@ -77,7 +76,7 @@ AsciiFile::AsciiFile(void)
 | 
			
		||||
, state_(NULL)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
AsciiFile::AsciiFile(const string name, const unsigned int mode)
 | 
			
		||||
AsciiFile::AsciiFile(const string &name, const unsigned int mode)
 | 
			
		||||
{
 | 
			
		||||
    openAscii(name, mode);
 | 
			
		||||
}
 | 
			
		||||
@@ -85,7 +84,7 @@ AsciiFile::AsciiFile(const string name, const unsigned int mode)
 | 
			
		||||
// destructor //////////////////////////////////////////////////////////////////
 | 
			
		||||
AsciiFile::~AsciiFile(void)
 | 
			
		||||
{
 | 
			
		||||
    clear();
 | 
			
		||||
    closeAscii();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// tests ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
@@ -97,10 +96,11 @@ bool AsciiFile::isOpen() const
 | 
			
		||||
// IO //////////////////////////////////////////////////////////////////////////
 | 
			
		||||
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())
 | 
			
		||||
    {
 | 
			
		||||
@@ -114,19 +114,12 @@ void AsciiFile::save(void)
 | 
			
		||||
    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");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// internal functions //////////////////////////////////////////////////////////
 | 
			
		||||
void AsciiFile::clear()
 | 
			
		||||
{
 | 
			
		||||
    deleteData();
 | 
			
		||||
    closeAscii();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AsciiFile::openAscii(const string name, const unsigned int mode)
 | 
			
		||||
void AsciiFile::openAscii(const string &name, const unsigned int mode)
 | 
			
		||||
{
 | 
			
		||||
    if (!isOpen())
 | 
			
		||||
    {
 | 
			
		||||
@@ -161,6 +154,33 @@ void AsciiFile::closeAscii(void)
 | 
			
		||||
    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()
 | 
			
		||||
{
 | 
			
		||||
    _ioAscii_parse(state_);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										113
									
								
								latan/Io.hpp
									
									
									
									
									
								
							
							
						
						
									
										113
									
								
								latan/Io.hpp
									
									
									
									
									
								
							@@ -36,24 +36,28 @@ public:
 | 
			
		||||
public:
 | 
			
		||||
    // constructors
 | 
			
		||||
    File(void);
 | 
			
		||||
    File(const std::string name, const unsigned int mode);
 | 
			
		||||
    File(const std::string &name, const unsigned int mode);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~File(void);
 | 
			
		||||
    // access
 | 
			
		||||
    std::string  getName(void) const;
 | 
			
		||||
    unsigned int getMode(void) const;
 | 
			
		||||
    template <typename IoT>
 | 
			
		||||
    const IoT&   read(const std::string &name);
 | 
			
		||||
    // tests
 | 
			
		||||
    virtual bool isOpen(void) const = 0;
 | 
			
		||||
    // Io
 | 
			
		||||
    virtual void close(void)                                           = 0;
 | 
			
		||||
    virtual void open(const std::string name, const unsigned int mode) = 0;
 | 
			
		||||
    virtual void save(void)                                            = 0;
 | 
			
		||||
    virtual void saveAs(const std::string name)                        = 0;
 | 
			
		||||
    // IO
 | 
			
		||||
    virtual void close(void)                                            = 0;
 | 
			
		||||
    virtual void open(const std::string &name, const unsigned int mode) = 0;
 | 
			
		||||
    virtual void save(void)                                             = 0;
 | 
			
		||||
    virtual void saveAs(const std::string &name)                        = 0;
 | 
			
		||||
protected:
 | 
			
		||||
    // data access
 | 
			
		||||
    void         deleteData(void);
 | 
			
		||||
    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:
 | 
			
		||||
    std::string  name_;
 | 
			
		||||
    unsigned int mode_;
 | 
			
		||||
@@ -62,60 +66,69 @@ protected:
 | 
			
		||||
 | 
			
		||||
// Template implementations
 | 
			
		||||
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
 | 
			
		||||
    {
 | 
			
		||||
        LATAN_ERROR(Range, "no data with name '" + dataName + "'");
 | 
			
		||||
        LATAN_ERROR(Definition, "no data with name '" + name + "'");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                          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
 | 
			
		||||
{
 | 
			
		||||
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:
 | 
			
		||||
    // constructors
 | 
			
		||||
    AsciiFile(void);
 | 
			
		||||
    AsciiFile(const std::string name, const unsigned int mode);
 | 
			
		||||
    AsciiFile(const std::string &name, const unsigned int mode);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~AsciiFile(void);
 | 
			
		||||
    // access
 | 
			
		||||
    template <typename IoT>
 | 
			
		||||
    const IoT& read(const std::string name);
 | 
			
		||||
    // tests
 | 
			
		||||
    virtual bool isOpen(void) const;
 | 
			
		||||
    // Io
 | 
			
		||||
    // IO
 | 
			
		||||
    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 saveAs(const std::string name);
 | 
			
		||||
    virtual void saveAs(const std::string &name);
 | 
			
		||||
private:
 | 
			
		||||
    void clear(void);
 | 
			
		||||
    void openAscii(const std::string name, const unsigned int mode);
 | 
			
		||||
    // IO
 | 
			
		||||
    void openAscii(const std::string &name, const unsigned int mode);
 | 
			
		||||
    void closeAscii(void);
 | 
			
		||||
    virtual void load(const std::string &name);
 | 
			
		||||
    // parser
 | 
			
		||||
    void parse(void);
 | 
			
		||||
private:
 | 
			
		||||
    std::fstream      fileStream_;
 | 
			
		||||
@@ -123,32 +136,6 @@ private:
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
    using namespace std;
 | 
			
		||||
    using namespace Latan;
 | 
			
		||||
    
 | 
			
		||||
	#define YY_EXTRA_TYPE  AsciiParserState*
 | 
			
		||||
	#define YY_EXTRA_TYPE  AsciiFile::AsciiParserState*
 | 
			
		||||
	#define YY_USER_ACTION \
 | 
			
		||||
    yylloc->first_line   = yylloc->last_line = yylineno;\
 | 
			
		||||
    yylloc->first_column = yylloc->last_column + 1;\
 | 
			
		||||
@@ -62,13 +62,13 @@ BLANK   [ \t]
 | 
			
		||||
 | 
			
		||||
%%
 | 
			
		||||
 | 
			
		||||
void AsciiParserState::initScanner()
 | 
			
		||||
void AsciiFile::AsciiParserState::initScanner()
 | 
			
		||||
{
 | 
			
		||||
	yylex_init(&scanner);
 | 
			
		||||
	yyset_extra(this, scanner);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AsciiParserState::destroyScanner()
 | 
			
		||||
void AsciiFile::AsciiParserState::destroyScanner()
 | 
			
		||||
{
 | 
			
		||||
	yylex_destroy(scanner);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@
 | 
			
		||||
%locations
 | 
			
		||||
%defines
 | 
			
		||||
%error-verbose
 | 
			
		||||
%parse-param { Latan::AsciiParserState* state }
 | 
			
		||||
%parse-param { Latan::AsciiFile::AsciiParserState* state }
 | 
			
		||||
%initial-action {yylloc.last_column = 0;}
 | 
			
		||||
%lex-param { void* scanner }
 | 
			
		||||
 | 
			
		||||
@@ -38,7 +38,8 @@
 | 
			
		||||
%{
 | 
			
		||||
	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;
 | 
			
		||||
        
 | 
			
		||||
 
 | 
			
		||||
@@ -20,8 +20,8 @@ public:
 | 
			
		||||
        };
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    virtual ~IoObject(void)            = 0;
 | 
			
		||||
    virtual unsigned int getType(void) = 0;
 | 
			
		||||
    virtual ~IoObject(void) {};
 | 
			
		||||
    virtual unsigned int getType(void) const = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
LATAN_END_CPPDECL
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ DMat::DMat(const unsigned int nRow, const unsigned int nCol)
 | 
			
		||||
: DMatBase(nRow,nCol)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
unsigned int DMat::getType(void)
 | 
			
		||||
unsigned int DMat::getType(void) const
 | 
			
		||||
{
 | 
			
		||||
    return IoType::dMat;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,9 @@ public:
 | 
			
		||||
    DMat(const DMat& M);
 | 
			
		||||
    DMat(const unsigned int nRow, const unsigned int nCol);
 | 
			
		||||
    // IO
 | 
			
		||||
    virtual unsigned int getType(void);
 | 
			
		||||
    virtual unsigned int getType(void) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
LATAN_END_CPPDECL
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include <latan/Global.hpp>
 | 
			
		||||
#include <latan/Function.hpp>
 | 
			
		||||
#include <latan/MathCompiler.hpp>
 | 
			
		||||
#include <latan/MathInterpreter.hpp>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
LATAN_BEGIN_CPPDECL
 | 
			
		||||
@@ -70,4 +70,4 @@ namespace STDMATH_NAMESPACE
 | 
			
		||||
 | 
			
		||||
LATAN_END_CPPDECL
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -43,4 +43,4 @@ ParserState<DataObj>::~ParserState(void)
 | 
			
		||||
 | 
			
		||||
LATAN_END_CPPDECL
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user