Skip to content

Commit e6a403f

Browse files
committed
Merge branch 'master' of https://github.com/G-Node/nix into 1.4
2 parents 15b7ebd + f9382a1 commit e6a403f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+650
-317
lines changed

.dir-locals.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
(tab-width . 4)
44
(c-basic-offset . 4)
55
(fill-column . 80)
6-
(c-offsets-alist . ((innamespace . [0]))))))
6+
(eval . (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode)))
7+
(eval . (if (boundp 'c-offsets-alist)
8+
(add-to-list 'c-offsets-alist '(innamespace . -)))))))

CMakeLists.txt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set(VERSION_PATCH 0)
1616

1717
set(VERSION_ABI 1)
1818

19+
option(BUILD_STATIC "Build static version of the library" OFF)
20+
1921
if(NOT WIN32)
2022
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -std=c++11") ## Optimize
2123
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wunreachable-code")
@@ -44,24 +46,20 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
4446

4547
#########################################
4648
# HDF-5
47-
if(WIN32)
48-
set(HDF5_USE_STATIC_LIBS OFF)
49-
find_package (HDF5 NO_MODULE)
50-
else()
51-
set(HDF5_USE_STATIC_LIBS OFF)
52-
find_package (HDF5 REQUIRED COMPONENTS C)
53-
endif()
49+
set(HDF5_USE_STATIC_LIBRARIES ${BUILD_STATIC})
50+
find_package (HDF5 REQUIRED COMPONENTS C)
5451
include_directories (${HDF5_INCLUDE_DIRS})
5552
set (LINK_LIBS ${LINK_LIBS} ${HDF5_LIBRARIES})
5653

5754

5855
########################################
5956
# Boost
6057
if(WIN32)
58+
# On windows we always use the static version of boost
6159
set(Boost_USE_STATIC_LIBS ON)
6260
set(Boost_USE_STATIC_RUNTIME OFF)
6361
else()
64-
set(Boost_USE_STATIC_LIBS OFF)
62+
set(Boost_USE_STATIC_LIBS ${BUILD_STATIC})
6563
endif()
6664

6765
set(Boost_USE_MULTITHREADED ON)
@@ -127,8 +125,17 @@ endforeach()
127125

128126
### LIBRARY
129127

130-
add_library(nix SHARED ${nix_INCLUDES} ${nix_SOURCES})
128+
if(BUILD_STATIC)
129+
set(NIX_LIBTYPE STATIC)
130+
add_definitions(-DNIX_STATIC=1)
131+
else()
132+
set(NIX_LIBTYPE SHARED)
133+
endif()
134+
135+
add_library(nix ${NIX_LIBTYPE} ${nix_INCLUDES} ${nix_SOURCES})
131136
target_link_libraries(nix ${LINK_LIBS})
137+
set_target_properties(nix PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
138+
set_target_properties(nix PROPERTIES COMPILE_FLAGS "-fPIC")
132139
set_target_properties(nix PROPERTIES
133140
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
134141
SOVERSION ${VERSION_ABI})
@@ -233,6 +240,7 @@ endif()
233240

234241
install(TARGETS nix nix-tool
235242
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
243+
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
236244
FRAMEWORK DESTINATION "/Library/Frameworks"
237245
RUNTIME DESTINATION bin)
238246
install(DIRECTORY include/ DESTINATION ${INCLUDE_INSTALL_DIR})
@@ -256,10 +264,13 @@ if(WIN32)
256264
DESTINATION ./
257265
COMPONENT libraries)
258266

