Skip to content

Commit 3b8c92e

Browse files
committed
solution for reading graph
1 parent f9770af commit 3b8c92e

File tree

12 files changed

+173
-35
lines changed

12 files changed

+173
-35
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"source_location": "cpp",
6868
"stdfloat": "cpp",
6969
"cinttypes": "cpp",
70-
"typeindex": "cpp"
70+
"typeindex": "cpp",
71+
"list": "cpp"
7172
}
7273
}

CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
88

99
set(ARMADILLO_LIBRARY "C:\\armadillo\\lib")
1010
set(ARMADILLO_INCLUDE_DIR "C:\\armadillo\\include")
11+
set(BOOST_ROOT "C:/local/boost_1_85_0")
1112

12-
13-
set(Boost_USE_STATIC_LIBS ON) # Use static linking (optional)
13+
set(Boost_USE_STATIC_LIBS ON)
1414
set(Boost_USE_MULTITHREADED ON)
1515
set(Boost_USE_STATIC_RUNTIME OFF)
1616

17-
set(BOOST_ROOT "C:/local/boost_1_85_0")
18-
19-
find_package(Boost 1.85 REQUIRED COMPONENTS filesystem system program_options serialization chrono)
20-
2117
find_package(MKL REQUIRED)
2218

2319
find_package(Armadillo REQUIRED)
2420

