From ddf1ff435882226538196c4f6254627f63af6264 Mon Sep 17 00:00:00 2001 From: Mauricio 'Pacha' Vargas Sepulveda Date: Wed, 6 Nov 2024 11:48:34 -0500 Subject: [PATCH] Merge tiny GHA and refactors test rhub USING R-HUB IMAGES simplify r test modify rhub fix docker dependencies separate deps and check run line use of with install dependencies install pak fix cd arguments specify r user pkg dir install openssl dont use apt when it is not recognized install rcmdcheck explicit use of apt-get correct cmd syntax try script remove multiple lines in gha install rcmdcheck on docker correct docker image call simplify docker docker: use local dir use devtools with docker try pak again use devtools with docker check with rcmdcheck on docker install decor on docker test with all rhub images update pkg desc + add more devel R images correct clang versions dont' install curl on docker use old cache for ols OSes downgrade checkout with ols OS try checkout v2 try old OS again remove old OSes for now install pandoc on redhat simplify gha simplify gha more skip R setup on docker install pak install pak via rscript indent pak fix asan errors? full refactor + use libpng for mac m1 rpkg: use cpp/xxx.hpp instead of cpp11.hpp consistent use of ThrowIfBad + add link to microdata add microdata to main readme and pypkg micro data in pypkg readme --- .github/workflows/build-rpkg.yml | 79 ++++++++++---- README.md | 12 ++ dev/05-clear-gha-workflows.r | 2 +- dev/mac-distribution.xml | 14 --- pypkg/README.md | 14 +++ rpkg/.Rbuildignore | 8 ++ rpkg/DESCRIPTION | 9 +- rpkg/README.md | 18 ++- rpkg/cleanup | 2 + rpkg/configure | 35 ++++++ rpkg/configure.win | 0 rpkg/cran-comments.md | 103 +----------------- rpkg/man/redatam-package.Rd | 2 +- rpkg/src/Makevars | 15 +-- rpkg/src/Makevars.in | 29 +++++ rpkg/src/Makevars.win | 7 +- rpkg/src/main.cpp | 3 +- rpkg/src/redatamlib/entities/Entity.cpp | 30 +++-- rpkg/src/redatamlib/entities/Entity.hpp | 10 +- .../redatamlib/entities/RedatamDatabase.cpp | 26 ++--- .../redatamlib/entities/RedatamDatabase.hpp | 12 +- rpkg/src/redatamlib/entities/Variable.cpp | 95 +++++++++------- rpkg/src/redatamlib/entities/Variable.hpp | 18 +-- .../exporters/ParentIDCalculator.cpp | 2 +- .../exporters/ParentIDCalculator.hpp | 8 +- .../redatamlib/exporters/RListExporter.cpp | 85 ++++++++------- .../redatamlib/exporters/RListExporter.hpp | 15 ++- .../src/redatamlib/readers/BitArrayReader.cpp | 12 +- .../src/redatamlib/readers/BitArrayReader.hpp | 10 +- .../redatamlib/readers/ByteArrayReader.cpp | 40 +++---- .../redatamlib/readers/ByteArrayReader.hpp | 32 +++--- .../readers/FuzzyVariableParser.cpp | 3 +- rpkg/src/redatamlib/readers/XMLParser.cpp | 3 +- rpkg/src/redatamlib/utils.cpp | 7 +- rpkg/src/redatamlib/utils.hpp | 13 ++- rpkg/src/vendor/pugixml.cpp | 10 +- 36 files changed, 427 insertions(+), 356 deletions(-) delete mode 100644 dev/mac-distribution.xml create mode 100755 rpkg/cleanup create mode 100755 rpkg/configure create mode 100644 rpkg/configure.win create mode 100644 rpkg/src/Makevars.in diff --git a/.github/workflows/build-rpkg.yml b/.github/workflows/build-rpkg.yml index 3e66086..2a0ab6d 100644 --- a/.github/workflows/build-rpkg.yml +++ b/.github/workflows/build-rpkg.yml @@ -13,53 +13,92 @@ permissions: read-all jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} + container: ${{ matrix.config.container }} - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + name: ${{ matrix.config.name }} strategy: fail-fast: false matrix: config: - - {os: macos-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - - {os: ubuntu-latest, r: 'release'} + - {os: macos-13, r: 'release', container: null, name: 'macos-13-r-release'} + - {os: macos-14, r: 'release', container: null, name: 'macos-14-r-release'} + - {os: ubuntu-latest, r: 'release', container: null, name: 'ubuntu-latest-r-release'} + - {os: windows-latest, r: 'release', container: null, name: 'windows-latest-r-release'} + - {os: macos-13, r: 'devel', container: null, name: 'macos-13-r-devel'} + - {os: macos-14, r: 'devel', container: null, name: 'macos-14-r-devel'} + - {os: ubuntu-latest, r: 'devel', container: null, name: 'ubuntu-latest-r-devel'} + - {os: windows-latest, r: 'devel', container: null, name: 'windows-latest-r-devel'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/ubuntu-gcc12:latest' }, name: 'r-devel-linux-x86_64-debian-gcc'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/ubuntu-clang:latest' }, name: 'r-devel-linux-x86_64-debian-clang'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/atlas:latest' }, name: 'ATLAS'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/c23:latest' }, name: 'C23'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang-asan:latest' }, name: 'clang-ASAN'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang16:latest' }, name: 'clang16'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang17:latest' }, name: 'clang17'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang18:latest' }, name: 'clang18'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang19:latest' }, name: 'clang19'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/clang20:latest' }, name: 'clang20'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/donttest:latest' }, name: 'donttest'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/gcc13:latest' }, name: 'gcc13'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/gcc13:latest' }, name: 'gcc14'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/intel:latest' }, name: 'intel'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/mkl:latest' }, name: 'mkl'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/nold:latest' }, name: 'noLD'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/noremap:latest' }, name: 'noRemap'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/valgrind:latest' }, name: 'rchk'} + - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/valgrind:latest' }, name: 'valgrind'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - uses: r-lib/actions/setup-pandoc@v2 + - name: Setup pandoc + if: matrix.config.container == null + uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v2 + - name: Setup R + if: matrix.config.container == null + uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - name: Restore R package cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/R key: ${{ runner.os }}-r-${{ matrix.config.r }}-cache - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - working-directory: './rpkg' - extra-packages: any::rcmdcheck - needs: check + - name: Install libpng (macOS) + if: matrix.config.os == 'macos-14' && matrix.config.r == 'devel' + run: | + curl -LO https://mac.r-project.org/bin/darwin20/arm64/libpng-1.6.38-darwin.20-arm64.tar.xz + sudo tar -xvf libpng-1.6.38-darwin.20-arm64.tar.xz -C / + echo "PKG_CONFIG_PATH=/opt/R/arm64/lib/pkgconfig" >> $GITHUB_ENV - - uses: r-lib/actions/check-r-package@v2 - with: - working-directory: './rpkg' - upload-snapshots: true - build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' + - name: Install dependencies + run: | + Rscript -e 'if (!requireNamespace("pak", quietly = TRUE)) { install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") }' + Rscript -e 'pak::pkg_install("decor", dependencies = TRUE)' + Rscript -e 'pak::pkg_install("rcmdcheck", dependencies = TRUE)' + Rscript -e 'pak::pkg_install("pkgbuild", dependencies = TRUE)' + Rscript -e 'pak::pkg_install(".", dependencies = TRUE)' + working-directory: ./rpkg + + - name: Check + run: | + Rscript -e 'pkgbuild::check_build_tools(debug = TRUE)' + Rscript -e 'rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), build_args = "--no-manual", error_on = "error")' + working-directory: ./rpkg - name: Save R package cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/R key: ${{ runner.os }}-r-${{ matrix.config.r }}-cache - \ No newline at end of file diff --git a/README.md b/README.md index ae85fdc..0c60e1f 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,18 @@ This software is a full C++ ground-up rewrite of the original [Redatam Converter **For the Python package that allows to directly read REDATAM databases in Python, see the [pypkg](pypkg) directory.** +**If you only need the processed data, you can download the [microdata repository](https://github.com/pachadotdev/redatam-microdata/releases). It is available in RDS format for easy loading into R.** + +**Available datasets:** + +- **Argentina: 1991, 2001, 2010** +- **Bolivia: 2001, 2012** +- **Chile: 2017** +- **Ecuador: 2010** +- **El Salvador: 2007** +- **Guatemala: 2018** +- **Mexico: 2000** + ## Installation ### From binaries diff --git a/dev/05-clear-gha-workflows.r b/dev/05-clear-gha-workflows.r index 731de04..b8880d1 100644 --- a/dev/05-clear-gha-workflows.r +++ b/dev/05-clear-gha-workflows.r @@ -16,4 +16,4 @@ delete_old_workflow_runs <- function(owner, repo, keep = 1) { } # Call the function to delete old workflow runs, keeping only the latest 1 run -delete_old_workflow_runs("pachadotdev", "open-redatam", keep = 1) \ No newline at end of file +delete_old_workflow_runs("pachadotdev", "open-redatam", keep = 5) diff --git a/dev/mac-distribution.xml b/dev/mac-distribution.xml deleted file mode 100644 index 15ba05a..0000000 --- a/dev/mac-distribution.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - Open Redatam Installer - - - - - - - - - - #package.pkg - diff --git a/pypkg/README.md b/pypkg/README.md index 4f04408..ac9225f 100644 --- a/pypkg/README.md +++ b/pypkg/README.md @@ -35,6 +35,20 @@ rm -rf build dist redatam.egg-info pip install --use-pep517 . ``` +## Processed data + +If you only need the processed data, you can download the [microdata repository](https://github.com/pachadotdev/redatam-microdata/releases). It is available in RDS format for easy loading into R. + +Available datasets: + +- **Argentina**: 1991, 2001, 2010 +- **Bolivia**: 2001, 2012 +- **Chile**: 2017 +- **Ecuador**: 2010 +- **El Salvador**: 2007 +- **Guatemala**: 2018 +- **Mexico**: 2000 + ## Requirements Python 3.8 or higher. diff --git a/rpkg/.Rbuildignore b/rpkg/.Rbuildignore index 6de2657..d0c2c8a 100644 --- a/rpkg/.Rbuildignore +++ b/rpkg/.Rbuildignore @@ -15,3 +15,11 @@ ^cran-comments\.md$ ^inst/extdata/galapagos$ ^_pkgdown\.yml$ +^microdata$ +^redatam$ +^src/Makevars$ +^src/.*\.o$ +^src/.*\.so$ +^src/.*\.dll$ +^src/.*\.dylib$ +^libs$ diff --git a/rpkg/DESCRIPTION b/rpkg/DESCRIPTION index e5478ce..2802612 100644 --- a/rpkg/DESCRIPTION +++ b/rpkg/DESCRIPTION @@ -1,7 +1,7 @@ Package: redatam Type: Package Title: Import 'REDATAM' Files -Version: 2.0.1 +Version: 2.0.3 Authors@R: c( person( given = "Mauricio", @@ -32,14 +32,13 @@ Suggests: rmarkdown, testthat (>= 3.0.0) Depends: R(>= 3.5.0) -Description: Import 'REDATAM' files into R. 'REDATAM' is a software for the - manipulation of microdata from censuses and surveys. This package provides - functions to import 'REDATAM' files into R. It is based on De Grande (2016) +Description: Import 'REDATAM' formats into R via the 'Open REDATAM' C++ library + based on De Grande (2016) . License: Apache License (>= 2) URL: https://github.com/litalbarkai/open-redatam BugReports: https://github.com/litalbarkai/open-redatam/issues -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Encoding: UTF-8 NeedsCompilation: yes VignetteBuilder: knitr diff --git a/rpkg/README.md b/rpkg/README.md index e9c3b31..dd0d76d 100644 --- a/rpkg/README.md +++ b/rpkg/README.md @@ -13,14 +13,22 @@ For the standalone C++ command line application and desktop app, see the [main d To install the R package, run the following command: ```r -install.packages("redatam") +remotes::install_github("pachadotdev/open-redatam", subdir = "rpkg") ``` -Or install the development version from GitHub: +## Processed data -```r -remotes::install_github("pachadotdev/open-redatam/rpkg", subdir = "rpkg") -``` +If you only need the processed data, you can download the [microdata repository](https://github.com/pachadotdev/redatam-microdata/releases). It is available in RDS format for easy loading into R. + +Available datasets: + +- **Argentina**: 1991, 2001, 2010 +- **Bolivia**: 2001, 2012 +- **Chile**: 2017 +- **Ecuador**: 2010 +- **El Salvador**: 2007 +- **Guatemala**: 2018 +- **Mexico**: 2000 ## Requirements diff --git a/rpkg/cleanup b/rpkg/cleanup new file mode 100755 index 0000000..894bb4d --- /dev/null +++ b/rpkg/cleanup @@ -0,0 +1,2 @@ +#!/bin/sh +rm -f src/Makevars configure.log diff --git a/rpkg/configure b/rpkg/configure new file mode 100755 index 0000000..7ac09aa --- /dev/null +++ b/rpkg/configure @@ -0,0 +1,35 @@ +#!/bin/sh + +PKG_CONFIG_NAME="redatam" + +# Check for pkg-config +pkg-config --version >/dev/null 2>&1 +if [ $? -eq 0 ]; then + PKGCONFIG_CFLAGS=`pkg-config --cflags --silence-errors` + PKGCONFIG_LIBS=`pkg-config --libs` +fi + +# Set default flags +PKG_CFLAGS="-Ivendor -Iredatamlib -Iredatamlib/entities -Iredatamlib/exporters -Iredatamlib/readers" +PKG_LIBS="-Lvendor -Lredatamlib" + +# Use pkg-config if available +if [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then + echo "Found pkg-config cflags and libs!" + PKG_CFLAGS=${PKGCONFIG_CFLAGS} + PKG_LIBS=${PKGCONFIG_LIBS} +fi + +# Uncomment CXXFLAGS in Makevars.in to debug +# CXXFLAGS="-O0 -g -stdlib=libc++" +LDFLAGS="-stdlib=libc++" + +# Write to Makevars using sed to replace placeholders +sed -e "s|@cflags@|$PKG_CFLAGS|" \ + -e "s|@libs@|$PKG_LIBS|" \ + -e "s|@cxxflags@|$CXXFLAGS|" \ + -e "s|@ldflags@|$LDFLAGS|" \ + src/Makevars.in > src/Makevars + +# Success +exit 0 diff --git a/rpkg/configure.win b/rpkg/configure.win new file mode 100644 index 0000000..e69de29 diff --git a/rpkg/cran-comments.md b/rpkg/cran-comments.md index c3c2079..cf55644 100644 --- a/rpkg/cran-comments.md +++ b/rpkg/cran-comments.md @@ -2,105 +2,4 @@ 0 errors | 0 warnings | 1 note -* The reported CRAN errors on clang-asan/ubsan seem to come from a bug - external to the package -* The bug was reported here - https://github.com/microsoft/DirectXShaderCompiler/issues/5971 -* The workaround is to set export ASAN_OPTIONS=alloc_dealloc_mismatch=0 -* After testing with clang-asan locally (see my clang setup at the end), I get - this - -``` -ℹ Testing redatam -dotcode.c:1963:2: runtime error: call to function foo through pointer to incorrect function type 'void (*)(void *)' -/tmp/RtmpawfzRb/foo.c:1: note: foo defined here -SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior dotcode.c:1963:2 -✔ | F W S OK | Context -⠏ | 0 | galapagos Opening dictionary file... -Exporting cg15... -Exporting provin... -Exporting canton... -Exporting parroq... -Exporting zona... -Fixing encoding... -Tidying names... -Tidying variables... -⠋ | 1 | galapagos Opening dictionary file... -Exporting cg15... -Exporting provin... -Exporting canton... -Exporting parroq... -Exporting zona... -Fixing encoding... -Tidying names... -Tidying variables... -✔ | 16 | galapagos - -══ Results ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ -[ FAIL 0 | WARN 0 | SKIP 0 | PASS 16 ] -``` - -# Clang setup - -``` -# install clang-19 - -wget https://apt.llvm.org/llvm.sh -O dev/llvm.sh -chmod +x dev/llvm.sh -sudo ./dev/llvm.sh 19 -sudo apt install clang-19 lldb-19 libc++-dev libc++abi-dev -sudo apt install libstdc++-12-dev - -export ASAN_OPTIONS=detect_leaks=0 -export RJAVA_JVM_STACK_WORKAROUND=0 -export RGL_USE_NULL=true -export R_DONT_USE_TK=true - -sudo ln -s /usr/bin/clang-19 /usr/bin/clang -sudo ln -s /usr/bin/clang++-19 /usr/bin/clang++ - -# install R-devel from source - -sudo apt update -sudo apt install -y build-essential gfortran libreadline-dev libx11-dev libxt-dev \ - libpng-dev libjpeg-dev libcairo2-dev xvfb libbz2-dev \ - libzstd-dev liblzma-dev libcurl4-openssl-dev \ - texinfo texlive texlive-fonts-extra \ - texlive-fonts-recommended texlive-latex-extra \ - libpcre2-dev libharfbuzz-dev libfribidi-dev \ - libclang-dev llvm-dev - -wget https://cran.r-project.org/src/base-prerelease/R-devel.tar.gz -O dev/R-devel.tar.gz -cd dev -tar -xzvf R-devel.tar.gz -cd R-devel - -# add this to config.site -## clang-ASAN, clang-UBSAN: -CC="clang -fsanitize=address,undefined -fno-sanitize=float-divide-by-zero -fno-sanitize=alignment -fno-omit-frame-pointer" -CXX="clang++ -fsanitize=address,undefined -fno-sanitize=float-divide-by-zero -fno-sanitize=alignment -fno-omit-frame-pointer -frtti -stdlib=libc++" -CFLAGS="-g -O3 -Wall -pedantic" -FFLAGS="-g -O2 -mtune=native" -CXXFLAGS="-g -O3 -Wall -pedantic -stdlib=libc++" -MAIN_LD="clang++ -fsanitize=undefined,address -stdlib=libc++" -export ASAN_OPTIONS='detect_leaks=0:detect_odr_violation=0' -export UBSAN_OPTIONS='print_stacktrace=1' -export RGL_USE_NULL="true" -export R_DONT_USE_TK="true" - -./configure \ - --prefix=/opt/R/${R_VERSION} \ - --enable-memory-profiling \ - --enable-R-shlib \ - --with-blas \ - --with-lapack - -make - -dev/R-devel/bin/R -# install.packages(c("knitr", "cpp11", "data.table", "stringi", "janitor", "rmarkdown", "devtools")) - -dev/R-devel/bin/R -# devtools::clean_dll() -# devtools::test() -``` +* This was tested with all available R-Hub images. diff --git a/rpkg/man/redatam-package.Rd b/rpkg/man/redatam-package.Rd index 83fcd7c..762ffbf 100644 --- a/rpkg/man/redatam-package.Rd +++ b/rpkg/man/redatam-package.Rd @@ -6,7 +6,7 @@ \alias{redatam-package} \title{redatam: Import 'REDATAM' Files} \description{ -Import 'REDATAM' files into R. 'REDATAM' is a software for the manipulation of microdata from censuses and surveys. This package provides functions to import 'REDATAM' files into R. It is based on De Grande (2016) \url{https://www.jstor.org/stable/24890658}. +Import 'REDATAM' formats into R via the 'Open REDATAM' C++ library \url{https://github.com/litalbarkai/open-redatam} based on De Grande (2016) \url{https://www.jstor.org/stable/24890658}. } \seealso{ Useful links: diff --git a/rpkg/src/Makevars b/rpkg/src/Makevars index 02b1059..2d6defc 100644 --- a/rpkg/src/Makevars +++ b/rpkg/src/Makevars @@ -1,11 +1,7 @@ -PKG_CPPFLAGS = -Ivendor -Iredatamlib -Iredatamlib/entities -Iredatamlib/exporters -Iredatamlib/readers -PKG_LIBS = -Lvendor -Lredatamlib - -# Debug with clang -# PKG_CFLAGS = -g -O0 -fsanitize=address,undefined -# PKG_CXXFLAGS = -g -O0 -fsanitize=address,undefined -# PKG_LDFLAGS = -fsanitize=address,undefined -# CXXFLAGS = -O0 -g +PKG_CPPFLAGS=-Ivendor -Iredatamlib -Iredatamlib/entities -Iredatamlib/exporters -Iredatamlib/readers +PKG_LIBS=-Lvendor -Lredatamlib +# CXXFLAGS=-g -O2 -ffile-prefix-map=/build/r-base-2y82rL/r-base-4.4.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always +LDFLAGS=-stdlib=libc++ # Explicitly list all source files SOURCES = vendor/pugixml.cpp \ @@ -30,5 +26,4 @@ all: $(SHLIB) $(SHLIB): $(OBJECTS) -clean: - rm -f $(OBJECTS) $(SHLIB) +clean: rm -f $(OBJECTS) $(SHLIB) diff --git a/rpkg/src/Makevars.in b/rpkg/src/Makevars.in new file mode 100644 index 0000000..51b7c75 --- /dev/null +++ b/rpkg/src/Makevars.in @@ -0,0 +1,29 @@ +PKG_CPPFLAGS=@cflags@ +PKG_LIBS=@libs@ +# CXXFLAGS=@cxxflags@ +LDFLAGS=@ldflags@ + +# Explicitly list all source files +SOURCES = vendor/pugixml.cpp \ + redatamlib/readers/BitArrayReader.cpp \ + redatamlib/readers/ByteArrayReader.cpp \ + redatamlib/entities/Entity.cpp \ + redatamlib/readers/FuzzyEntityParser.cpp \ + redatamlib/readers/FuzzyVariableParser.cpp \ + redatamlib/exporters/ParentIDCalculator.cpp \ + redatamlib/exporters/RListExporter.cpp \ + redatamlib/entities/RedatamDatabase.cpp \ + redatamlib/entities/Variable.cpp \ + redatamlib/readers/XMLParser.cpp \ + redatamlib/utils.cpp \ + main.cpp \ + cpp11.cpp + +# Convert source files to object files +OBJECTS = $(SOURCES:.cpp=.o) + +all: $(SHLIB) + +$(SHLIB): $(OBJECTS) + +clean: rm -f $(OBJECTS) $(SHLIB) diff --git a/rpkg/src/Makevars.win b/rpkg/src/Makevars.win index 623ee32..d9befe6 100644 --- a/rpkg/src/Makevars.win +++ b/rpkg/src/Makevars.win @@ -1,5 +1,5 @@ -PKG_CPPFLAGS = -Ivendor -Iredatamlib -Iredatamlib/entities -Iredatamlib/exporters -Iredatamlib/readers -PKG_LIBS = -Lvendor -Lredatamlib +PKG_CPPFLAGS=-Ivendor -Iredatamlib -Iredatamlib/entities -Iredatamlib/exporters -Iredatamlib/readers +PKG_LIBS=-Lvendor -Lredatamlib # Explicitly list all source files SOURCES = vendor/pugixml.cpp \ @@ -24,5 +24,4 @@ all: $(SHLIB) $(SHLIB): $(OBJECTS) -clean: - rm -f $(OBJECTS) $(SHLIB) +clean: rm -f $(OBJECTS) $(SHLIB) diff --git a/rpkg/src/main.cpp b/rpkg/src/main.cpp index 9e3ce20..231f812 100644 --- a/rpkg/src/main.cpp +++ b/rpkg/src/main.cpp @@ -1,5 +1,6 @@ #include -#include + +#include // cpp11::stop #include "redatamlib/entities/RedatamDatabase.hpp" diff --git a/rpkg/src/redatamlib/entities/Entity.cpp b/rpkg/src/redatamlib/entities/Entity.cpp index c73970b..ab097ef 100644 --- a/rpkg/src/redatamlib/entities/Entity.cpp +++ b/rpkg/src/redatamlib/entities/Entity.cpp @@ -3,25 +3,37 @@ namespace RedatamLib { Entity::Entity() - : m_name(""), m_parentName(""), m_description(""), m_indexFilename(""), - m_child(nullptr), m_variables(), m_bounds({0, 0}), m_reader(), + : m_name(""), + m_parentName(""), + m_description(""), + m_indexFilename(""), + m_child(nullptr), + m_variables(), + m_bounds({0, 0}), + m_reader(), m_rowsCount(0) {} Entity::Entity(const string &name, const string &parentName, const string &description, const string &idxFileName, pair bounds) - : m_name(name), m_parentName(parentName), m_description(description), - m_indexFilename(idxFileName), m_child(nullptr), m_variables(), - m_bounds(bounds), m_reader(idxFileName), m_rowsCount(0) { - // PTR files shouldn't be empty, but in the odd case it is - treat it as - // holding zeros + : m_name(name), + m_parentName(parentName), + m_description(description), + m_indexFilename(idxFileName), + m_child(nullptr), + m_variables(), + m_bounds(bounds), + m_reader(idxFileName), + m_rowsCount(0) { + // PTR files shouldn't be empty, but in the odd case it is - treat it as + // holding zeros if (m_reader.GetEndPos() == m_reader.GetPos()) { m_rowsCount = 0; } else { m_reader.SetPos(m_reader.GetEndPos() - 4); m_rowsCount = m_reader.ReadInt32LE(); - m_reader.SetPos(4); // advance past header of zeros + m_reader.SetPos(4); // advance past header of zeros } } @@ -49,4 +61,4 @@ void Entity::AttachVariables(shared_ptr> variables) { m_variables = variables; } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/entities/Entity.hpp b/rpkg/src/redatamlib/entities/Entity.hpp index 3338e7d..723cd4a 100644 --- a/rpkg/src/redatamlib/entities/Entity.hpp +++ b/rpkg/src/redatamlib/entities/Entity.hpp @@ -3,7 +3,7 @@ #include #include -#include // std::pair +#include // std::pair #include #include "ByteArrayReader.hpp" @@ -16,7 +16,7 @@ using std::string; using std::vector; class Entity { -public: + public: explicit Entity(); explicit Entity(const string &name, const string &parentName, const string &description, const string &idxFileName, @@ -39,7 +39,7 @@ class Entity { void AttachChild(Entity *child); void AttachVariables(shared_ptr> variables); -private: + private: string m_name; string m_parentName; string m_description; @@ -50,6 +50,6 @@ class Entity { ByteArrayReader m_reader; size_t m_rowsCount; }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_ENTITY_HPP +#endif // REDATAMLIB_ENTITY_HPP diff --git a/rpkg/src/redatamlib/entities/RedatamDatabase.cpp b/rpkg/src/redatamlib/entities/RedatamDatabase.cpp index b1aec89..c873193 100644 --- a/rpkg/src/redatamlib/entities/RedatamDatabase.cpp +++ b/rpkg/src/redatamlib/entities/RedatamDatabase.cpp @@ -1,13 +1,12 @@ -#include // std::tolower -#include // std::invalid_argument -#include // find_last_of, substr, npos -#include +#include "RedatamDatabase.hpp" + +#include // std::tolower +#include // find_last_of, substr, npos #include "FuzzyEntityParser.hpp" -#include "RedatamDatabase.hpp" -#include "XMLParser.hpp" -#include "utils.hpp" // ThrowIfBad, GetFileExtension #include "RListExporter.hpp" +#include "XMLParser.hpp" +#include "utils.hpp" // ThrowIfBad, GetFileExtension namespace RedatamLib { using std::invalid_argument; @@ -27,17 +26,16 @@ cpp11::list RedatamDatabase::ExportRLists() const { void RedatamDatabase::OpenDictionary(const string &fileName) { string ext = GetFileExtension(fileName); - if (".dic" == ext) { + if (ext == ".dic") { FuzzyEntityParser parser(fileName); m_entities = parser.ParseEntities(); - } else if (".dicx" == ext) { + } else if (ext == ".dicx") { XMLParser parser; m_entities = parser.ParseFile(fileName); } else { - ThrowIfBad( - false, - invalid_argument( - "Error: Dictionary file's extension must be .dic or .dicx .")); + ThrowIfBad( + false, + "Error: Dictionary file's extension must be .dic or .dicx."); } } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/entities/RedatamDatabase.hpp b/rpkg/src/redatamlib/entities/RedatamDatabase.hpp index 7ef8fdf..65628b5 100644 --- a/rpkg/src/redatamlib/entities/RedatamDatabase.hpp +++ b/rpkg/src/redatamlib/entities/RedatamDatabase.hpp @@ -1,9 +1,11 @@ #ifndef REDATAMLIB_REDATAMDATABASE_HPP #define REDATAMLIB_REDATAMDATABASE_HPP +#include // std::invalid_argument #include #include -#include + +#include #include "Entity.hpp" @@ -12,7 +14,7 @@ using std::string; using std::vector; class RedatamDatabase { -public: + public: // Throws invalid_argument explicit RedatamDatabase(const string &fileName); ~RedatamDatabase() = default; @@ -22,12 +24,12 @@ class RedatamDatabase { cpp11::list ExportRLists() const; -private: + private: vector m_entities; void OpenDictionary(const string &fileName); }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_REDATAMDATABASE_HPP +#endif // REDATAMLIB_REDATAMDATABASE_HPP diff --git a/rpkg/src/redatamlib/entities/Variable.cpp b/rpkg/src/redatamlib/entities/Variable.cpp index 768acfc..0ab7a4c 100644 --- a/rpkg/src/redatamlib/entities/Variable.cpp +++ b/rpkg/src/redatamlib/entities/Variable.cpp @@ -1,17 +1,33 @@ -#include "BitArrayReader.hpp" #include "Variable.hpp" +#include "BitArrayReader.hpp" +#include "ByteArrayReader.hpp" + namespace RedatamLib { + Variable::Variable() - : m_name(""), m_type(NA), m_idxFileName(""), m_dataSize(0), m_filter(""), - m_range(""), m_tags(), m_description(""), m_decimals(0) {} + : m_name(""), + m_type(NA), + m_idxFileName(""), + m_dataSize(0), + m_filter(""), + m_range(""), + m_tags(), + m_description(""), + m_decimals(0) {} Variable::Variable(const string &name, VarType type, const string &idxFileName, size_t dataSize, const string &filter, const string &range, vector tags, const string &description, size_t decimals) - : m_name(name), m_type(type), m_idxFileName(idxFileName), - m_dataSize(dataSize), m_filter(filter), m_range(range), m_tags(tags), - m_description(description), m_decimals(decimals) { + : m_name(name), + m_type(type), + m_idxFileName(idxFileName), + m_dataSize(dataSize), + m_filter(filter), + m_range(range), + m_tags(tags), + m_description(description), + m_decimals(decimals) { ParseValues(); } @@ -39,33 +55,33 @@ void Variable::ParseValues() { ByteArrayReader reader(m_idxFileName); switch (m_type) { - case BIN: - ParseBIN(m_dataSize, reader); - break; + case BIN: + ParseBIN(m_dataSize, reader); + break; - case CHR: - ParseStrings(m_dataSize, reader); - break; + case CHR: + ParseStrings(m_dataSize, reader); + break; - case DBL: - ParseFloats(reader); - break; + case DBL: + ParseFloats(reader); + break; - case INT: - ParseIntegers(2, reader); - break; + case INT: + ParseIntegers(2, reader); + break; - case LNG: - ParseIntegers(4, reader); - break; + case LNG: + ParseIntegers(4, reader); + break; - case PCK: - ParsePCK(m_dataSize, reader); - break; + case PCK: + ParsePCK(m_dataSize, reader); + break; - case NA: - default: - break; + case NA: + default: + break; } } @@ -97,17 +113,17 @@ void Variable::ParseIntegers(size_t size, ByteArrayReader reader) { try { switch (size) { - case 2: - while (true) { - vals->push_back(reader.ReadInt16LE()); - } - break; - - case 4: - while (true) { - vals->push_back(reader.ReadInt32LE()); - } - break; + case 2: + while (true) { + vals->push_back(reader.ReadInt16LE()); + } + break; + + case 4: + while (true) { + vals->push_back(reader.ReadInt32LE()); + } + break; } } catch (const std::out_of_range &) { } @@ -177,4 +193,5 @@ void Variable::ParseBIN(size_t size, ByteArrayReader reader) { m_values = shared_ptr(static_cast(vals), Deleter()); } -} // namespace RedatamLib + +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/entities/Variable.hpp b/rpkg/src/redatamlib/entities/Variable.hpp index 64882f3..a49b429 100644 --- a/rpkg/src/redatamlib/entities/Variable.hpp +++ b/rpkg/src/redatamlib/entities/Variable.hpp @@ -1,13 +1,11 @@ #ifndef REDATAMLIB_VARIABLE_HPP #define REDATAMLIB_VARIABLE_HPP -#include // std::shared_ptr +#include // std::shared_ptr #include -#include // std::pair +#include // std::pair #include -#include "ByteArrayReader.hpp" - namespace RedatamLib { using std::pair; using std::shared_ptr; @@ -15,10 +13,12 @@ using std::string; using std::vector; enum VarType { BIN, CHR, DBL, INT, LNG, PCK, NA }; -using Tag = pair; // Tag = +using Tag = pair; // Tag = + +class ByteArrayReader; // Forward declaration class Variable { -public: + public: explicit Variable(); explicit Variable(const string &name, VarType type, const string &idxFileName, size_t dataSize, const string &filter, const string &range, @@ -37,7 +37,7 @@ class Variable { size_t GetDecimals() const; std::shared_ptr GetValues() const; -private: + private: string m_name; VarType m_type; string m_idxFileName; @@ -58,6 +58,6 @@ class Variable { void ParseFloats(ByteArrayReader reader); }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_VARIABLE_HPP +#endif // REDATAMLIB_VARIABLE_HPP diff --git a/rpkg/src/redatamlib/exporters/ParentIDCalculator.cpp b/rpkg/src/redatamlib/exporters/ParentIDCalculator.cpp index ee70774..6537a09 100644 --- a/rpkg/src/redatamlib/exporters/ParentIDCalculator.cpp +++ b/rpkg/src/redatamlib/exporters/ParentIDCalculator.cpp @@ -13,4 +13,4 @@ size_t ParentIDCalculator::GetParentID(size_t currRow) { return m_currID; } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/exporters/ParentIDCalculator.hpp b/rpkg/src/redatamlib/exporters/ParentIDCalculator.hpp index 0285a3a..1eda7f9 100644 --- a/rpkg/src/redatamlib/exporters/ParentIDCalculator.hpp +++ b/rpkg/src/redatamlib/exporters/ParentIDCalculator.hpp @@ -5,7 +5,7 @@ namespace RedatamLib { class ParentIDCalculator { -public: + public: explicit ParentIDCalculator(Entity *child); ~ParentIDCalculator() = default; @@ -14,11 +14,11 @@ class ParentIDCalculator { size_t GetParentID(size_t currRow); -private: + private: Entity *m_child; size_t m_currID; size_t m_currLimit; }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_PARENTIDCALCULATOR_HPP +#endif // REDATAMLIB_PARENTIDCALCULATOR_HPP diff --git a/rpkg/src/redatamlib/exporters/RListExporter.cpp b/rpkg/src/redatamlib/exporters/RListExporter.cpp index 2e546cc..1442d49 100644 --- a/rpkg/src/redatamlib/exporters/RListExporter.cpp +++ b/rpkg/src/redatamlib/exporters/RListExporter.cpp @@ -1,10 +1,9 @@ -#include // For std::replace +#include // For std::replace #include -#include -#include "RListExporter.hpp" #include "Entity.hpp" #include "ParentIDCalculator.hpp" +#include "RListExporter.hpp" namespace RedatamLib { using std::endl; @@ -18,8 +17,8 @@ ListExporter::ListExporter(const std::string &outputDirectory) } } -cpp11::list -ListExporter::ExportAllR(const std::vector &entities) const { +cpp11::list ListExporter::ExportAllR( + const std::vector &entities) const { cpp11::writable::list result; cpp11::writable::strings resultNames; @@ -62,45 +61,47 @@ ListExporter::ExportAllR(const std::vector &entities) const { for (const Variable &v : *(entity.GetVariables().get())) { try { switch (v.GetType()) { - case BIN: - case PCK: - case INT: - case LNG: { - auto values = - static_cast *>(v.GetValues().get()); - cpp11::writable::integers rvalues(numRows); - for (size_t i = 0; i < numRows; i++) { - rvalues[i] = values->at(i); + case BIN: + case PCK: + case INT: + case LNG: { + auto values = + static_cast *>(v.GetValues().get()); + cpp11::writable::integers rvalues(numRows); + for (size_t i = 0; i < numRows; i++) { + rvalues[i] = values->at(i); + } + entityList.push_back(rvalues); + break; } - entityList.push_back(rvalues); - break; - } - case CHR: { - auto values = - static_cast *>(v.GetValues().get()); - cpp11::writable::strings rvalues(numRows); - for (size_t i = 0; i < numRows; i++) { - // replace '\0' with ' ' - std::string clean_string = values->at(i); - std::replace(clean_string.begin(), clean_string.end(), '\0', ' '); - rvalues[i] = clean_string; + case CHR: { + auto values = + static_cast *>(v.GetValues().get()); + cpp11::writable::strings rvalues(numRows); + for (size_t i = 0; i < numRows; i++) { + // replace '\0' with ' ' + std::string clean_string = values->at(i); + std::replace(clean_string.begin(), clean_string.end(), '\0', ' '); + rvalues[i] = clean_string; + } + entityList.push_back(rvalues); + break; } - entityList.push_back(rvalues); - break; - } - case DBL: { - auto values = static_cast *>(v.GetValues().get()); - cpp11::writable::doubles rvalues(numRows); - for (size_t i = 0; i < numRows; i++) { - rvalues[i] = values->at(i); + case DBL: { + auto values = + static_cast *>(v.GetValues().get()); + cpp11::writable::doubles rvalues(numRows); + for (size_t i = 0; i < numRows; i++) { + rvalues[i] = values->at(i); + } + entityList.push_back(rvalues); + break; } - entityList.push_back(rvalues); - break; - } - default: - std::string unknownTypeMsg = "Unknown variable type: " + v.GetName(); - cpp11::message(unknownTypeMsg.c_str()); - break; + default: + std::string unknownTypeMsg = + "Unknown variable type: " + v.GetName(); + cpp11::message(unknownTypeMsg.c_str()); + break; } } catch (const std::exception &e) { std::string errorExportingVariableMsg = @@ -161,4 +162,4 @@ void ListExporter::AddVariableLabels(const Variable &v, resultNames.push_back(tableName); } } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/exporters/RListExporter.hpp b/rpkg/src/redatamlib/exporters/RListExporter.hpp index 400365f..fc54752 100644 --- a/rpkg/src/redatamlib/exporters/RListExporter.hpp +++ b/rpkg/src/redatamlib/exporters/RListExporter.hpp @@ -3,19 +3,24 @@ #include #include -#include + +#include +#include +#include +#include +#include // cpp11::message #include "Entity.hpp" namespace RedatamLib { class ListExporter { -public: + public: ListExporter(const std::string &outputDirectory); void ExportAll(std::vector &entities); cpp11::list ExportAllR(const std::vector &entities) const; -private: + private: std::string m_path; void ListEntity(Entity &entity, cpp11::writable::list &result) const; @@ -28,6 +33,6 @@ class ListExporter { const std::string &entityName); }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // RLISTEXPORTER_HPP +#endif // RLISTEXPORTER_HPP diff --git a/rpkg/src/redatamlib/readers/BitArrayReader.cpp b/rpkg/src/redatamlib/readers/BitArrayReader.cpp index df9e2c8..73c5c3c 100644 --- a/rpkg/src/redatamlib/readers/BitArrayReader.cpp +++ b/rpkg/src/redatamlib/readers/BitArrayReader.cpp @@ -1,12 +1,12 @@ -#include -#include - #include "BitArrayReader.hpp" namespace RedatamLib { BitArrayReader::BitArrayReader(size_t dataSize) - : m_varSize(dataSize), m_remainderSize(0), m_mask(CreateMask(dataSize)), - m_data(0), m_remainder(0) {} + : m_varSize(dataSize), + m_remainderSize(0), + m_mask(CreateMask(dataSize)), + m_data(0), + m_remainder(0) {} std::bitset<32> BitArrayReader::CreateMask(size_t size) { std::bitset<32> mask = 0; @@ -44,4 +44,4 @@ void BitArrayReader::ParseBits(std::vector *results, uint32_t data) { m_remainderSize -= m_varSize; } } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/readers/BitArrayReader.hpp b/rpkg/src/redatamlib/readers/BitArrayReader.hpp index 00a6614..bc2424f 100644 --- a/rpkg/src/redatamlib/readers/BitArrayReader.hpp +++ b/rpkg/src/redatamlib/readers/BitArrayReader.hpp @@ -2,7 +2,7 @@ #define REDATAMLIB_BITARRREADER_HPP #include -#include // uint16_t, uint32_t +#include // uint16_t, uint32_t #include namespace RedatamLib { @@ -10,7 +10,7 @@ using std::bitset; using std::vector; class BitArrayReader { -public: + public: BitArrayReader(size_t dataSize); ~BitArrayReader() = default; @@ -19,7 +19,7 @@ class BitArrayReader { void ParseBits(vector *results, uint32_t data); -private: + private: size_t m_varSize; size_t m_remainderSize; bitset<32> m_mask; @@ -29,6 +29,6 @@ class BitArrayReader { bitset<32> CreateMask(size_t size); }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_BITARRREADER_HPP +#endif // REDATAMLIB_BITARRREADER_HPP diff --git a/rpkg/src/redatamlib/readers/ByteArrayReader.cpp b/rpkg/src/redatamlib/readers/ByteArrayReader.cpp index 2be970f..2a72b5a 100644 --- a/rpkg/src/redatamlib/readers/ByteArrayReader.cpp +++ b/rpkg/src/redatamlib/readers/ByteArrayReader.cpp @@ -1,15 +1,14 @@ -#include // std::transform, std::all_of, std::search -#include // std::isalnum -#include // std::ifstream, std::ios::binary -#include // std::ios_base::failure +#include // std::search +#include // std::ifstream #include // std::ostream_iterator, std::istreambuf_iterator -#include // std::ostringstream +#include // std::ostringstream #include "ByteArrayReader.hpp" #include "utils.hpp" namespace RedatamLib { -ByteArrayReader::ByteArrayReader() : m_data(), m_currPos(0), m_endPos(0) {} + +ByteArrayReader::ByteArrayReader() : m_currPos(0), m_endPos(0) {} ByteArrayReader::ByteArrayReader(const string &filePath) : m_data(), m_currPos(0), m_endPos(0) { @@ -81,8 +80,8 @@ ByteArrayReader::ByteArrayReader(const string &filePath) } } - m_data = vector{std::istreambuf_iterator(fs), - std::istreambuf_iterator()}; + m_data = vector((std::istreambuf_iterator(fs)), + std::istreambuf_iterator()); m_endPos = fs.tellg(); } @@ -109,9 +108,9 @@ bool ByteArrayReader::TryReadStr(string *output, bool filterByContent) { try { uint16_t len = ReadInt16LE(); - ThrowIfBad(0 < len && 128 > len && - m_currPos + len <= m_endPos, - length_error("Error: Invalid string length.")); + ThrowIfBad( + 0 < len && 128 > len && m_currPos + len <= m_endPos, + length_error("Error: Invalid string length.")); *output = ReadString(len); } catch (const std::bad_alloc &e) { @@ -137,13 +136,13 @@ string ByteArrayReader::ReadString(size_t length) { } string ByteArrayReader::GetFormerString() { - size_t offset = 2; // string length is indicated by 2 bytes + size_t offset = 2; // string length is indicated by 2 bytes MovePos(-offset); uint16_t len = ReadInt16LE(); while (len != offset - 2) { ++offset; - MovePos(-3); // string length + 1 to move backwards + MovePos(-3); // string length + 1 to move backwards len = ReadInt16LE(); } @@ -155,7 +154,6 @@ size_t ByteArrayReader::FindNextMatch(const vector &subArr, auto nextPosIt = std::search(m_data.begin() + startPos, m_data.end() - len + 1, subArr.begin(), subArr.end()); - return nextPosIt - m_data.begin(); } @@ -166,6 +164,10 @@ bool ByteArrayReader::IsValidStr(const string &str) { } unsigned char ByteArrayReader::ReadByte() { + if (m_currPos >= m_data.size()) { + throw std::out_of_range("Attempt to read beyond buffer size"); + } + unsigned char ret = m_data[m_currPos]; MovePos(1); @@ -173,8 +175,8 @@ unsigned char ByteArrayReader::ReadByte() { } uint16_t ByteArrayReader::ReadInt16LE() { - return static_cast(ReadByte()) | static_cast(ReadByte()) - << 8; + return static_cast(ReadByte()) | + (static_cast(ReadByte()) << 8); } uint32_t ByteArrayReader::ReadInt32LE() { @@ -183,13 +185,13 @@ uint32_t ByteArrayReader::ReadInt32LE() { } uint16_t ByteArrayReader::ReadInt16BE() { - return static_cast(ReadByte()) << 8 | + return (static_cast(ReadByte()) << 8) | static_cast(ReadByte()); } uint32_t ByteArrayReader::ReadInt32BE() { - return static_cast(ReadInt16BE()) << 16 | + return (static_cast(ReadInt16BE()) << 16) | static_cast(ReadInt16BE()); } -} // namespace RedatamLib +} // namespace RedatamLib diff --git a/rpkg/src/redatamlib/readers/ByteArrayReader.hpp b/rpkg/src/redatamlib/readers/ByteArrayReader.hpp index d7b6287..fd5cad8 100644 --- a/rpkg/src/redatamlib/readers/ByteArrayReader.hpp +++ b/rpkg/src/redatamlib/readers/ByteArrayReader.hpp @@ -1,9 +1,9 @@ #ifndef REDATAMLIB_BYTEARRREADER_HPP #define REDATAMLIB_BYTEARRREADER_HPP -#include // size_t -#include // uint16_t, uint32_t -#include // std::out_of_range, std::length_error +#include // size_t +#include // uint16_t, uint32_t +#include // std::out_of_range, std::length_error #include #include @@ -14,9 +14,9 @@ using std::string; using std::vector; class ByteArrayReader { -public: + public: ByteArrayReader(); - // throws std::ios_base::failure if fails to open file + // throws std::ios_base::failure if fails to open file ByteArrayReader(const string &filePath); ~ByteArrayReader() = default; @@ -24,31 +24,31 @@ class ByteArrayReader { size_t GetPos() const; size_t GetEndPos() const; - // throws std::out_of_range + // throws std::out_of_range void SetPos(int newPos); void MovePos(int bytes); void MovePosTo(const string &subArr); - // str's length is between 0 and 128 bytes - // filterByContent checks if output is an alpha-numeric string (including - // whitespaces) + // str's length is between 0 and 128 bytes + // filterByContent checks if output is an alpha-numeric string (including + // whitespaces) bool TryReadStr(string *output, bool filterByContent = true); - // throws std::out_of_range + // throws std::out_of_range string ReadString(size_t length); - // throws std::out_of_range if there isn't such string - // used to find variable names + // throws std::out_of_range if there isn't such string + // used to find variable names string GetFormerString(); - // throws std::out_of_range; LE = little-endian, BE = big-endian + // throws std::out_of_range; LE = little-endian, BE = big-endian unsigned char ReadByte(); uint16_t ReadInt16LE(); uint32_t ReadInt32LE(); uint16_t ReadInt16BE(); uint32_t ReadInt32BE(); -private: + private: vector m_data; size_t m_currPos; size_t m_endPos; @@ -58,6 +58,6 @@ class ByteArrayReader { bool IsValidStr(const string &str); }; -} // namespace RedatamLib +} // namespace RedatamLib -#endif // REDATAMLIB_BYTEARRREADER_HPP +#endif // REDATAMLIB_BYTEARRREADER_HPP diff --git a/rpkg/src/redatamlib/readers/FuzzyVariableParser.cpp b/rpkg/src/redatamlib/readers/FuzzyVariableParser.cpp index 850cd53..edb9447 100644 --- a/rpkg/src/redatamlib/readers/FuzzyVariableParser.cpp +++ b/rpkg/src/redatamlib/readers/FuzzyVariableParser.cpp @@ -1,7 +1,8 @@ #include // std::replace #include // std::regex, std::smatch, std::regex_search #include -#include // cpp11::stop + +#include // cpp11::stop #include "FuzzyVariableParser.hpp" #include "utils.hpp" // GetFileExtension, ThrowIfBad diff --git a/rpkg/src/redatamlib/readers/XMLParser.cpp b/rpkg/src/redatamlib/readers/XMLParser.cpp index 1f1195a..02c0121 100644 --- a/rpkg/src/redatamlib/readers/XMLParser.cpp +++ b/rpkg/src/redatamlib/readers/XMLParser.cpp @@ -1,6 +1,7 @@ #include // std::replace #include // std::ifstream -#include // replace std::cerr + +#include // cpp11::message #include "XMLParser.hpp" #include "utils.hpp" diff --git a/rpkg/src/redatamlib/utils.cpp b/rpkg/src/redatamlib/utils.cpp index 1885166..8585061 100644 --- a/rpkg/src/redatamlib/utils.cpp +++ b/rpkg/src/redatamlib/utils.cpp @@ -90,12 +90,11 @@ bool TryGetFileExtension(const string &fileName, string *output) { string GetFileExtension(const string &fileName) { size_t extPos = fileName.find_last_of('.'); ThrowIfBad( - extPos != string::npos, - invalid_argument("Error: No file extension found.")); + extPos != string::npos, + "Error: No file extension found."); string ext = fileName.substr(extPos); - std::transform(ext.begin(), ext.end(), ext.begin(), - [](unsigned char c) { return std::tolower(c); }); + transform(ext.begin(), ext.end(), ext.begin(), ::tolower); return ext; } diff --git a/rpkg/src/redatamlib/utils.hpp b/rpkg/src/redatamlib/utils.hpp index c15cb30..3d02e8c 100644 --- a/rpkg/src/redatamlib/utils.hpp +++ b/rpkg/src/redatamlib/utils.hpp @@ -17,8 +17,8 @@ string GetFileExtension(const string &fileName); bool TryGetFileExtension(const string &fileName, string *output); -template -void ThrowIfBad(bool is_good_, std::error_code err_, const string &e_msg_) { +template void ThrowIfBad(bool is_good_, std::error_code err_, + const string &e_msg_) { if (!is_good_) { throw E(err_, e_msg_); } @@ -27,7 +27,7 @@ void ThrowIfBad(bool is_good_, std::error_code err_, const string &e_msg_) { template void ThrowIfBad(bool is_good_, int errno_) { if (!is_good_) { throw E(std::error_code(errno_, std::generic_category()), - string(std::strerror(errno_))); + std::strerror(errno_)); } } @@ -37,6 +37,13 @@ template void ThrowIfBad(bool is_good_, const E &e_) { } } +template +void ThrowIfBad(bool is_good_, const std::string &e_msg_) { + if (!is_good_) { + throw E(e_msg_); + } +} + } // namespace RedatamLib #endif // REDATAMLIB_UTILS_HPP diff --git a/rpkg/src/vendor/pugixml.cpp b/rpkg/src/vendor/pugixml.cpp index b312b5b..96ce66a 100644 --- a/rpkg/src/vendor/pugixml.cpp +++ b/rpkg/src/vendor/pugixml.cpp @@ -54,11 +54,11 @@ #pragma warning(disable : 4996) // this function or variable may be unsafe #endif -#if defined(_MSC_VER) && defined(__c2__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored \ - "-Wdeprecated" // this function or variable may be unsafe -#endif +// commented to avoid R CMD check warning +// #if defined(_MSC_VER) && defined(__c2__) +// #pragma clang diagnostic push +// #pragma clang diagnostic ignored "-Wdeprecated" // this function or variable may be unsafe +// #endif #ifdef __INTEL_COMPILER #pragma warning(disable : 177) // function was declared but never referenced