267+
if(NOT BUILD_STATIC)
259268
file(GLOB HDF5_DLLS "${HDF5_DIR}/../../bin/*.dll")
260269
install(FILES ${HDF5_DLLS}
261270
DESTINATION bin
262271
COMPONENT libraries)
272+
endif()
273+
263274
file(GLOB HDF5_COPYING "${HDF5_DIR}/../../COPYING")
264275
install(FILES ${HDF5_COPYING}
265276
DESTINATION ./
@@ -290,6 +301,8 @@ get_directory_property(incdirs INCLUDE_DIRECTORIES)
290301

291302
MESSAGE(STATUS "READY. ")
292303
MESSAGE(STATUS "===============================")
304+
MESSAGE(STATUS "STATIC: ${BUILD_STATIC}")
305+
MESSAGE(STATUS "===============================")
293306
MESSAGE(STATUS "INCDIRS: ${incdirs}")
294307
MESSAGE(STATUS "CFLAGS: ${CMAKE_CXX_FLAGS}")
295308
MESSAGE(STATUS "BOOST: ${Boost_LIBRARIES}")

backend/fs/BlockFS.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ BlockFS::BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &lo
2323

2424

2525
BlockFS::BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id,
26-
const std::string &type, const std::string &name)
27-
: EntityWithMetadataFS(file, loc, id, type, name)
26+
const std::string &type, const std::string &name, const Compression &compression)
27+
: EntityWithMetadataFS(file, loc, id, type, name), compr(compression)
2828
{
2929
createSubFolders(file);
3030
}
3131

3232

3333
BlockFS::BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id,
34-
const std::string &type, const std::string &name, time_t time)
35-
: EntityWithMetadataFS(file, loc, id, type, name, time)
34+
const std::string &type, const std::string &name, time_t time, const Compression &compression)
35+
: EntityWithMetadataFS(file, loc, id, type, name, time), compr(compression)
3636
{
3737
createSubFolders(file);
3838
}
@@ -250,7 +250,8 @@ bool BlockFS::deleteSource(const std::string &name_or_id) {
250250
//--------------------------------------------------
251251

252252
std::shared_ptr<base::IDataArray> BlockFS::createDataArray(const std::string &name, const std::string &type,
253-
nix::DataType data_type, const NDSize &shape) {
253+
nix::DataType data_type, const NDSize &shape,
254+
const Compression &compression) {
254255
if (name.empty()) {
255256
throw EmptyString("Block::createDataArray empty name provided!");
256257
}
@@ -259,7 +260,7 @@ std::shared_ptr<base::IDataArray> BlockFS::createDataArray(const std::string &na
259260
}
260261
std::string id = util::createId();
261262
DataArrayFS da(file(), block(), data_array_dir.location(), id, type, name);
262-
da.createData(data_type, shape);
263+
da.createData(data_type, shape, compression);
263264
return std::make_shared<DataArrayFS>(da);
264265
}
265266

backend/fs/BlockFS.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class BlockFS : virtual public base::IBlock, public EntityWithMetadataFS,
3030

3131
private:
3232
Directory data_array_dir, tag_dir, multi_tag_dir, source_dir, group_dir;
33+
Compression compr;
3334

3435
void createSubFolders(const std::shared_ptr<base::IFile> &file);
3536

@@ -56,7 +57,8 @@ class BlockFS : virtual public base::IBlock, public EntityWithMetadataFS,
5657
* @param type The type of this block.
5758
* @param name The name of this block.
5859
*/
59-
BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id, const std::string &type, const std::string &name);
60+
BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id,
61+
const std::string &type, const std::string &name, const Compression &compression);
6062

6163
/**
6264
* Standard constructor for a new Block.
@@ -68,7 +70,8 @@ class BlockFS : virtual public base::IBlock, public EntityWithMetadataFS,
6870
* @param name The name of this block.
6971
* @param time The creation time of this block.
7072
*/
71-
BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id, const std::string &type, const std::string &name, time_t time);
73+
BlockFS(const std::shared_ptr<base::IFile> &file, const std::string &loc, const std::string &id,
74+
const std::string &type, const std::string &name, time_t time, const Compression &compression);
7275

7376
//--------------------------------------------------
7477
// Generic entity methods
@@ -113,7 +116,8 @@ class BlockFS : virtual public base::IBlock, public EntityWithMetadataFS,
113116
//--------------------------------------------------
114117

115118
std::shared_ptr<base::IDataArray> createDataArray(const std::string &name, const std::string &type,
116-
nix::DataType data_type, const NDSize &shape);
119+
nix::DataType data_type, const NDSize &shape,
120+
const Compression &compression);
117121

118122
//--------------------------------------------------
119123
// Methods concerning tags.

backend/fs/DataArrayFS.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ std::vector<double> DataArrayFS::polynomCoefficients() const {
148148
}
149149

150150

