Skip to content

Commit

Permalink
Implemented save/load to file.
Browse files Browse the repository at this point in the history
Also added some more words to technical report, but its not finished.
  • Loading branch information
navrkald committed May 18, 2014
1 parent 7b26cc7 commit 282cd19
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 48 deletions.
2 changes: 1 addition & 1 deletion RegularConvertor/finite_machine/computationalrules.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ComputationalRules// : public QObject
ComputationalRules(QString _from, QString _to, QString _symbol);
ComputationalRules(QString rule);
ComputationalRules(const ComputationalRules& _object);//Toto je kopirovaci konstruktor
ComputationalRules &operator=(const ComputationalRules& _rule);
ComputationalRules& operator=(const ComputationalRules& _rule);
QString toString() const{return from + " " + symbol + "-> " + to;}


Expand Down
115 changes: 86 additions & 29 deletions RegularConvertor/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,42 +940,79 @@ void MainWindow::on_Determinization_advanced_example_4_triggered()
}
void MainWindow::on_action_save_triggered()
{
QFile file("/tmp/test.txt");
if(activeConversion == none)
{
showStatusMessage(tr("ERROR: No conversion selected!"));
return;
}
QString filename = "";
if((filename = QFileDialog::getSaveFileName(this,tr("Save conversion"))) == "")
return;

QFile file(filename);
file.open(QIODevice::WriteOnly);
QDataStream out(&file); // we will serialize the data into the file
out << activeConversion << mode;
switch(activeConversion)
{
case none:
break;
case RE_to_FA:
out << *reg_exp_algorithm->re;
{
// In play mode does not make sence to save output fa
if(mode == Algorithm::PLAY_MODE)
{
out << reg_exp_algorithm->re->regexp;
}
else
{
out << *reg_exp_algorithm->re;
}
}
break;
case REMOVE_EPSILON:
if(mode == Algorithm::PLAY_MODE)
{
out << remove_epsilon_algorithm->FA;
}
else
{
out << remove_epsilon_algorithm->FA << remove_epsilon_algorithm->non_epsilon_FA;
}
break;
case DFA:
out << DFA_algorithm->FA << DFA_algorithm->DFA;
if(mode == Algorithm::PLAY_MODE)
{
out << DFA_algorithm->FA;
}
else
{
out << DFA_algorithm->FA << DFA_algorithm->DFA;
}
break;
// This should never happend
case none:
break;
}
file.close();
}

void MainWindow::on_action_open_file_triggered()
{
QFile read("/tmp/test.txt");
QString filename = "";
if((filename = QFileDialog::getOpenFileName(this, tr("Open conversion")))=="")
return;

QFile read(filename);
read.open(QIODevice::ReadOnly);
QDataStream in(&read); // read the data serialized from the file
FiniteAutomata FA;
//
Conversions conversion;
Conversions conversion = none;
Algorithm::modes tmp_mode = Algorithm::NONE;

in >> conversion;
in >> mode;
switch (mode)
in >> tmp_mode;
switch (tmp_mode)
{
case Algorithm::NONE:

break;
case Algorithm::CHECK_MODE:
on_action_check_mode_triggered();
break;
Expand All @@ -985,44 +1022,64 @@ void MainWindow::on_action_open_file_triggered()
case Algorithm::STEP_MODE:
on_action_step_mode_triggered();
break;
case Algorithm::NONE:
showStatusMessage(tr("ERROR: Input file in wrong format!"));
return;
break;
}
mode = tmp_mode;

switch(conversion)
{
case none:
qDebug() << "Conversion: none";
break;
case RE_to_FA:
{
qDebug() << "Conversion: RE_to_FA";
RegExp re;
in >> re;
prepareREtoFA(new RegExp(re));
if(mode == Algorithm::PLAY_MODE)
{
QString regexp_str;
in >> regexp_str;
prepareREtoFA(new RegExp(regexp_str));
}
else
{
RegExp re;
in >> re;
prepareREtoFA(new RegExp(re));
}
}
break;
case REMOVE_EPSILON:
{
qDebug() << "Conversion: REMOVE_EPSILON";
FiniteAutomata in_FA;
FiniteAutomata out_FA;
in >> in_FA >> out_FA;
in >> in_FA;
prepareRemoveEpsilon();
remove_epsilon_algorithm->setInputFA(in_FA);
remove_epsilon_algorithm->setOutputFA(out_FA);
if(mode != Algorithm::PLAY_MODE)
{
FiniteAutomata out_FA;
in >> out_FA;
remove_epsilon_algorithm->setOutputFA(out_FA);
}
}
break;
case DFA:
qDebug() << "Conversion: DFA";
{
FiniteAutomata in_FA;
FiniteAutomata out_FA;
in >> in_FA >> out_FA;
in >> in_FA;
prepareDFA();
DFA_algorithm->setInputFA(in_FA);
DFA_algorithm->setOutputFA(out_FA);
if(mode != Algorithm::PLAY_MODE)
{
FiniteAutomata out_FA;
in >> out_FA;
DFA_algorithm->setOutputFA(out_FA);
}
}
break;
case none:
showStatusMessage(tr("ERROR: Input file in wrong format!"));
return;
break;
}

qDebug() << FA;
}

