Skip to content

Commit

Permalink
Merge pull request #23 from njoy/develop
Browse files Browse the repository at this point in the history
tools v0.3.0
  • Loading branch information
whaeck authored Apr 23, 2024
2 parents 3747d6e + 0e28cfe commit 368dbd9
Show file tree
Hide file tree
Showing 245 changed files with 23,401 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ContinuousIntegration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
which ${{matrix.cxx}}
${{matrix.cxx}} --version
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir bin
run: mkdir bin
- name: cmake
Expand Down
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if( DEFINED PROJECT_NAME )
endif()

project( tools
VERSION 0.2.0
VERSION 0.3.0
LANGUAGES CXX
)

Expand All @@ -33,7 +33,7 @@ cmake_dependent_option(
cmake_dependent_option(
tools.python
"Build tools python bindings" ON
"NOT ${subproject}" OFF
"NOT ${subproject} OR DEFINED require.tools.python " OFF
)

########################################################################
Expand Down Expand Up @@ -77,8 +77,11 @@ target_include_directories( tools
target_link_libraries( tools
INTERFACE
spdlog::spdlog
FastFloat::fast_float
)

target_compile_definitions( tools INTERFACE -DNANORANGE_NO_STD_FORWARD_DECLARATIONS )

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# tools : python bindings
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -100,9 +103,11 @@ if( tools.python )

message( STATUS "Building tools' python API" )

list( APPEND SCION_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR} )
list( APPEND TOOLS_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR} )

include( cmake/unit_testing_python.cmake )
if( tools.tests )
include( cmake/unit_testing_python.cmake )
endif()

endif()

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ A common set of tools used in njoy libraries.

## LICENSE
The software contained in this repository is covered under the associated [LICENSE](LICENSE) file.

This library incorporates parts of [NanoRange](https://github.com/tcbrindle/NanoRange), a C++-17 implementation of the C++-20 ranges standard. Modifications were made to ensure that this implementation of the C++-20 ranges standard compiles on intel classic C++ compilers. The NanoRange license file can be found [here](src/tools/std20/LICENSE_1_0.txt).
7 changes: 7 additions & 0 deletions cmake/develop_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ FetchContent_Declare( pybind11
GIT_SHALLOW TRUE
)

FetchContent_Declare( fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float
GIT_TAG v6.1.1
GIT_SHALLOW TRUE
)

#######################################################################
# Load dependencies
#######################################################################

FetchContent_MakeAvailable(
spdlog
fast_float
)
6 changes: 6 additions & 0 deletions cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ FetchContent_Declare( Catch2
GIT_TAG 3f0283de7a9c43200033da996ff9093be3ac84dc # tag: v3.3.2
)

FetchContent_Declare( fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float
GIT_TAG f476bc713fda06fbd34dc621b466745a574b3d4c # tag: v6.1.1
)

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242 # tag: v2.10.4
Expand All @@ -26,5 +31,6 @@ set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )
#######################################################################

FetchContent_MakeAvailable(
fast_float
spdlog
)
29 changes: 29 additions & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ endfunction()
#######################################################################

add_subdirectory( src/tools/Log/test )

add_subdirectory( src/tools/disco/functions/test )
add_subdirectory( src/tools/disco/BaseField/test )
add_subdirectory( src/tools/disco/FreeFormatCharacter/test )
add_subdirectory( src/tools/disco/FreeFormatInteger/test )
add_subdirectory( src/tools/disco/FreeFormatReal/test )
add_subdirectory( src/tools/disco/BaseFixedWidthField/test )
add_subdirectory( src/tools/disco/Column/test )
add_subdirectory( src/tools/disco/Character/test )
add_subdirectory( src/tools/disco/Integer/test )
add_subdirectory( src/tools/disco/Real/test )
add_subdirectory( src/tools/disco/FixedPoint/test )
add_subdirectory( src/tools/disco/Scientific/test )
add_subdirectory( src/tools/disco/ENDF/test )
add_subdirectory( src/tools/disco/Record/test )

add_subdirectory( src/tools/std20/algorithm/test )
add_subdirectory( src/tools/std20/concepts/test )
add_subdirectory( src/tools/std20/functional/test )
add_subdirectory( src/tools/std20/iterator/concepts/test )
add_subdirectory( src/tools/std20/iterator/operations/test )
add_subdirectory( src/tools/std20/iterator/test )
add_subdirectory( src/tools/std20/ranges/access/test )
add_subdirectory( src/tools/std20/ranges/concepts/test )
add_subdirectory( src/tools/std20/type_traits/test )
add_subdirectory( src/tools/std20/views/test )

add_subdirectory( src/tools/views/AnyIterator/test )
add_subdirectory( src/tools/views/AnyView/test )
2 changes: 1 addition & 1 deletion cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function( add_python_test name source )
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
set_tests_properties( ${test_name}
PROPERTIES ENVIRONMENT
PYTHONPATH=${SCION_PYTHONPATH}:$ENV{PYTHONPATH})
PYTHONPATH=${TOOLS_PYTHONPATH}:$ENV{PYTHONPATH})

endfunction()

Expand Down
32 changes: 32 additions & 0 deletions python/src/tools.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <pybind11/stl.h>

// other includes
#include "tools/views/views-python.hpp"