151-
void DataArrayFS::polynomCoefficients(const std::vector<double> &coefficients) {
151+
void DataArrayFS::polynomCoefficients(const std::vector<double> &coefficients,
152+
const Compression &compression) {
152153
setAttr("polynom_coefficients", coefficients);
153154
forceUpdatedAt();
154155
}
@@ -239,8 +240,7 @@ bool DataArrayFS::deleteDimensions() {
239240
DataArrayFS::~DataArrayFS() {
240241
}
241242

242-
243-
void DataArrayFS::createData(DataType dtype, const NDSize &size) {
243+
void DataArrayFS::createData(DataType dtype, const NDSize &size, const Compression &compression) {
244244
setDtype(dtype);
245245
dataExtent(size);
246246
/*
@@ -343,4 +343,4 @@ void DataArrayFS::setDtype(nix::DataType dtype) {
343343
}
344344

345345
} // ns nix::file
346-
} // ns nix
346+
} // ns nix

backend/fs/DataArrayFS.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <nix/base/IDataArray.hpp>
1818
#include "EntityWithSourcesFS.hpp"
19+
#include <nix/Compression.hpp>
1920

2021
#include <boost/multi_array.hpp>
2122
#include "Directory.hpp"
@@ -93,7 +94,8 @@ class DataArrayFS : virtual public base::IDataArray, public EntityWithSourcesFS
9394
void expansionOrigin(const none_t t);
9495

9596

96-
void polynomCoefficients(const std::vector<double> &polynom_coefficients);
97+
void polynomCoefficients(const std::vector<double> &polynom_coefficients,
98+
const Compression &compression = Compression::None);
9799

98100

99101
std::vector<double> polynomCoefficients() const;
@@ -138,7 +140,7 @@ class DataArrayFS : virtual public base::IDataArray, public EntityWithSourcesFS
138140
// Methods concerning data access.
139141
//--------------------------------------------------
140142

141-
virtual void createData(DataType dtype, const NDSize &size);
143+
virtual void createData(DataType dtype, const NDSize &size, const Compression &compression);
142144

143145

144146
bool hasData() const;

backend/fs/FileFS.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ namespace nix {
1616
namespace file {
1717

1818

19-
FileFS::FileFS(const std::string &name, FileMode mode)
20-
: DirectoryWithAttributes(name, mode, true){
19+
FileFS::FileFS(const std::string &name, FileMode mode, Compression compression)
20+
: DirectoryWithAttributes(name, mode, true) {
2121
this->mode = mode;
22+
this->compr = compression;
2223
if (mode == FileMode::Overwrite) {
2324
removeAll();
2425
}
@@ -81,7 +82,7 @@ std::shared_ptr<base::IBlock> FileFS::createBlock(const std::string &name, const
8182
throw DuplicateName("Block with the given name already exists!");
8283
}
8384
std::string id = util::createId();
84-
BlockFS b(file(), data_dir.location(), id, type, name);
85+
BlockFS b(file(), data_dir.location(), id, type, name, this->compression());
8586
return std::make_shared<BlockFS>(b);
8687
}
8788

@@ -257,6 +258,10 @@ FileMode FileFS::fileMode() const {
257258
return mode;
258259
}
259260

261+
Compression FileFS::compression() const {
262+
return compr;
263+
}
264+
260265
FileFS::~FileFS() {}
261266

262267
} // namespace file

backend/fs/FileFS.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ class FileFS : public base::IFile, public DirectoryWithAttributes, public std::e
2323

2424
private:
2525
Directory data_dir, metadata_dir;
26+
Compression compr;
2627
FileMode mode;
2728

2829
void create_subfolders(const std::string &loc);
2930

3031
public:
31-
FileFS(const std::string &name, const FileMode mode = FileMode::ReadWrite);
32+
FileFS(const std::string &name, const FileMode mode = FileMode::ReadWrite, const Compression compression = Compression::Auto);
3233

3334

3435
bool flush() { return true; };
@@ -113,6 +114,9 @@ class FileFS : public base::IFile, public DirectoryWithAttributes, public std::e
113114
FileMode fileMode() const;
114115

115116

117+
Compression compression() const;
118+
119+
116120
bool operator==(const FileFS &other) const;
117121

118122

backend/hdf5/BlockHDF5.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ BlockHDF5::BlockHDF5(const std::shared_ptr<base::IFile> &file, const H5Group &gr
3434
groups_group = this->group().openOptGroup("groups");
3535
}
3636

37-
BlockHDF5::BlockHDF5(const shared_ptr<IFile> &file, const H5Group &group, const string &id, const string &type, const string &name)
38-
: BlockHDF5(file, group, id, type, name, util::getTime()) {
37+
BlockHDF5::BlockHDF5(const shared_ptr<IFile> &file, const H5Group &group, const string &id,
38+
const string &type, const string &name, const Compression &compression)
39+
: BlockHDF5(file, group, id, type, name, util::getTime(), compression) {
3940
}
4041

4142

42-
BlockHDF5::BlockHDF5(const shared_ptr<IFile> &file, const H5Group &group, const string &id, const string &type, const string &name, time_t time)
43-
: EntityWithMetadataHDF5(file, group, id, type, name, time) {
43+
BlockHDF5::BlockHDF5(const shared_ptr<IFile> &file, const H5Group &group, const string &id,
44+
const string &type, const string &name, time_t time, const Compression &compression)
45+
: EntityWithMetadataHDF5(file, group, id, type, name, time), compr(compression) {
4446
data_array_group = this->group().openOptGroup("data_arrays");
4547
tag_group = this->group().openOptGroup("tags");
4648
multi_tag_group = this->group().openOptGroup("multi_tags");
@@ -290,15 +292,16 @@ shared_ptr<ITag> BlockHDF5::createTag(const std::string &name, const std::string
290292
shared_ptr<IDataArray> BlockHDF5::createDataArray(const std::string &name,
291293
const std::string &type,
292294
nix::DataType data_type,
293-
const NDSize &shape) {
295+
const NDSize &shape,
296+
const Compression &compression) {
294297
string id = util::createId();
295298
boost::optional<H5Group> g = data_array_group(true);
296299

297300
H5Group group = g->openGroup(name, true);
298301
auto da = make_shared<DataArrayHDF5>(file(), block(), group, id, type, name);
299302

300303
// now create the actual H5::DataSet
301-
da->createData(data_type, shape);
304+
da->createData(data_type, shape, compression == Compression::Auto ? compr : compression);
302305
return da;
303306
}
304307

backend/hdf5/BlockHDF5.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BlockHDF5 : virtual public base::IBlock, public EntityWithMetadataHDF5,
2828
private:
2929

3030
optGroup data_array_group, tag_group, multi_tag_group, source_group, groups_group;
31-
31+
Compression compr;
3232
public:
3333

3434
/**
@@ -48,7 +48,8 @@ class BlockHDF5 : virtual public base::IBlock, public EntityWithMetadataHDF5,
4848
* @param type The type of this block.
4949
* @param name The name of this block.
5050
*/
51-
BlockHDF5(const std::shared_ptr<base::IFile> &file, const H5Group &group, const std::string &id, const std::string &type, const std::string &name);
51+
BlockHDF5(const std::shared_ptr<base::IFile> &file, const H5Group &group, const std::string &id,
52+
const std::string &type, const std::string &name, const Compression &compression);
5253

5354
/**
5455
* Standard constructor for a new Block.
@@ -60,7 +61,8 @@ class BlockHDF5 : virtual public base::IBlock, public EntityWithMetadataHDF5,
6061
* @param name The name of this block.
6162
* @param time The creation time of this block.
6263
*/
63-
BlockHDF5(const std::shared_ptr<base::IFile> &file, const H5Group &group, const std::string &id, const std::string &type, const std::string &name, time_t time);
64+
BlockHDF5(const std::shared_ptr<base::IFile> &file, const H5Group &group, const std::string &id,
65+
const std::string &type, const std::string &name, time_t time, const Compression &compression);
6466

6567

6668
private:
@@ -112,7 +114,8 @@ class BlockHDF5 : virtual public base::IBlock, public EntityWithMetadataHDF5,
112114
//--------------------------------------------------
113115

114116
std::shared_ptr<base::IDataArray> createDataArray(const std::string &name, const std::string &type,
115-
nix::DataType data_type, const NDSize &shape);
117+
nix::DataType data_type, const NDSize &shape,
118+
const Compression &compression);
116119

117120

118121
//--------------------------------------------------

0 commit comments

Comments
 (0)