Skip to content

Commit 1b41c6c

Browse files
committed
refactorization work part 3
1 parent 0494fa8 commit 1b41c6c

File tree

11 files changed

+49
-41
lines changed

11 files changed

+49
-41
lines changed

include/graphconverter.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class GraphConverter
2424
GReader reader;
2525
GWriter writer;
2626
FileReader config;
27-
// FilesystemUtils fs_utils;
2827
ResourceLocation resource;
2928

3029
public:

include/graphreader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class GraphReader : public IReadable
1212
{
1313
public:
14-
virtual GFile* read(GFile &file);
14+
virtual GFile* read(GFile &file) const;
1515
private:
1616
unsigned short read_word(FILE* in) const;
1717
void read_graph(FILE* in, VGraphFile &file) const;

include/greader.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@
77
#include <cassert>
88
#include <memory>
99

10+
/*
11+
12+
explicit Context(std::unique_ptr<Strategy> &&strategy = {}) : strategy_(std::move(strategy))
13+
void set_strategy(std::unique_ptr<Strategy> &&strategy)
14+
15+
*/
16+
1017
class GReader
1118
{
1219
private:
13-
IReadable* gcontext;
20+
std::unique_ptr<IReadable> context;
21+
// IReadable* gcontext;
1422
public:
15-
GReader(){};
16-
GReader(IReadable &gcontext);
17-
void set_context(IReadable &gcontext);
23+
// GReader(){};
24+
// explicit GReader(std::unique_ptr<IReadable> &&context = {}) : context(std::move(context)){};
25+
void set_context(std::unique_ptr<IReadable> &&context);
26+
// GReader(IReadable &gcontext);
27+
// void set_context(IReadable &gcontext);
1828
GFile* read(GFile &file) const;
1929
};
2030

include/groundreader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class GroundReader : public IReadable
1010
{
1111
public:
12-
virtual GFile* read(GFile &file);
12+
virtual GFile* read(GFile &file) const;
1313
private:
1414
};
1515

include/gwriter.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
class GWriter
1212
{
1313
private:
14-
std::unique_ptr<IWriteable> gcontext;
14+
std::unique_ptr<IWriteable> context;
1515
public:
16-
GWriter(){};
17-
GWriter(std::unique_ptr<IWriteable> &gcontext);
18-
void set_context(std::unique_ptr<IWriteable> &gcontext);
16+
void set_context(std::unique_ptr<IWriteable> &&context);
1917
bool write(GFile &file) const;
2018
};
2119

include/ireadable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IReadable
99
{
1010
public:
1111
virtual ~IReadable() = default;
12-
virtual GFile* read(GFile &file) = 0;
12+
virtual GFile* read(GFile &file) const = 0;
1313
};
1414

1515

src/graphconverter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void GraphConverter::preactions() const
1515

1616
void GraphConverter::postactions()
1717
{
18-
// reader.set_context(std::make_unique<GroundReader>());
19-
// writer.set_context(std::make_unique<GroundWriter>());
18+
reader.set_context(std::make_unique<GroundReader>());
19+
writer.set_context(std::make_unique<GroundWriter>());
2020

2121
GroundFile* ground;
2222

@@ -46,10 +46,10 @@ void GraphConverter::postactions()
4646

4747
void GraphConverter::convert()
4848
{
49-
// reader.set_context(std::make_unique<GraphReader>());
50-
// writer.set_context(std::make_unique<GraphWriter>());
51-
GraphReader* greader = new GraphReader();
52-
GraphWriter* gwriter = new GraphWriter();
49+
reader.set_context(std::make_unique<GraphReader>());
50+
writer.set_context(std::make_unique<GraphWriter>());
51+
// GraphReader* greader = new GraphReader();
52+
// GraphWriter* gwriter = new GraphWriter();
5353
// reader.set_context(greader);
5454
// writer.set_context(gwriter);
5555

@@ -60,7 +60,7 @@ void GraphConverter::convert()
6060
if (std::filesystem::is_regular_file(entry.path())) {
6161
graph = new VGraphFile(entry.path());
6262
try {
63-
graph = dynamic_cast<VGraphFile*>(greader->read(*graph));
63+
graph = dynamic_cast<VGraphFile*>(reader.read(*graph));
6464
graph->build_target_absolute(this->resource);
6565
} catch (std::exception ex) {
6666
BOOST_LOG_TRIVIAL(error) << "An error occured during reading graph file";
@@ -69,7 +69,7 @@ void GraphConverter::convert()
6969

7070
try {
7171
// this->writer.write(*graph);
72-
gwriter->write(*graph);
72+
writer.write(*graph);
7373
BOOST_LOG_TRIVIAL(info) << "Graph was processed (" << processed << "/" << 145600 << ")";
7474
} catch (std::exception ex) {
7575
BOOST_LOG_TRIVIAL(error) << "An error occured during writing graph file";
@@ -80,8 +80,8 @@ void GraphConverter::convert()
8080
}
8181
}
8282
delete graph;
83-
delete greader;
84-
delete gwriter;
83+
// delete greader;
84+
// delete gwriter;
8585
BOOST_LOG_TRIVIAL(info) << "Database was processed";
8686
}
8787

src/graphreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "graphreader.hpp"
22

3-
GFile* GraphReader::read(GFile &file)
3+
GFile* GraphReader::read(GFile &file) const
44
{
55
FILE* in = fopen(file.absolute().string().c_str(), "rb");
66

src/greader.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
#include "greader.hpp"
22

3-
GReader::GReader(IReadable &gcontext)
4-
{
5-
this->gcontext = &gcontext;
6-
}
3+
// GReader::GReader(IReadable &gcontext)
4+
// {
5+
// this->gcontext = &gcontext;
6+
// }
7+
8+
// void GReader::set_context(IReadable &gcontext)
9+
// {
10+
// this->gcontext = &gcontext;
11+
// }
712

8-
void GReader::set_context(IReadable &gcontext)
13+
void GReader::set_context(std::unique_ptr<IReadable> &&context)
914
{
10-
this->gcontext = &gcontext;
15+
this->context = std::move(context);
1116
}
1217

13-
GFile* GReader::read(GFile &file) const
18+
GFile *GReader::read(GFile &file) const
1419
{
15-
return gcontext->read(file);
20+
assert(context);
21+
return context->read(file);
1622
}

src/groundreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "groundreader.hpp"
22

3-
GFile* GroundReader::read(GFile &file)
3+
GFile* GroundReader::read(GFile &file) const
44
{
55
return new GroundFile();
66
}

0 commit comments

Comments
 (0)