Skip to content

Commit 2637a4e

Browse files
committed
Release v0.10.3
* Add clang-tidy to CI pipeline * Fix minor linting issue * Fix example build
2 parents da70f8e + 82540c8 commit 2637a4e

File tree

14 files changed

+121
-64
lines changed

14 files changed

+121
-64
lines changed

.clang-tidy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# https://clang.llvm.org/extra/clang-tidy/checks/list.html
2+
3+
# gtest's TEST & TEST_F trigger
4+
# - cppcoreguidelines-owning-memory (TEST_F only)
5+
# - cppcoreguidelines-special-member-functions
6+
# - modernize-use-equals-delete
7+
8+
# gtest's ASSERT_THROW & ASSERT_NO_THROW trigger
9+
# cppcoreguidelines-avoid-goto
10+
11+
# gtest's ASSERT_EQ triggers
12+
# cppcoreguidelines-pro-type-vararg
13+
14+
# cppcoreguidelines-pro-bounds-array-to-pointer-decay reports:
15+
# lib/HdfFile.cpp:118:33: warning: do not implicitly decay an array into a pointer;
16+
# consider using gsl::array_view or an explicit cast instead
17+
# char nameGroup[MAX_NAME_LENGTH];
18+
# ...
19+
# if (name == std::string(nameGroup)) {
20+
# ^
21+
22+
Checks: >-
23+
bugprone-*,
24+
cppcoreguidelines-*,
25+
-cppcoreguidelines-avoid-goto,
26+
-cppcoreguidelines-owning-memory,
27+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
28+
-cppcoreguidelines-pro-type-vararg,
29+
-cppcoreguidelines-special-member-functions,
30+
misc-*,
31+
modernize-*,
32+
-modernize-use-equals-delete,
33+
performance-*,
34+
readability-*,
35+
36+
# TODO fix remaining warnings in this list
37+
WarningsAsErrors: >-
38+
*,
39+
-clang-diagnostic-return-type,
40+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ install:
2121

2222
script:
2323
# https://cmake.org/cmake/help/v3.12/module/FindGTest.html
24-
- GTEST_ROOT="$PWD/gtest" cmake .
24+
- GTEST_ROOT="$PWD/gtest"
25+
cmake
26+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
27+
-DCMAKE_CXX_CLANG_TIDY='clang-tidy;-p=compile_commands.json'
28+
.
2529
- make --jobs=$(nproc)
2630
- tests/hdf4cpp-tests

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ endif ()
6767
option(HDF4CPP_BUILD_TESTS "Enable building tests" ON)
6868
option(HDF4CPP_BUILD_EXAMPLES "Enable building examples" ON)
6969

70+
if (NOT DEFINED TEST_DATA_PATH)
71+
set(TEST_DATA_PATH "${PROJECT_SOURCE_DIR}/tests/test_data/")
72+
message(STATUS "No path to test data defined, using ${TEST_DATA_PATH} as default")
73+
endif ()
74+
7075
if (HDF4CPP_BUILD_TESTS)
7176
add_subdirectory(tests)
7277
endif()

examples/ReadingSData.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using namespace hdf4cpp;
88

9+
// NOLINTNEXTLINE(bugprone-exception-escape)
910
int main() {
1011
// Open the file
1112
HdfFile file(TEST_DATA_PATH "small_test.hdf");
@@ -33,9 +34,9 @@ int main() {
3334
std::vector<int32> dims = item.getDims();
3435
for (const auto &dim : dims) {
3536
if (dim >= 1) {
36-
ranges.push_back(Range(0, dim - 1));
37+
ranges.emplace_back(0, dim - 1);
3738
} else {
38-
ranges.push_back(Range(0, dim));
39+
ranges.emplace_back(0, dim);
3940
}
4041
}
4142
item.read(vec, ranges);

examples/ReadingVData.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using namespace hdf4cpp;
88

9+
// NOLINTNEXTLINE(bugprone-exception-escape)
910
int main() {
1011
// Open the file
1112
HdfFile file(TEST_DATA_PATH "small_test.hdf");
@@ -43,4 +44,4 @@ int main() {
4344
}
4445
std::cout << std::endl;
4546
}
46-
}
47+
}

