Commit 9a897e23 authored by Michael Kuron's avatar Michael Kuron 🔬 Committed by Christian Godenschwager

[API] Remove boost::any and boost::optional

API changes in blockforest::PhantomBlockForest, blockforest::loadbalancing, pe::amr::weight_assignment
mpi can now only send/receive walberla::optional instead of boost::optional
parent 8145e769
......@@ -474,6 +474,30 @@ else()
endif()
endif()
try_compile( WALBERLA_USE_STD_ANY "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestStdAny.cpp"
COMPILE_DEFINITIONS -DWALBERLA_USE_STD_ANY -std=c++14 )
if( WALBERLA_USE_STD_ANY )
message( STATUS "Found std::any")
else()
try_compile( WALBERLA_USE_STD_EXPERIMENTAL_ANY "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestStdAny.cpp"
COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_ANY -std=c++14 )
if( WALBERLA_USE_STD_EXPERIMENTAL_ANY )
message( STATUS "Found std::experimental::any")
endif()
endif()
try_compile( WALBERLA_USE_STD_OPTIONAL "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestStdOptional.cpp"
COMPILE_DEFINITIONS -DWALBERLA_USE_STD_OPTIONAL -std=c++14 )
if( WALBERLA_USE_STD_OPTIONAL )
message( STATUS "Found std::optional")
else()
try_compile( WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestStdOptional.cpp"
COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL -std=c++14 )
if( WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL )
message( STATUS "Found std::experimental::optional")
endif()
endif()
############################################################################################################################
......
......@@ -1285,7 +1285,7 @@ public:
markEmptyBlocks_( markEmptyBlocks ), state_( state )
{}
void operator()( std::vector< std::pair< const PhantomBlock *, boost::any > > & blockData, const PhantomBlockForest & )
void operator()( std::vector< std::pair< const PhantomBlock *, walberla::any > > & blockData, const PhantomBlockForest & )
{
for( auto it = blockData.begin(); it != blockData.end(); ++it )
{
......@@ -1309,7 +1309,7 @@ struct Pseudo2DPhantomWeightPackUnpack
buffer << block.getData< Pseudo2DPhantomWeight >().weight();
}
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, boost::any & data )
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, walberla::any & data )
{
Pseudo2DPhantomWeight::weight_t w;
buffer >> w;
......
#include <iostream>
#if defined(WALBERLA_USE_STD_ANY)
#include <any>
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_ANY)
#include <experimental/any>
#endif
int main() {
#if defined(WALBERLA_USE_STD_ANY)
auto a = std::any(42);
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_ANY)
auto a = std::experimental::any(42);
#endif
std::cout << std::experimental::any_cast<int>(a) << std::endl;
return 0;
}
#include <iostream>
#if defined(WALBERLA_USE_STD_OPTIONAL)
#include <optional>
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL)
#include <experimental/optional>
#endif
int main() {
#if defined(WALBERLA_USE_STD_OPTIONAL)
auto a = std::optional<int>();
auto b = std::optional<int>(42);
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL)
auto a = std::experimental::optional<int>();
auto b = std::experimental::optional<int>(42);
#endif
if (b)
std::cout << a.value_or(b.value()) << std::endl;
return 0;
}
......@@ -28,11 +28,10 @@
#include "core/debug/Debug.h"
#include "core/math/AABB.h"
#include "core/uid/SUID.h"
#include "core/Any.h"
#include <vector>
#include <boost/any.hpp>
namespace walberla {
......@@ -86,7 +85,7 @@ public:
void addData( const T & data ) { data_ = data; }
template< typename T >
T getData() const { return boost::any_cast<T>( data_ ); }
T getData() const { return walberla::any_cast<T>( data_ ); }
bool hasData() const { return !(data_.empty()); }
......@@ -143,7 +142,7 @@ private:
uint_t level_;
// set by the user/application via callback
boost::any data_;
walberla::any data_;
std::vector< NeighborBlock* > neighborhoodSection_[26]; // the 26 neighborhood sections (can be restored from 'neighborhood_')
std::vector< NeighborBlock > neighborhood_; // all neighbor blocks
......
......@@ -256,13 +256,13 @@ void PhantomBlockForest::assignBlockData( const PhantomBlockDataAssignmentFuncti
{
if( function )
{
std::vector< std::pair< const PhantomBlock *, boost::any > > blockData;
std::vector< std::pair< const PhantomBlock *, walberla::any > > blockData;
for( auto it = blocks_.begin(); it != blocks_.end(); ++it )
{
auto & block = it->second;
WALBERLA_ASSERT_NOT_NULLPTR( block.get() );
blockData.push_back( std::make_pair( block.get(), boost::any() ) );
blockData.push_back( std::make_pair( block.get(), walberla::any() ) );
}
function( blockData, *this );
......@@ -484,7 +484,7 @@ void PhantomBlockForest::migrate( const PhantomBlockDataPackFunction & packBlock
if( unpackBlockData )
{
WALBERLA_ASSERT( static_cast<bool>(packBlockData) );
boost::any data;
walberla::any data;
unpackBlockData( buffer, *phantom, data );
phantom->addData( data );
}
......
......@@ -45,7 +45,7 @@ public:
typedef std::function< Set<SUID> ( const std::vector< std::pair< BlockID, Set<SUID> > > & source, const BlockID & destintation ) >
BlockStateDeterminationFunction;
typedef std::function< void ( std::vector< std::pair< const PhantomBlock *, boost::any > > & blockData,
typedef std::function< void ( std::vector< std::pair< const PhantomBlock *, walberla::any > > & blockData,
const PhantomBlockForest & phantomForest ) >
PhantomBlockDataAssignmentFunction;
......@@ -58,7 +58,7 @@ public:
MigrationPreparationFunction; // = load balancing
typedef std::function< void ( mpi::SendBuffer & buffer, const PhantomBlock & block ) > PhantomBlockDataPackFunction;
typedef std::function< void ( mpi::RecvBuffer & buffer, const PhantomBlock & block, boost::any & data ) > PhantomBlockDataUnpackFunction;
typedef std::function< void ( mpi::RecvBuffer & buffer, const PhantomBlock & block, walberla::any & data ) > PhantomBlockDataUnpackFunction;
......
......@@ -119,7 +119,7 @@ struct DynamicParMetisBlockInfoPackUnpack
block.getData< DynamicParMetisBlockInfo >().toBuffer( buffer );
}
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, boost::any & data )
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, walberla::any & data )
{
data = DynamicParMetisBlockInfo( buffer );
}
......
......@@ -53,7 +53,7 @@ struct PODPhantomWeightPackUnpack
buffer << block.getData< PODPhantomWeight<T> >().weight();
}
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, boost::any & data )
void operator()( mpi::RecvBuffer & buffer, const PhantomBlock &, walberla::any & data )
{
typename PODPhantomWeight<T>::weight_t w;
buffer >> w;
......
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla 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
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Any.h
//! \ingroup core
//! \author Michael Kuron <mkuron@icp.uni-stuttgart.de>
//
//======================================================================================================================
#pragma once
#if defined(WALBERLA_USE_STD_ANY)
#include <any>
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_ANY)
#include <experimental/any>
#else
#include <boost/any.hpp>
#endif
namespace walberla {
#if defined(WALBERLA_USE_STD_ANY)
using std::any;
using std::any_cast;
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_ANY)
using std::experimental::any;
using std::experimental::any_cast;
#else
using boost::any;
using boost::any_cast;
#endif
}
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) OPTIONAL later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// OPTIONAL WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file Optional.h
//! \ingroup core
//! \author Michael Kuron <mkuron@icp.uni-stuttgart.de>
//
//======================================================================================================================
#pragma once
#if defined(WALBERLA_USE_STD_OPTIONAL)
#include <optional>
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL)
#include <experimental/optional>
#else
#include <boost/optional.hpp>
#endif
namespace walberla {
#if defined(WALBERLA_USE_STD_OPTIONAL)
using std::optional;
using std::nullopt;
#elif defined(WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL)
using std::experimental::optional;
using std::experimental::nullopt;
#else
using boost::optional;
const boost::none_t nullopt = boost::none;
#endif
}
......@@ -27,10 +27,10 @@
#include "SendBuffer.h"
#include "core/Conversion.h"
#include "core/DataTypes.h"
#include "core/Optional.h"
#include <boost/array.hpp>
#include <boost/integer.hpp>
#include <boost/optional.hpp>
#include <boost/uuid/uuid.hpp>
#include <deque>
......@@ -465,18 +465,18 @@ struct BufferSizeTrait< std::multimap<K,T,C,A> > { static const bool constantSiz
// ---------------------------------------------------------------------------------------------------------------------
// ------------------------------------- Boost optional Support --------------------------------------------------------
// ------------------------------------------- optional Support --------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
template< typename T, // Element type of SendBuffer
typename G, // Growth policy of SendBuffer
typename OT> // Optional type
GenericSendBuffer<T,G>& operator<<( GenericSendBuffer<T,G> & buf, const boost::optional<OT> & o )
GenericSendBuffer<T,G>& operator<<( GenericSendBuffer<T,G> & buf, const walberla::optional<OT> & o )
{
buf.addDebugMarker( "op" );
bool hasContent = true;
if (o == boost::none)
if (o == walberla::nullopt)
hasContent = false;
buf << hasContent;
......@@ -489,7 +489,7 @@ GenericSendBuffer<T,G>& operator<<( GenericSendBuffer<T,G> & buf, const boost::o
template< typename T, // Element type of RecvBuffer
typename OT> // Optional type
GenericRecvBuffer<T>& operator>>( GenericRecvBuffer<T> & buf, boost::optional<OT> & o )
GenericRecvBuffer<T>& operator>>( GenericRecvBuffer<T> & buf, walberla::optional<OT> & o )
{
buf.readDebugMarker( "op" );
......@@ -509,7 +509,7 @@ GenericRecvBuffer<T>& operator>>( GenericRecvBuffer<T> & buf, boost::optional<OT
}
else
{
o = boost::none;
o = walberla::nullopt;
}
return buf;
......
......@@ -38,7 +38,7 @@ public:
MetisAssignmentFunctor( const shared_ptr<InfoCollection>& ic ) : ic_( ic )
{}
void operator()( std::vector< std::pair< const PhantomBlock *, boost::any > > & blockData, const PhantomBlockForest & )
void operator()( std::vector< std::pair< const PhantomBlock *, walberla::any > > & blockData, const PhantomBlockForest & )
{
for( auto it = blockData.begin(); it != blockData.end(); ++it )
{
......
......@@ -40,7 +40,7 @@ public:
WeightAssignmentFunctor( shared_ptr<InfoCollection>& ic ) : ic_(ic) {}
void operator()( std::vector< std::pair< const PhantomBlock *, boost::any > > & blockData, const PhantomBlockForest & )
void operator()( std::vector< std::pair< const PhantomBlock *, walberla::any > > & blockData, const PhantomBlockForest & )
{
for( auto it = blockData.begin(); it != blockData.end(); ++it )
{
......
......@@ -44,6 +44,10 @@
#cmakedefine WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM
#cmakedefine WALBERLA_USE_STD_FILESYSTEM
#cmakedefine WALBERLA_USE_STD_EXPERIMENTAL_ANY
#cmakedefine WALBERLA_USE_STD_ANY
#cmakedefine WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL
#cmakedefine WALBERLA_USE_STD_OPTIONAL
// SIMD
#cmakedefine WALBERLA_SIMD_FORCE_SCALAR
......
......@@ -263,7 +263,7 @@ void bufferTestUInt8()
{
std::string stdString("Hello World!"), stdStringEmpty;
boost::optional<int> optional0, optional1, optional2, optional3;
walberla::optional<int> optional0, optional1, optional2, optional3;
optional2 = 23;
optional3 = 42;
......@@ -277,7 +277,7 @@ void bufferTestUInt8()
std::string recvStdString, recvStdStringEmpty;
boost::optional<int> recvOptional0, recvOptional1, recvOptional2, recvOptional3;
walberla::optional<int> recvOptional0, recvOptional1, recvOptional2, recvOptional3;
recvOptional0 = 123;
recvOptional1 = 123;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment