Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakub Janák
tss
Commits
a3fb1ab4
Commit
a3fb1ab4
authored
4 months ago
by
Jakub Janák
Browse files
Options
Downloads
Patches
Plain Diff
you could have overridden the file with a new one in save solution, this is solved
parent
e51da794
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
files/FileManager.cpp
+27
-9
27 additions, 9 deletions
files/FileManager.cpp
files/FileManager.h
+3
-3
3 additions, 3 deletions
files/FileManager.h
with
30 additions
and
12 deletions
files/FileManager.cpp
+
27
−
9
View file @
a3fb1ab4
...
...
@@ -17,14 +17,14 @@ const std::string FileManager::INSTANCES_PATH = "../files/instances";
const
std
::
string
FileManager
::
RESULTS_PATH
=
"../files/results"
;
std
::
unique_ptr
<
TSInstance
>
FileManager
::
readDotFile
(
const
std
::
string
&
filename
)
{
std
::
unique_ptr
<
TSInstance
>
FileManager
::
readDotFile
(
const
std
::
string
&
file
_
name
)
{
// graphviz context
GVC_t
*
gvc
=
gvContext
();
// Open the .dot file
FILE
*
file
=
fopen
(
filename
.
c_str
(),
"r"
);
FILE
*
file
=
fopen
(
file
_
name
.
c_str
(),
"r"
);
if
(
!
file
)
{
std
::
cout
<<
"Error opening file: "
<<
filename
<<
" in: "
<<
INSTANCES_PATH
<<
std
::
endl
;
std
::
cout
<<
"Error opening file: "
<<
file
_
name
<<
" in: "
<<
INSTANCES_PATH
<<
std
::
endl
;
return
nullptr
;
}
...
...
@@ -33,7 +33,7 @@ std::unique_ptr<TSInstance> FileManager::readDotFile(const std::string &filename
fclose
(
file
);
if
(
!
graph
)
{
std
::
cout
<<
"Error reading DOT file: "
<<
filename
<<
std
::
endl
;
std
::
cout
<<
"Error reading DOT file: "
<<
file
_
name
<<
std
::
endl
;
return
nullptr
;
}
...
...
@@ -88,9 +88,9 @@ std::unique_ptr<TSInstance> FileManager::readDotFile(const std::string &filename
return
std
::
make_unique
<
TSInstance
>
(
std
::
move
(
nodes
),
std
::
move
(
edges
));
}
std
::
vector
<
std
::
filesystem
::
directory_entry
>
FileManager
::
getDotInstances
(
const
std
::
string
&
directory
P
ath
)
{
std
::
vector
<
std
::
filesystem
::
directory_entry
>
FileManager
::
getDotInstances
(
const
std
::
string
&
directory
_p
ath
)
{
std
::
vector
<
std
::
filesystem
::
directory_entry
>
entries
;
for
(
const
auto
&
entry
:
std
::
filesystem
::
directory_iterator
(
directory
P
ath
))
{
for
(
const
auto
&
entry
:
std
::
filesystem
::
directory_iterator
(
directory
_p
ath
))
{
if
(
entry
.
is_regular_file
()
&&
entry
.
path
().
extension
()
==
".dot"
)
{
std
::
cout
<<
"found: "
<<
entry
.
path
().
filename
()
<<
std
::
endl
;
entries
.
push_back
(
entry
);
...
...
@@ -99,11 +99,29 @@ std::vector<std::filesystem::directory_entry> FileManager::getDotInstances(const
return
entries
;
}
void
FileManager
::
saveSolution
(
const
std
::
string
&
fileName
,
const
std
::
string
&
fileContent
)
{
void
FileManager
::
saveSolution
(
const
std
::
string
&
file_name
,
const
std
::
string
&
file_content
)
{
// creating the results folder if not exists
if
(
!
std
::
filesystem
::
exists
(
RESULTS_PATH
))
{
if
(
std
::
filesystem
::
create_directory
(
RESULTS_PATH
))
{
std
::
cout
<<
"Created results directory: "
<<
RESULTS_PATH
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Error creating results directory: "
<<
RESULTS_PATH
<<
std
::
endl
;
}
}
// check for output file conflicts
int
num
=
1
;
std
::
string
output_file
;
do
{
std
::
string
number_string
=
(
num
==
1
)
?
""
:
"_"
+
std
::
to_string
(
num
);
output_file
=
RESULTS_PATH
+
"/"
+
file_name
+
number_string
+
".dot"
;
num
++
;
}
while
(
std
::
filesystem
::
exists
(
output_file
));
// Check if the file is open
if
(
std
::
ofstream
outFile
(
RESULTS_PATH
+
"/"
+
fileName
+
".dot"
);
outFile
.
is_open
())
{
if
(
std
::
ofstream
outFile
(
output_file
);
outFile
.
is_open
())
{
// Write the string to the file
outFile
<<
file
C
ontent
;
outFile
<<
file
_c
ontent
;
// Close the file
outFile
.
close
();
...
...
This diff is collapsed.
Click to expand it.
files/FileManager.h
+
3
−
3
View file @
a3fb1ab4
...
...
@@ -16,11 +16,11 @@ public:
static
const
std
::
string
RESULTS_PATH
;
static
std
::
unique_ptr
<
TSInstance
>
readDotFile
(
const
std
::
string
&
filename
);
static
std
::
unique_ptr
<
TSInstance
>
readDotFile
(
const
std
::
string
&
file
_
name
);
static
std
::
vector
<
std
::
filesystem
::
directory_entry
>
getDotInstances
(
const
std
::
string
&
directory
P
ath
);
static
std
::
vector
<
std
::
filesystem
::
directory_entry
>
getDotInstances
(
const
std
::
string
&
directory
_p
ath
);
static
void
saveSolution
(
const
std
::
string
&
file
N
ame
,
const
std
::
string
&
file
C
ontent
);
static
void
saveSolution
(
const
std
::
string
&
file
_n
ame
,
const
std
::
string
&
file
_c
ontent
);
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment