Skip to content

Commit

Permalink
Add dsplib/assert.h header. Remove dsplib/throw.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalsong committed Sep 8, 2024
1 parent 9c8e513 commit 8cc8226
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 52 deletions.
1 change: 1 addition & 0 deletions include/dsplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <dsplib/resample.h>
#include <dsplib/spectrum.h>
#include <dsplib/stft.h>
#include <dsplib/assert.h>

#include <dsplib/audio/noise-gate.h>
#include <dsplib/audio/compressor.h>
Expand Down
2 changes: 1 addition & 1 deletion include/dsplib/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <dsplib/types.h>
#include <dsplib/slice.h>
#include <dsplib/indexing.h>
#include <dsplib/throw.h>
#include <dsplib/assert.h>

namespace dsplib {

Expand Down
44 changes: 44 additions & 0 deletions include/dsplib/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <dsplib/defs.h>
#include <cassert>

#ifdef DSPLIB_NO_EXCEPTIONS

#include <iostream>

//TODO: add filename to message
#define DSPLIB_THROW(MSG) \
std::cerr << (std::string("dsplib: ") + MSG) << std::endl; \
std::abort();

#else

#include <stdexcept>

#define DSPLIB_THROW(MSG) throw std::runtime_error(std::string("dsplib: ") + MSG);

Check warning on line 19 in include/dsplib/assert.h

View check run for this annotation

Codecov / codecov/patch

include/dsplib/assert.h#L19

Added line #L19 was not covered by tests

#endif

#define DSPLIB_ASSERT(condition, message) \
if (!(condition)) { \
DSPLIB_THROW(message); \

Check warning on line 25 in include/dsplib/assert.h

View check run for this annotation

Codecov / codecov/patch

include/dsplib/assert.h#L25

Added line #L25 was not covered by tests
}

#ifdef _MSC_VER
#define DSPLIB_ASSUME(cond) \
assert(cond); \
__assume(cond);
#elif defined(__clang__)
#define DSPLIB_ASSUME(cond) \
assert(cond); \
__builtin_assume(cond)
#elif defined(__GNUC__)
#define DSPLIB_ASSUME(cond) \
assert(cond); \
((cond) ? static_cast<void>(0) : __builtin_unreachable());
#else
#define DSPLIB_ASSUME(cond) \
assert(cond); \
static_cast<void>((cond) ? 0 : 0);
#endif
2 changes: 1 addition & 1 deletion include/dsplib/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <algorithm>
#include <cstring>

#include <dsplib/throw.h>
#include <dsplib/assert.h>
#include <dsplib/iterator.h>

namespace dsplib {
Expand Down
36 changes: 0 additions & 36 deletions include/dsplib/throw.h

This file was deleted.

1 change: 0 additions & 1 deletion lib/agc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <dsplib/math.h>
#include <cmath>

#include "dsplib/throw.h"
#include "ma-filter.h"

namespace dsplib {
Expand Down
2 changes: 2 additions & 0 deletions lib/corr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ real_t corr(const arr_real& x, const arr_real& y, Correlation type) {
return _spearman_corr(x, y);
case Correlation::Kendall:
return _kendall_corr(x, y);
default:
return 0;

Check warning on line 85 in lib/corr.cpp

View check run for this annotation

Codecov / codecov/patch

lib/corr.cpp#L84-L85

Added lines #L84 - L85 were not covered by tests
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/fft/czt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <dsplib/ifft.h>
#include <dsplib/math.h>
#include <dsplib/utils.h>
#include <dsplib/throw.h>

#include <memory>

Expand Down
1 change: 0 additions & 1 deletion lib/fft/pow2-fft.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "fft/pow2-fft.h"

#include <dsplib/math.h>
#include <dsplib/throw.h>
#include <dsplib/types.h>

#include <cmath>
Expand Down
1 change: 0 additions & 1 deletion lib/fft/primes-fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "dsplib/czt.h"
#include "dsplib/fft.h"
#include "dsplib/math.h"
#include "dsplib/throw.h"
#include "dsplib/utils.h"

#include <cassert>
Expand Down
3 changes: 1 addition & 2 deletions lib/hilbert.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <dsplib/throw.h>
#include <dsplib/window.h>
#include <dsplib/hilbert.h>
#include <dsplib/window.h>
#include <dsplib/fft.h>
#include <dsplib/ifft.h>
#include <dsplib/math.h>
Expand Down
2 changes: 0 additions & 2 deletions lib/lru-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <cassert>
#include <cstddef>

#include <dsplib/throw.h>

namespace dsplib {

template<typename Key, typename Value>
Expand Down
1 change: 0 additions & 1 deletion lib/math.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "dsplib/array.h"
#include "dsplib/keywords.h"
#include "dsplib/math.h"
#include "dsplib/throw.h"
#include "dsplib/types.h"
#include "dsplib/utils.h"

Expand Down
1 change: 0 additions & 1 deletion lib/medfilt.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <dsplib/medfilt.h>
#include <dsplib/utils.h>
#include <dsplib/throw.h>

#include <cassert>
#include <algorithm>
Expand Down
1 change: 0 additions & 1 deletion lib/resample/fir-decimator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "dsplib/resample.h"
#include "dsplib/throw.h"

namespace dsplib {

Expand Down
1 change: 0 additions & 1 deletion lib/resample/fir-rate-converter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "dsplib/resample.h"
#include "dsplib/throw.h"

#include <cassert>

Expand Down
1 change: 0 additions & 1 deletion lib/snr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <dsplib/window.h>
#include <dsplib/math.h>
#include <dsplib/utils.h>
#include <dsplib/throw.h>

#include <utility>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion lib/spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "dsplib/fft.h"
#include "dsplib/keywords.h"
#include "dsplib/math.h"
#include "dsplib/throw.h"
#include "dsplib/utils.h"
#include "dsplib/window.h"

Expand Down

0 comments on commit 8cc8226

Please sign in to comment.