include/hdf4cpp/HdfAttribute.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class HdfAttribute : public HdfObject {
5151
int32 size() const;
5252

5353
private:
54-
int32 _size;
55-
int32 dataType;
54+
int32 _size{};
55+
int32 dataType{};
5656

5757
void get(void *dest);
5858
int32 getDataType() const;
@@ -81,17 +81,17 @@ class HdfAttribute : public HdfObject {
8181
int32 size() const;
8282

8383
private:
84-
int32 _size;
85-
int32 dataType;
84+
int32 _size{};
85+
int32 dataType{};
8686
void get(void *dest);
8787
int32 getDataType() const;
8888
};
8989

9090
public:
9191
HdfAttribute(const HdfAttribute &) = delete;
92-
HdfAttribute(HdfAttribute &&other);
92+
HdfAttribute(HdfAttribute &&other) noexcept;
9393
HdfAttribute &operator=(const HdfAttribute &attribute) = delete;
94-
HdfAttribute &operator=(HdfAttribute &&other);
94+
HdfAttribute &operator=(HdfAttribute &&other) noexcept;
9595
/// \returns the number of elements of the attribute data
9696
int32 size() const;
9797

include/hdf4cpp/HdfFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class HdfFile : public HdfObject {
2020
public:
2121
HdfFile(const std::string &path);
2222
HdfFile(const HdfFile &file) = delete;
23-
HdfFile(HdfFile &&file);
23+
HdfFile(HdfFile &&file) noexcept;
2424
HdfFile &operator=(const HdfFile &file) = delete;
25-
HdfFile &operator=(HdfFile &&file);
25+
HdfFile &operator=(HdfFile &&file) noexcept;
2626
~HdfFile();
2727

2828
int32 getSId() const;

include/hdf4cpp/HdfItem.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class HdfAttribute;
6161
class HdfItem : public HdfObject {
6262
public:
6363
HdfItem(const HdfItem &item) = delete;
64-
HdfItem(HdfItem &&item);
64+
HdfItem(HdfItem &&other) noexcept;
6565
HdfItem &operator=(const HdfItem &item) = delete;
66-
HdfItem &operator=(HdfItem &&it);
66+
HdfItem &operator=(HdfItem &&it) noexcept;
6767

6868
/// \returns The name of the item
6969
std::string getName() const;
@@ -216,7 +216,7 @@ class HdfItem : public HdfObject {
216216

217217
private:
218218
int32 _size;
219-
int32 dataType;
219+
int32 dataType{};
220220
std::string name;
221221
std::vector<int32> dims;
222222
};
@@ -332,12 +332,11 @@ class HdfItem : public HdfObject {
332332
}
333333

334334
private:
335-
int32 _size;
336335
std::string name;
337336

338-
int32 nrRecords;
339-
int32 interlace;
340-
int32 recordSize;
337+
int32 nrRecords{};
338+
int32 interlace{};
339+
int32 recordSize{};
341340
};
342341

343342
HdfItem(HdfItemBase *item, int32 sId, int32 vId);

include/hdf4cpp/HdfObject.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class HdfObject {
2424
: endFunction(endFunction)
2525
, id(id) {
2626
}
27+
HdfDestroyer(const HdfDestroyer& other)
28+
: endFunction(other.endFunction)
29+
, id(other.id) {
30+
}
2731
~HdfDestroyer() {
2832
endFunction(id);
2933
}
@@ -38,14 +42,24 @@ class HdfObject {
3842
/// then the destructor of the destroyer will call the end access function.
3943
class HdfDestroyerChain {
4044
public:
41-
HdfDestroyerChain() {
42-
}
43-
HdfDestroyerChain(const HdfDestroyerChain &other)
45+
HdfDestroyerChain() = default;
46+
HdfDestroyerChain(const HdfDestroyerChain &other) noexcept
4447
: chain(other.chain) {
4548
}
49+
HdfDestroyerChain(HdfDestroyerChain &&other) noexcept
50+
: chain(std::move(other.chain)) {
51+
}
52+
HdfDestroyerChain &operator=(const HdfDestroyerChain &other) noexcept {
53+
chain = other.chain; // copy
54+
return *this;
55+
}
56+
HdfDestroyerChain &operator=(HdfDestroyerChain &&other) noexcept {
57+
chain = std::move(other.chain);
58+
return *this;
59+
}
4660

47-
void pushBack(HdfDestroyer *destroyer) {
48-
chain.push_back(std::shared_ptr<HdfDestroyer>(destroyer));
61+
void emplaceBack(const std::function<int32(int32)> &endFunction, int32 id) {
62+
chain.emplace_back(new HdfDestroyer(endFunction, id));
4963
}
5064

5165
private:
@@ -54,12 +68,12 @@ class HdfObject {
5468

5569
public:
5670
/// \returns the type of the object
57-
virtual Type getType() const {
71+
virtual Type getType() const noexcept {
5872
return type;
5973
}
6074

6175
/// \returns the class type of the object
62-
virtual ClassType getClassType() const {
76+
virtual ClassType getClassType() const noexcept {
6377
return classType;
6478
}
6579

@@ -69,16 +83,21 @@ class HdfObject {
6983
, classType(classType)
7084
, chain(chain) {
7185
}
86+
HdfObject(const Type &type, const ClassType &classType, HdfDestroyerChain &&chain)
87+
: type(type)
88+
, classType(classType)
89+
, chain(std::move(chain)) {
90+
}
7291
HdfObject(const HdfObject *object)
7392
: type(object->getType())
7493
, classType(object->getClassType())
7594
, chain(object->chain) {
7695
}
7796

78-
virtual void setType(const Type &type) {
97+
virtual void setType(const Type &type) noexcept {
7998
this->type = type;
8099
}
81-
virtual void setClassType(const ClassType &classType) {
100+
virtual void setClassType(const ClassType &classType) noexcept {
82101
this->classType = classType;
83102
}
84103

lib/HdfAttribute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ void hdf4cpp::HdfAttribute::HdfDataAttribute::get(void *dest) {
8484
int32 hdf4cpp::HdfAttribute::HdfDataAttribute::getDataType() const {
8585
return dataType;
8686
}
87-
hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other)
87+
hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other) noexcept
8888
: HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
8989
, attribute(std::move(other.attribute)) {
9090
}
91-
hdf4cpp::HdfAttribute &hdf4cpp::HdfAttribute::operator=(HdfAttribute &&other) {
91+
hdf4cpp::HdfAttribute &hdf4cpp::HdfAttribute::operator=(HdfAttribute &&other) noexcept {
9292
attribute = std::move(other.attribute);
9393
setType(attribute->getType());
9494
setClassType(attribute->getClassType());

0 commit comments

Comments
 (0)