Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jakub.both/dune-common
  • samuel.burbulla/dune-common
  • patrick.jaap/dune-common
  • tobias.leibner/dune-common
  • alexander.mueller/dune-common
  • pipping/dune-common
  • Xinyun.Li/dune-common
  • felix.schindler/dune-common
  • simon.praetorius/dune-common
  • ani.anciaux-sedrakian/dune-common
  • henrik.stolzmann/dune-common
  • matthew.t.collins/dune-common
  • liam.keegan/dune-common
  • felix.mueller/dune-common
  • ansgar/dune-common
  • dominic/dune-common
  • lars.lubkoll/dune-common
  • exadune/dune-common
  • felix.gruber/dune-common
  • govind.sahai/dune-common
  • michael.sghaier/dune-common
  • core/dune-common
  • kilian.weishaupt/dune-common
  • markus.blatt/dune-common
  • joscha.podlesny/dune-common
  • andreas.thune/dune-common
  • lars.bilke/dune-common
  • daniel.kienle/dune-common
  • lukas.renelt/dune-common
  • smuething/dune-common
  • stephan.hilb/dune-common
  • tkoch/dune-common
  • nils.dreier/dune-common
  • rene.milk/dune-common
  • lasse.hinrichsen/dune-common
  • yunus.sevinchan/dune-common
  • lisa_julia.nebel/dune-common
  • claus-justus.heine/dune-common
  • lorenzo.cerrone/dune-common
  • eduardo.bueno/dune-common
