This commit is contained in:
Zengtudor 2024-09-18 15:53:36 +08:00
parent 9dfa5e7bac
commit 5be58df294
2 changed files with 18 additions and 14 deletions

View File

@ -1,15 +1,19 @@
#include <exception> #include <exception>
#include <filesystem> #include <filesystem>
#include<fstream> #include<fstream>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include<string> #include<string>
#include<algorithm> #include<algorithm>
#include<iostream> #include<iostream>
#include <type_traits>
#include"tools.hpp" #include"tools.hpp"
// std::string reversedComplement(std::string DNAsequence); // std::string reversedComplement(std::string DNAsequence);
#define OPEN_IFS_AND_CHECK(file_path,value_name)std::ifstream value_name(file_path);if(value_name.is_open()==false){std::stringstream ss;ss<<"cannot open input file stream : "<<file_path.filename();throw std::runtime_error(ss.str());}
#define OPEN_OFS_AND_CHECK(file_path,value_name)std::ofstream value_name(file_path);if(value_name.is_open()==false){std::stringstream ss;ss<<"cannot open output file stream : "<<file_path.filename();throw std::runtime_error(ss.str());}
std::string reverseComplement(std::string DNAsequence) std::string reverseComplement(std::string DNAsequence)
{ {
using namespace std; using namespace std;
@ -40,12 +44,10 @@ std::string reverseComplement(std::string DNAsequence)
return l; return l;
} }
int main() int main()
{ {
try{ try{
std::ios_base::sync_with_stdio(false); //加了没效果 // std::ios_base::sync_with_stdio(false); //加了没效果
using namespace std; using namespace std;
char buf[50000]; char buf[50000];
@ -53,8 +55,10 @@ int main()
filesystem::path input_path("filteredReads.txt"),output_path("reversedSequence.txt"); filesystem::path input_path("filteredReads.txt"),output_path("reversedSequence.txt");
ifstream input_file_stream(input_path); // ifstream input_file_stream(input_path);
ofstream output_file_stream(output_path); // ofstream output_file_stream(output_path);
OPEN_IFS_AND_CHECK(input_path, input_file_stream)
OPEN_OFS_AND_CHECK(output_path, output_file_stream)
zt::check_fstream_isopen(input_file_stream, output_file_stream); zt::check_fstream_isopen(input_file_stream, output_file_stream);

View File

@ -70,12 +70,12 @@ namespace zt {
return; return;
} }
template <class ...Args> // template <class ...Args>
inline void check_fstream_isopen(const Args&...args)noexcept(false){ // inline void check_fstream_isopen(const Args&...args)noexcept(false){
bool is_open=true; // bool is_open=true;
(((!args.is_open())?is_open=false:true),...); // (((!args.is_open())?is_open=false:true),...);
if(is_open==false){ // if(is_open==false){
throw std::runtime_error("cannot open file stream "); // throw std::runtime_error("cannot open file stream ");
} // }
} // }
} }