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

Using fast_float to do local independent parsing #325

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on: [push, pull_request]
name: Build
jobs:
build-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- run: sudo apt install -y valgrind uuid-dev
- uses: actions/checkout@v2
Expand All @@ -25,7 +25,7 @@ jobs:
name: bindings.zip
path: build/bindings.zip
build-macos:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -42,7 +42,7 @@ jobs:
path: build/lib3mf.dylib

codecoverage-macos:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -65,7 +65,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./build/Test_CPP_Bindings_filtered.info
fail_ci_if_error: true # optional (default = false)
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)

build-windows-release:
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- run: ctest -V
working-directory: ./build
assemble-sdk:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: [build-windows-release, build-linux, build-macos]
steps:
- run: sudo apt install -y zip unzip
Expand All @@ -161,7 +161,7 @@ jobs:
name: lib3mf_sdk.zip
path: build/lib3mf_sdk.zip
deploy-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: [assemble-sdk]
steps:
- run: sudo apt install -y zip unzip
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
cmake --build . --config Release
./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf
deploy-macos:
runs-on: macos-10.15
runs-on: macos-latest
needs: [assemble-sdk]
steps:
- name: Download lib3mf_sdk artifact
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "submodules/AutomaticComponentToolkit"]
path = submodules/AutomaticComponentToolkit
url = https://github.com/Autodesk/AutomaticComponentToolkit.git
[submodule "submodules/fast_float"]
path = submodules/fast_float
url = https://github.com/fastfloat/fast_float.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ else()
endif()


target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/submodules/fast_float/include)


set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" )
# This makes sure symbols are exported
target_compile_options(${PROJECT_NAME} PRIVATE "-D__LIB3MF_EXPORTS")
Expand Down
3 changes: 3 additions & 0 deletions Include/Common/NMR_StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ and Exception-safe

#include "Common/NMR_Types.h"
#include "Common/NMR_Local.h"

#include <fast_float/fast_float.h>

#include <string>
#include <string.h>
#include <vector>
Expand Down
13 changes: 5 additions & 8 deletions Source/Common/NMR_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,14 @@ namespace NMR {
nfDouble dResult = 0.0;

// Convert to double and make a input and range check!
nfChar * pEndPtr;

dResult = strtod(pszValue, &pEndPtr);
auto answer = fast_float::from_chars(pszValue, pszValue + strlen(pszValue), dResult);

// Check if any conversion happened
if ((pEndPtr == pszValue) || (!pEndPtr))
if (answer.ec != std::errc())
{
throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION);

if ((*pEndPtr != '\0') && (*pEndPtr != ' '))
throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION);

}

if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL))
throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace NMR {
__NMRASSERT(pAttributeValue);

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_U) == 0) {
m_fU = strtof(pAttributeValue, nullptr);
m_fU = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fU))
throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES);
if (fabs (m_fU) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand All @@ -95,7 +95,7 @@ namespace NMR {
}

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_V) == 0) {
m_fV = strtof(pAttributeValue, nullptr);
m_fV = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fV))
throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES);
if (fabs(m_fV) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand Down
6 changes: 3 additions & 3 deletions Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace NMR {
__NMRASSERT(pAttributeValue);

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) {
m_fX = strtof(pAttributeValue, nullptr);
m_fX = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fX))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand All @@ -91,7 +91,7 @@ namespace NMR {
}

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) {
m_fY = strtof(pAttributeValue, nullptr);
m_fY = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fY))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand All @@ -100,7 +100,7 @@ namespace NMR {
}

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) {
m_fZ = strtof(pAttributeValue, nullptr);
m_fZ = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fZ))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand Down
6 changes: 3 additions & 3 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ namespace NMR {
__NMRASSERT(pAttributeValue);

if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) {
m_fX = strtof(pAttributeValue, nullptr);
m_fX = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fX))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE)
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
m_bHasX = true;
}
else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) {
m_fY = strtof(pAttributeValue, nullptr);
m_fY = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fY))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE)
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
m_bHasY = true;
}
else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) {
m_fZ = strtof(pAttributeValue, nullptr);
m_fZ = fnStringToFloat(pAttributeValue);
if (std::isnan (m_fZ))
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE)
Expand Down
1 change: 1 addition & 0 deletions submodules/fast_float
Submodule fast_float added at 1dfad2
Loading