Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CPP 17 standard instead of cpp11 #841

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ option(BUILD_COVERAGE "Build with coverage information" OFF)
set(HAVE_COVERAGE OFF)

if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -std=c++11") ## Optimize
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -std=c++17") ## Optimize
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wunreachable-code")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef") # boost + clang

Expand Down Expand Up @@ -104,8 +104,8 @@ include_directories("${PROJECT_BINARY_DIR}/include")

### scan files
include_directories(BEFORE include)
file(GLOB_RECURSE nix_SOURCES src/*.cpp)
file(GLOB_RECURSE nix_INCLUDES include/*.hpp)
file(GLOB_RECURSE nix_SOURCES "src/[!.#]*.cpp")
file(GLOB_RECURSE nix_INCLUDES "include/[!.#]*.hpp")
list(APPEND nix_INCLUDES "${PROJECT_BINARY_DIR}/include/nix/nixversion.hpp")

### BACKENDS
Expand All @@ -115,8 +115,8 @@ set(backends "hdf5")
include_directories(${CMAKE_SOURCE_DIR}/backend)

foreach(backend ${backends})
file(GLOB_RECURSE backend_SOURCES "backend/${backend}/*.cpp")
file(GLOB_RECURSE backend_INCLUDES "backend/${backend}/*.hpp")
file(GLOB_RECURSE backend_SOURCES "backend/${backend}/[!.#]*.cpp")
file(GLOB_RECURSE backend_INCLUDES "backend/${backend}/[!.#]*.hpp")

list(APPEND nix_SOURCES ${backend_SOURCES})
list(APPEND nix_INCLUDES ${backend_INCLUDES})
Expand Down
24 changes: 12 additions & 12 deletions backend/hdf5/BaseTagHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ bool BaseTagHDF5::hasReference(const std::string &name_or_id) const {


ndsize_t BaseTagHDF5::referenceCount() const {
boost::optional<H5Group> g = refs_group(false);
std::optional<H5Group> g = refs_group(false);
return g ? g->objectCount() : size_t(0);
}


std::shared_ptr<IDataArray> BaseTagHDF5::getReference(const std::string &name_or_id) const {
std::shared_ptr<IDataArray> da;
boost::optional<H5Group> g = refs_group(false);
std::optional<H5Group> g = refs_group(false);

std::string id = block()->resolveEntityId({name_or_id, ObjectType::DataArray});
if (g && hasReference(id)) {
Expand All @@ -72,13 +72,13 @@ std::shared_ptr<IDataArray> BaseTagHDF5::getReference(const std::string &name_o
}

std::shared_ptr<IDataArray> BaseTagHDF5::getReference(ndsize_t index) const {
boost::optional<H5Group> g = refs_group(false);
std::optional<H5Group> g = refs_group(false);
std::string id = g ? g->objectName(index) : "";
return getReference(id);
}

void BaseTagHDF5::addReference(const std::string &name_or_id) {
boost::optional<H5Group> g = refs_group(true);
std::optional<H5Group> g = refs_group(true);

if (!block()->hasEntity({name_or_id, ObjectType::DataArray}))
throw std::runtime_error("BaseTagHDF5::addReference: DataArray not found in block!");
Expand All @@ -90,7 +90,7 @@ void BaseTagHDF5::addReference(const std::string &name_or_id) {


bool BaseTagHDF5::removeReference(const std::string &name_or_id) {
boost::optional<H5Group> g = refs_group(false);
std::optional<H5Group> g = refs_group(false);
bool removed = false;

if (g && hasReference(name_or_id)) {
Expand Down Expand Up @@ -124,19 +124,19 @@ bool BaseTagHDF5::hasFeature(const std::string &name_or_id) const {


ndsize_t BaseTagHDF5::featureCount() const {
boost::optional<H5Group> g = feature_group(false);
std::optional<H5Group> g = feature_group(false);
return g ? g->objectCount() : size_t(0);
}


std::shared_ptr<IFeature> BaseTagHDF5::getFeature(const std::string &name_or_id) const {
std::shared_ptr<FeatureHDF5> feature;
boost::optional<H5Group> g = feature_group(false);
std::optional<H5Group> g = feature_group(false);

if (g) {
boost::optional<H5Group> group = g->findGroupByNameOrAttribute("name", name_or_id);
std::optional<H5Group> group = g->findGroupByNameOrAttribute("name", name_or_id);
if (group)
feature = std::make_shared<FeatureHDF5>(file(), block(), group.get());
feature = std::make_shared<FeatureHDF5>(file(), block(), group.value());
else {
for (ndsize_t i = 0; i < g->objectCount(); i++) {
H5Group gr = g->openGroup(g->objectName(i), false);
Expand All @@ -154,7 +154,7 @@ std::shared_ptr<IFeature> BaseTagHDF5::getFeature(const std::string &name_or_id)


std::shared_ptr<IFeature> BaseTagHDF5::getFeature(ndsize_t index) const {
boost::optional<H5Group> g = feature_group(false);
std::optional<H5Group> g = feature_group(false);
std::string id = g->objectName(index);
return getFeature(id);
}
Expand All @@ -165,7 +165,7 @@ std::shared_ptr<IFeature> BaseTagHDF5::createFeature(const std::string &name_or
throw std::runtime_error("DataArray not found in Block!");
}
std::string rep_id = util::createId();
boost::optional<H5Group> g = feature_group(true);
std::optional<H5Group> g = feature_group(true);

H5Group group = g->openGroup(rep_id, true);
DataArray data = std::dynamic_pointer_cast<IDataArray>(block()->getEntity({name_or_id, ObjectType::DataArray}));
Expand All @@ -174,7 +174,7 @@ std::shared_ptr<IFeature> BaseTagHDF5::createFeature(const std::string &name_or


bool BaseTagHDF5::deleteFeature(const std::string &name_or_id) {
boost::optional<H5Group> g = feature_group(false);
std::optional<H5Group> g = feature_group(false);
bool deleted = false;

if (g && hasFeature(name_or_id)) {
Expand Down
44 changes: 22 additions & 22 deletions backend/hdf5/BlockHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ BlockHDF5::BlockHDF5(const shared_ptr<IFile> &file, const H5Group &group, const
// Generic access methods
//--------------------------------------------------

boost::optional<H5Group> BlockHDF5::groupForObjectType(ObjectType type, bool create) const {
boost::optional<H5Group> p;
std::optional<H5Group> BlockHDF5::groupForObjectType(ObjectType type, bool create) const {
std::optional<H5Group> p;

switch (type) {
case ObjectType::DataArray:
Expand Down Expand Up @@ -87,20 +87,20 @@ boost::optional<H5Group> BlockHDF5::groupForObjectType(ObjectType type, bool cre
break;

default:
p = boost::optional<H5Group>(create);
p = std::optional<H5Group>(create);
}

return p;
}

boost::optional<H5Group> BlockHDF5::findEntityGroup(const nix::Identity &ident) const {
boost::optional<H5Group> p = groupForObjectType(ident.type());
std::optional<H5Group> BlockHDF5::findEntityGroup(const nix::Identity &ident) const {
std::optional<H5Group> p = groupForObjectType(ident.type());

if (!p) {
return p;
}

boost::optional<H5Group> g;
std::optional<H5Group> g;
const std::string &iname = ident.name();
const std::string &iid = ident.id();

Expand All @@ -115,7 +115,7 @@ boost::optional<H5Group> BlockHDF5::findEntityGroup(const nix::Identity &ident)
bool foundNeedle = p->hasObject(needle);

if (foundNeedle) {
g = boost::make_optional(p->openGroup(needle, false));
g = std::make_optional(p->openGroup(needle, false));
} else if (haveId) {
g = p->findGroupByAttribute("entity_id", iid);
}
Expand All @@ -125,7 +125,7 @@ boost::optional<H5Group> BlockHDF5::findEntityGroup(const nix::Identity &ident)
g->getAttr("entity_id", eid);

if (eid != iid) {
return boost::optional<H5Group>();
return std::optional<H5Group>();
}
}

Expand All @@ -137,7 +137,7 @@ std::string BlockHDF5::resolveEntityId(const nix::Identity &ident) const {
return ident.id();
}

boost::optional<H5Group> g = findEntityGroup(ident);
std::optional<H5Group> g = findEntityGroup(ident);
if (!g) {
return "";
}
Expand All @@ -149,12 +149,12 @@ std::string BlockHDF5::resolveEntityId(const nix::Identity &ident) const {
}

bool BlockHDF5::hasEntity(const nix::Identity &ident) const {
boost::optional<H5Group> p = findEntityGroup(ident);
std::optional<H5Group> p = findEntityGroup(ident);
return !!p;
}

std::shared_ptr<base::IEntity> BlockHDF5::getEntity(const nix::Identity &ident) const {
boost::optional<H5Group> eg = findEntityGroup(ident);
std::optional<H5Group> eg = findEntityGroup(ident);

switch (ident.type()) {
case ObjectType::DataArray: {
Expand Down Expand Up @@ -213,19 +213,19 @@ std::shared_ptr<base::IEntity> BlockHDF5::getEntity(const nix::Identity &ident)
}

std::shared_ptr<base::IEntity>BlockHDF5::getEntity(ObjectType type, ndsize_t index) const {
boost::optional<H5Group> eg = groupForObjectType(type);
std::optional<H5Group> eg = groupForObjectType(type);
string name = eg ? eg->objectName(index) : "";
return getEntity({name, "", type});
}

ndsize_t BlockHDF5::entityCount(ObjectType type) const {
boost::optional<H5Group> g = groupForObjectType(type);
std::optional<H5Group> g = groupForObjectType(type);
return g ? g->objectCount() : ndsize_t(0);
}

bool BlockHDF5::removeEntity(const nix::Identity &ident) {
boost::optional<H5Group> p = groupForObjectType(ident.type());
boost::optional<H5Group> eg = findEntityGroup(ident);
std::optional<H5Group> p = groupForObjectType(ident.type());
std::optional<H5Group> eg = findEntityGroup(ident);

if (!p || !eg) {
return false;
Expand Down Expand Up @@ -255,15 +255,15 @@ bool BlockHDF5::removeEntity(const nix::Identity &ident) {

shared_ptr<ISource> BlockHDF5::createSource(const string &name, const string &type) {
string id = util::createId();
boost::optional<H5Group> g = source_group(true);
std::optional<H5Group> g = source_group(true);

H5Group group = g->openGroup(name, true);
return make_shared<SourceHDF5>(file(), block(), group, id, type, name);
}


bool BlockHDF5::deleteSource(const string &name_or_id) {
boost::optional<H5Group> g = source_group();
std::optional<H5Group> g = source_group();
bool deleted = false;

if (g) {
Expand Down Expand Up @@ -293,7 +293,7 @@ bool BlockHDF5::deleteSource(const string &name_or_id) {
shared_ptr<ITag> BlockHDF5::createTag(const std::string &name, const std::string &type,
const std::vector<double> &position) {
string id = util::createId();
boost::optional<H5Group> g = tag_group(true);
std::optional<H5Group> g = tag_group(true);

H5Group group = g->openGroup(name);
return make_shared<TagHDF5>(file(), block(), group, id, type, name, position);
Expand All @@ -310,7 +310,7 @@ shared_ptr<IDataArray> BlockHDF5::createDataArray(const std::string &name,
const NDSize &shape,
const Compression &compression) {
string id = util::createId();
boost::optional<H5Group> g = data_array_group(true);
std::optional<H5Group> g = data_array_group(true);

H5Group group = g->openGroup(name, true);
auto da = make_shared<DataArrayHDF5>(file(), block(), group, id, type, name);
Expand All @@ -330,7 +330,7 @@ std::shared_ptr<IDataFrame> BlockHDF5::createDataFrame(const std::string &name,
const Compression &compression) {

string id = util::createId();
boost::optional<H5Group> g = data_frame_group(true);
std::optional<H5Group> g = data_frame_group(true);
H5Group group = g->openGroup(name, true);

auto df = make_shared<DataFrameHDF5>(file(), block(), group, id, type, name);
Expand All @@ -346,7 +346,7 @@ std::shared_ptr<IDataFrame> BlockHDF5::createDataFrame(const std::string &name,
shared_ptr<IMultiTag> BlockHDF5::createMultiTag(const std::string &name, const std::string &type,
const DataArray &positions) {
string id = util::createId();
boost::optional<H5Group> g = multi_tag_group(true);
std::optional<H5Group> g = multi_tag_group(true);

H5Group group = g->openGroup(name);
return make_shared<MultiTagHDF5>(file(), block(), group, id, type, name, positions);
Expand All @@ -358,7 +358,7 @@ shared_ptr<IMultiTag> BlockHDF5::createMultiTag(const std::string &name, const s

shared_ptr<IGroup> BlockHDF5::createGroup(const std::string &name, const std::string &type) {
string id = util::createId();
boost::optional<H5Group> g = groups_group(true);
std::optional<H5Group> g = groups_group(true);

H5Group group = g->openGroup(name);
return make_shared<GroupHDF5>(file(), block(), group, id, type, name);
Expand Down
6 changes: 3 additions & 3 deletions backend/hdf5/BlockHDF5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <vector>
#include <string>
#include <boost/optional.hpp>
#include <optional>

namespace nix {
namespace hdf5 {
Expand Down Expand Up @@ -67,9 +67,9 @@ class BlockHDF5 : virtual public base::IBlock, public EntityWithMetadataHDF5,

private:
// Helper methods for generic entity related methods below
boost::optional<H5Group> groupForObjectType(ObjectType ot, bool create = false) const;
std::optional<H5Group> groupForObjectType(ObjectType ot, bool create = false) const;

boost::optional<H5Group> findEntityGroup(const nix::Identity &ident) const;
std::optional<H5Group> findEntityGroup(const nix::Identity &ident) const;

public:
//--------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions backend/hdf5/DataArrayHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ DataArrayHDF5::DataArrayHDF5(const shared_ptr<IFile> &file, const shared_ptr<IBl
// Element getters and setters
//--------------------------------------------------

boost::optional<std::string> DataArrayHDF5::label() const {
boost::optional<std::string> ret;
std::optional<std::string> DataArrayHDF5::label() const {
std::optional<std::string> ret;
string value;
bool have_attr = group().getAttr("label", value);

Expand All @@ -68,8 +68,8 @@ void DataArrayHDF5::label(const none_t t) {
}


boost::optional<std::string> DataArrayHDF5::unit() const {
boost::optional<std::string> ret;
std::optional<std::string> DataArrayHDF5::unit() const {
std::optional<std::string> ret;
string value;
bool have_attr = group().getAttr("unit", value);
if (have_attr) {
Expand All @@ -94,8 +94,8 @@ void DataArrayHDF5::unit(const none_t t) {


// TODO use defaults
boost::optional<double> DataArrayHDF5::expansionOrigin() const {
boost::optional<double> ret;
std::optional<double> DataArrayHDF5::expansionOrigin() const {
std::optional<double> ret;
double expansion_origin;
bool have_attr = group().getAttr("expansion_origin", expansion_origin);
if (have_attr) {
Expand Down Expand Up @@ -157,7 +157,7 @@ void DataArrayHDF5::polynomCoefficients(const none_t t) {


ndsize_t DataArrayHDF5::dimensionCount() const {
boost::optional<H5Group> g = dimension_group();
std::optional<H5Group> g = dimension_group();
ndsize_t count = 0;
if (g) {
count = g->objectCount();
Expand All @@ -168,7 +168,7 @@ ndsize_t DataArrayHDF5::dimensionCount() const {

shared_ptr<IDimension> DataArrayHDF5::getDimension(ndsize_t index) const {
shared_ptr<IDimension> dim;
boost::optional<H5Group> g = dimension_group();
std::optional<H5Group> g = dimension_group();

if (g) {
string str_id = util::numToStr(index);
Expand Down Expand Up @@ -219,7 +219,7 @@ std::shared_ptr<base::IDataFrameDimension> DataArrayHDF5::createDataFrameDimensi


H5Group DataArrayHDF5::createDimensionGroup(ndsize_t index) {
boost::optional<H5Group> g = dimension_group(true);
std::optional<H5Group> g = dimension_group(true);

ndsize_t dim_max = dimensionCount() + 1;
if (index > dim_max || index <= 0)
Expand All @@ -236,7 +236,7 @@ H5Group DataArrayHDF5::createDimensionGroup(ndsize_t index) {

bool DataArrayHDF5::deleteDimensions() {
string dim_id;
boost::optional<H5Group> g = dimension_group();
std::optional<H5Group> g = dimension_group();
for (ndsize_t i = dimensionCount(); i > 0; --i) {
dim_id = util::numToStr(i);
if (g->hasGroup(dim_id)) {
Expand Down
Loading