Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/disco #20

Merged
merged 47 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4d5efe4
Starting work on integrating disco into tools
whaeck Mar 27, 2024
325c49b
Adding tests for BaseField
whaeck Mar 27, 2024
fe5c07d
Not all std::isspace implementation are constexpr
whaeck Mar 27, 2024
076c909
More functions for the base field
whaeck Mar 27, 2024
2f85769
Adding the base class for fixed width fields
whaeck Mar 27, 2024
8e4aa9a
Saving work
whaeck Mar 27, 2024
bcd5db8
Adding base class for fixed width fields
whaeck Apr 1, 2024
a45dc8f
Adding fast_float as a dependency
whaeck Apr 2, 2024
1999b3f
Finishing up BaseField testing
whaeck Apr 2, 2024
b1e4f79
Testting the base class for fixed width fields
whaeck Apr 2, 2024
440fbbf
Adding FixedWidthReal and test
whaeck Apr 2, 2024
c3ce16d
Adding test for empty fields and fields with newline and eof characters
whaeck Apr 2, 2024
e6a19bb
Renamed class
whaeck Apr 3, 2024
7bd1015
Adding FixedWidthScientific
whaeck Apr 3, 2024
1bd1713
Adding test
whaeck Apr 3, 2024
94d8fea
Adding infinity
whaeck Apr 3, 2024
e3e5f9a
Renaming a few classes
whaeck Apr 3, 2024
fff397c
Some more name changes
whaeck Apr 3, 2024
c530cd2
Updating Scientific
whaeck Apr 4, 2024
b99481b
Adding Column to skip columns
whaeck Apr 4, 2024
1cd1073
Adding Integer
whaeck Apr 4, 2024
3ef39d6
moving certain functions to their own file
whaeck Apr 4, 2024
e7fdfc6
Removing code
whaeck Apr 4, 2024
4c4b5af
updating incldue file
whaeck Apr 4, 2024
adcc66b
Adding Record
whaeck Apr 4, 2024
c4ffca6
Adding Character
whaeck Apr 4, 2024
b655a96
Some changes
whaeck Apr 5, 2024
47c1e9f
Adding FixedPoint
whaeck Apr 5, 2024
d3b861e
Update compiler guard
whaeck Apr 5, 2024
632e75f
Updating documentation
whaeck Apr 8, 2024
8905953
Adding Inf values for integers
whaeck Apr 8, 2024
133e203
Ensuring that writing integers never go over the width
whaeck Apr 8, 2024
4f3e8a4
More test changes
whaeck Apr 9, 2024
a727a8f
More testing of record
whaeck Apr 9, 2024
f073483
more updates
whaeck Apr 9, 2024
0c3d612
Fixing an ambiguous abs issue in ACEtk
whaeck Apr 9, 2024
540e045
Adding comment
whaeck Apr 9, 2024
92a9f86
more tests for real, move to fortran style
whaeck Apr 15, 2024
698b47c
saving work
whaeck Apr 15, 2024
e5293cb
Adding ENDF
whaeck Apr 15, 2024
b586f40
adding test
whaeck Apr 15, 2024
f1768ad
more testing
whaeck Apr 16, 2024
8db01f6
Adding some more documentation
whaeck Apr 16, 2024
52c75ea
Updating integer test
whaeck Apr 16, 2024
ab015c6
Adding free format read functions
whaeck Apr 16, 2024
322879d
Updatign compiler guards
whaeck Apr 16, 2024
d96f5f3
Fixing some indentation
whaeck Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ target_include_directories( tools
target_link_libraries( tools
INTERFACE
spdlog::spdlog
FastFloat::fast_float
)

target_compile_definitions( tools INTERFACE -DNANORANGE_NO_STD_FORWARD_DECLARATIONS )
Expand Down
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
)
15 changes: 15 additions & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ 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 )
Expand Down
3 changes: 3 additions & 0 deletions src/tools.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// disco
#include "tools/disco.hpp"

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

Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

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

// other includes

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

template < unsigned int Width >
class TestBaseFixedWidthField : protected BaseFixedWidthField< Width > {

public:

using BaseFixedWidthField< Width >::skipPlusSign;
using BaseFixedWidthField< Width >::skipSpaces;
};

SCENARIO( "BaseFixedWidthField" ) {

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();
TestBaseFixedWidthField< 6 >::skipPlusSign( iter, position );
CHECK( iter == string.begin() + 1 );
CHECK( position == 1 );

string = "abc";
position = 0;
iter = string.begin();
TestBaseFixedWidthField< 6 >::skipPlusSign( iter, position );
CHECK( iter == string.begin() );
CHECK( position == 0 );

string = " ";
position = 0;
iter = string.begin();
TestBaseFixedWidthField< 6 >::skipSpaces( iter, position );
CHECK( iter == string.end() );
CHECK( position == 6 );

string = " ";
position = 0;
iter = string.begin();
TestBaseFixedWidthField< 6 >::skipSpaces( iter, position );
CHECK( iter == string.end() - 1 );
CHECK( position == 6 );
} // SCENARIO
1 change: 1 addition & 0 deletions src/tools/disco/BaseFixedWidthField/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( disco.BaseFixedWidthField BaseFixedWidthField.test.cpp )
90 changes: 90 additions & 0 deletions src/tools/disco/Character.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ifndef NJOY_TOOLS_DISCO_CHARACTER
#define NJOY_TOOLS_DISCO_CHARACTER

// system includes
#include <sstream>
#include <iomanip>

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

namespace njoy {
namespace tools {
namespace disco {

/**
* @brief A class for reading and writing fixed width data fields containing
* characters.
*/
template< unsigned int Width >
class Character : public BaseFixedWidthField< Width > {

/* fields */

protected:

using BaseFixedWidthField< Width >::skipSpaces;
using BaseFixedWidthField< Width >::skipPlusSign;

public:

/**
* @brief Read character data from the fixed width field
*
* The resulting character data has a length equal to the width of the field.
* Spaces are appended to the character data if a new line character or if the
* end of file character is encountered.
*
* @param[in,out] iter an iterator to a character in a range
*/
template < typename Representation, typename Iterator >
static Representation read( Iterator& iter, const Iterator& ) {

Representation value;
value.reserve( Width );

unsigned int position = 0;
while( position < Width && ! ( isNewLine( iter ) || isEndOfFile( iter ) ) ) {

++position;
value.push_back( *iter++ );
}
while ( position < Width ) {

++position;
value.push_back( ' ' );
}

return value;
}

template < typename Iterator >
static std::string read( Iterator& iter, const Iterator& end ) {

return read< std::string >( iter, end );
}

template< typename Representation, typename Iterator >
static void write( const Representation& value, Iterator& iter ) {

unsigned int position = 0;
const unsigned int difference = value.size() >= Width ? 0 : Width - value.size();
while ( position < difference ) {

++position;
*iter++ = ' ';
}
auto viter = value.begin();
while ( position < Width ) {

++position;
*iter++ = *viter++;
}
}
};

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

#endif
1 change: 1 addition & 0 deletions src/tools/disco/Character/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( disco.Character Character.test.cpp )
Loading