Skip to content

Commit 5449eb3

Browse files
committed
Modernize code to C++11
* All APIs should be callable with size parameters.
1 parent c6a2450 commit 5449eb3

File tree

4 files changed

+402
-443
lines changed

4 files changed

+402
-443
lines changed

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $(PROG) $(EXAMPLE): $(LOBJS)
3636
endif
3737

3838
$(EXAMPLE_CPP): example.cpp $(LOBJS) $(LCPPOBJS)
39-
$(CXX) $(LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ -lm -lz
39+
$(CXX) $(LDFLAGS) $(CPPFLAGS) -std=c++11 -pedantic $(CXXFLAGS) -o $@ $^ -lm -lz
4040

4141
$(JAVA_LIB): sswjni.c ssw.c ssw.h
4242
$(CC) $(CFLAGS) $(JAVA_INLCUDES) -fPIC -shared -rdynamic -o $@ $< ssw.c
@@ -57,7 +57,7 @@ ssw.o: ssw.c ssw.h
5757
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
5858

5959
ssw_cpp.o: ssw_cpp.cpp ssw_cpp.h ssw.h
60-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
60+
$(CXX) $(CPPFLAGS) -std=c++11 -pedantic $(CXXFLAGS) -c -o $@ $<
6161

6262
clean:
6363
-rm -f $(LOBJS) $(LCPPOBJS) $(PROG) $(LIB) $(EXAMPLE) $(EXAMPLE_CPP) $(JAVA_LIB) $(JAVA_JAR) $(JAVA_OBJ) *~

src/example.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
// Last revision by Mengyao Zhao on 2023-Apr-21
99
// ==========================
1010

11+
#include <algorithm>
1112
#include <iostream>
12-
#include <string.h>
13+
#include <string>
1314

1415
#include "ssw_cpp.h"
1516

16-
using std::string;
1717
using std::cout;
1818
using std::endl;
19+
using std::string;
1920

2021
static void PrintAlignment(const StripedSmithWaterman::Alignment& alignment);
2122

2223
int main() {
23-
const string ref = "CAGCCTTTCTGACCCGGAAATCAAAATAGGCACAACAAA";
24-
const string query = "CTGAGCCGGTAAATC";
25-
int32_t maskLen = strlen(query.c_str())/2;
26-
maskLen = maskLen < 15 ? 15 : maskLen;
24+
const string ref = "CAGCCTTTCTGACCCGGAAATCAAAATAGGCACAACAAA";
25+
const string query = "CTGAGCCGGTAAATC";
26+
const int32_t maskLen = std::max(query.size() / 2, size_t(15));
2727

2828
// Declares a default Aligner
2929
StripedSmithWaterman::Aligner aligner;
@@ -32,14 +32,14 @@ int main() {
3232
// Declares an alignment that stores the result
3333
StripedSmithWaterman::Alignment alignment;
3434
// Aligns the query to the ref
35-
aligner.Align(query.c_str(), ref.c_str(), ref.size(), filter, &alignment, maskLen);
35+
aligner.Align(query.c_str(), query.size(), ref.c_str(), ref.size(), filter, alignment, maskLen);
3636

3737
PrintAlignment(alignment);
3838

3939
return 0;
4040
}
4141

42-
static void PrintAlignment(const StripedSmithWaterman::Alignment& alignment){
42+
static void PrintAlignment(const StripedSmithWaterman::Alignment& alignment) {
4343
cout << "===== SSW result =====" << endl;
4444
cout << "Best Smith-Waterman score:\t" << alignment.sw_score << endl
4545
<< "Next-best Smith-Waterman score:\t" << alignment.sw_score_next_best << endl

0 commit comments

Comments
 (0)