// namespace aliases
namespace python = pybind11;
Expand All @@ -17,4 +18,35 @@ namespace python = pybind11;
*/
PYBIND11_MODULE( tools, module ) {

// create the views submodule
python::module viewmodule = module.def_submodule(

"sequence",
"sequence - tools sequences (internal use only)"
);

// wrap some basic recurring views
// none of these are supposed to be created directly by the user
// @todo test performance against range-v3
wrapBasicRandomAccessAnyViewOf< double >(
viewmodule,
"AnyRandomAccessView< double >" );
wrapBasicRandomAccessAnyViewOf< int >(
viewmodule,
"AnyRandomAccessView< int >" );
wrapBasicRandomAccessAnyViewOf< unsigned int >(
viewmodule,
"AnyRandomAccessView< unsigned int >" );
wrapBasicRandomAccessAnyViewOf< long >(
viewmodule,
"AnyRandomAccessView< long >" );
wrapBasicRandomAccessAnyViewOf< BasicRandomAccessAnyView< double > >(
viewmodule,
"any_view< any_view< double, random_access >, random_access >" );
wrapBasicRandomAccessAnyViewOf< BasicRandomAccessAnyView< BasicRandomAccessAnyView< double > > >(
viewmodule,
"any_view< any_view< any_view< double, random_access >, random_access >, random_access >" );
wrapBasicRandomAccessAnyViewOf< std::complex< double > >(
viewmodule,
"any_view< std::complex< double , random_access >" );
}
14 changes: 14 additions & 0 deletions src/tools.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
// disco
#include "tools/disco.hpp"

// the logging tool
#include "tools/Log.hpp"

// an overload struct to collect lambdas for std::visit
#include "tools/overload.hpp"

// a partial C++-17 implementation of the C++-20 ranges standard
#include "tools/std20.hpp"

// custom views
#include "tools/views.hpp"

14 changes: 14 additions & 0 deletions src/tools/disco.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "tools/disco/functions.hpp"
#include "tools/disco/BaseField.hpp"
#include "tools/disco/FreeFormatCharacter.hpp"
#include "tools/disco/FreeFormatInteger.hpp"
#include "tools/disco/FreeFormatReal.hpp"
#include "tools/disco/BaseFixedWidthField.hpp"
#include "tools/disco/Column.hpp"
#include "tools/disco/Character.hpp"
#include "tools/disco/Integer.hpp"
#include "tools/disco/Real.hpp"
#include "tools/disco/FixedPoint.hpp"
#include "tools/disco/Scientific.hpp"
#include "tools/disco/ENDF.hpp"
#include "tools/disco/Record.hpp"
51 changes: 51 additions & 0 deletions src/tools/disco/BaseField.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef NJOY_TOOLS_DISCO_BASEFIELD
#define NJOY_TOOLS_DISCO_BASEFIELD

// system includes
#include <cctype>

// other includes
#include "tools/disco/functions.hpp"

namespace njoy {
namespace tools {
namespace disco {

/**
* @brief A base class for reading data fields (either fixed width or free
* format).
*/
class BaseField {

/* fields */

protected:

/* auxiliary functions */

/**
* @brief Skip the '+' character
*
* Note: when a plus sign is encountered, the position is incremented.
* In the case of a fixed width field, this may put the position over
* the width so this must be checked prior to calling this function.
*
* @param[in,out] iter an iterator to a character in a range
* @param[in,out] position the current position in the field
*/
template < typename Iterator >
static void skipPlusSign( Iterator& iter, unsigned int& position ) {

if ( *iter == '+' ) {

++iter;
++position;
}
}
};

} // disco namespace
} // tools namespace
} // njoy namespace

#endif
39 changes: 39 additions & 0 deletions src/tools/disco/BaseField/test/BaseField.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/disco/BaseField.hpp"

// other includes

// convenience typedefs
using namespace njoy::tools::disco;

class TestBaseField : protected BaseField {

public:

using BaseField::skipPlusSign;
};

SCENARIO( "BaseField" ) {

std::string string = " a\t\n\r\n\f";
string += char{ std::char_traits<char>::eof() };
auto iter = string.begin();
unsigned int position = 0;

string = "+abc";
position = 0;
iter = string.begin();
TestBaseField::skipPlusSign( iter, position );
CHECK( iter == string.begin() + 1 );
CHECK( position == 1 );

string = "abc";
position = 0;
iter = string.begin();
TestBaseField::skipPlusSign( iter, position );
CHECK( iter == string.begin() );
CHECK( position == 0 );
} // SCENARIO
1 change: 1 addition & 0 deletions src/tools/disco/BaseField/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( disco.BaseField BaseField.test.cpp )
48 changes: 48 additions & 0 deletions src/tools/disco/BaseFixedWidthField.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef NJOY_TOOLS_DISCO_BASEFIXEDWIDTHFIELD
#define NJOY_TOOLS_DISCO_BASEFIXEDWIDTHFIELD

// system includes
#include <cctype>

// other includes
#include "tools/disco/BaseField.hpp"

namespace njoy {
namespace tools {
namespace disco {

/**
* @brief A base class for reading fixed width data fields
*/
template < unsigned int Width >
class BaseFixedWidthField : public BaseField {

/* fields */

protected:

using BaseField::skipPlusSign;

/**
* @brief Skip over spaces until the end of the field or until
* a non-space character is encountered
*
* @param[in,out] iter an iterator to a character in a range
* @param[in,out] position the current position in the field
*/
template < typename Iterator >
static void skipSpaces( Iterator& iter, unsigned int& position ) {

while( position < Width && isSpace( iter ) ) {

++position;
++iter;
}
}
};

} // disco namespace
} // tools namespace
} // njoy namespace

#endif
Loading

0 comments on commit 368dbd9

Please sign in to comment.