Skip to content

Commit 1fed9af

Browse files
committed
Move functions to libPATO
1 parent 5ed7b0d commit 1fed9af

File tree

7 files changed

+84
-65
lines changed

7 files changed

+84
-65
lines changed

include/PATO/tfo_finder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ enum class find_tfo_motifs_result : unsigned {
3434
};
3535

3636
find_tfo_motifs_result find_tfo_motifs(const options_t &opts);
37+
bool handle_find_tfo_motifs_result(find_tfo_motifs_result result,
38+
std::ostream &errs, const options_t &opts);
3739

3840
} // namespace pato
3941

include/PATO/tpx_finder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum class find_tpx_result : unsigned {
3535
};
3636

3737
find_tpx_result find_tpxes(const options_t &opts);
38+
bool handle_find_tpx_result(find_tpx_result result, std::ostream &errs,
39+
const options_t &opts);
3840

3941
} // namespace pato
4042

include/PATO/tts_finder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ enum class find_tts_motifs_result : unsigned {
3434
};
3535

3636
find_tts_motifs_result find_tts_motifs(const options_t &opts);
37+
bool handle_find_tts_motifs_result(find_tts_motifs_result result,
38+
std::ostream &errs, const options_t &opts);
3739

3840
} // namespace pato
3941

lib/PATO/tfo_finder.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,19 @@ pato::find_tfo_motifs(const pato::options_t &opts) {
249249

250250
return pato::find_tfo_motifs_result::success;
251251
}
252+
253+
bool pato::handle_find_tfo_motifs_result(pato::find_tfo_motifs_result result,
254+
std::ostream &errs,
255+
const pato::options_t &opts) {
256+
switch (result) {
257+
case pato::find_tfo_motifs_result::success:
258+
return true;
259+
case pato::find_tfo_motifs_result::cannot_open_tfo_file:
260+
errs << "PATO: error opening input file '" << opts.tfo_file << "'\n";
261+
break;
262+
case pato::find_tfo_motifs_result::cannot_create_output_file:
263+
errs << "PATO: error opening output file '" << opts.output_file << "'\n";
264+
break;
265+
}
266+
return false;
267+
}

lib/PATO/tpx_finder.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,22 @@ pato::find_tpx_result pato::find_tpxes(const pato::options_t &opts) {
344344

345345
return pato::find_tpx_result::success;
346346
}
347+
348+
bool pato::handle_find_tpx_result(pato::find_tpx_result result,
349+
std::ostream &errs,
350+
const pato::options_t &opts) {
351+
switch (result) {
352+
case pato::find_tpx_result::success:
353+
return true;
354+
case pato::find_tpx_result::cannot_open_tfo_file:
355+
errs << "PATO: error opening input file '" << opts.tfo_file << "'\n";
356+
break;
357+
case pato::find_tpx_result::cannot_open_tts_file:
358+
errs << "PATO: error opening input file '" << opts.tts_file << "'\n";
359+
break;
360+
case pato::find_tpx_result::cannot_create_output_file:
361+
errs << "PATO: error opening output file '" << opts.output_file << "'\n";
362+
break;
363+
}
364+
return false;
365+
}

lib/PATO/tts_finder.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,19 @@ pato::find_tts_motifs(const pato::options_t &opts) {
216216

217217
return pato::find_tts_motifs_result::success;
218218
}
219+
220+
bool pato::handle_find_tts_motifs_result(pato::find_tts_motifs_result result,
221+
std::ostream &errs,
222+
const pato::options_t &opts) {
223+
switch (result) {
224+
case pato::find_tts_motifs_result::success:
225+
return true;
226+
case pato::find_tts_motifs_result::cannot_open_tts_file:
227+
errs << "PATO: error opening input file '" << opts.tts_file << "'\n";
228+
break;
229+
case pato::find_tts_motifs_result::cannot_create_output_file:
230+
errs << "PATO: error opening output file '" << opts.output_file << "'\n";
231+
break;
232+
}
233+
return false;
234+
}

tools/PATO/main.cpp

Lines changed: 27 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,6 @@
2727

2828
#include <iostream>
2929