21+
find_package(Boost 1.85 REQUIRED COMPONENTS
22+
filesystem
23+
system
24+
program_options
25+
serialization
26+
chrono
27+
log
28+
)
29+
2530
set(SOURCES
2631
src/main.cpp
2732
src/graphio.cpp
33+
src/graphfilebase.cpp
34+
src/graphfile.cpp
2835
src/fileio.cpp
2936
src/filereader.cpp
3037
src/filewriter.cpp

config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[database]
2-
source=C:\\Users\\Kacper\\Desktop\\DBGRAPH\\graphs\\db\\bin\\iso\\bvg\\b03
2+
source=C:\\Users\\Kacper\\Desktop\\DBGRAPH\\graphs\\db\\bin
33
target=D:\\db_test

include/fileio.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class FileIO {
2727
// defined config.ini properties
2828
static const std::string CONFIG_DB_SOURCE;
2929
static const std::string CONFIG_DB_TARGET;
30+
31+
// extensions, separators, etc.
32+
static const std::string CSV_EXTENSION;
33+
static const std::string UNDERSCORE;
3034
};
3135

3236
#endif //FILE_IO_H

include/graphfile.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#ifndef GRAPH_FILE_DETAILS
4+
#define GRAPH_FILE_DETAILS
5+
6+
#include "graphfilebase.hpp"
7+
#include <boost/algorithm/string.hpp>
8+
9+
class GraphFile : public GraphFileBase {
10+
11+
private:
12+
std::string congruence;
13+
std::string group;
14+
std::string size_group;
15+
std::string ordinal;
16+
17+
public:
18+
GraphFile(std::filesystem::path& path);
19+
const std::string build_target_absolute() const;
20+
};
21+
22+
#endif //GRAPH_FILE_DETAILS

include/graphfilebase.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#ifndef GRAPH_FILE_H
4+
#define GRAPH_FILE_H
5+
6+
#include "filereader.hpp"
7+
8+
class GraphFileBase : public FileIO {
9+
10+
private:
11+
FileReader reader;
12+
13+
std::string filename;
14+
std::string relative;
15+
std::string source_absolute;
16+
std::string target_absolute;
17+
std::string target_filename;
18+
19+
public:
20+
GraphFileBase(std::filesystem::path& path);
21+
void to_string() const;
22+
23+
// getters for instance
24+
const std::string get_filename() const;
25+
const std::string get_relative() const;
26+
const std::string get_source_absolute() const;
27+
const std::string get_target_absolute() const;
28+
const std::string get_target_filename() const;
29+
const FileReader get_reader() const;
30+
31+
// setters
32+
void set_target_absolute(std::string target_absolute);
33+
void set_target_filename(std::string target_filename);
34+
};
35+
36+
#endif //GRAPH_FILE_H

include/graphio.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#ifndef GRAPH_IO_H
44
#define GRAPH_IO_H
55

6+
#include <armadillo>
67
#include "filereader.hpp"
78
#include "filewriter.hpp"
9+
#include "graphfile.hpp"
810

911
class GraphIO {
1012

@@ -13,9 +15,7 @@ class GraphIO {
1315
FileWriter writer;
1416

1517
public:
16-
void generate_name(const std::string old_filename) const;
1718
void convert() const;
18-
1919
};
2020

2121
#endif //GRAPH_IO_H

src/fileio.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ const std::string FileIO::WINDOWS_SEPARATOR = "\\";
55
const std::string FileIO::CONFIG_FILE_PATH = "../config.ini";
66

77
const std::string FileIO::CONFIG_DB_SOURCE = "database.source";
8-
const std::string FileIO::CONFIG_DB_TARGET = "database.target";
8+
const std::string FileIO::CONFIG_DB_TARGET = "database.target";
9+
10+
const std::string FileIO::CSV_EXTENSION = ".csv";
11+
const std::string FileIO::UNDERSCORE = "_";

src/graphfile.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "graphfile.hpp"
2+
3+
GraphFile::GraphFile(std::filesystem::path &path) : GraphFileBase(path)
4+
{
5+
std::vector<std::string> filename_parts;
6+
boost::split(filename_parts, this->get_filename(), boost::is_any_of("_."));
7+
8+
this->congruence = filename_parts.at(0);
9+
this->group = filename_parts.at(1);
10+
this->size_group = filename_parts.at(2);
11+
this->ordinal = filename_parts.at(3);
12+
13+
this->set_target_filename(boost::algorithm::join(filename_parts, FileIO::UNDERSCORE).append(FileIO::CSV_EXTENSION));
14+
this->set_target_absolute(this->build_target_absolute());
15+
}
16+
17+
const std::string GraphFile::build_target_absolute() const
18+
{
19+
std::string target_uri = this->get_reader().read_property(FileIO::CONFIG_DB_TARGET);
20+
return target_uri
21+
.append(this->get_relative())
22+
.append(this->get_target_filename());
23+
}

src/graphfilebase.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "graphfilebase.hpp"
2+
3+
GraphFileBase::GraphFileBase(std::filesystem::path &path)
4+
{
5+
this->filename = path.filename().string();
6+
this->relative = this->reader.relative_path(path.parent_path().string(), this->reader.read_property(FileIO::CONFIG_DB_SOURCE));
7+
this->source_absolute = std::filesystem::absolute(path).string();
8+
}
9+
10+
void GraphFileBase::to_string() const
11+
{
12+
std::cout << std::string(60, '_') << std::endl;
13+
std::cout << "Filename: " << this->filename << std::endl;
14+
std::cout << "Relative: " << this->relative << std::endl;
15+
std::cout << "New filename: " << this->target_filename << std::endl;
16+
std::cout << "Source absolute path: " << this->source_absolute << std::endl;
17+
std::cout << "Target absolute path: " << this->target_absolute << std::endl;
18+
std::cout << std::string(60, '_') << std::endl;
19+
}
20+
21+
//getters
22+
23+
const std::string GraphFileBase::get_filename() const
24+
{
25+
return this->filename;
26+
}
27+
28+
const std::string GraphFileBase::get_relative() const
29+
{
30+
return this->relative;
31+
}
32+
33+
const std::string GraphFileBase::get_source_absolute() const
34+
{
35+
return this->source_absolute;
36+
}
37+
38+
const std::string GraphFileBase::get_target_absolute() const
39+
{
40+
return this->target_absolute;
41+
}
42+
43+
const std::string GraphFileBase::get_target_filename() const
44+
{
45+
return this->target_filename;
46+
}
47+
48+
const FileReader GraphFileBase::get_reader() const
49+
{
50+
return this->reader;
51+
}
52+
53+
void GraphFileBase::set_target_absolute(std::string target_absolute)
54+
{
55+
this->target_absolute = std::move(target_absolute);
56+
}
57+
58+
void GraphFileBase::set_target_filename(std::string target_filename)
59+
{
60+
this->target_filename = std::move(target_filename);
61+
}

0 commit comments

Comments
 (0)