40 results
Show changes
Commits on Source (33)
Showing
with 393 additions and 256 deletions
......@@ -225,8 +225,8 @@ while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do
while [ -z "$MAINTAINER" ]; do
read -p "4) Maintainer's email address? " MAINTAINER
done
while [ "$ENABLE_ALL" != "y" -a "$ENABLE_ALL" != "Y" ]; do
read -p "5) Enable all found packages? (WE strongly recommend yes, unless you know exactly what you are doing) [y/N]" ENABLE_ALL
while [ "$ENABLE_ALL" != "y" -a "$ENABLE_ALL" != "N" ]; do
read -p "5) Enable all found packages? (This will result in a simplified build system. Read the doc in dune-common/cmake/modules/DuneEnableAllPackages.cmake for details.) [y/N]" ENABLE_ALL
done
echo
......
......@@ -60,7 +60,33 @@ check_cxx_source_compiles("
return 0;
}
" HAVE_NULLPTR
)
)
if(HAVE_NULLPTR)
check_cxx_source_compiles("
#include <cstddef>
int main(void)
{
std::nullptr_t npt = nullptr;
return 0;
}
" HAVE_NULLPTR_T
)
if (NOT HAVE_NULLPTR_T)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
message(FATAL_ERROR "Your compiler supports the 'nullptr' keyword, but not the type std::nullptr_t.
You are using an Intel compiler, where this error is typically caused by an outdated underlying system GCC.
Check if 'gcc --version' gives you at least GCC 4.6, otherwise please install a newer GCC and point your Intel compiler at it using the '-gcc-name' or '-gxx-name' options (see 'man icc' for further details)."
)
else()
message(FATAL_ERROR "Your compiler supports the 'nullptr' keyword, but not the type std::nullptr_t.
THIS SHOULD NOT HAPPEN FOR YOUR COMPILER!
Please submit a bug at https://dune-project.org/flyspray/"
)
endif()
endif()
endif()
# __attribute__((unused))
check_cxx_source_compiles("
......@@ -278,8 +304,16 @@ if(${CMAKE_VERSION} VERSION_LESS "3.1")
else()
find_package(Threads)
endif()
set(STDTHREAD_LINK_FLAGS "${CMAKE_THREAD_LIBS_INIT}"
CACHE STRING "Linker flags needed to get working C++11 threads support")
# see whether threading needs -no-as-needed
if(EXISTS /etc/dpkg/origins/ubuntu)
set(NO_AS_NEEDED "-Wl,-no-as-needed ")
else(EXISTS /etc/dpkg/origins/ubuntu)
set(NO_AS_NEEDED "")
endif(EXISTS /etc/dpkg/origins/ubuntu)
set(STDTHREAD_LINK_FLAGS "${NO_AS_NEEDED}${CMAKE_THREAD_LIBS_INIT}"
CACHE STRING "Linker flags needed to get working C++11 threads support. On Ubuntu it may be necessary to include -Wl,-no-as-needed (see FS#1650).")
# set linker flags
#
......
......@@ -8,7 +8,8 @@
# perform tests
include(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES("#include <cxxabi.h>
CHECK_CXX_SOURCE_COMPILES("#include <typeinfo>
#include <cxxabi.h>
int main(void){
int foobar = 0;
const char *foo = typeid(foobar).name();
......
# This module provides the macros necessary for a simplified CMake build system
#
# The dune build system relies on the user to choose and add the compile and link flags
# The DUNE build system relies on the user to choose and add the compile and link flags
# necessary to build an executable. While this offers full control to the user, it
# is an error-prone procedure.
#
# Alternatively, users may use this modules macros to simply add the compile flags for all
# found external modules to all executables in a module. Likewise, all found libraries are
# Alternatively, users may use the macros in this module to simply add the compile flags for all
# found external modules to all executables in a DUNE module. Likewise, all found libraries are
# linked to all targets.
#
# This module provides the following macros:
#
# dune_enable_all_packages(INCLUDE_DIRS [include_dirs]
# COMPILE_DEFINITIONS [compile_definitions]
# COMPILE_OPTIONS [compile_options]
# MODULE_LIBRARIES [libraries]
# [VERBOSE] [APPEND]
# )
......@@ -32,37 +33,53 @@
# Warning: The library feature requires CMake 3.1+. If you use the feature with older versions, CMake
# will emit a fatal error. Moreover, it will issue a warning if the cmake_minimum_required()
# version is older than 3.1.
# Note: If you want to use dune_enable_all_packages() with an older version of CMake and your DUNE mdule
# creates its own library, you have to manually create the library in the top-level CMakeLists.txt
# file using dune_add_library() (with all sources listed within that call), use
# dune_target_enable_all_packages() to add all packages to the library and finally list that library
# under LIBRARIES in the call to dune_register_package_flags(). See dune-pdelab for an example of
# how to do this correctly.
#
# For a description of the APPEND option, see the documentation of dune_register_package_flags().
# With the VERBOSE option being set, the list of flags is printed during configure.
#
# dune_register_package_flags(COMPILE_DEFINITIONS flags
# INCLUDE_DIRS includes
# LIBRARIES libs
# [APPEND]
# )
#
# To implement above feature, the compile flags, include paths and link flags of all
# found packages must be registered with this macro. This macro is only necessary for people
# that do link against additional libraries which are not supported by the dune core modules.
# Call this at the end of every find module. If you are using an external find module which
# you cannot alter, call it after the call find_package().
# The APPEND parameter appends the given flags to the global list instead of prepending.
# Only use it, if you know what you are doing.
# With the VERBOSE option set, the list of flags is printed during configure.
#
#
# dune_target_enable_all_packages(TARGETS [target] ...)
#
# Adds all currently registered package flags (see dune_register_package_flags()) to the given targets.
# This macro is mainly intended to help write DUNE modules that want to use dune_enable_all_packages() and
# define their own libraries, but need to be compatible with CMake < 3.1.
#
#
# dune_register_package_flags(COMPILE_DEFINITIONS [flags]
# COMPILE_OPTIONS [options]
# INCLUDE_DIRS {includes]
# LIBRARIES [libs]
# [APPEND]
# )
#
# To correctly implement the automatic handling of external libraries, the compile flags, include paths and link
# flags of all found packages must be registered with this function. This macro is only necessary for people that
# want to write their own FindFooBar CMake modules to link against additional libraries which are not supported by
# the DUNE core modules. Call this function at the end of every find module. If you are using an external FindFoo
# module which you cannot alter, call it after the call to find_package(foo).
# The APPEND parameter appends the given flags to the global list instead of prepending. Only use it, if you know
# what you are doing.
#
#
# dune_library_add_sources(module_library
# SOURCES [sources]
# )
#
# Adds the source files listed in [sources] to the module library module_library created by an earlier
# call to dune_enable_all_packages.
# Adds the source files listed in [sources] to the DUNE module library module_library created by an earlier
# call to dune_enable_all_packages() in the current DUNE module.
#
function(dune_register_package_flags)
include(CMakeParseArguments)
set(OPTIONS APPEND)
set(SINGLEARGS)
set(MULTIARGS COMPILE_DEFINITIONS INCLUDE_DIRS LIBRARIES)
set(MULTIARGS COMPILE_DEFINITIONS COMPILE_OPTIONS INCLUDE_DIRS LIBRARIES)
cmake_parse_arguments(REGISTRY "${OPTIONS}" "${SINGLEARGS}" "${MULTIARGS}" ${ARGN})
if(REGISTRY_UNPARSED_ARGUMENTS)
......@@ -73,18 +90,21 @@ function(dune_register_package_flags)
set_property(GLOBAL APPEND PROPERTY ALL_PKG_INCS "${REGISTRY_INCLUDE_DIRS}")
set_property(GLOBAL APPEND PROPERTY ALL_PKG_LIBS "${REGISTRY_LIBRARIES}")
set_property(GLOBAL APPEND PROPERTY ALL_PKG_DEFS "${REGISTRY_COMPILE_DEFINITIONS}")
set_property(GLOBAL APPEND PROPERTY ALL_PKG_OPTS "${REGISTRY_COMPILE_OPTIONS}")
else(REGISTRY_APPEND)
get_property(all_incs GLOBAL PROPERTY ALL_PKG_INCS)
get_property(all_libs GLOBAL PROPERTY ALL_PKG_LIBS)
get_property(all_defs GLOBAL PROPERTY ALL_PKG_DEFS)
get_property(all_opts GLOBAL PROPERTY ALL_PKG_OPTS)
set_property(GLOBAL PROPERTY ALL_PKG_INCS "${REGISTRY_INCLUDE_DIRS}" "${all_incs}")
set_property(GLOBAL PROPERTY ALL_PKG_LIBS "${REGISTRY_LIBRARIES}" "${all_libs}")
set_property(GLOBAL PROPERTY ALL_PKG_DEFS "${REGISTRY_COMPILE_DEFINITIONS}" "${all_defs}")
set_property(GLOBAL PROPERTY ALL_PKG_OPTS "${REGISTRY_COMPILE_OPTIONS}" "${all_opts}")
endif(REGISTRY_APPEND)
endfunction(dune_register_package_flags)
macro(dune_enable_all_packages)
function(dune_enable_all_packages)
include(CMakeParseArguments)
set(OPTIONS APPEND VERBOSE)
set(SINGLEARGS)
......@@ -115,7 +135,7 @@ macro(dune_enable_all_packages)
# handle additional compile definitions specified in dune_enable_all_packages
if(DUNE_ENABLE_ALL_PACKAGES_COMPILE_DEFINITIONS)
if(DUNE_ENABLE_ALL_PACKAGES_COMPILE_DEFINITIONS)
if(DUNE_ENABLE_ALL_PACKAGES_APPEND)
set_property(GLOBAL APPEND PROPERTY ALL_PKG_DEFS "${DUNE_ENABLE_ALL_PACKAGES_COMPILE_DEFINITIONS}")
else(DUNE_ENABLE_ALL_PACKAGES_APPEND)
get_property(all_defs GLOBAL PROPERTY ALL_PKG_DEFS)
......@@ -125,14 +145,37 @@ macro(dune_enable_all_packages)
# add compile definitions to all targets in module
get_property(all_defs GLOBAL PROPERTY ALL_PKG_DEFS)
foreach(def ${all_defs})
add_definitions("-D${def}")
endforeach(def in ${all_defs})
# We have to do this in a loop because add_definitions() is kind of broken: even though it is supposed
# to be *the* function for adding compile definitions, it does not prepend "-D" (as opposed to
# target_compile_definitions(), which does). Well, whatever...
foreach(_definition ${all_defs})
if(_definition)
add_definitions("-D${_definition}")
endif()
endforeach()
# verbose output of compile definitions
if(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
message("Compile definitions for this project: ${all_defs}")
endif(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
# handle additional compile options specified in dune_enable_all_packages
if(DUNE_ENABLE_ALL_PACKAGES_COMPILE_OPTIONS)
if(DUNE_ENABLE_ALL_PACKAGES_APPEND)
set_property(GLOBAL APPEND PROPERTY ALL_PKG_OPTS "${DUNE_ENABLE_ALL_PACKAGES_COMPILE_OPTIONS}")
else(DUNE_ENABLE_ALL_PACKAGES_APPEND)
get_property(all_opts GLOBAL PROPERTY ALL_PKG_OPTS)
set_property(GLOBAL PROPERTY ALL_PKG_OPTS "${DUNE_ENABLE_ALL_PACKAGES_COMPILE_OPTIONS}" "${all_opts}")
endif(DUNE_ENABLE_ALL_PACKAGES_APPEND)
endif(DUNE_ENABLE_ALL_PACKAGES_COMPILE_OPTIONS)
# add compile options to all targets in module
get_property(all_opts GLOBAL PROPERTY ALL_PKG_OPTS)
add_compile_options(${all_opts})
# verbose output of compile definitions
if(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
message("Compile options for this project: ${all_opts}")
endif(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
# handle libraries
# this is a little tricky because the libraries defined within the current module require special
# handling to avoid tripping over CMake policies CMP022 and CMP038
......@@ -178,6 +221,14 @@ Update the cmake_minimum_required() call in your main CMakeLists.txt file to get
# ...and add it to all future targets in the module
link_libraries(${module_lib})
endforeach(module_lib ${DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES})
# export the DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES variable to the parent scope
# this is required to make dune_library_add_sources() work (see further down)
set(
DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES
${DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES}
PARENT_SCOPE
)
endif(DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES)
if(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
......@@ -185,10 +236,29 @@ Update the cmake_minimum_required() call in your main CMakeLists.txt file to get
message("Libraries for this project: ${all_libs}")
endif(DUNE_ENABLE_ALL_PACKAGES_VERBOSE)
endmacro(dune_enable_all_packages)
endfunction(dune_enable_all_packages)
function(dune_target_enable_all_packages)
foreach(_target ${ARGN})
get_property(all_incs GLOBAL PROPERTY ALL_PKG_INCS)
target_include_directories(${_target} PUBLIC ${all_incs})
get_property(all_defs GLOBAL PROPERTY ALL_PKG_DEFS)
target_compile_definitions(${_target} PUBLIC ${all_defs})
get_property(all_opts GLOBAL PROPERTY ALL_PKG_OPTS)
target_compile_options(${_target} PUBLIC ${all_opts})
get_property(all_libs GLOBAL PROPERTY ALL_PKG_LIBS)
target_link_libraries(${_target} PUBLIC ${DUNE_LIBS} ${all_libs})
endforeach()
endfunction(dune_target_enable_all_packages)
macro(dune_library_add_sources lib)
function(dune_library_add_sources lib)
# This only works for CMAKE 3.1+ because target_sources() - which we use to add sources to the
# libraries after creating them - was added in that version
......@@ -207,7 +277,6 @@ macro(dune_library_add_sources lib)
"Attempt to add sources to library ${lib}, which has not been defined in dune_enable_all_packages.
List of libraries defined in dune_enable_all_packages: ${DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES}")
endif()
unset(lib_defined)
include(CMakeParseArguments)
cmake_parse_arguments(DUNE_LIBRARY_ADD_SOURCES "" "" "SOURCES" ${ARGN})
......@@ -219,4 +288,4 @@ List of libraries defined in dune_enable_all_packages: ${DUNE_ENABLE_ALL_PACKAGE
foreach(source ${DUNE_LIBRARY_ADD_SOURCES_SOURCES})
target_sources(${lib} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${source})
endforeach()
endmacro()
endfunction()
......@@ -27,16 +27,16 @@
# in the source tree. This file will be copied
# to the build tree.
#
# dune_symlink_to_source_tree()
# dune_symlink_to_source_tree([NAME name])
#
# add a symlink called src_dir to all directories in the build tree.
# add a symlink called NAME to all directories in the build tree (defaults to src_dir).
# That symlink points to the corresponding directory in the source tree.
# Call the macro from the toplevel CMakeLists.txt file of your project.
# You can also call it from some other directory, creating only symlinks
# in that directory and all directories below. A warning is issued on
# Windows systems.
#
# dune_symlink_to_source_files(files)
# dune_symlink_to_source_files(FILES files)
#
# add symlinks to the build tree, which point to files in the source tree.
# Foreach file given in "files", a symlink of that name is created in the
......@@ -63,7 +63,14 @@ macro(dune_add_copy_dependency target file_name)
add_dependencies(${target} "${target}_copy_${file_name}")
endmacro(dune_add_copy_dependency)
macro(dune_symlink_to_source_tree)
function(dune_symlink_to_source_tree)
# parse arguments
include(CMakeParseArguments)
cmake_parse_arguments(ARG "" "NAME" "" ${ARGN})
if(NOT ARG_NAME)
set(ARG_NAME "src_dir")
endif()
# check for Windows to issue a warning
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(NOT DEFINED DUNE_WINDOWS_SYMLINK_WARNING)
......@@ -78,15 +85,22 @@ macro(dune_symlink_to_source_tree)
foreach(f ${files})
get_filename_component(dir ${f} DIRECTORY)
if(NOT "${CMAKE_SOURCE_DIR}/${dir}" MATCHES "${CMAKE_BINARY_DIR}/*")
execute_process(COMMAND ${CMAKE_COMMAND} "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/${dir}" "${CMAKE_BINARY_DIR}/${dir}/src_dir")
execute_process(COMMAND ${CMAKE_COMMAND} "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/${dir}" "${CMAKE_BINARY_DIR}/${dir}/${ARG_NAME}")
endif(NOT "${CMAKE_SOURCE_DIR}/${dir}" MATCHES "${CMAKE_BINARY_DIR}/*")
endforeach()
endif()
endmacro(dune_symlink_to_source_tree)
endfunction(dune_symlink_to_source_tree)
function(dune_symlink_to_source_files)
# parse arguments
include(CMakeParseArguments)
cmake_parse_arguments(ARG "" "" "FILES" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(WARNING "You are using dune_symlink_to_source_files without named arguments (or have typos in your named arguments)!")
endif()
macro(dune_symlink_to_source_files files)
# create symlinks for all given files
foreach(f ${files})
foreach(f ${ARG_FILES})
# check for Windows to issue a warning
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(NOT DEFINED DUNE_WINDOWS_SYMLINK_WARNING)
......@@ -99,4 +113,4 @@ macro(dune_symlink_to_source_files files)
execute_process(COMMAND ${CMAKE_COMMAND} "-E" "create_symlink" "${CMAKE_CURRENT_SOURCE_DIR}/${f}" "${CMAKE_CURRENT_BINARY_DIR}/${f}")
endif()
endforeach()
endmacro(dune_symlink_to_source_files files)
endfunction(dune_symlink_to_source_files)
......@@ -7,7 +7,7 @@
#
include(DuneBoost)
if(BOOST_FOUND)
if(HAVE_DUNE_BOOST)
message(STATUS "Checking whether the Boost::FUSION library is available.")
check_cxx_source_compiles("
\#include <boost/fusion/container.hpp>
......@@ -18,6 +18,6 @@ int main(){
if(HAVE_BOOST_FUSION)
message(STATUS "Boost::FUSION is available")
endif(HAVE_BOOST_FUSION)
else(BOOST_FOUND)
else()
message(STATUS "Skipping check for Boost::FUSION as Boost is not available.")
endif(BOOST_FOUND)
endif()
# Where to search and which files to use
INPUT += @srcdir@/mainpage \
@srcdir@/modules \
@top_srcdir@/dune/common/modules \
INPUT += @srcdir@/mainpage.txt \
@srcdir@/modules.txt \
@top_srcdir@/dune/common/modules.txt \
@top_srcdir@/dune/common
EXCLUDE += @top_srcdir@/dune/common/test \
@top_srcdir@/dune/common/debugallocator.cc
......
File moved
File moved
......@@ -6,7 +6,9 @@
#include <iostream>
#include <limits>
#include <cstdint>
#include <cstdlib>
#include <type_traits>
#include <dune/common/exceptions.hh>
#include <dune/common/hash.hh>
......@@ -28,6 +30,33 @@ namespace Dune
struct MPITraits;
#endif
namespace {
// numeric_limits_helper provides std::numeric_limits access to the internals
// of bigunsignedint. Previously, the correct specialization of std::numeric_limits
// was a friend of bigunsignedint, but that creates problems on recent versions
// of clang with the alternative libc++ library, because that library declares the
// base template of std::numeric_limits as a class and clang subsequently complains
// if the friend declaration uses 'struct'. Unfortunately, libstdc++ uses a struct,
// making it impossible to keep clang happy for both standard libraries.
// So we move the access helper functionality into a custom struct and simply let
// the numeric_limits specialization inherit from the helper.
template<typename T>
struct numeric_limits_helper
{
protected:
static std::uint16_t& digit(T& big_unsigned_int, std::size_t i)
{
return big_unsigned_int.digit[i];
}
};
}
/**
* @brief Portable very large unsigned integers
*
......@@ -42,7 +71,7 @@ namespace Dune
public:
// unsigned short is 16 bits wide, n is the number of digits needed
enum { bits=std::numeric_limits<unsigned short>::digits, n=k/bits+(k%bits!=0),
enum { bits=std::numeric_limits<std::uint16_t>::digits, n=k/bits+(k%bits!=0),
hexdigits=4, bitmask=0xFFFF, compbitmask=0xFFFF0000,
overflowmask=0x1 };
......@@ -50,10 +79,11 @@ namespace Dune
bigunsignedint ();
//! Construct from signed int
bigunsignedint (int x);
template<typename Signed>
bigunsignedint (Signed x, typename std::enable_if<std::is_integral<Signed>::value && std::is_signed<Signed>::value>::type* = 0);
//! Construct from unsigned int
bigunsignedint (std::size_t x);
bigunsignedint (std::uintmax_t x);
//! Print number in hex notation
void print (std::ostream& s) const ;
......@@ -122,7 +152,7 @@ namespace Dune
//! export to other types
// operator unsigned int () const;
unsigned int touint() const;
std::uint_least32_t touint() const;
/**
* @brief Convert to a double.
*
......@@ -131,7 +161,7 @@ namespace Dune
double todouble() const;
friend class bigunsignedint<k/2>;
friend struct std::numeric_limits< bigunsignedint<k> >;
friend struct numeric_limits_helper< bigunsignedint<k> >;
inline friend std::size_t hash_value(const bigunsignedint& arg)
{
......@@ -139,11 +169,11 @@ namespace Dune
}
private:
unsigned short digit[n];
std::uint16_t digit[n];
#if HAVE_MPI
friend struct MPITraits<bigunsignedint<k> >;
#endif
inline void assign(std::size_t x);
inline void assign(std::uintmax_t x);
} ;
......@@ -156,22 +186,24 @@ namespace Dune
}
template<int k>
bigunsignedint<k>::bigunsignedint (int y)
template<typename Signed>
bigunsignedint<k>::bigunsignedint (Signed y, typename std::enable_if<std::is_integral<Signed>::value && std::is_signed<Signed>::value>::type*)
{
std::size_t x = std::abs(y);
assign(x);
if (y < 0)
DUNE_THROW(Dune::Exception, "Trying to construct a Dune::bigunsignedint from a negative integer: " << y);
assign(y);
}
template<int k>
bigunsignedint<k>::bigunsignedint (std::size_t x)
bigunsignedint<k>::bigunsignedint (std::uintmax_t x)
{
assign(x);
}
template<int k>
void bigunsignedint<k>::assign(std::size_t x)
void bigunsignedint<k>::assign(std::uintmax_t x)
{
int no=std::min(static_cast<int>(n),
static_cast<int>(std::numeric_limits<std::size_t>::digits/bits));
static const int no=std::min(static_cast<int>(n),
static_cast<int>(std::numeric_limits<std::uintmax_t>::digits/bits));
for(int i=0; i<no; ++i) {
digit[i] = (x&bitmask);
......@@ -182,7 +214,7 @@ namespace Dune
// export
template<int k>
inline unsigned int bigunsignedint<k>::touint () const
inline std::uint_least32_t bigunsignedint<k>::touint () const
{
return (digit[1]<<bits)+digit[0];
}
......@@ -242,11 +274,11 @@ namespace Dune
inline bigunsignedint<k> bigunsignedint<k>::operator+ (const bigunsignedint<k>& x) const
{
bigunsignedint<k> result;
int overflow=0;
std::uint_fast32_t overflow=0;
for (unsigned int i=0; i<n; i++)
{
int sum = ((int)digit[i]) + ((int)x.digit[i]) + overflow;
std::uint_fast32_t sum = static_cast<std::uint_fast32_t>(digit[i]) + static_cast<std::uint_fast32_t>(x.digit[i]) + overflow;
result.digit[i] = sum&bitmask;
overflow = (sum>>bits)&overflowmask;
}
......@@ -257,16 +289,19 @@ namespace Dune
inline bigunsignedint<k> bigunsignedint<k>::operator- (const bigunsignedint<k>& x) const
{
bigunsignedint<k> result;
int overflow=0;
std::int_fast32_t overflow=0;
for (unsigned int i=0; i<n; i++)
{
int diff = ((int)digit[i]) - (((int)x.digit[i]) + overflow);
std::int_fast32_t diff = static_cast<std::int_fast32_t>(digit[i]) - static_cast<std::int_fast32_t>(x.digit[i]) - overflow;
if (diff>=0)
result.digit[i] = (unsigned short) diff;
{
result.digit[i] = static_cast<std::uint16_t>(diff);
overflow = 0;
}
else
{
result.digit[i] = (unsigned short) (diff+bitmask);
result.digit[i] = static_cast<std::uint16_t>(diff+bitmask+1);
overflow = 1;
}
}
......@@ -281,11 +316,11 @@ namespace Dune
for (unsigned int m=0; m<n; m++) // digit in right factor
{
bigunsignedint<2*k> singleproduct(0);
unsigned int overflow(0);
std::uint_fast32_t overflow(0);
for (unsigned int i=0; i<n; i++)
{
unsigned int digitproduct = ((unsigned int)digit[i])*((unsigned int)x.digit[m])+overflow;
singleproduct.digit[i+m] = (unsigned short) (digitproduct&bitmask);
std::uint_fast32_t digitproduct = static_cast<std::uint_fast32_t>(digit[i])*static_cast<std::uint_fast32_t>(x.digit[m])+overflow;
singleproduct.digit[i+m] = static_cast<std::uint16_t>(digitproduct&bitmask);
overflow = (digitproduct>>bits)&bitmask;
}
finalproduct = finalproduct+singleproduct;
......@@ -299,11 +334,11 @@ namespace Dune
template <int k>
inline bigunsignedint<k>& bigunsignedint<k>::operator++ ()
{
int overflow=1;
std::uint_fast32_t overflow=1;
for (unsigned int i=0; i<n; i++)
{
int sum = ((int)digit[i]) + overflow;
std::uint_fast32_t sum = static_cast<std::uint_fast32_t>(digit[i]) + overflow;
digit[i] = sum&bitmask;
overflow = (sum>>bits)&overflowmask;
}
......@@ -334,11 +369,9 @@ namespace Dune
{
// better slow than nothing
bigunsignedint<k> temp(*this);
bigunsignedint<k> result(0);
while (temp>=x)
{
++result;
temp = temp-x;
}
......@@ -398,7 +431,7 @@ namespace Dune
{
unsigned int temp = result.digit[i];
temp = temp<<j;
result.digit[i] = (unsigned short) (temp&bitmask);
result.digit[i] = static_cast<std::uint16_t>(temp&bitmask);
temp = temp>>bits;
if (i+1<(int)n)
result.digit[i+1] = result.digit[i+1]|temp;
......@@ -421,9 +454,9 @@ namespace Dune
j=shift%bits;
for (unsigned int i=0; i<n; i++)
{
unsigned int temp = result.digit[i];
std::uint_fast32_t temp = result.digit[i];
temp = temp<<(bits-j);
result.digit[i] = (unsigned short) ((temp&compbitmask)>>bits);
result.digit[i] = static_cast<std::uint16_t>((temp&compbitmask)>>bits);
if (i>0)
result.digit[i-1] = result.digit[i-1] | (temp&bitmask);
}
......@@ -477,70 +510,70 @@ namespace Dune
template <int k>
inline bigunsignedint<k> operator+ (const bigunsignedint<k>& x, std::size_t y)
inline bigunsignedint<k> operator+ (const bigunsignedint<k>& x, std::uintmax_t y)
{
bigunsignedint<k> temp(y);
return x+temp;
}
template <int k>
inline bigunsignedint<k> operator- (const bigunsignedint<k>& x, std::size_t y)
inline bigunsignedint<k> operator- (const bigunsignedint<k>& x, std::uintmax_t y)
{
bigunsignedint<k> temp(y);
return x-temp;
}
template <int k>
inline bigunsignedint<k> operator* (const bigunsignedint<k>& x, std::size_t y)
inline bigunsignedint<k> operator* (const bigunsignedint<k>& x, std::uintmax_t y)
{
bigunsignedint<k> temp(y);
return x*temp;
}
template <int k>
inline bigunsignedint<k> operator/ (const bigunsignedint<k>& x, std::size_t y)
inline bigunsignedint<k> operator/ (const bigunsignedint<k>& x, std::uintmax_t y)
{
bigunsignedint<k> temp(y);
return x/temp;
}
template <int k>
inline bigunsignedint<k> operator% (const bigunsignedint<k>& x, std::size_t y)
inline bigunsignedint<k> operator% (const bigunsignedint<k>& x, std::uintmax_t y)
{
bigunsignedint<k> temp(y);
return x%temp;
}
template <int k>
inline bigunsignedint<k> operator+ (std::size_t x, const bigunsignedint<k>& y)
inline bigunsignedint<k> operator+ (std::uintmax_t x, const bigunsignedint<k>& y)
{
bigunsignedint<k> temp(x);
return temp+y;
}
template <int k>
inline bigunsignedint<k> operator- (std::size_t x, const bigunsignedint<k>& y)
inline bigunsignedint<k> operator- (std::uintmax_t x, const bigunsignedint<k>& y)
{
bigunsignedint<k> temp(x);
return temp-y;
}
template <int k>
inline bigunsignedint<k> operator* (std::size_t x, const bigunsignedint<k>& y)
inline bigunsignedint<k> operator* (std::uintmax_t x, const bigunsignedint<k>& y)
{
bigunsignedint<k> temp(x);
return temp*y;
}
template <int k>
inline bigunsignedint<k> operator/ (std::size_t x, const bigunsignedint<k>& y)
inline bigunsignedint<k> operator/ (std::uintmax_t x, const bigunsignedint<k>& y)
{
bigunsignedint<k> temp(x);
return temp/y;
}
template <int k>
inline bigunsignedint<k> operator% (std::size_t x, const bigunsignedint<k>& y)
inline bigunsignedint<k> operator% (std::uintmax_t x, const bigunsignedint<k>& y)
{
bigunsignedint<k> temp(x);
return temp%y;
......@@ -554,6 +587,7 @@ namespace std
{
template<int k>
struct numeric_limits<Dune::bigunsignedint<k> >
: private Dune::numeric_limits_helper<Dune::bigunsignedint<k> > // for access to internal state of bigunsignedint
{
public:
static const bool is_specialized = true;
......@@ -567,7 +601,9 @@ namespace std
{
Dune::bigunsignedint<k> max_;
for(std::size_t i=0; i < Dune::bigunsignedint<k>::n; ++i)
max_.digit[i]=std::numeric_limits<unsigned short>::max();
// access internal state via the helper base class
Dune::numeric_limits_helper<Dune::bigunsignedint<k> >::
digit(max_,i)=std::numeric_limits<std::uint16_t>::max();
return max_;
}
......
......@@ -9,6 +9,7 @@
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <new>
#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
......@@ -143,7 +144,7 @@ namespace Dune
// compute page address
void* page_ptr =
static_cast<void*>(
(char*)(ptr) - ((difference_type)(ptr) % page_size));
(char*)(ptr) - ((std::uintptr_t)(ptr) % page_size));
// search list
AllocationList::iterator it;
unsigned int i = 0;
......
......@@ -42,7 +42,8 @@ namespace Dune {
template<class K>
inline typename FieldTraits<K>::real_type absreal (const K& k)
{
return std::abs(k);
using std::abs;
return abs(k);
}
/**
......@@ -52,7 +53,8 @@ namespace Dune {
template<class K>
inline typename FieldTraits<K>::real_type absreal (const std::complex<K>& c)
{
return std::abs(c.real()) + std::abs(c.imag());
using std::abs;
return abs(c.real()) + abs(c.imag());
}
/**
......@@ -84,7 +86,8 @@ namespace Dune {
{
static inline typename FieldTraits<K>::real_type sqrt (const K& k)
{
return std::sqrt(k);
using std::sqrt;
return sqrt(k);
}
};
......@@ -97,7 +100,8 @@ namespace Dune {
{
static inline typename FieldTraits<K>::real_type sqrt (const K& k)
{
return typename FieldTraits<K>::real_type(std::sqrt(double(k)));
using std::sqrt;
return typename FieldTraits<K>::real_type(sqrt(double(k)));
}
};
......@@ -564,9 +568,10 @@ namespace Dune {
//! one norm (sum over absolute values of entries)
typename FieldTraits<value_type>::real_type one_norm() const {
using std::abs;
typename FieldTraits<value_type>::real_type result( 0 );
for (size_type i=0; i<size(); i++)
result += std::abs((*this)[i]);
result += abs((*this)[i]);
return result;
}
......@@ -601,29 +606,35 @@ namespace Dune {
//! infinity norm (maximum of absolute values of entries)
typename FieldTraits<value_type>::real_type infinity_norm () const
{
using std::abs;
using std::max;
typedef typename FieldTraits<value_type>::real_type real_type;
if (size() == 0)
return 0.0;
ConstIterator it = begin();
typename FieldTraits<value_type>::real_type max = std::abs(*it);
real_type max_val = abs(*it);
for (it = it + 1; it != end(); ++it)
max = std::max(max, std::abs(*it));
max_val = max(max_val, real_type(abs(*it)));
return max;
return max_val;
}
//! simplified infinity norm (uses Manhattan norm for complex values)
typename FieldTraits<value_type>::real_type infinity_norm_real () const
{
using std::max;
if (size() == 0)
return 0.0;
ConstIterator it = begin();
typename FieldTraits<value_type>::real_type max = fvmeta::absreal(*it);
typename FieldTraits<value_type>::real_type max_val = fvmeta::absreal(*it);
for (it = it + 1; it != end(); ++it)
max = std::max(max, fvmeta::absreal(*it));
max_val = max(max_val, fvmeta::absreal(*it));
return max;
return max_val;
}
//===== sizes
......
......@@ -8,6 +8,7 @@
*/
#include <iostream>
#include <string>
#if HAVE_GMP
......@@ -23,22 +24,34 @@ namespace Dune
typedef mpf_class Base;
public:
/** default constructor, iitialize to zero */
GMPField ()
: Base(0,precision)
{}
template< class T >
GMPField ( const T &v )
: Base( v,precision )
/** \brief initialize from a string
\note this is the only reliable way to initialize with higher values
*/
GMPField ( const char* str )
: Base(str,precision)
{}
/*
GMPField &operator=(const GMPField &other)
{
Base(*this) = Base(other);
return *this;
}
/** \brief initialize from a string
\note this is the only reliable way to initialize with higher values
*/
GMPField ( const std::string& str )
: Base(str,precision)
{}
/** \brief initialize from a compatible scalar type
*/
template< class T,
typename EnableIf = typename std::enable_if<
std::is_convertible<T, mpf_class>::value>::type
>
GMPField ( const T &v )
: Base( v,precision )
{}
// type conversion operators
operator double () const
......@@ -46,82 +59,8 @@ namespace Dune
return this->get_d();
}
operator float () const
{
return this->get_d();
}
};
template< unsigned int precision >
inline GMPField< precision >
operator+ ( const GMPField< precision > &a, const GMPField< precision > &b )
{
typedef mpf_class F;
return ((const F &)a + (const F &)b);
}
template< unsigned int precision >
inline GMPField< precision >
operator- ( const GMPField< precision > &a, const GMPField< precision > &b )
{
typedef mpf_class F;
return ((const F &)a - (const F &)b);
}
template< unsigned int precision >
inline GMPField< precision >
operator- ( const GMPField< precision > &a )
{
typedef mpf_class F;
return -((const F &)a);
}
template< unsigned int precision >
inline GMPField< precision >
operator* ( const GMPField< precision > &a, const GMPField< precision > &b )
{
typedef mpf_class F;
return ((const F &)a * (const F &)b);
}
template< unsigned int precision >
inline GMPField< precision >
operator/ ( const GMPField< precision > &a, const GMPField< precision > &b )
{
typedef mpf_class F;
return ((const F &)a / (const F &)b);
}
template< unsigned int precision >
inline std::ostream &
operator<< ( std::ostream &out, const GMPField< precision > &value )
{
return out << static_cast<const mpf_class&>(value);
}
}
namespace std
{
template< unsigned int precision >
inline Dune::GMPField< precision >
sqrt ( const Dune::GMPField< precision > &a )
{
return Dune::GMPField< precision >(sqrt(static_cast<const mpf_class&>(a)));
}
template< unsigned int precision >
inline Dune::GMPField< precision >
abs ( const Dune::GMPField< precision > &a )
{
return Dune::GMPField< precision >( abs( static_cast< const mpf_class & >( a ) ) );
}
}
#endif // HAVE_GMP
......
......@@ -132,20 +132,23 @@ namespace Dune {
// Macro for defining a std::hash specialization for type.
// This should not be called directly. Call DUNE_DEFINE_HASH
// instead.
#define DUNE_DEFINE_STD_HASH(template_args,type) \
namespace std { \
\
#define DUNE_DEFINE_STD_HASH(template_args,type) \
namespace std { \
\
template<template_args> \
struct hash<type> \
{ \
\
typedef type argument_type; \
typedef std::size_t result_type; \
\
std::size_t operator()(const type& arg) const \
{ \
return hash_value(arg); \
} \
}; \
\
} \
\
} \
// Wrapper macro for template arguments.
// This is required because the template arguments can contain commas,
......
......@@ -2,13 +2,13 @@
documentation within the dune-common module. It works like this:
@defgroup commands appear only in this file here which is
parsed before the other files (because it is mentioned first
parsed before the other files (because it is mentioned first
in the Doxyfile).
Only @addtogroup is used in the code documentation.
*/
/**
@defgroup COGeometryType GeometryType
@ingroup Common
* @defgroup COGeometryType GeometryType
* @ingroup Common
*/
......@@ -9,6 +9,7 @@
#include <algorithm>
#include <iostream>
#include <cstddef>
#include <dune/common/genericiterator.hh>
#include <initializer_list>
......
......@@ -74,7 +74,7 @@ namespace Dune
* This is deleted, since, according to the standard this should not
* participate in overload resolution
*
* \param n Size of array to allocate
* \param args Dummy arguments
*/
template<typename T, typename ...Args>
typename MakeUniqueHelper<T>::KnownBoundArrayUniquePtr
......
......@@ -72,7 +72,7 @@ namespace Dune {
static std::string formatString(const std::string& s, const T&... args)
{
static const int bufferSize=1000;
static char buffer[bufferSize];
char buffer[bufferSize];
// try to format with static buffer
int r = std::snprintf(buffer, bufferSize, s.c_str(), args...);
......
......@@ -4,73 +4,89 @@
#include "config.h"
#endif
#include <cstdint>
#include <limits>
#include <iostream>
#include <dune/common/bigunsignedint.hh>
#include <dune/common/hash.hh>
#define CHECK(x) \
do { \
if (!(x)) { \
pass = false; \
std::cerr << "FAILED: " << #x << std::endl; \
} \
} while(false)
int main()
{
bool pass = true;
typedef Dune::bigunsignedint<16> ShortInteger;
typedef Dune::bigunsignedint<128> BigInteger;
/* Test std::numeric_limits for ShortInteger (should be same as for uint16_t) */
CHECK(std::numeric_limits<ShortInteger>::min() == std::numeric_limits<std::uint16_t>::min());
CHECK(std::numeric_limits<ShortInteger>::max() == std::numeric_limits<std::uint16_t>::max());
CHECK(std::numeric_limits<ShortInteger>::digits == std::numeric_limits<std::uint16_t>::digits);
CHECK(std::numeric_limits<ShortInteger>::epsilon() == std::numeric_limits<std::uint16_t>::epsilon());
CHECK(std::numeric_limits<ShortInteger>::round_error() == std::numeric_limits<std::uint16_t>::round_error());
CHECK(std::numeric_limits<ShortInteger>::is_exact);
CHECK(std::numeric_limits<ShortInteger>::is_integer);
CHECK(!std::numeric_limits<ShortInteger>::is_signed);
std::cout<<"unsigned short: max="<<std::numeric_limits<unsigned short>::max()
<<" min="<<std::numeric_limits<unsigned short>::min()
<<" digits="<<std::numeric_limits<unsigned short>::digits<<std::endl;
std::cout<<"int: max="<<std::numeric_limits<int>::max()<<" min="
<<std::numeric_limits<int>::min()<<" digits="
<<std::numeric_limits<int>::digits<<std::endl;
std::cout<<"unsigned int: max="<<std::numeric_limits<unsigned int>::max()
<<" min="<<std::numeric_limits<unsigned int>::min()<<" digits="
<<std::numeric_limits<unsigned int>::digits<<" digits10="
<<std::numeric_limits<unsigned int>::digits10<<" radix="
<<std::numeric_limits<unsigned int>::radix<<" eps="
<<std::numeric_limits<unsigned int>::epsilon()
<<" round_error="
<<std::numeric_limits<unsigned int>::round_error()
<<" min_exponent="
<<std::numeric_limits<unsigned int>::min_exponent
<<" float_denorm_style="
<<std::numeric_limits<unsigned int>::has_denorm
<<" traps="<<std::numeric_limits<unsigned int>::traps
<<std::endl;
std::cout<<"bigunsignedint: max="<<std::numeric_limits<Dune::bigunsignedint<32> >::max()
<<" min="<<std::numeric_limits<Dune::bigunsignedint<32> >::min()<<" digits="<<std::numeric_limits<Dune::bigunsignedint<32> >::digits<<std::endl;
std::cout<<"bigunsignedint: max="<<std::numeric_limits<Dune::bigunsignedint<100> >::max()
<<" min="<<std::numeric_limits<Dune::bigunsignedint<100> >::min()<<" digits="<<std::numeric_limits<Dune::bigunsignedint<100> >::digits
<<" traps="<<std::numeric_limits<Dune::bigunsignedint<100> >::traps
<<std::endl;
int a1, b1, c1;
a1=100;
b1=3;
c1=a1/b1;
std::cout<<a1<<"/"<<b1<<"="<<c1<<std::endl;
Dune::bigunsignedint<100> a, b, c;
a=100;
b=3;
c=a/b;
std::cout<<a<<"/"<<b<<"="<<c<<std::endl;
try{
a=100;
b=0;
c=a/1;
std::cout<<a1<<"/"<<b1<<"="<<c1<<std::endl;
a=1000000;
std::cout<<a.todouble()<<std::endl;
std::cout<<a.touint()<<std::endl;
b=a;
a=a*b*b;
std::cout<<a.todouble()<<std::endl;
Dune::hash<Dune::bigunsignedint<100> > hasher;
std::cout << "Dune::hash: " << hasher(a) << std::endl;
/* Test std::numeric_limits for BigInteger */
CHECK(std::numeric_limits<BigInteger>::min() == 0u);
CHECK(std::numeric_limits<BigInteger>::digits == 128);
CHECK(std::numeric_limits<BigInteger>::epsilon() == 0u);
CHECK(std::numeric_limits<BigInteger>::round_error() == 0u);
CHECK(std::numeric_limits<BigInteger>::is_exact);
CHECK(std::numeric_limits<BigInteger>::is_integer);
CHECK(!std::numeric_limits<BigInteger>::is_signed);
/* Test constructor */
CHECK(BigInteger(10u) == 10u);
CHECK(BigInteger(10) == BigInteger(10u));
try {
BigInteger tmp(-10);
pass = false;
std::cerr << "FAILED: BigInteger(-10) should throw an exception." << std::endl;
}
catch(const Dune::Exception&) {
/* Ignore */
}
catch(Dune::MathError e) {
std::cout<<e<<std::endl;
catch(...) {
pass = false;
std::cerr << "FAILED: BigInteger(-10) threw an unexpected exception." << std::endl;
}
/* Test conversion */
CHECK(BigInteger(10u).touint() == 10u);
CHECK(BigInteger(10u).todouble() == 10.0);
/* Check BigInteger arithmetic */
CHECK(BigInteger(10u) + BigInteger(3u) == BigInteger(10u + 3u));
CHECK(BigInteger(10u) - BigInteger(3u) == BigInteger(10u - 3u));
CHECK(BigInteger(10u) * BigInteger(3u) == BigInteger(10u * 3u));
CHECK(BigInteger(10u) / BigInteger(3u) == BigInteger(10u / 3u));
CHECK(BigInteger(10u) % BigInteger(3u) == BigInteger(10u % 3u));
CHECK(BigInteger(100000u) + BigInteger(30000u) == BigInteger(100000u + 30000u));
CHECK(BigInteger(100000u) - BigInteger(30000u) == BigInteger(100000u - 30000u));
CHECK(BigInteger(70000u) - BigInteger(30000u) == BigInteger(70000u - 30000u));
CHECK(BigInteger(100000u) * BigInteger(30000u) == BigInteger(100000u * 30000u));
CHECK(BigInteger(100000u) / BigInteger(30000u) == BigInteger(100000u / 30000u));
CHECK(BigInteger(100000u) % BigInteger(30000u) == BigInteger(100000u % 30000u));
/* Test hashing */
{
Dune::hash<BigInteger> hasher;
CHECK(hasher(BigInteger(100)) == hasher(BigInteger(100)));
}
return pass ? 0 : 1;
}
......@@ -7,6 +7,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/classname.hh>
#include <dune/common/gmpfield.hh>
#include <iostream>
#include <complex>
#include <typeinfo>
......@@ -380,6 +381,17 @@ int main()
FieldVectorTest<double, 3>();
FieldVectorTest<int, 1>();
FieldVectorTest<double, 1>();
#if HAVE_GMP
// we skip the complex test and the int test, as these will be very hard to implement with GMPField
typedef Dune::GMPField<128u> ft;
FieldVectorMainTest<ft,ft,3>();
FieldVectorMainTest<ft,ft,2>();
FieldVectorMainTest<ft,ft,1>();
FieldVectorMainTest<ft,ft,0>();
ScalarOperatorTest<ft>();
ScalarOrderingTest<ft>();
DotProductTest<ft,3>();
#endif // HAVE_GMP
test_nan();
test_infinity_norms();
......