30-
static int handle_tfo_search(const pato::options_t &opts) {
31-
switch (pato::find_tfo_motifs(opts)) {
32-
case pato::find_tfo_motifs_result::success:
33-
return 0;
34-
case pato::find_tfo_motifs_result::cannot_open_tfo_file:
35-
std::cerr << "PATO: error opening input file '" << opts.tfo_file << "'\n";
36-
break;
37-
case pato::find_tfo_motifs_result::cannot_create_output_file:
38-
std::cerr << "PATO: error opening output file '" << opts.output_file
39-
<< "'\n";
40-
break;
41-
}
42-
return 1;
43-
}
44-
45-
static int handle_tts_search(const pato::options_t &opts) {
46-
switch (pato::find_tts_motifs(opts)) {
47-
case pato::find_tts_motifs_result::success:
48-
return 0;
49-
case pato::find_tts_motifs_result::cannot_open_tts_file:
50-
std::cerr << "PATO: error opening input file '" << opts.tts_file << "'\n";
51-
break;
52-
case pato::find_tts_motifs_result::cannot_create_output_file:
53-
std::cerr << "PATO: error opening output file '" << opts.output_file
54-
<< "'\n";
55-
break;
56-
}
57-
return 1;
58-
}
59-
60-
static int handle_tpx_search(const pato::options_t &opts) {
61-
switch (pato::find_tpxes(opts)) {
62-
case pato::find_tpx_result::success:
63-
return 0;
64-
case pato::find_tpx_result::cannot_open_tfo_file:
65-
std::cerr << "PATO: error opening input file '" << opts.tfo_file << "'\n";
66-
break;
67-
case pato::find_tpx_result::cannot_open_tts_file:
68-
std::cerr << "PATO: error opening input file '" << opts.tts_file << "'\n";
69-
break;
70-
case pato::find_tpx_result::cannot_create_output_file:
71-
std::cerr << "PATO: error opening output file '" << opts.output_file
72-
<< "'\n";
73-
break;
74-
}
75-
return 1;
76-
}
77-
7830
namespace {
7931

8032
template <typename... Tys> struct visitors_t : Tys... {
@@ -87,21 +39,31 @@ template <typename... Tys> visitors_t(Tys...) -> visitors_t<Tys...>;
8739
int main(int argc, char *argv[]) {
8840
pato::parse_result_t result =
8941
pato::parse_command_line(argc, argv, std::cout, std::cerr);
90-
return std::visit(visitors_t{[](int return_code) { return return_code; },
91-
[](pato::options_t &opts) {
92-
int result;
93-
switch (opts.run_mode) {
94-
case pato::run_mode_t::tfo_search:
95-
result = handle_tfo_search(opts);
96-
break;
97-
case pato::run_mode_t::tts_search:
98-
result = handle_tts_search(opts);
99-
break;
100-
case pato::run_mode_t::tpx_search:
101-
result = handle_tpx_search(opts);
102-
break;
103-
}
104-
return result;
105-
}},
106-
result);
42+
return std::visit(
43+
visitors_t{
44+
[](int return_code) { return return_code; },
45+
[](pato::options_t &opts) {
46+
bool success = false;
47+
switch (opts.run_mode) {
48+
case pato::run_mode_t::tfo_search: {
49+
pato::find_tfo_motifs_result result = pato::find_tfo_motifs(opts);
50+
success =
51+
pato::handle_find_tfo_motifs_result(result, std::cerr, opts);
52+
break;
53+
}
54+
case pato::run_mode_t::tts_search: {
55+
pato::find_tts_motifs_result result = pato::find_tts_motifs(opts);
56+
success =
57+
pato::handle_find_tts_motifs_result(result, std::cerr, opts);
58+
break;
59+
}
60+
case pato::run_mode_t::tpx_search: {
61+
pato::find_tpx_result result = pato::find_tpxes(opts);
62+
success = pato::handle_find_tpx_result(result, std::cerr, opts);
63+
break;
64+
}
65+
}
66+
return success ? 0 : 1;
67+
}},
68+
result);
10769
}

0 commit comments

Comments
 (0)