Skip to content

Commit

Permalink
[MISC] Do not throw in destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Dec 6, 2019
1 parent 1d0c24b commit a1335e7
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 23 deletions.
12 changes: 10 additions & 2 deletions doc/tutorial/alignment_file/alignment_file_snippets.cpp
@@ -1,4 +1,6 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

//![include_aligned_sequence]
Expand All @@ -7,6 +9,8 @@

struct write_file_dummy_struct
{
std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"example.sam";

write_file_dummy_struct()
{

Expand All @@ -20,14 +24,18 @@ r003 2064 ref 29 17 5M * 0 0 TAGGC *
r001 147 ref 37 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)//![sam_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"example.sam"};
std::ofstream file{file_path};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"example.sam");
std::error_code ec{};
std::filesystem::remove(file_path, ec);

if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';
}
};

Expand Down
23 changes: 19 additions & 4 deletions doc/tutorial/alignment_file/alignment_file_solution2.cpp
@@ -1,11 +1,15 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const tmp_path = std::filesystem::temp_directory_path();

write_file_dummy_struct()
{

auto fasta_file_raw = R"//![ref_file](
>chr1
ACAGCAGGCATCTATCGGCGGATCGATCAGGCAGGCAGCTACTGG
Expand All @@ -23,19 +27,30 @@ r004 0 chr2 16 60 6M14N5M * 0 0 ATAGCTTCAGC *
r003 2064 chr2 18 10 5M * 0 0 TAGGC *
)//![sam_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"mapping.sam"};
std::ofstream file{tmp_path/"mapping.sam"};
std::string str{file_raw};
file << str.substr(1); // skip first newline

std::ofstream reffile{std::filesystem::temp_directory_path()/"reference.fasta"};
std::ofstream reffile{tmp_path/"reference.fasta"};
std::string fasta_file_rawstr{fasta_file_raw};
reffile << fasta_file_rawstr.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"mapping.sam");
std::filesystem::remove(std::filesystem::temp_directory_path()/"reference.fasta");
std::error_code ec{};
std::filesystem::path file_path{};

file_path = tmp_path/"mapping.sam";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

file_path = tmp_path/"reference.fasta";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

}
};

Expand Down
29 changes: 22 additions & 7 deletions doc/tutorial/sequence_file/sequence_file_snippets.cpp
Expand Up @@ -20,6 +20,8 @@

struct write_file_dummy_struct
{
std::filesystem::path const tmp_path = std::filesystem::temp_directory_path();

write_file_dummy_struct()
{

Expand All @@ -38,22 +40,36 @@ AGCGATCGAGGAATATAT
IIIIHHGIIIIHHGIIIH
)//![fastq_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"};
std::ofstream file{tmp_path/"my.fastq"};
std::string str{file_raw};
file << str.substr(1); // skip first newline

std::ofstream file2{std::filesystem::temp_directory_path()/"my.qq"};
std::ofstream file2{tmp_path/"my.qq"};
file2 << str.substr(1); // skip first newline

std::ofstream file3{std::filesystem::temp_directory_path()/"my.fasta"};
std::ofstream file3{tmp_path/"my.fasta"};
file3 << ">seq1\nAVAV\n>seq2\nAVAVA\n";
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.qq");
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fasta");
std::error_code ec{};
std::filesystem::path file_path{};

file_path = tmp_path/"my.fastq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

file_path = tmp_path/"my.qq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

file_path = tmp_path/"my.fasta";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';
}
};

Expand Down Expand Up @@ -178,5 +194,4 @@ sequence_file_output{tmp_dir/"output.fasta"} = sequence_file_input{tmp_dir/"my.f

std::filesystem::remove(std::filesystem::temp_directory_path()/"output.fasta");
std::filesystem::remove(std::filesystem::temp_directory_path()/"output.fastq");

}
11 changes: 9 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution1.cpp
@@ -1,9 +1,12 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fastq";

write_file_dummy_struct()
{

Expand All @@ -22,14 +25,18 @@ AGCGATCGAGGAATATAT
IIIIHHGIIIIHHGIIIH
)//![fastq_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"};
std::ofstream file{file_path};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::error_code ec{};
std::filesystem::remove(file_path, ec);

if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';
}
};

Expand Down
11 changes: 9 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution2.cpp
@@ -1,9 +1,12 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fasta";

write_file_dummy_struct()
{

Expand All @@ -14,14 +17,18 @@ AGCT
CGATCGA
)//![fasta_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fasta"};
std::ofstream file{file_path};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::error_code ec{};
std::filesystem::remove(file_path, ec);

if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';
}
};

Expand Down
11 changes: 9 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution3.cpp
@@ -1,9 +1,12 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fastq";

write_file_dummy_struct()
{

Expand All @@ -30,14 +33,18 @@ AGCTAGCAGCGATCG
IIIIIHIIJJIIIII
)//![fastq_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"};
std::ofstream file{file_path};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::error_code ec{};
std::filesystem::remove(file_path, ec);

if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';
}
};

Expand Down
19 changes: 17 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution4.cpp
@@ -1,9 +1,12 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const tmp_path = std::filesystem::temp_directory_path();

write_file_dummy_struct()
{

Expand All @@ -30,14 +33,26 @@ AGCTAGCAGCGATCG
IIIIIHIIJJIIIII
)//![fastq_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"};
std::ofstream file{tmp_path/"my.fastq"};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::error_code ec{};
std::filesystem::path file_path{};

file_path = tmp_path/"my.fastq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

file_path = tmp_path/"output.fastq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

}
};

Expand Down
19 changes: 17 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution5.cpp
@@ -1,9 +1,12 @@
#include <fstream>

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/std/filesystem>

struct write_file_dummy_struct
{
std::filesystem::path const tmp_path = std::filesystem::temp_directory_path();

write_file_dummy_struct()
{

Expand All @@ -30,14 +33,26 @@ AGCTAGCAGCGATCG
IIIIIHIIJJIIIII
)//![fastq_file]";

std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"};
std::ofstream file{tmp_path/"my.fastq"};
std::string str{file_raw};
file << str.substr(1); // skip first newline
}

~write_file_dummy_struct()
{
std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq");
std::error_code ec{};
std::filesystem::path file_path{};

file_path = tmp_path/"my.fastq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

file_path = tmp_path/"output.fastq";
std::filesystem::remove(file_path, ec);
if (ec)
seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n';

}
};

Expand Down
3 changes: 3 additions & 0 deletions test/include/seqan3/test/tmp_filename.hpp
Expand Up @@ -118,6 +118,9 @@ class tmp_filename
}

/*!\brief Destructs the temporary directory path.
*
* \details
*
* Removes the temporary directory and all its subdirectories and files contained.
*/
~tmp_filename()
Expand Down

0 comments on commit a1335e7

Please sign in to comment.