diff --git a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp index 5d567effac..02a4fe598d 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp @@ -29,7 +29,6 @@ #include "openPMD/IO/IOTask.hpp" #include "openPMD/IO/InvalidatableFile.hpp" #include "openPMD/auxiliary/JSON_internal.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/backend/Writable.hpp" #include "openPMD/config.hpp" #include "openPMD/IterationEncoding.hpp" @@ -47,6 +46,7 @@ #include #include #include // shared_ptr +#include #include #include #include @@ -320,11 +320,11 @@ class ADIOS2IOHandlerImpl * @return first parameter: the operators, second parameters: whether * operators have been configured */ - auxiliary::Option< std::vector< ParameterizedOperator > > + std::optional< std::vector< ParameterizedOperator > > getOperators( json::TracingJSON config ); // use m_config - auxiliary::Option< std::vector< ParameterizedOperator > > + std::optional< std::vector< ParameterizedOperator > > getOperators(); std::string @@ -367,7 +367,7 @@ class ADIOS2IOHandlerImpl // Helper methods. - auxiliary::Option< adios2::Operator > + std::optional< adios2::Operator > getCompressionOperator( std::string const & compression ); /* @@ -1227,7 +1227,7 @@ namespace detail private: ADIOS2IOHandlerImpl * m_impl; - auxiliary::Option< adios2::Engine > m_engine; //! ADIOS engine + std::optional< adios2::Engine > m_engine; //! ADIOS engine /** * The ADIOS2 engine type, to be passed to adios2::IO::SetEngine */ @@ -1343,8 +1343,8 @@ namespace detail * the map that would be returned by a call to * IO::Available(Attributes|Variables). */ - auxiliary::Option< AttributeMap_t > m_availableAttributes; - auxiliary::Option< AttributeMap_t > m_availableVariables; + std::optional< AttributeMap_t > m_availableAttributes; + std::optional< AttributeMap_t > m_availableVariables; /* * finalize() will set this true to avoid running twice. diff --git a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp index ba5247284a..92d39ceabb 100644 --- a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp +++ b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp @@ -25,9 +25,9 @@ # include "openPMD/IO/AbstractIOHandlerImpl.hpp" # include "openPMD/auxiliary/JSON_internal.hpp" -# include "openPMD/auxiliary/Option.hpp" # include +# include # include # include #endif @@ -88,7 +88,7 @@ namespace openPMD std::string name; hid_t id; }; - auxiliary::Option< File > getFile( Writable * ); + std::optional< File > getFile( Writable * ); }; // HDF5IOHandlerImpl #else class HDF5IOHandlerImpl diff --git a/include/openPMD/Iteration.hpp b/include/openPMD/Iteration.hpp index 0e3f57dab0..173b1eb25d 100644 --- a/include/openPMD/Iteration.hpp +++ b/include/openPMD/Iteration.hpp @@ -20,7 +20,6 @@ */ #pragma once -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/Variant.hpp" #include "openPMD/backend/Attributable.hpp" #include "openPMD/backend/Container.hpp" @@ -29,6 +28,8 @@ #include "openPMD/ParticleSpecies.hpp" #include "openPMD/Streaming.hpp" +#include + namespace openPMD { @@ -100,7 +101,7 @@ namespace internal * Information on a parsing request that has not yet been executed. * Otherwise empty. */ - auxiliary::Option< DeferredParseAccess > m_deferredParseAccess{}; + std::optional< DeferredParseAccess > m_deferredParseAccess{}; }; } /** @brief Logical compilation of data from one snapshot (e.g. a single simulation cycle). diff --git a/include/openPMD/ReadIterations.hpp b/include/openPMD/ReadIterations.hpp index 915b1446ac..0890881e90 100644 --- a/include/openPMD/ReadIterations.hpp +++ b/include/openPMD/ReadIterations.hpp @@ -23,6 +23,8 @@ #include "openPMD/Iteration.hpp" #include "openPMD/Series.hpp" +#include + namespace openPMD { /** @@ -51,7 +53,7 @@ class SeriesIterator { using iteration_index_t = IndexedIteration::index_t; - using maybe_series_t = auxiliary::Option< Series >; + using maybe_series_t = std::optional< Series >; maybe_series_t m_series; iteration_index_t m_currentIteration = 0; diff --git a/include/openPMD/Series.hpp b/include/openPMD/Series.hpp index 7416a1ce08..309aec7567 100644 --- a/include/openPMD/Series.hpp +++ b/include/openPMD/Series.hpp @@ -30,7 +30,6 @@ #include "openPMD/IterationEncoding.hpp" #include "openPMD/Streaming.hpp" #include "openPMD/WriteIterations.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/Variant.hpp" #include "openPMD/backend/Attributable.hpp" #include "openPMD/backend/Container.hpp" @@ -42,6 +41,7 @@ #endif #include +#include #include // expose private and protected members for invasive testing @@ -85,7 +85,7 @@ class SeriesData : public AttributableData * This ensures that Series::writeIteration() always returns * the same instance. */ - auxiliary::Option< WriteIterations > m_writeIterations; + std::optional< WriteIterations > m_writeIterations; /** * Needed if reading a single iteration of a file-based series. * Users may specify the concrete filename of one iteration instead of the @@ -95,7 +95,7 @@ class SeriesData : public AttributableData * Instead, the user-specified filename should be used directly. * Store that filename in the following Option to indicate this situation. */ - auxiliary::Option< std::string > m_overrideFilebasedFilename; + std::optional< std::string > m_overrideFilebasedFilename; /** * Name of the iteration without filename suffix. * In case of file-based iteration encoding, with expansion pattern. diff --git a/include/openPMD/WriteIterations.hpp b/include/openPMD/WriteIterations.hpp index 7483a1d22c..137e99bc7c 100644 --- a/include/openPMD/WriteIterations.hpp +++ b/include/openPMD/WriteIterations.hpp @@ -21,9 +21,10 @@ #pragma once #include "openPMD/Iteration.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/backend/Container.hpp" +#include + namespace openPMD { @@ -61,7 +62,7 @@ class WriteIterations struct SharedResources { iterations_t iterations; - auxiliary::Option< uint64_t > currentlyOpen; + std::optional< uint64_t > currentlyOpen; SharedResources( iterations_t ); ~SharedResources(); diff --git a/include/openPMD/auxiliary/JSON_internal.hpp b/include/openPMD/auxiliary/JSON_internal.hpp index 1ca8f011aa..12120d4533 100644 --- a/include/openPMD/auxiliary/JSON_internal.hpp +++ b/include/openPMD/auxiliary/JSON_internal.hpp @@ -24,11 +24,12 @@ #include "openPMD/config.hpp" #include "openPMD/Error.hpp" -#include "openPMD/auxiliary/Option.hpp" #include #include +#include + #if openPMD_HAVE_MPI # include #endif @@ -223,12 +224,12 @@ namespace json * If it is a bool, convert it to either "0" or "1". * If it is not a literal, return an empty option. */ - auxiliary::Option< std::string > asStringDynamic( nlohmann::json const & ); + std::optional< std::string > asStringDynamic( nlohmann::json const & ); /** * Like asStringDynamic(), but convert the string to lowercase afterwards. */ - auxiliary::Option< std::string > + std::optional< std::string > asLowerCaseStringDynamic( nlohmann::json const & ); /** diff --git a/include/openPMD/auxiliary/Option.hpp b/include/openPMD/auxiliary/Option.hpp deleted file mode 100644 index 94c8955681..0000000000 --- a/include/openPMD/auxiliary/Option.hpp +++ /dev/null @@ -1,172 +0,0 @@ -/* Copyright 2020-2021 Franz Poeschel - * - * This file is part of openPMD-api. - * - * openPMD-api is free software: you can redistribute it and/or modify - * it under the terms of of either the GNU General Public License or - * the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * openPMD-api is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with openPMD-api. - * If not, see . - */ - -#pragma once - -#include // std::forward, std::move -#include -#include // IWYU pragma: export - - -namespace openPMD -{ -namespace auxiliary -{ - namespace detail - { - struct Empty - { - }; - } // namespace detail - - /** - * @brief Simple Option type based on std::variant. - * - * @tparam T Type that can be optionally stored in an Optional object. - */ - template< typename T > - class Option - { - using data_t = std::variant< T, detail::Empty >; - data_t m_data; - - public: - /** Create an empty Option. - */ - explicit Option() : m_data( detail::Empty() ) - { - } - - /** Create a full Option. - * - * @param data The object to emplace in the Option. - */ - Option( T data ) : m_data( std::move( data ) ) - { - } - - Option( Option const & other ) = default; - - Option & - operator=( Option && other ) - { - if( other.has_value() ) - { - m_data.template emplace< 0 >( std::move( other.get() ) ); - } - else - { - m_data.template emplace< 1 >( detail::Empty() ); - } - return *this; - } - - Option & - operator=( Option const & other ) - { - if( other.has_value() ) - { - m_data.template emplace< 0 >( other.get() ); - } - else - { - m_data.template emplace< 1 >( detail::Empty() ); - } - return *this; - } - - bool - operator==( Option const & other ) const - { - if( has_value() ) - { - return !other.has_value(); - } - else - { - if( !other.has_value() ) - { - return false; - } - else - { - return get() == other.get(); - } - } - } - - bool - operator!=( Option const & other ) const - { - return !( *this == other ); - } - - /** - * @return Is an object constantly stored in this? - */ - bool - has_value() const - { - return m_data.index() == 0; - } - - /** - * @return Is an object constantly stored in this? - */ - operator bool() const - { - return has_value(); - } - - /** - * @brief Access the emplaced object if one is present. - * - * @throw std::bad_variant_access if no object is present. - * @return The emplaced object. - */ - T const & - get() const - { - return std::template get< T >( m_data ); - } - - /** - * @brief Access the emplaced object if one is present. - * - * @throw std::bad_variant_access if no object is present. - * @return The emplaced object. - */ - T & - get() - { - return std::template get< T >( m_data ); - } - }; - - template< typename T > - Option< typename std::decay< T >::type > - makeOption( T && val ) - { - return Option< typename std::decay< T >::type >( - std::forward< T >( val ) ); - } -} // namespace auxiliary -} // namespace openPMD diff --git a/include/openPMD/openPMD.hpp b/include/openPMD/openPMD.hpp index 55a39cf2bb..82403491e1 100644 --- a/include/openPMD/openPMD.hpp +++ b/include/openPMD/openPMD.hpp @@ -56,7 +56,6 @@ namespace openPMD {} #include "openPMD/auxiliary/Date.hpp" #include "openPMD/auxiliary/DerefDynamicCast.hpp" #include "openPMD/auxiliary/JSON.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/OutOfRangeMsg.hpp" #include "openPMD/auxiliary/ShareRaw.hpp" #include "openPMD/auxiliary/StringManip.hpp" diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index 7dcc80e8a0..69b5c024f4 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -153,7 +153,7 @@ ADIOS2IOHandlerImpl::init( json::TracingJSON cfg ) json::asLowerCaseStringDynamic( engineTypeConfig ); if( maybeEngine.has_value() ) { - m_engineType = std::move( maybeEngine.get() ); + m_engineType = std::move( maybeEngine.value() ); } else { @@ -166,17 +166,17 @@ ADIOS2IOHandlerImpl::init( json::TracingJSON cfg ) auto operators = getOperators(); if( operators ) { - defaultOperators = std::move( operators.get() ); + defaultOperators = std::move( operators.value() ); } } // environment-variable based configuration m_schema = auxiliary::getEnvNum( "OPENPMD2_ADIOS2_SCHEMA", m_schema ); } -auxiliary::Option< std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator > > +std::optional< std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator > > ADIOS2IOHandlerImpl::getOperators( json::TracingJSON cfg ) { - using ret_t = auxiliary::Option< std::vector< ParameterizedOperator > >; + using ret_t = std::optional< std::vector< ParameterizedOperator > >; std::vector< ParameterizedOperator > res; if( !cfg.json().contains( "dataset" ) ) { @@ -208,7 +208,7 @@ ADIOS2IOHandlerImpl::getOperators( json::TracingJSON cfg ) if( maybeString.has_value() ) { adiosParams[ paramIterator.key() ] = - std::move( maybeString.get() ); + std::move( maybeString.value() ); } else { @@ -221,19 +221,19 @@ ADIOS2IOHandlerImpl::getOperators( json::TracingJSON cfg ) } } } - auxiliary::Option< adios2::Operator > adiosOperator = + std::optional< adios2::Operator > adiosOperator = getCompressionOperator( type ); if( adiosOperator ) { res.emplace_back( ParameterizedOperator{ - adiosOperator.get(), std::move( adiosParams ) } ); + adiosOperator.value(), std::move( adiosParams ) } ); } } _operators.declareFullyRead(); - return auxiliary::makeOption( std::move( res ) ); + return std::make_optional( std::move( res ) ); } -auxiliary::Option< std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator > > +std::optional< std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator > > ADIOS2IOHandlerImpl::getOperators() { return getOperators( m_config ); @@ -388,7 +388,7 @@ void ADIOS2IOHandlerImpl::createDataset( json::TracingJSON datasetConfig( options[ "adios2" ] ); auto datasetOperators = getOperators( datasetConfig ); - operators = datasetOperators ? std::move( datasetOperators.get() ) + operators = datasetOperators ? std::move( datasetOperators.value() ) : defaultOperators; } else @@ -1157,7 +1157,7 @@ std::shared_ptr< ADIOS2FilePosition > ADIOS2IOHandlerImpl::extendFilePosition( oldPos->gd ); } -auxiliary::Option< adios2::Operator > +std::optional< adios2::Operator > ADIOS2IOHandlerImpl::getCompressionOperator( std::string const & compression ) { adios2::Operator res; @@ -1173,7 +1173,7 @@ ADIOS2IOHandlerImpl::getCompressionOperator( std::string const & compression ) "method " << compression << ". Continuing without compression." << std::endl; - return auxiliary::Option< adios2::Operator >(); + return std::optional< adios2::Operator >(); } m_operators.emplace( compression, res ); } @@ -1181,7 +1181,7 @@ ADIOS2IOHandlerImpl::getCompressionOperator( std::string const & compression ) { res = it->second; } - return auxiliary::makeOption( adios2::Operator( res ) ); + return std::make_optional( adios2::Operator( res ) ); } std::string @@ -2252,7 +2252,7 @@ namespace detail } if( m_engine ) { - auto & engine = m_engine.get(); + auto & engine = m_engine.value(); // might have been closed previously if( engine ) { @@ -2371,7 +2371,7 @@ namespace detail if( maybeString.has_value() ) { m_IO.SetParameter( - it.key(), std::move( maybeString.get() ) ); + it.key(), std::move( maybeString.value() ) ); } else { @@ -2532,12 +2532,12 @@ namespace detail // the streaming API was used. m_IO.DefineAttribute< ADIOS2Schema::schema_t >( ADIOS2Defaults::str_adios2Schema, m_impl->m_schema ); - m_engine = auxiliary::makeOption( + m_engine = std::make_optional( adios2::Engine( m_IO.Open( m_file, m_mode ) ) ); break; } case adios2::Mode::Read: { - m_engine = auxiliary::makeOption( + m_engine = std::make_optional( adios2::Engine( m_IO.Open( m_file, m_mode ) ) ); // decide attribute layout // in streaming mode, this needs to be done after opening @@ -2570,7 +2570,7 @@ namespace detail } else { - if( m_engine.get().BeginStep() != + if( m_engine.value().BeginStep() != adios2::StepStatus::OK ) { throw std::runtime_error( @@ -2587,7 +2587,7 @@ namespace detail break; } case StreamStatus::OutsideOfStep: - if( m_engine.get().BeginStep() != adios2::StepStatus::OK ) + if( m_engine.value().BeginStep() != adios2::StepStatus::OK ) { throw std::runtime_error( "[ADIOS2] Unexpected step status when " @@ -2601,7 +2601,7 @@ namespace detail } if( attributeLayout() == AttributeLayout::ByAdiosVariables ) { - preloadAttributes.preloadAttributes( m_IO, m_engine.get() ); + preloadAttributes.preloadAttributes( m_IO, m_engine.value() ); } break; } @@ -2610,12 +2610,12 @@ namespace detail "[ADIOS2] Invalid ADIOS access mode" ); } - if( !m_engine.get() ) + if( !m_engine.value() ) { throw std::runtime_error( "[ADIOS2] Failed opening Engine." ); } } - return m_engine.get(); + return m_engine.value(); } adios2::Engine & BufferedActions::requireActiveStep( ) @@ -2627,7 +2627,7 @@ namespace detail if( m_mode == adios2::Mode::Read && attributeLayout() == AttributeLayout::ByAdiosVariables ) { - preloadAttributes.preloadAttributes( m_IO, m_engine.get() ); + preloadAttributes.preloadAttributes( m_IO, m_engine.value() ); } streamStatus = StreamStatus::DuringStep; } @@ -2852,7 +2852,7 @@ namespace detail attributeLayout() == AttributeLayout::ByAdiosVariables ) { preloadAttributes.preloadAttributes( - m_IO, m_engine.get() ); + m_IO, m_engine.value() ); } } AdvanceStatus res = AdvanceStatus::OK; @@ -2935,7 +2935,7 @@ namespace detail void BufferedActions::invalidateAttributesMap() { - m_availableAttributes = auxiliary::Option< AttributeMap_t >(); + m_availableAttributes = std::optional< AttributeMap_t >(); } BufferedActions::AttributeMap_t const & @@ -2943,20 +2943,20 @@ namespace detail { if( m_availableAttributes ) { - return m_availableAttributes.get(); + return m_availableAttributes.value(); } else { m_availableAttributes = - auxiliary::makeOption( m_IO.AvailableAttributes() ); - return m_availableAttributes.get(); + std::make_optional( m_IO.AvailableAttributes() ); + return m_availableAttributes.value(); } } void BufferedActions::invalidateVariablesMap() { - m_availableVariables = auxiliary::Option< AttributeMap_t >(); + m_availableVariables = std::optional< AttributeMap_t >(); } BufferedActions::AttributeMap_t const & @@ -2964,13 +2964,13 @@ namespace detail { if( m_availableVariables ) { - return m_availableVariables.get(); + return m_availableVariables.value(); } else { m_availableVariables = - auxiliary::makeOption( m_IO.AvailableVariables() ); - return m_availableVariables.get(); + std::make_optional( m_IO.AvailableVariables() ); + return m_availableVariables.value(); } } diff --git a/src/IO/ADIOS/CommonADIOS1IOHandler.cpp b/src/IO/ADIOS/CommonADIOS1IOHandler.cpp index fefa5d479d..531e924d33 100644 --- a/src/IO/ADIOS/CommonADIOS1IOHandler.cpp +++ b/src/IO/ADIOS/CommonADIOS1IOHandler.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -468,10 +469,10 @@ CommonADIOS1IOHandlerImpl< ChildClass >::createPath(Writable* writable, } } -static auxiliary::Option< std::string > datasetTransform( +static std::optional< std::string > datasetTransform( json::TracingJSON config ) { - using ret_t = auxiliary::Option< std::string >; + using ret_t = std::optional< std::string >; if( !config.json().contains( "dataset" ) ) { return ret_t{}; @@ -485,7 +486,7 @@ static auxiliary::Option< std::string > datasetTransform( auto maybeRes = json::asStringDynamic( config.json() ); if( maybeRes.has_value() ) { - return std::move( maybeRes.get() ); + return std::move( maybeRes.value() ); } else { @@ -558,7 +559,7 @@ CommonADIOS1IOHandlerImpl< ChildClass >::createDataset(Writable* writable, auto maybeTransform = datasetTransform( options ); if( maybeTransform.has_value() ) { - transform = maybeTransform.get(); + transform = maybeTransform.value(); } parameters.warnUnusedParameters( @@ -1761,7 +1762,7 @@ void CommonADIOS1IOHandlerImpl< ChildClass >::initJson( auto maybeTransform = datasetTransform( config[ "adios1" ] ); if( maybeTransform.has_value() ) { - m_defaultTransform = std::move( maybeTransform.get() ); + m_defaultTransform = std::move( maybeTransform.value() ); } auto shadow = config.invertShadow(); if( shadow.size() > 0 ) diff --git a/src/IO/HDF5/HDF5IOHandler.cpp b/src/IO/HDF5/HDF5IOHandler.cpp index a78df95833..fccf0b4ff9 100644 --- a/src/IO/HDF5/HDF5IOHandler.cpp +++ b/src/IO/HDF5/HDF5IOHandler.cpp @@ -102,7 +102,7 @@ HDF5IOHandlerImpl::HDF5IOHandlerImpl( datasetConfig[ "chunks" ].json() ); if( maybeChunks.has_value() ) { - m_chunks = std::move( maybeChunks.get() ); + m_chunks = std::move( maybeChunks.value() ); } else { @@ -260,7 +260,7 @@ HDF5IOHandlerImpl::createPath(Writable* writable, position = writable->parent; else position = writable; /* root does not have a parent but might still have to be written */ - File file = getFile( position ).get(); + File file = getFile( position ).value(); hid_t node_id = H5Gopen(file.id, concrete_h5_file_position(position).c_str(), gapl); @@ -357,7 +357,7 @@ HDF5IOHandlerImpl::createDataset(Writable* writable, /* Open H5Object to write into */ auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id = H5Gopen(file.id, concrete_h5_file_position(writable).c_str(), gapl); @@ -484,7 +484,7 @@ HDF5IOHandlerImpl::extendDataset(Writable* writable, auto res = getFile( writable ); if( !res ) res = getFile( writable->parent ); - hid_t dataset_id = H5Dopen(res.get().id, + hid_t dataset_id = H5Dopen(res.value().id, concrete_h5_file_position(writable).c_str(), H5P_DEFAULT); VERIFY(dataset_id >= 0, "[HDF5] Internal error: Failed to open HDF5 dataset during dataset extension"); @@ -639,7 +639,7 @@ HDF5IOHandlerImpl::closeFile( "[HDF5] Trying to close a file that is not " "present in the backend" ); } - File file = optionalFile.get(); + File file = optionalFile.value(); H5Fclose( file.id ); m_openFileIDs.erase( file.id ); m_fileNames.erase( writable ); @@ -652,7 +652,7 @@ HDF5IOHandlerImpl::openPath( Writable * writable, Parameter< Operation::OPEN_PATH > const & parameters ) { - File file = getFile(writable->parent).get(); + File file = getFile(writable->parent).value(); hid_t node_id, path_id; hid_t gapl = H5Pcreate(H5P_GROUP_ACCESS); @@ -703,7 +703,7 @@ void HDF5IOHandlerImpl::openDataset(Writable* writable, Parameter< Operation::OPEN_DATASET > & parameters) { - File file = getFile( writable->parent ).get(); + File file = getFile( writable->parent ).value(); hid_t node_id, dataset_id; hid_t gapl = H5Pcreate(H5P_GROUP_ACCESS); @@ -823,7 +823,7 @@ HDF5IOHandlerImpl::deleteFile(Writable* writable, if( writable->written ) { - hid_t file_id = getFile( writable ).get().id; + hid_t file_id = getFile( writable ).value().id; herr_t status = H5Fclose(file_id); VERIFY(status == 0, "[HDF5] Internal error: Failed to close HDF5 file during file deletion"); @@ -866,7 +866,7 @@ HDF5IOHandlerImpl::deletePath(Writable* writable, * Work around this by deleting from the parent */ auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id = H5Gopen(file.id, concrete_h5_file_position(writable->parent).c_str(), H5P_DEFAULT); @@ -909,7 +909,7 @@ HDF5IOHandlerImpl::deleteDataset(Writable* writable, * Work around this by deleting from the parent */ auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id = H5Gopen(file.id, concrete_h5_file_position(writable->parent).c_str(), H5P_DEFAULT); @@ -944,7 +944,7 @@ HDF5IOHandlerImpl::deleteAttribute(Writable* writable, /* Open H5Object to delete in */ auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id = H5Oopen(file.id, concrete_h5_file_position(writable).c_str(), H5P_DEFAULT); @@ -967,7 +967,7 @@ HDF5IOHandlerImpl::writeDataset(Writable* writable, throw std::runtime_error("[HDF5] Writing into a dataset in a file opened as read only is not possible."); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t dataset_id, filespace, memspace; herr_t status; @@ -1061,7 +1061,7 @@ HDF5IOHandlerImpl::writeAttribute(Writable* writable, throw std::runtime_error("[HDF5] Writing an attribute in a file opened as read only is not possible."); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id, attribute_id; hid_t fapl = H5Pcreate(H5P_LINK_ACCESS); @@ -1340,7 +1340,7 @@ HDF5IOHandlerImpl::readDataset(Writable* writable, Parameter< Operation::READ_DATASET > & parameters) { auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t dataset_id, memspace, filespace; herr_t status; dataset_id = H5Dopen(file.id, @@ -1430,7 +1430,7 @@ HDF5IOHandlerImpl::readAttribute(Writable* writable, throw std::runtime_error("[HDF5] Internal error: Writable not marked written during attribute read"); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t obj_id, attr_id; herr_t status; @@ -1871,7 +1871,7 @@ HDF5IOHandlerImpl::listPaths(Writable* writable, throw std::runtime_error("[HDF5] Internal error: Writable not marked written during path listing"); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t gapl = H5Pcreate(H5P_GROUP_ACCESS); #if H5_VERSION_GE(1,10,0) && openPMD_HAVE_MPI @@ -1916,7 +1916,7 @@ HDF5IOHandlerImpl::listDatasets(Writable* writable, throw std::runtime_error("[HDF5] Internal error: Writable not marked written during dataset listing"); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t gapl = H5Pcreate(H5P_GROUP_ACCESS); #if H5_VERSION_GE(1,10,0) && openPMD_HAVE_MPI @@ -1960,7 +1960,7 @@ void HDF5IOHandlerImpl::listAttributes(Writable* writable, throw std::runtime_error("[HDF5] Internal error: Writable not marked written during attribute listing"); auto res = getFile( writable ); - File file = res ? res.get() : getFile( writable->parent ).get(); + File file = res ? res.value() : getFile( writable->parent ).value(); hid_t node_id; hid_t fapl = H5Pcreate(H5P_LINK_ACCESS); @@ -2015,24 +2015,23 @@ void HDF5IOHandlerImpl::listAttributes(Writable* writable, VERIFY(status == 0, "[HDF5] Internal error: Failed to close HDF5 property during dataset listing"); } -auxiliary::Option< HDF5IOHandlerImpl::File > +std::optional< HDF5IOHandlerImpl::File > HDF5IOHandlerImpl::getFile( Writable * writable ) { - using namespace auxiliary; auto it = m_fileNames.find( writable ); if( it == m_fileNames.end() ) { - return Option< File >(); + return std::optional< File >(); } auto it2 = m_fileNamesWithID.find( it->second ); if( it2 == m_fileNamesWithID.end() ) { - return Option< File >(); + return std::optional< File >(); } File res; res.name = it->second; res.id = it2->second; - return makeOption( std::move( res ) ); + return std::make_optional( std::move( res ) ); } #endif diff --git a/src/IO/JSON/JSONIOHandlerImpl.cpp b/src/IO/JSON/JSONIOHandlerImpl.cpp index 878ea9e847..4de27707a4 100644 --- a/src/IO/JSON/JSONIOHandlerImpl.cpp +++ b/src/IO/JSON/JSONIOHandlerImpl.cpp @@ -21,7 +21,6 @@ #include "openPMD/auxiliary/Filesystem.hpp" #include "openPMD/auxiliary/Memory.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/StringManip.hpp" #include "openPMD/backend/Writable.hpp" #include "openPMD/Datatype.hpp" @@ -30,6 +29,7 @@ #include #include +#include namespace openPMD @@ -436,7 +436,7 @@ namespace openPMD * Check whether two chunks can be merged to form a large one * and optionally return that larger chunk */ - auxiliary::Option< WrittenChunkInfo > + std::optional< WrittenChunkInfo > mergeChunks( WrittenChunkInfo const & chunk1, WrittenChunkInfo const & chunk2 ) @@ -490,10 +490,10 @@ namespace openPMD Offset offset( c1->offset ); Extent extent( c1->extent ); extent[ dim ] += c2->extent[ dim ]; - return auxiliary::makeOption( + return std::make_optional( WrittenChunkInfo( offset, extent ) ); } - return auxiliary::Option< WrittenChunkInfo >(); + return std::optional< WrittenChunkInfo >(); } /* @@ -518,7 +518,7 @@ namespace openPMD { for( auto j = i + 1; j < table.end(); ++j ) { - auxiliary::Option< WrittenChunkInfo > merged = + std::optional< WrittenChunkInfo > merged = mergeChunks( *i, *j ); if( merged ) { @@ -527,7 +527,7 @@ namespace openPMD table.erase( j ); table.erase( i ); table.emplace_back( - std::move( merged.get() ) ); + std::move( merged.value() ) ); return true; } } diff --git a/src/Iteration.cpp b/src/Iteration.cpp index cb5b2fb709..698e4b10e0 100644 --- a/src/Iteration.cpp +++ b/src/Iteration.cpp @@ -323,7 +323,7 @@ Iteration::flush() void Iteration::deferParseAccess( DeferredParseAccess dr ) { get().m_deferredParseAccess = - auxiliary::makeOption< DeferredParseAccess >( std::move( dr ) ); + std::make_optional< DeferredParseAccess >( std::move( dr ) ); } void Iteration::read() @@ -333,7 +333,7 @@ void Iteration::read() { return; } - auto const & deferred = it.m_deferredParseAccess.get(); + auto const & deferred = it.m_deferredParseAccess.value(); if( deferred.fileBased ) { readFileBased( deferred.filename, deferred.path ); @@ -343,7 +343,7 @@ void Iteration::read() readGorVBased( deferred.path ); } // reset this thing - it.m_deferredParseAccess = auxiliary::Option< DeferredParseAccess >(); + it.m_deferredParseAccess = std::optional< DeferredParseAccess >(); } void Iteration::reread( std::string const & path ) diff --git a/src/ReadIterations.cpp b/src/ReadIterations.cpp index 6c88ccd2be..92d520a92b 100644 --- a/src/ReadIterations.cpp +++ b/src/ReadIterations.cpp @@ -96,7 +96,7 @@ SeriesIterator & SeriesIterator::operator++() *this = end(); return *this; } - Series & series = m_series.get(); + Series & series = m_series.value(); auto & iterations = series.iterations; auto & currentIteration = iterations[ m_currentIteration ]; if( !currentIteration.closed() ) @@ -163,7 +163,7 @@ SeriesIterator & SeriesIterator::operator++() IndexedIteration SeriesIterator::operator*() { return IndexedIteration( - m_series.get().iterations[ m_currentIteration ], m_currentIteration ); + m_series.value().iterations[ m_currentIteration ], m_currentIteration ); } bool SeriesIterator::operator==( SeriesIterator const & other ) const diff --git a/src/Series.cpp b/src/Series.cpp index 519710aa3f..8147792d78 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -1182,7 +1182,7 @@ Series::iterationFilename( uint64_t i ) auto & series = get(); if( series.m_overrideFilebasedFilename.has_value() ) { - return series.m_overrideFilebasedFilename.get(); + return series.m_overrideFilebasedFilename.value(); } std::stringstream iteration( "" ); iteration << std::setw( series.m_filenamePadding ) @@ -1488,7 +1488,7 @@ namespace json::asLowerCaseStringDynamic( config[ key ].json() ); if( maybeString.has_value() ) { - dest = std::move( maybeString.get() ); + dest = std::move( maybeString.value() ); } else { @@ -1573,7 +1573,7 @@ SeriesData::~SeriesData() try { // WriteIterations gets the first shot at flushing - this->m_writeIterations = auxiliary::Option< WriteIterations >(); + this->m_writeIterations = std::optional< WriteIterations >(); /* * Scenario: A user calls `Series::flush()` but does not check for * thrown exceptions. The exception will propagate further up, usually @@ -1669,7 +1669,7 @@ Series::writeIterations() { series.m_writeIterations = WriteIterations( this->iterations ); } - return series.m_writeIterations.get(); + return series.m_writeIterations.value(); } namespace diff --git a/src/WriteIterations.cpp b/src/WriteIterations.cpp index 678767ae60..7e90a33391 100644 --- a/src/WriteIterations.cpp +++ b/src/WriteIterations.cpp @@ -35,7 +35,7 @@ WriteIterations::SharedResources::~SharedResources() if( currentlyOpen.has_value() && iterations.retrieveSeries().get().m_lastFlushSuccessful ) { - auto lastIterationIndex = currentlyOpen.get(); + auto lastIterationIndex = currentlyOpen.value(); auto & lastIteration = iterations.at( lastIterationIndex ); if( !lastIteration.closed() ) { @@ -60,7 +60,7 @@ WriteIterations::mapped_type & WriteIterations::operator[]( key_type && key ) { if( shared->currentlyOpen.has_value() ) { - auto lastIterationIndex = shared->currentlyOpen.get(); + auto lastIterationIndex = shared->currentlyOpen.value(); auto & lastIteration = shared->iterations.at( lastIterationIndex ); if( lastIterationIndex != key && !lastIteration.closed() ) { diff --git a/src/auxiliary/JSON.cpp b/src/auxiliary/JSON.cpp index 214116ae84..1e78d61538 100644 --- a/src/auxiliary/JSON.cpp +++ b/src/auxiliary/JSON.cpp @@ -23,7 +23,6 @@ #include "openPMD/auxiliary/JSON_internal.hpp" #include "openPMD/auxiliary/Filesystem.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/StringManip.hpp" #include @@ -33,6 +32,7 @@ #include #include // std::cerr #include +#include #include #include // std::forward #include @@ -132,7 +132,7 @@ namespace openPMD::json } namespace { - auxiliary::Option< std::string > + std::optional< std::string > extractFilename( std::string const & unparsed ) { std::string trimmed = auxiliary::trim( @@ -142,11 +142,11 @@ namespace openPMD::json trimmed = trimmed.substr( 1 ); trimmed = auxiliary::trim( trimmed, []( char c ) { return std::isspace( c ); } ); - return auxiliary::makeOption( trimmed ); + return std::make_optional( trimmed ); } else { - return auxiliary::Option< std::string >{}; + return std::optional< std::string >{}; } } @@ -324,11 +324,11 @@ namespace openPMD::json { std::fstream handle; handle.open( - filename.get(), std::ios_base::binary | std::ios_base::in ); + filename.value(), std::ios_base::binary | std::ios_base::in ); ParsedConfig res; - if( auxiliary::ends_with( filename.get(), ".toml" ) ) + if( auxiliary::ends_with( filename.value(), ".toml" ) ) { - toml::value tomlVal = toml::parse( handle, filename.get() ); + toml::value tomlVal = toml::parse( handle, filename.value() ); res.config = tomlToJson( tomlVal ); res.originallySpecifiedAs = SupportedLanguages::TOML; } @@ -342,7 +342,7 @@ namespace openPMD::json { throw std::runtime_error( "Failed reading JSON config from file " + - filename.get() + "." ); + filename.value() + "." ); } lowerCase( res.config ); return res; @@ -362,14 +362,14 @@ namespace openPMD::json { ParsedConfig res; std::string fileContent = - auxiliary::collective_file_read( filename.get(), comm ); - if( auxiliary::ends_with( filename.get(), ".toml" ) ) + auxiliary::collective_file_read( filename.value(), comm ); + if( auxiliary::ends_with( filename.value(), ".toml" ) ) { std::istringstream istream( fileContent.c_str(), std::ios_base::binary | std::ios_base::in ); res.config = - tomlToJson( toml::parse( istream, filename.get() ) ); + tomlToJson( toml::parse( istream, filename.value() ) ); res.originallySpecifiedAs = SupportedLanguages::TOML; } else @@ -482,7 +482,7 @@ namespace openPMD::json } ); } - auxiliary::Option< std::string > + std::optional< std::string > asStringDynamic( nlohmann::json const & value ) { if( value.is_string() ) @@ -501,16 +501,16 @@ namespace openPMD::json { return std::string( value.get< bool >() ? "1" : "0" ); } - return auxiliary::Option< std::string >{}; + return std::optional< std::string >{}; } - auxiliary::Option< std::string > + std::optional< std::string > asLowerCaseStringDynamic( nlohmann::json const & value ) { auto maybeString = asStringDynamic( value ); if( maybeString.has_value() ) { - auxiliary::lowerCase( maybeString.get() ); + auxiliary::lowerCase( maybeString.value() ); } return maybeString; } diff --git a/test/AuxiliaryTest.cpp b/test/AuxiliaryTest.cpp index 2004809603..c56fbb84d8 100644 --- a/test/AuxiliaryTest.cpp +++ b/test/AuxiliaryTest.cpp @@ -9,7 +9,6 @@ #include "openPMD/backend/Container.hpp" #include "openPMD/auxiliary/DerefDynamicCast.hpp" #include "openPMD/auxiliary/Filesystem.hpp" -#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/StringManip.hpp" #include "openPMD/auxiliary/Variant.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" @@ -41,33 +40,6 @@ struct TestHelper : public Attributable } // openPMD -TEST_CASE( "optional", "[auxiliary]" ) { - using namespace auxiliary; - - Option opt; - - REQUIRE_THROWS_AS(opt.get(), std::bad_variant_access); - REQUIRE_THROWS_AS(opt.get() = 42, std::bad_variant_access); - REQUIRE(!opt); - REQUIRE(!opt.has_value()); - - opt = 43; - REQUIRE(opt); - REQUIRE(opt.has_value()); - REQUIRE(opt.get() == 43); - - Option opt2{ opt }; - REQUIRE(opt2); - REQUIRE(opt2.has_value()); - REQUIRE(opt2.get() == 43); - - Option opt3 = makeOption( 3 ); - REQUIRE(opt3); - REQUIRE(opt3.has_value()); - REQUIRE(opt3.get() == 3); -} - - TEST_CASE( "deref_cast_test", "[auxiliary]" ) { using namespace auxiliary; diff --git a/test/JSONTest.cpp b/test/JSONTest.cpp index fc3ea0e14e..268c92368f 100644 --- a/test/JSONTest.cpp +++ b/test/JSONTest.cpp @@ -173,29 +173,3 @@ TEST_CASE( "json_merging", "auxiliary" ) json::merge( defaultVal, overwrite ) == json::parseOptions( expect, false ).config.dump() ); } - -TEST_CASE( "optional", "[auxiliary]" ) { - using namespace auxiliary; - - Option opt; - - REQUIRE_THROWS_AS(opt.get(), std::bad_variant_access); - REQUIRE_THROWS_AS(opt.get() = 42, std::bad_variant_access); - REQUIRE(!opt); - REQUIRE(!opt.has_value()); - - opt = 43; - REQUIRE(opt); - REQUIRE(opt.has_value()); - REQUIRE(opt.get() == 43); - - Option opt2{ opt }; - REQUIRE(opt2); - REQUIRE(opt2.has_value()); - REQUIRE(opt2.get() == 43); - - Option opt3 = makeOption( 3 ); - REQUIRE(opt3); - REQUIRE(opt3.has_value()); - REQUIRE(opt3.get() == 3); -}