QDataStream& operator>>(QDataStream& in, MainWindow::Conversions& e)
Expand Down
24 changes: 12 additions & 12 deletions RegularConvertor/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:12pt;&quot;&gt;Welcome in program Regular Convertor!&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;Please choose &lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:600;&quot;&gt;mode and conversion&lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt; or choose &lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:600;&quot;&gt;example&lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;You can also change program language.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Welcome in program Regular Convertor!&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Please choose &lt;/span&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;mode and conversion&lt;/span&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt; or choose &lt;/span&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;example&lt;/span&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;You can also change program language.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand All @@ -48,7 +48,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>816</width>
<height>21</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuSoubor">
Expand Down Expand Up @@ -343,21 +343,21 @@ p, li { white-space: pre-wrap; }
</action>
<action name="action_save">
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Save</string>
</property>
</action>
<action name="action_open_file">
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Open</string>
Expand Down
31 changes: 31 additions & 0 deletions RegularConvertor/reg_exp/charpos.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
#include "charpos.h"
#include <QDataStream>

bool operator==(const CharPos& c1, const CharPos& c2)
{
return c1.charter == c2.charter && c1.pos == c2.pos && c1.terminal == c2.terminal &&
c1.bold == c2.bold;
}


QDataStream &operator<<(QDataStream &out, const CharPos& ch)
{
out << ch.charter << ch.pos << ch.terminal << ch.bold;
return out;
}


QDataStream &operator>>(QDataStream &in, CharPos& ch)
{
qint32 tmp_pos;
in >> ch.charter;
in >> tmp_pos;
in >> ch.terminal;
in >> ch.bold;
ch.pos = (int)tmp_pos;
return in;
}


//CharPos operator=(const CharPos c)
//{
// CharPos r;
// r.bold = c.bold;
// r.charter = c.charter;
// r.pos = c.pos;
// r.terminal = c.terminal;
// return r;
//}
17 changes: 16 additions & 1 deletion RegularConvertor/reg_exp/charpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QString>
#include <QList>
#include "finite_machine/computationalrules.h"


//Struktura ve které jsou uloženy data v uzlu stromu reprezentujici regulární výraz

Expand All @@ -21,12 +23,25 @@ struct CharPos
terminal = _terminal;
bold = _bold;
}
// CharPos operator=(const CharPos c)
// {
// CharPos r;
// r.bold = c.bold;
// r.charter = c.charter;
// r.pos = c.pos;
// r.terminal = c.terminal;
// return r;
// }
};

//operator nad strukturou
//operators above structure
bool operator==(const CharPos& c1, const CharPos& c2);


//pomocná konstanta dolaru, ktery s pouziva pri syntakticke analyze RV
const CharPos dolar("$",-1,true, false);
const CharPos emptyString (EMPTYSET,0,true);
QDataStream &operator<<(QDataStream& out, const CharPos& ch);
QDataStream &operator>>(QDataStream& in, CharPos& ch);

#endif // CHARPOS_H
3 changes: 2 additions & 1 deletion RegularConvertor/reg_exp/regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

RegExp::RegExp()
{
CharPos emptyString (EMPTYSET,0,true);
rootNode = new RegExpNode(emptyString);
}

Expand Down Expand Up @@ -157,11 +156,13 @@ void RegExp::clean()
QDataStream &operator<<(QDataStream &out, const RegExp &reg_exp)
{
out << reg_exp.regexp;
RegExpNode::save(reg_exp.rootNode, out);
return out;
}

QDataStream &operator>>(QDataStream &in, RegExp &reg_exp)
{
in >> reg_exp.regexp;
reg_exp.rootNode = RegExpNode::load(in);
return in;
}
4 changes: 2 additions & 2 deletions RegularConvertor/reg_exp/regexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "charpos.h"
#include "regexpnode.h"

#define EMPTY_SET

class RegExp
{
Expand All @@ -18,6 +17,8 @@ class RegExp

bool init(QString _strToVal);
QList<CharPos> addConcOperator(QString _reqExp);


RegExpParser parser;
RegExpNode* rootNode;
QString regexp;
Expand All @@ -37,7 +38,6 @@ class RegExp
static bool isAlphabetChar(QString symbol);
static QString precedenceTable[7][7];
void clean();

};

QDataStream &operator<<(QDataStream &out, const RegExp &reg_exp);
Expand Down
Loading

0 comments on commit 282cd19

Please sign in to comment.