diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index 6f987cf69..f57079935 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -2,7 +2,10 @@ name: Continuous Integration # This workflow is triggered on pushes and pull requests to the repository. +# This workflow will also run each Monday on the default branch (i.e. master) on: + schedule: + - cron: '0 0 * * 1' push: branches: '**' pull_request: @@ -14,10 +17,16 @@ jobs: strategy: matrix: os: [ ubuntu-18.04, macos-10.15 ] - cxx: [ g++-9, clang++ ] + cxx: [ clang++, g++-9 ] build_type: [ Debug, Release ] steps: + - name: Install hdf5 libraries for Linux + if: matrix.os == 'ubuntu-18.04' + run: sudo apt-get install libhdf5-dev + - name: Install hdf5 libraries for MacOS + if: matrix.os == 'macos-10.15' + run: brew install hdf5 - name: which CXX run: | which ${{matrix.cxx}} diff --git a/.gitignore b/.gitignore index 9fdab1763..66939940f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build *~ metaconfigure/*.pyc docs/.build +debug +minsizerel +release diff --git a/CMakeLists.txt b/CMakeLists.txt index a33c52da1..989ccbd93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,54 +37,327 @@ include_directories( src/ ) add_library( GNDStk INTERFACE ) target_include_directories( GNDStk INTERFACE src/ ) -target_link_libraries( GNDStk +target_link_libraries( + GNDStk INTERFACE Log INTERFACE catch-adapter INTERFACE pugixml-adapter INTERFACE nlohmann_json::nlohmann_json + INTERFACE HighFive ) -add_executable( json2class.exe +add_executable( + json2class.exe EXCLUDE_FROM_ALL autogen/json2class.cpp ) -target_link_libraries( json2class.exe +target_link_libraries( + json2class.exe PRIVATE GNDStk PRIVATE nlohmann_json::nlohmann_json ) +set_target_properties( pugixml-adapter PROPERTIES POSITION_INDEPENDENT_CODE ON) + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # GNDStk : python bindings # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -include_directories( python/src/ ) +include_directories( + python/src/ + autogen/prototype/proto/src/ + standards/gnds-2.0-alpha/alpha/src + ) -pybind11_add_module( GNDStk.python +pybind11_add_module( + GNDStk.python EXCLUDE_FROM_ALL python/src/GNDStk.python.cpp + python/src/v2.0/GNDS.python.cpp python/src/core/Node.python.cpp - python/src/Interpolation.python.cpp + python/src/BoundaryCondition.python.cpp + python/src/ContributorType.python.cpp + python/src/DateType.python.cpp + python/src/DecayType.python.cpp + python/src/Frame.python.cpp python/src/GridStyle.python.cpp - python/src/v1.9/containers.python.cpp - python/src/v1.9/containers/Axis.python.cpp - python/src/v1.9/containers/Values.python.cpp - python/src/v1.9/containers/Link.python.cpp - python/src/v1.9/containers/Grid.python.cpp - python/src/v1.9/containers/Axes.python.cpp - python/src/v1.9/containers/XYs1d.python.cpp - python/src/v1.9/containers/Regions1d.python.cpp - python/src/v1.9/transport/CrossSection.python.cpp - python/src/v1.9/transport/Reaction.python.cpp - python/src/v1.9/transport/Reactions.python.cpp - python/src/v1.9/transport/ReactionSuite.python.cpp - python/src/v1.9/transport.python.cpp - python/src/v1.9/GNDS.python.cpp + python/src/HashAlgorithm.python.cpp + python/src/Interaction.python.cpp + python/src/Interpolation.python.cpp + python/src/InterpolationQualifier.python.cpp + python/src/Parity.python.cpp + python/src/RelationType.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g3d/Starts.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g3d/Lengths.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g3d/Array.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/SelfScatteringKernel.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Sums.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Values.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NuclearTerm.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ImaginaryAnomalousFactor.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/BoundAtomCrossSection.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Isotopes.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Standard.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Unresolved.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ThermalNeutronScatteringLaw_incoherentInelastic.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DecayMode.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/InternalConversionCoefficients.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Temperature.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Polynomial1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Product.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NuclearPlusInterference.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Branching1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FreeGasApproximation.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Isotope.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/MultiplicitySums.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ScatteringAtom.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Nuclide.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AverageEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PrimaryGamma.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Spectrum.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/OrphanProduct.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DelayedNeutronKE.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Time.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/IncidentEnergies.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Distribution.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Gridded3d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ThermalNeutronScatteringLaw1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AverageProductEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Q.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AngularTwoBody.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/R.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DecayPath.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Summand.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Title.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Continuum.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ResonanceReactions.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/G.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/EnergyAngular.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Institution.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/String.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Width.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CrossSectionSum.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ScatteringRadius.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Table.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Nuclides.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NuclearAmplitudeExpansion.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/GaugeBoson.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Spectra.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ProductYields.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Theta.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/LevelSpacing.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/J.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PromptProductKE.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Widths.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/MultiplicitySum.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Parameters.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Grid.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Add.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Slice.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ProductYield.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/MadlandNix.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/BindingEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DebyeWallerIntegral.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CovarianceSections.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Link.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AverageParameterCovariance.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Energy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Body.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Alias.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Uncertainty.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Reactions.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/XYs1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Configurations.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Weighted.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Resolved.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FissionEnergyReleases.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Baryon.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/IncoherentPhotonScattering.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ENDFconversionFlags.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FissionComponent.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ScatteringAtoms.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Configuration.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PromptGammaEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/E_max.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/IncompleteReactions.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CrossSectionReconstructed.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Productions.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Charge.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PhotonEmissionProbabilities.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Probability.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FissionComponents.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/XYs3d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/SpinGroups.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/T_M.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/SpinGroup.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DiscreteGamma.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Production.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CoulombPlusNuclearElastic.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ChemicalElements.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Unorthodox.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FormFactor.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/S_table.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/SimpleMaxwellianFission.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AverageEnergies.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Shell.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/RealAnomalousFactor.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CoherentPhotonScattering.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Background.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DecayData.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/KalbachMann.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DelayedBetaEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Lepton.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Dates.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DoubleDifferentialCrossSection.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Authors.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ElapsedTimes.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ScatteringFactor.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Ls.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/RutherfordScattering.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Fraction.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NBodyPhaseSpace.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ExternalFiles.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Conversion.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ParameterCovarianceMatrix.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/RMatrix.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/EFH.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ParameterLink.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ChemicalElement.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Constant1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Baryons.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ParameterCovariance.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/IncidentEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NonNeutrinoEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FastRegion.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Halflife.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Angular.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ProjectileEnergyDomain.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ExternalFile.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ResonanceReaction.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Data.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ApplicationData.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PromptNeutronKE.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/HardSphereRadius.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Reference.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Nucleus.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Function2ds.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Unspecified.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ShortRangeSelfScalingVariance.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Spin.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Leptons.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Author.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CovarianceSection.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/FissionEnergyRelease.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Channels.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Unorthodoxes.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Gridded2d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/OrphanProducts.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DelayedNeutron.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Slices.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ListOfCovariances.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Decay.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Axes.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Covariance.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Mass.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ThermalNeutronScatteringLaw_incoherentElastic.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/AngularEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/SCTApproximation.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DelayedNeutrons.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Multiplicity.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/WeightedFunctionals.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/EFL.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Column.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Integer.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DecayModes.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/XYs2d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Branching3d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ResonanceParameters.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ResolvedRegion.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/UnresolvedRegion.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/RealInterferenceTerm.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Intensity.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Discrete.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/TotalEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ParameterCovariances.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Regions1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/DelayedGammaEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/NeutrinoEnergy.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ColumnData.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ElapsedTime.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ColumnHeaders.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/PositronEmissionIntensity.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Recoil.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Evaluated.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Atomic.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CrossSectionSums.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Resonances.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CrossSection.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/BreitWigner.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Date.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Uncorrelated.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ThermalNeutronScatteringLaw_coherentElastic.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Isotropic2d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/L.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Products.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/F.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Legendre.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/U.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Mixed.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/E_critical.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/T_effective.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Channel.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Parity.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Sum.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Double.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Summands.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/GeneralEvaporation.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/TabulatedWidths.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Evaporation.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Yields.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Regions2d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ImaginaryInterferenceTerm.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/OutputChannel.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Js.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/EndfCompatible.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Reaction.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Documentation.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/MetaStable.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Rate.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/CovarianceMatrix.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Styles.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Array.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ThermalNeutronScatteringLaw.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Axis.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Aliases.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/RowData.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/Function1ds.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/GaugeBosons.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general/ResonancesWithBackground.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Polynomial1d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Product.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Distribution.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Nuclides.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/CrossSection.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Products.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Double.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/OutputChannel.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced/Function1ds.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g2d/Array.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/top/FissionFragmentData.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/top/ReactionSuite.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/top/PoPs.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/top/CovarianceSuite.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g3d.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/general.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/top.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/reduced.python.cpp + standards/gnds-2.0-alpha/alpha/python/src/v2.0/g2d.python.cpp ) + target_link_libraries( GNDStk.python PRIVATE GNDStk ) -target_compile_options( GNDStk.python PRIVATE "-fvisibility=hidden" ) +target_compile_options(GNDStk.python PRIVATE "-fvisibility=hidden" ) set_target_properties( GNDStk.python PROPERTIES OUTPUT_NAME GNDStk ) set_target_properties( GNDStk.python PROPERTIES COMPILE_DEFINITIONS "PYBIND11" ) -set_target_properties( pugixml-adapter PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties( GNDStk.python PROPERTIES POSITION_INDEPENDENT_CODE ON) ####################################################################### @@ -92,10 +365,8 @@ set_target_properties( GNDStk.python PROPERTIES POSITION_INDEPENDENT_CODE ON) ####################################################################### if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) - # unit testing if( GNDStk_unit_tests ) include( cmake/unit_testing.cmake ) endif() - endif() diff --git a/README.md b/README.md index a8734aac2..0d05e30ed 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ +![Continuous Integration](https://github.com/njoy/GNDStk/workflows/Continuous%20Integration/badge.svg) + # GNDStk -Generalized Nuclear Database Structure toolkit +Toolkit for reading and interacting with GNDS formatted files. This toolkit provides a full C++ library along with python bindings. ## LICENSE This software is copyrighted by Los Alamos National Laboratory and distributed according to the conditions in the accompanying [LICENSE](LICENSE) file. diff --git a/autogen/.gitignore b/autogen/.gitignore deleted file mode 100644 index 321656c44..000000000 --- a/autogen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -json2class.exe diff --git a/autogen/changes.json b/autogen/changes.json index 87832d157..a895b0e3a 100644 --- a/autogen/changes.json +++ b/autogen/changes.json @@ -11,7 +11,6 @@ "metadata": { "type": { "Boolean": "bool", - "string": "std::string", "encoding": "enums::Encoding", "frame": "enums::Frame", "interaction": "enums::Interaction", @@ -40,7 +39,7 @@ "nuclear": "enums::Interaction::nuclear", "atomic": "enums::Interaction::atomic", "thermalNeutronScatteringLaw": - "enums::Interaction::thermalNeutronScatteringLaw", + "enums::Interaction::thermalNeutronScatteringLaw", "// INTERPOLATION": {}, "flat": "enums::Interpolation::flat", diff --git a/autogen/json2class.cpp b/autogen/json2class.cpp index ff4a91686..2988b7286 100644 --- a/autogen/json2class.cpp +++ b/autogen/json2class.cpp @@ -4,13 +4,30 @@ // ----------------------------------------------------------------------------- #include "GNDStk.hpp" -#include "cstring" -using namespace njoy::GNDStk::core; +#include +using namespace njoy::GNDStk; // Report cases of nodes that have no metadata, and zero or one child node(s). // Where these exist, a simplification of the spec may be worth considering. const bool singletons = true; +// Extra debug/informational printing? +const bool debugging = false; + +// Put print statements in constructor and assignment calls. For debugging. +const bool printCtorCalls = false; + +// Optional type to use +#define OPTIONAL "std::optional" +//#define OPTIONAL "GNDStk::Optional" + +// Shortcut levels to utilize +// 0 = all +// 1 = none (child nodes are already there, by definition) +// 2 = to grandchildren +// 3 = to great-grandchildren +// ... +const int ShortcutLevels = 3; // ----------------------------------------------------------------------------- @@ -18,11 +35,9 @@ const bool singletons = true; // ----------------------------------------------------------------------------- // KeyValue -// Too bad the JSON library doesn't provide this more straightforwardly +// Too bad the JSON library doesn't provide this directly using KeyValue = nlohmann::detail::iteration_proxy_value< - nlohmann::detail::iter_impl< - const nlohmann::basic_json<> - > + nlohmann::detail::iter_impl >; // NamespaceAndClass @@ -57,17 +72,19 @@ struct Class2Dependencies { // InfoMetadata struct InfoMetadata { - // A .json spec can make a metadatum be: - // - a std::optional, or - // - a GNDStk::defaulted + // A JSON spec can make a metadatum be: + // - an optional, or + // - a Defaulted // but (in contrast with child nodes) can't make it be a vector of metadata. // An individual metadatum may be a vector in its own right, as in an XML - // construct such as (so that meta is a vector of + // construct such as (so that meta is a vector of // integers). We mean here that there isn't a vector of such [meta] entries, - // and shouldn't be (XML wouldn't allow it). + // and there shouldn't be (XML wouldn't allow it). + std::string original; // without e.g. the "double" to "Double" change std::string name; + std::string converter;// converter: callable w/operator() string to/from type std::string type; // underlying type - std::string typeFull; // WITH any optional<> or defaulted<> + std::string typeFull; // WITH any optional<> or Defaulted<> bool isOptional; bool isDefaulted; std::string defaultValue; @@ -75,13 +92,19 @@ struct InfoMetadata { // InfoChildren struct InfoChildren { - // A .json spec can make a child node be: - // - a std::optional, and/or - // - a std::vector - // but can't make it be a GNDStk::defaulted. (The use of a default value for + // A JSON spec can make a child node be: + // - an optional, and/or + // - a vector + // but can't make it be a GNDStk::Defaulted. (The use of a default value for // child nodes just doesn't exist in the GNDS specifications, even though the // concept would seem to make sense.) + std::string original; // without e.g. the "double" to "Double" change std::string name; + std::string converter;// converter: callable w/operator() Node to/from type + std::string filter; // filter: bool callable(const Node &) + std::string label; // filter: allow for node lookup by "label" metadatum + std::string ns; // enclosing namespace + std::string plain; // underlying type, excluding namespace std::string type; // underlying type std::string typeFull; // WITH any optional<> or vector<> std::string typeHalf; // withOUT any vector<> @@ -92,7 +115,9 @@ struct InfoChildren { // InfoVariantsChildren struct InfoVariantsChildren { std::string name; - std::string type; + std::string ns; // enclosing namespace + std::string plain; // underlying type, excluding namespace + std::string type; // underlying type bool isVector; }; @@ -116,6 +141,8 @@ struct PerNamespace { struct PerClass { std::string cppPython; // cpp file for this class' Python interface std::string hppGNDStk; // hpp file for this class in GNDStk + std::string headerC; // header that works with both C and C++ + std::string sourceC; // C++ backend source for the C interface std::string nsname; // name of this class' namespace std::string clname; // name of this class @@ -138,17 +165,24 @@ struct PerClass { { return metadata.size() + children.size() + variants.size(); } // Data node? - // If (and only if) isData, dataType is considered. If dataType == "", this - // is the situation in GNDS in which the type of data residing in a node is - // to be determined dynamically, via a string metadatum called valueType. If - // dataType != "" (for example, dataType == "int" or dataType == "double"), - // then dataType is considered to stipulate the given type. - bool isData; - std::string dataType; + // If (and only if) isDataVector, elementType is considered. If it's "", then + // this is the situation in GNDS in which the type of data residing in a node + // is to be determined dynamically, via a string metadatum called valueType. + // If elementType != "" (for example, elementType == "int" or "double"), then + // elementType stipulates the wanted type. + bool isDataString; // Example: This is a free-form text string + bool isDataVector; // Example: 1.2 3.45 6.789 + std::string elementType; + // isDataNode: for convenience: either isDataString; or, isDataVector AND + // per.elementType is NOT "" (so that we use DataNode instead of BlockData) + bool isDataNode; + bool cdata; // prefer "cdata" over plain data? + + // For shortcuts from objects of this class + std::multimap> name2path; }; - // ----------------------------------------------------------------------------- // InfoSpecs // ----------------------------------------------------------------------------- @@ -156,26 +190,32 @@ struct PerClass { // Overarching data structure reflecting all of the autogenerator's input // as well as various processed information struct InfoSpecs { - // From the .json file on the command line + // From the JSON file on the command line + std::string Path; + std::string Project; std::string JSONDir; - std::vector JSONFiles; - std::string GNDSDir; std::string Version; + std::vector JSONFiles; - // Version, but with '_' in place of '.' + // Version, but with '_'s in place of '.'s std::string VersionUnderscore; // Directory-prefixed names std::string hppVersion; // hpp file for this version - std::string hppKey; // hpp file for this version's Meta<>/Child<> keys + std::string hppKey; // hpp file for this version's Meta and Child keys + std::string hVersion; // header file for both C and C++ + std::string cVersion; // C++ backend source for the C interface - // Changes to apply to a metadatum's or child node's name. - // Example: "double" (GNDS v1.9 does have this) to "Double" for C++. + // Changes to apply to a metadatum's name or a child node's name. + // Example: "double" (GNDS v1.9 actually has "double") to "Double" for C++. std::map mapName; - // Changes to apply to metadata/attribute type and default. + // Changes to apply to metadata/attribute type. // Examples: "Boolean" to "bool", "interpolation" to "enums::Interpolation". - std::map mapMetaType; + // We'll give a string ==> std::string type change as a freebie. :-) + std::map mapMetaType = {{"string","std::string"}}; + + // Changes to apply to metadata/attribute default. std::map mapMetaDefault; // For each class in the input JSON specifications, the namespace(s) @@ -194,21 +234,54 @@ struct InfoSpecs { std::map namespace2data; // Map from namespace::class to information about the class - std::map class2data; -}; - + static inline const auto compare = + [](const auto &a, const auto &b) + { + // In the event that we display entries in the map, we prefer putting + // everything in alphabetical order based primarily on the class name, + // with namespace only a secondary consideration. Someone looking for + // a class need only consider its name, and not initially worry about + // what namespace it's in. + return + a.clname < b.clname || ( + a.clname == b.clname && + a.nsname < b.nsname); + }; + std::map class2data{compare}; +}; // InfoSpecs // ----------------------------------------------------------------------------- // Miscellaneous short functions // ----------------------------------------------------------------------------- +void action_helper(const std::string &str) +{ + static const int ncol = 80; + static const int last = ncol-1; + + for (int col = 0; col < ncol; ++col) { + int r = 255*(last-col)/last; + int g = 255 - std::abs(255*(last-col-col)/last); + int b = 255*col/last; + std::cout << "\033[48;2;" << r << ";" << g << ";" << b << "m" + << "\033[38;2;255;255;255m" + << (col < str.size() ? str[col] : ' '); + } + std::cout << color::reset << std::endl; +} + // Print text describing an action the code is about to take -void action(const std::string &str) +template +void action(const ARGS &...args) { - std::cout - << "\n" - << colors::plain::blue << str << "..." << colors::reset << std::endl; + static const std::string inverse = "\033[7m"; + static const std::string background(80,' '); + std::cout << '\n'; + action_helper(""); + (action_helper(args), ...); + action_helper(""); + std::cout << color::reset << std::endl; } // Is the string all whitespace? @@ -274,6 +347,19 @@ std::string allcaps(const std::string &str) return ret; } +// UpperCamel +std::string UpperCamel(const std::string &str) +{ + std::string ret; + for (size_t i = 0; i < str.size(); ++i) + if (str[i] != '_') + ret += i ? str[i] : toupper(str[i]); + else if (++i < str.size()) + ret += toupper(str[i]); + return ret; +} + + // Replace character std::string replace(const std::string &str, const char from, const char to) { @@ -286,10 +372,10 @@ std::string replace(const std::string &str, const char from, const char to) // Stringify JSON // See: https://github.com/nlohmann/json/issues/642 -std::string stringify(const nlohmann::json &j) +std::string stringify(const orderedJSON &j) { const auto tmp = j.dump(); - return j.type() == nlohmann::json::value_t::string + return j.type() == orderedJSON::value_t::string ? tmp.substr(1, tmp.size()-2) : tmp; } @@ -322,6 +408,33 @@ bool isClass(const KeyValue &keyval) return true; } +// getTimes +std::string getTimes( + const PerClass &per, const std::string &key, const orderedJSON &value +) { + const std::string times = "times"; // shorter, less easily misspelled + const std::string occurrence = "occurrence"; // accept; used in GNDS specs + + // need exactly one - not neither, not both + if (value.contains(times) == value.contains(occurrence)) { + log::error( + "In namespace \"{}\", class \"{}\":\n" + "Child node \"{}\" needs exactly one of \"times\" or \"occurrence\".\n" + "Or, did you possibly intend \"{}\" to be an attribute/metadatum?", + per.nsname, per.clname, key, key); + throw std::exception{}; + } + + return value.contains(times) + ? value[times] + : value[occurrence]; +} + +// sep +std::string sep(int &count, const int total) +{ + return ++count < total ? "," : ""; +} // ----------------------------------------------------------------------------- @@ -329,11 +442,28 @@ bool isClass(const KeyValue &keyval) // ----------------------------------------------------------------------------- // nameGNDS -// Name in GNDS (e.g., name of an XML element) -std::string nameGNDS(const KeyValue &keyval) -{ - // As-is, directly as stipulated in a key in the JSON spec, except - // that we allow a "name" entry to override the key. +// Name in a GNDS file (e.g., name of an XML element) +std::string nameGNDS( + const KeyValue &keyval, + const std::string &nsname = "", + const bool print = false +) { + // For debugging + if (debugging && print) { + const std::string key = keyval.key(); + const std::string name = keyval.value().contains("name") + ? std::string(keyval.value()["name"]) + : key; + std::cout + << "class: " + << std::setw(20) << std::left << nsname << " " + << std::setw(48) << std::left << key << " " + << (key == name ? " " : "*") << " " + << std::left << name << std::endl; + } + + // As-is, directly as stipulated in the key in the JSON spec, except + // that we allow a "name" entry in the key's value to override the key. return keyval.value().contains("name") ? std::string(keyval.value()["name"]) : keyval.key(); @@ -343,10 +473,11 @@ std::string nameGNDS(const KeyValue &keyval) // Name of a field (metadatum or child node) in an autogenerated class std::string nameField(const KeyValue &keyval, const InfoSpecs &specs) { - // Like nameGNDS, except that we apply any name-modification map that - // may have been provided. That can fix, for example, the name "double", - // which appears in GNDS v1.9 but is unsuitable for a name in C++. - const std::string name = nameGNDS(keyval); + const std::string name = keyval.key(); + // Here, we apply any name-modification map that may have been provided + // in a "changes" file. Such changes can fix, for example, the name "double" + // that appears in some GNDS specs as a JSON key, given that "double" is + // unsuitable for use as a variable name in C++. const auto it = specs.mapName.find(name); return it == specs.mapName.end() ? name : it->second; } @@ -355,8 +486,11 @@ std::string nameField(const KeyValue &keyval, const InfoSpecs &specs) // Name of an autogenerated class std::string nameClass(const KeyValue &keyval, const InfoSpecs &specs) { - // Like nameField, but capitalized (per our class naming convention). - return capital(nameField(keyval,specs)); + // Capitalized version of either the JSON key, or, if applicable, + // its change under the name-modification map in a "changes" file. + const std::string name = keyval.key(); + const auto it = specs.mapName.find(name); + return capital(it == specs.mapName.end() ? name : it->second); } // namePython @@ -376,13 +510,12 @@ std::string namePython(const std::string &name) } - // ----------------------------------------------------------------------------- // Functions for getting certain information from JSON input // ----------------------------------------------------------------------------- // Get the JSON's "namespace" -std::string getFileNamespace(const nlohmann::json &j) +std::string getFileNamespace(const orderedJSON &j) { return j.contains("__namespace__") ? j["__namespace__"] @@ -390,7 +523,7 @@ std::string getFileNamespace(const nlohmann::json &j) } // Get the JSON's "type", with any relevant specs.mapMetaType entry applied -std::string getMetadatumType(const nlohmann::json &j, const InfoSpecs &specs) +std::string getMetadatumType(const orderedJSON &j, const InfoSpecs &specs) { const std::string type = j["type"]; const auto it = specs.mapMetaType.find(type); @@ -400,9 +533,9 @@ std::string getMetadatumType(const nlohmann::json &j, const InfoSpecs &specs) // Determine to what namespace childClass belongs. Context: we're (1) in a JSON // spec with namespace parent.nsname, (2) in a parent node named parent.clname, // and (3) wish to determine the proper namespace for the parent's child node -// named "child". Parameter j is the JSON value ({...}) for this child node. +// named childClass. Parameter j is the JSON value ({...}) for this child node. std::string getChildNamespace( - const nlohmann::json &j, const InfoSpecs &specs, + const orderedJSON &j, const InfoSpecs &specs, const PerClass &per, const std::string &childClass ) { // childClass' namespace... @@ -414,7 +547,7 @@ std::string getChildNamespace( // ...isn't given, and this child isn't in any of the JSONs :-( if (specs.class2nspace.count(childClass) == 0) { log::warning( - "{}::{} has child of unknown class {}", + "{}::{} has a child of unknown class {}", per.nsname, per.clname, childClass ); return "unknownNamespace"; @@ -429,7 +562,13 @@ std::string getChildNamespace( const auto range = specs.class2nspace.equal_range(childClass); for (auto it = range.first; it != range.second; ++it) if (it->second == per.nsname) { - // fixme: a *warning* might be in order, re: our assumption + log::warning( + "{}::{} has a child {} that appears in the present\n" + "namespace but also in one or more other namespaces. We'll\n" + "assume that the one in the present namespace is intended.\n" + "If this is wrong, please provide a \"namespace\" entry.", + per.nsname, per.clname, childClass + ); return per.nsname; } @@ -440,7 +579,7 @@ std::string getChildNamespace( for (auto it = range.first; it != range.second; ++it) warn << (count++ == 0 ? "" : ", ") << it->second; log::warning( - "{}::{} has child of ambiguous class {}.\n" + "{}::{} has a child of ambiguous class {}.\n" "Child class {} appears in all of the following namespaces:\n{}", per.nsname, per.clname, childClass, childClass, warn.str() ); @@ -449,22 +588,28 @@ std::string getChildNamespace( } - // ----------------------------------------------------------------------------- // getClass* functions re: metadata, children, variant children // ----------------------------------------------------------------------------- // getClassMetadata void getClassMetadata( - const nlohmann::json &j, const InfoSpecs &specs, PerClass &per + const orderedJSON &j, const InfoSpecs &specs, + PerClass &per ) { for (const auto &field : j.items()) { + if (beginsin(field.key(), "//")) + continue; const auto &metaRHS = field.value(); // Name InfoMetadata m; + m.original = nameGNDS(field); m.name = nameField(field,specs); + // Converter, if given + m.converter = metaRHS.contains("converter") ? metaRHS["converter"] : ""; + // Type m.type = getMetadatumType(metaRHS,specs); @@ -472,18 +617,27 @@ void getClassMetadata( m.defaultValue = ""; if (metaRHS.contains("default") && !metaRHS["default"].is_null()) { m.defaultValue = stringify(metaRHS["default"]); + // Apply the "changes.json" change, if any, to the given value const auto it = specs.mapMetaDefault.find(m.defaultValue); if (it != specs.mapMetaDefault.end()) m.defaultValue = it->second; }; if (m.defaultValue != "") { // If it has a default, then presumably it isn't required... - assert(!metaRHS["required"]); + if (metaRHS["required"]) { + log::error( + "In namespace \"{}\", class \"{}\",\n" + "metadatum \"{}\" has a default ({}), but is required.\n" + "If it really is required, then it shouldn't have a default.\n" + "If it really has a default, then presumably it isn't required.", + per.nsname, per.clname, m.name, m.defaultValue); + throw std::exception{}; + } } // Optional? (not required, and has no default) m.isOptional = !metaRHS["required"] && m.defaultValue == ""; - const std::string optPrefix = m.isOptional ? "std::optional<" : ""; + const std::string optPrefix = m.isOptional ? OPTIONAL "<" : ""; const std::string optSuffix = m.isOptional ? ">" : ""; // Defaulted? (not required, but does have a default) @@ -491,7 +645,7 @@ void getClassMetadata( const std::string defPrefix = m.isDefaulted ? "Defaulted<" : ""; const std::string defSuffix = m.isDefaulted ? ">" : ""; - // Full type, including any optional or defaulted + // Full type, including any optional<> or Defaulted<> m.typeFull = optPrefix + defPrefix + m.type + @@ -505,37 +659,47 @@ void getClassMetadata( // getClassChildren void getClassChildren( - const nlohmann::json &j, const InfoSpecs &specs, + const orderedJSON &j, const InfoSpecs &specs, PerClass &per, Class2Dependencies &dep ) { for (const auto &field : j.items()) { + if (beginsin(field.key(), "//")) + continue; const auto &elemRHS = field.value(); // Choice children are handled elsewhere - const std::string occ = elemRHS["occurrence"]; - if (occ == "choice" || occ == "choice+" || occ == "choice2+") + const std::string times = getTimes(per, field.key(), elemRHS); + if (times == "choice" || times == "choice+" || times == "choice2+") continue; // Name InfoChildren c; + c.original = nameGNDS(field); c.name = nameField(field,specs); + // Converter, Filter, and Label, if given + c.converter = elemRHS.contains("converter") ? elemRHS["converter"] : ""; + c.filter = elemRHS.contains("filter") ? elemRHS["filter"] : ""; + c.label = elemRHS.contains("label") ? elemRHS["label"] : ""; + + // Type, excluding namespace + c.plain = nameClass(field,specs); + // Type, including namespace - c.type = nameClass(field,specs); - const std::string ns = getChildNamespace(elemRHS, specs, per, c.type); - c.type = ns + "::" + c.type; + c.ns = getChildNamespace(elemRHS, specs, per, c.plain); + c.type = c.ns + "::" + c.plain; // Optional? c.isOptional = !elemRHS["required"]; - const std::string optPrefix = c.isOptional ? "std::optional<" : ""; + const std::string optPrefix = c.isOptional ? OPTIONAL "<" : ""; const std::string optSuffix = c.isOptional ? ">" : ""; // Vector? - c.isVector = occ == "0+" || occ == "1+" || occ == "2+"; + c.isVector = times == "0+" || times == "1+" || times == "2+"; const std::string vecPrefix = c.isVector ? "std::vector<" : ""; const std::string vecSuffix = c.isVector ? ">" : ""; - // Full type, including any optional or vector + // Full type, including any optional<> or vector<> // If both, use optional; the reverse makes less sense c.typeFull = optPrefix + vecPrefix + @@ -553,7 +717,7 @@ void getClassChildren( // Save as a dependency (if it's not its own dependency) if (c.type != per.name()) dep.dependencies.push_back( - NamespaceAndClass(ns,nameClass(field,specs))); + NamespaceAndClass(c.ns,nameClass(field,specs))); // Add to per.children per.children.push_back(c); @@ -563,7 +727,7 @@ void getClassChildren( // getClassVariants void getClassVariants( - const nlohmann::json &j, const InfoSpecs &specs, + const orderedJSON &j, const InfoSpecs &specs, PerClass &per, Class2Dependencies &dep ) { // Initialize per.variants, a vector that has the "choice" @@ -585,10 +749,13 @@ void getClassVariants( // Collect "variant" names, and if ever it's absent, a to-be-determined // name for all choice children for which it's absent for (const auto &field : j.items()) { + if (beginsin(field.key(), "//")) + continue; + // Is it a choice child? const auto &elemRHS = field.value(); - const std::string occ = elemRHS["occurrence"]; - if (occ != "choice" && occ != "choice+" && occ != "choice2+") + const std::string times = getTimes(per,field.key(),elemRHS); + if (times != "choice" && times != "choice+" && times != "choice2+") continue; // Variant name @@ -600,29 +767,33 @@ void getClassVariants( // Pass 2 for (const auto &field : j.items()) { + if (beginsin(field.key(), "//")) + continue; + // Is it a choice child? const auto &elemRHS = field.value(); - const std::string occ = elemRHS["occurrence"]; - if (occ != "choice" && occ != "choice+" && occ != "choice2+") + const std::string times = getTimes(per,field.key(),elemRHS); + if (times != "choice" && times != "choice+" && times != "choice2+") continue; // Variant name - const std::string variant = elemRHS.contains("variant") + const std::string variantName = elemRHS.contains("variant") ? elemRHS["variant"] : ""; - auto it = map.find(variant); + auto it = map.find(variantName); assert(it != map.end()); // should be there from the earlier loop // For the individual child that's part of a choice... InfoVariantsChildren c; // ...its name c.name = nameField(field,specs); + // ...its type, excluding namespace + c.plain = nameClass(field,specs); // ...its type, including namespace - c.type = nameClass(field,specs); - const std::string ns = getChildNamespace(elemRHS, specs, per, c.type); - c.type = ns + "::" + c.type; + c.ns = getChildNamespace(elemRHS, specs, per, c.plain); + c.type = c.ns + "::" + c.plain; // ...its vector-ness - c.isVector = occ == "choice+" || occ == "choice2+"; + c.isVector = times == "choice+" || times == "choice2+"; // The GNDS JSON specifications all have "required":false for individual // choices in a set of choices; the concept of "the entire choice can be @@ -637,7 +808,7 @@ void getClassVariants( // Save as a dependency (if it's not its own dependency) if (c.type != per.name()) dep.dependencies.push_back( - NamespaceAndClass(ns,nameClass(field,specs))); + NamespaceAndClass(c.ns,nameClass(field,specs))); } // Pass 3 @@ -664,7 +835,6 @@ void getClassVariants( } // getClassVariants - // ----------------------------------------------------------------------------- // writer // ----------------------------------------------------------------------------- @@ -695,9 +865,9 @@ class writer { if (recurse == 0) { using last = decltype( std::get(std::make_tuple(value,args...))); - const size_t nsub = std::count(str.begin(), str.end(), substitute); + const std::size_t nsub = std::count(str.begin(),str.end(),substitute); // a bool last argument is not interpreted as an argument to print... - const size_t narg = + const std::size_t narg = 1 + sizeof...(args) - std::is_same_v,bool>; if (narg != nsub) { log::error( @@ -817,636 +987,859 @@ class writer { int writer::recurse = 0; +// helper +template +void section(writer &out, const std::string &str, Ts &&...args) +{ + out(); + out(); + out(largeComment); + out(str, std::forward(args)...); + out(largeComment); +} // ----------------------------------------------------------------------------- -// write* -// Autogenerated admonishment, and class prefix/suffix +// writeClassPrefix // ----------------------------------------------------------------------------- -// Class prefix void writeClassPrefix(writer &out, const PerClass &per) { + // namespace + out("namespace @ {", per.nsname); + // comment introducing class out(); - out(); - out(); out(largeComment); out("// @::", per.nsname); out("// class @", per.clname); out(largeComment); - // namespace+class begin - out(); - out("namespace @ {", per.nsname); + // class begin + // A namespace prefix in Component<> prevents possible ambiguities with the + // Child<> object, for the class, brought in through key.hpp. Normally the + // class name is capitalized while the Child<> object isn't, but if the node + // name was already capitalized in the specs (an example we encountered was + // the name "XYs1d"), then the Child<> key would reflect that. Then, without + // the nsname:: below, we'd have an ambiguity. out(); - out("class @ : public Component<@@> {", - per.clname, per.clname, - per.isData - ? (",true" + (per.dataType == "" ? "" : "," + per.dataType)) - : "" - ); + out("class @ :", per.clname); + + if (per.isDataVector && per.elementType == "") { + out(1,"public Component<@::@,true>", per.nsname, per.clname); + } else if (per.isDataVector) { + out(1,"public Component<@::@>,", per.nsname, per.clname); + out(1,"public DataNode,@>", per.elementType, + per.cdata ? "true" : "false"); + } else if (per.isDataString) { + out(1,"public Component<@::@>,", per.nsname, per.clname); + out(1,"public DataNode", + std::string(per.cdata ? "true" : "false")); + } else { + out(1,"public Component<@::@>", per.nsname, per.clname); + } + + out("{"); + out(1,"friend class Component;"); } // writeClassPrefix +// ----------------------------------------------------------------------------- +// nameMap +// ----------------------------------------------------------------------------- + +const std::map> nameMap = +{ + // ---------------------- ----------- ----------------- + // In per.elementType The A name to use + // or in per.metadata's appropriate for the function + // valueType defaultValue C++ type that returns them + // ---------------------- ----------- ----------------- + + // Described in the GNDS manual. + // I'm not sure which of the several types that map to std::string can, + // or would, appear in any GNDS specifications in such a way that we'd + // need it here, but listing all "string-like" types shouldn't hurt. + { "Integer32" , { "int" , "ints" } }, + { "UInteger32" , { "unsigned" , "uints" } }, + { "Float64" , { "double" , "doubles" } }, + { "XMLName" , { "std::string" , "strings" } }, + { "UTF8Text" , { "std::string" , "strings" } }, + { "printableText" , { "std::string" , "strings" } }, + { "quotedText" , { "std::string" , "strings" } }, + { "tdText" , { "std::string" , "strings" } }, + + // Our versions of the above. + { "int" , { "int" , "ints" } }, + { "unsigned" , { "unsigned" , "uints" } }, + { "double" , { "double" , "doubles" } }, + { "string" , { "std::string" , "strings" } }, + { "std::string" , { "std::string" , "strings" } }, + + // Allow other sensible things. + { "char" , { "char" , "chars" } }, + { "signed char" , { "signed char" , "schars" } }, + { "short" , { "short" , "shorts" } }, + { "long" , { "long" , "longs" } }, + { "long long" , { "long long" , "longlongs" } }, + { "unsigned char" , { "unsigned char" , "uchars" } }, + { "unsigned short" , { "unsigned short" , "ushorts" } }, + { "unsigned int" , { "unsigned" , "uints" } }, + { "unsigned long" , { "unsigned long" , "ulongs" } }, + { "unsigned long long" , { "unsigned long long" , "ulonglongs" } }, + { "float" , { "float" , "floats" } }, + { "long double" , { "long double" , "longdoubles" } }, + { "quad" , { "long double" , "quads" } } +}; + + +// ----------------------------------------------------------------------------- // writeClassForComponent +// ----------------------------------------------------------------------------- + void writeClassForComponent(writer &out, const PerClass &per) { // using [name for variant] = ... - out(); + if (per.variants.size()) + out(); for (const auto &v : per.variants) { out(1,"using @ = std::variant<", v.type); - int count = 0, total = v.children.size(); + int count = 0; + const int total = v.children.size(); for (const auto &c : v.children) - out(2,"@@", c.type, ++count == total ? "" : ","); + out(2,"@@", c.type, sep(count,total)); out(1,">;"); } + // ------------------------ + // Simple functions + // ------------------------ + out(); out(1,smallComment); out(1,"// For Component"); out(1,smallComment); out(); - out(1,"friend class Component;"); - out(); - out(1,"// Current namespace, current class, and GNDS node name"); - out(1,"static auto namespaceName() { return \"@\"; }", per.nsname); - out(1,"static auto className() { return \"@\"; }", per.clname); - out(1,"static auto GNDSName() { return \"@\"; }", per.nameGNDS); + out(1,"// Names: this namespace and class, " + "and original nodes (as in XML <...>)"); + out(1,"static auto NAMESPACE() { return \"@\"; }", per.nsname); + out(1,"static auto CLASS() { return \"@\"; }", per.clname); + out(1,"static auto NODENAME() { return \"@\"; }", per.nameGNDS); + + // ------------------------ + // KEYS() + // ------------------------ - // keys() begin + // KEYS() begin out(); - out(1,"// Core Interface multi-query to extract metadata and child nodes"); - out(1,"static auto keys()"); + out(1,"// Core Interface multi-query to transfer information to/from core Nodes"); + out(1,"static auto KEYS()"); out(1,"{"); - // keys() contents - int count = 0, total = per.nfields(); - if (total == 0) - out(2,"return std::tuple<>{};"); - else { - out(2,"return"); + // KEYS() contents + int count = 0; + const int total = per.nfields() + int(per.isDataNode); + out(2,"return"); - // metadata - if (per.metadata.size()) - out(3,"// metadata"); - for (const auto &m : per.metadata) { - out(3,"@{@}", m.typeFull, initializer(m)); - out(4,"/ Meta<>(\"@\")@", m.name, ++count < total ? " |" : ""); - } + // comment + out(3,"// comment"); + out(3,"++Child(special::comment) / CommentConverter{}@", + std::string(total ? " |" : "")); - // children - if (per.children.size() || per.variants.size()) - out(3,"// children"); - for (const auto &c : per.children) { - out(3,"@{}", c.typeHalf); // w/o any std::vector - out(4,"/ @Child<>(\"@\")@", - c.isVector ? "++" : "--", c.name, ++count < total ? " |" : ""); - } + // metadata + if (per.metadata.size()) { + out(); + out(3,"// metadata"); + } + for (const auto &m : per.metadata) { + out(3,"@{@}", m.typeFull, initializer(m)); + out(4,"/ Meta<>(\"@\")@@", + m.original, + // direct-specified converter, if any + m.converter == "" ? "" : (" / " + m.converter), + // separator between next entry + ++count < total ? " |" : "" + ); + } - // variants - for (const auto &v : per.variants) { - out(3,"@{}", v.typeHalf); // w/o any std::vector - out(4,"/ @(", v.isVector ? "++" : "--", false); - int n = 0; // for alternatives; not to be confused w/count - for (const auto &c : v.children) - out("@Child<>(\"@\")", n++ == 0 ? "" : " || ", c.name, false); - out(")@", ++count < total ? " |" : ""); - } + // children + if (per.children.size() || per.variants.size()) { + out(); + out(3,"// children"); + } + for (const auto &c : per.children) { + out(3,"@Child<@>", + c.isVector ? "++" : "--", + c.typeHalf // without any std::vector + ); + out(4,"(\"@\")@@@@", + c.original, + // direct-specified converter, if any + c.converter == "" ? "" : (" / " + c.converter), + // direct-specified filter, if any + c.filter == "" ? "" : (" + " + c.filter), + // simple filter: value required for metadatum label, if any; + // this augments (it doesn't replace) any direct-given filter + c.label == "" ? "" : (" | \"" + c.label + '"'), + // separator between next entry + ++count < total ? " |" : "" + ); + } - out(2,";"); + // variants + for (const auto &v : per.variants) { + out(3,"@{}", v.typeHalf); // without any std::vector + out(4,"/ @(", v.isVector ? "++" : "--", false); + int n = 0; // for alternatives; not to be confused w/count + for (const auto &c : v.children) + out("@Child<>(\"@\")", n++ == 0 ? "" : " || ", c.name, false); + out(")@", + ++count < total ? " |" : "" + ); + } + + // data + if (per.isDataNode) { + out(); + out(3,"// data"); + out(3,"--Child(special::self) / DataConverter{}"); } - // keys() end + // KEYS() end + out(2,";"); out(1,"}"); + + // ------------------------ + // FIELDNAMES() + // ------------------------ + out(); - out("public:"); + out(1,"// Data member names. " + "Usually - but not necessarily - the same as the node"); + out(1,"// names appearing in KEYS(). " + "These are used by Component's prettyprinter."); + out(1,"static const auto &FIELDNAMES()"); + out(1,"{"); + out(2,"static const std::vector names = {"); + + count = 0; + out(3,"\"comment\"@", std::string(total ? "," : "")); + for (const auto &m : per.metadata) + out(3,"\"@\"@", m.name, ++count < total ? "," : ""); + for (const auto &c : per.children) + out(3,"\"@\"@", c.name, ++count < total ? "," : ""); + for (const auto &v : per.variants) + out(3,"\"@\"@", v.name, ++count < total ? "," : ""); + + // Here, and in the Python case below, I'm not - for now - dealing with + // the case of a dynamic data type, as with the "valueType" flag discussed + // in the original GNDS specs. We may or may not really need support for + // that If we do, we'll perhaps end up with several names: at least ints, + // doubles, and strings. The way we use *references* in the C++ classes + // (referring from inside the class to the base DataNode in the + // vector case), isn't compatible, as-is, with the dynamic data type case. + // There, I suppose we'd need a reference to the variant that can contain + // vector. (For python bindings we call functions, rather + // than having references of some sort.) + if (per.isDataNode) { + if (per.isDataString) + out(3,"\"string\""); + else { + auto it = nameMap.find(per.elementType); + if (it != nameMap.end()) + out(3,"\"@\"", it->second.second); + else + out(3,"\"\""); // really shouldn't happen + } + } + + out(2,"};"); + out(2,"return names;"); + out(1,"}"); + + // ------------------------ + // PYTHONNAMES() + // ------------------------ + + out(); + out(1,"// Data member names, as they'll be presented " + "in the Python bindings."); + out(1,"static const auto &PYTHONNAMES()"); + out(1,"{"); + out(2,"static const std::vector names = {"); + + count = 0; + out(3,"\"comment\"@", std::string(total ? "," : "")); + for (const auto &m : per.metadata) + out(3,"\"@\"@", namePython(m.name), ++count < total ? "," : ""); + for (const auto &c : per.children) + out(3,"\"@\"@", namePython(c.name), ++count < total ? "," : ""); + for (const auto &v : per.variants) + out(3,"\"@\"@", namePython(v.name), ++count < total ? "," : ""); + + if (per.isDataNode) { + if (per.isDataString) + out(3,"\"string\""); + else { + auto it = nameMap.find(per.elementType); + if (it != nameMap.end()) + out(3,"\"@\"", it->second.second); + else + out(3,"\"\""); // really shouldn't happen + } + } + + out(2,"};"); + out(2,"return names;"); + out(1,"}"); } // writeClassForComponent -// Class suffix +// ----------------------------------------------------------------------------- +// writeClassSuffix +// ----------------------------------------------------------------------------- + void writeClassSuffix( - writer &out, const PerClass &per, const std::string &version + writer &out, const PerClass &per, const InfoSpecs &specs ) { + // ------------------------ // assignment + // ------------------------ + out(); out(1,smallComment); - out(1,"// Assignment"); + out(1,"// Assignment operators"); out(1,smallComment); out(); + + // copy out(1,"// copy"); - out(1,"@ &operator=(const @ &) = default;", per.clname, per.clname); + out(1,"@ &operator=(const @ &other)", per.clname, per.clname); + out(1,"{"); + out(2,"if (this != &other) {"); + if (printCtorCalls) + out(3,"std::cout << \"assign: @: copy\" << std::endl;", per.clname); + out(3,"Component::operator=(other);"); + if (per.isDataNode) + out(3,"DataNode::operator=(other);"); + out(3,"comment = other.comment;"); + if (per.nfields() > 0) { + for (const auto &m : per.metadata) + out(3,"@ = other.@;", m.name, m.name); + for (const auto &c : per.children) + out(3,"@ = other.@;", c.name, c.name); + for (const auto &v : per.variants) + out(3,"@ = other.@;", v.name, v.name); + } + out(2,"}"); + out(2,"return *this;"); + out(1,"}"); out(); + + // move out(1,"// move"); - out(1,"@ &operator=(@ &&) = default;", per.clname, per.clname); + out(1,"@ &operator=(@ &&other)", per.clname, per.clname); + out(1,"{"); + out(2,"if (this != &other) {"); + if (printCtorCalls) + out(3,"std::cout << \"assign: @: move\" << std::endl;", per.clname); + out(3,"Component::operator=(std::move(other));"); + if (per.isDataNode) + out(3,"DataNode::operator=(std::move(other));"); + out(3,"comment = std::move(other.comment);"); + if (per.nfields() > 0) { + for (const auto &m : per.metadata) + out(3,"@ = std::move(other.@);", m.name, m.name); + for (const auto &c : per.children) + out(3,"@ = std::move(other.@);", c.name, c.name); + for (const auto &v : per.variants) + out(3,"@ = std::move(other.@);", v.name, v.name); + } + out(2,"}"); + out(2,"return *this;"); + out(1,"}"); + // ------------------------ // customization #include + // ------------------------ + out(); out(1,smallComment); out(1,"// Custom functionality"); out(1,smallComment); out(); - out(1,"#include \"GNDStk/@/@/@/src/custom.hpp\"", - version, per.nsname, per.clname); + out(1,"#include \"@/@/@/@/src/custom.hpp\"", + specs.Project, specs.Version, per.nsname, per.clname); + // this *follows* the customization #include (because it might be used there) + out(1,"#undef GNDSTK_COMPONENT"); + + // ------------------------ // class+namespace end - out(); + // ------------------------ + out("}; // class @", per.clname); out(); out("} // namespace @", per.nsname); } // writeClassSuffix - - // ----------------------------------------------------------------------------- // writeClass* // For metadata, children, and variant children // ----------------------------------------------------------------------------- // writeClassContentMetadata -void writeClassContentMetadata(writer &out, const PerClass &per) -{ - if (per.metadata.size()) - out(2,"// metadata"); +void writeClassContentMetadata( + writer &out, const PerClass &per, + std::string &title +) { + if (per.metadata.size()) { + out(); + out(1,"// metadata"); + } + for (const auto &m : per.metadata) { - per.isData && ( - m.name == "length" || m.name == "start" || m.name == "valueType") - ? out(2,"mutable @ @", m.typeFull, m.name, false) - : out(2, "@ @", m.typeFull, m.name, false); + if (m.type == "bool" && m.isOptional) { + std::cout + << title + << color::custom::red + << " Metadatum will be an optional bool (not recommended): " + << color::custom::blue << m.name + << color::reset << std::endl; + title = ""; + } + + if (per.isDataVector && per.elementType == "" && + (m.name == "length" || m.name == "start" || m.name == "valueType") + ) { + out(1,"mutable Field<@>", m.typeFull); + out(2,"@{this", m.name, false); + } else { + out(1,"Field<@>", m.typeFull); + out(2,"@{this", m.name, false); + } if (m.defaultValue != "") - out("{@}", initializer(m), false); - out(";"); + out(",defaults.@", m.name, false); + out("};"); } } // writeClassContentChildren void writeClassContentChildren(writer &out, const PerClass &per) { - if (per.children.size()) - out(2,"// children"); - for (const auto &c : per.children) - out(2,"@ @;", c.typeFull, c.name); + if (per.children.size()) { + out(); + out(1,"// children"); + } + + for (const auto &c : per.children) { + out(1,"Field<@>", c.typeFull); + out(2,"@{this};", c.name); + + if (debugging && c.name == "xs") { + // todo + // Consider some terminology changes... + // ns ==> nsname + // plain ==> key (as in, the JSON key) + // typeFull ==> ? + // typeHalf ==> ? + // Also ordering: + // nsname + // key + // name + // type + // typeFull + // typeHalf + std::cout << "name == " << c.name << std::endl; + std::cout << "ns == " << c.ns << std::endl; + std::cout << "plain == " << c.plain << std::endl; + std::cout << "type == " << c.type << std::endl; + std::cout << "typeFull == " << c.typeFull << std::endl; + std::cout << "typeHalf == " << c.typeHalf << std::endl; + } + } } // writeClassContentVariants void writeClassContentVariants(writer &out, const PerClass &per) { - if (per.variants.size()) - out(2,"// children - variant"); - for (const auto &v : per.variants) - out(2,"@ @;", v.typeFull, v.name); -} - - - -// ----------------------------------------------------------------------------- -// writeClassGetters -// ----------------------------------------------------------------------------- - -void writeClassGetters(writer &out, const PerClass &per) -{ - out(); - out(1,smallComment); - out(1,"// Getters"); - out(1,"// const and non-const"); - out(1,smallComment); - - const auto write = - [&out](auto &&i, const bool isVector) - { - // i: info for metadatum, child, or variant - out(); - out(1,"// @", i.name); - out(1,"const @ &@() const", i.typeFull, i.name); - out(2,"{ return content.@; }", i.name); - out(1, "@ &@()", i.typeFull, i.name); - out(2,"{ return content.@; }", i.name); - - const auto indlab = - [&out,&i](const auto &T, const auto &par) - { - // T par: index or label parameter - out(); - out(1,"// @(@)", i.name, par); - out(1,"const @ &@(const @@) const", i.type, i.name, T, par); - out(2,"{ return getter(@(), @, \"@\"); }", i.name, par, i.name); - out(1, "@ &@(const @@)", i.type, i.name, T, par); - out(2,"{ return getter(@(), @, \"@\"); }", i.name, par, i.name); - }; - - if (isVector) { - // with index or label - indlab("std::size_t ", "index"); - indlab("std::string &", "label"); - } - }; - - // metadata, children, variants - for (const auto &m : per.metadata) write(m, false); - for (const auto &c : per.children) write(c, c.isVector); - for (const auto &v : per.variants) write(v, v.isVector); + if (per.variants.size()) { + out(); + out(1,"// children - variant"); + } - // variant alternatives for (const auto &v : per.variants) { + out(1,"Field<@>", v.typeFull); + out(2,"@{this};", v.name); + for (const auto &c : v.children) { - const auto indlab = - [&out,&v,&c](const auto &T, const auto &par) - { - // T par: index or label parameter - out(); - out(1,"// @(@)", c.name, par); - out(1,"const @ *@(const @@) const", c.type, c.name, T, par); - out(2,"{ return getter<@>(@(), @, \"@\"); }", - c.type, v.name, par, c.name); - out(1, "@ *@(const @@)", c.type, c.name, T, par); - out(2,"{ return getter<@>(@(), @, \"@\"); }", - c.type, v.name, par, c.name); - }; - - if (v.isVector) { - // with index or label - indlab("std::size_t ", "index"); - indlab("std::string &", "label"); - } else { - out(); - out(1,"// @", c.name); - out(1,"const @ *@() const", c.type, c.name); - out(2,"{ return getter<@>(@(), \"@\"); }", c.type, v.name, c.name); - out(1, "@ *@()", c.type, c.name); - out(2,"{ return getter<@>(@(), \"@\"); }", c.type, v.name, c.name); - } + out(1,"FieldPart @{@};", + v.name, c.type, c.name, v.name); } } -} // writeClassGetters - +} // ----------------------------------------------------------------------------- -// writeClassSetter* +// writeClassCtor* // ----------------------------------------------------------------------------- -// writeClassSetterChild -template // InfoChildren or InfoVariants -void writeClassSetterChild( - writer &out, const PerClass &parent, const INFO &child +// writeClassCtorComponent +void writeClassCtorComponent( + writer &out, const PerClass &per, const bool copyOrMove, + const bool newline = true ) { - // setter - // note that if type is optional, a T can still be sent - out(); - out(1,"// @(value)", child.name); - out(1,"@ &@(const @ &obj)", parent.clname, child.name, child.typeFull); - out(2,"{ @() = obj; return *this; }", child.name); + out(2,"GNDSTK_COMPONENT(@)", + std::string(copyOrMove ? "other.baseBlockData()" : "BlockData{}"), + newline); +} - const auto indlab = - [&out,&parent,&child](const auto &T, const auto &par) - { - // T par: index or label parameter - out(); - out(1,"// @(@,value)", child.name, par); - out(1,"@ &@(", parent.clname, child.name); - out(2,"const @@,", T, par); - out(2,"const @ &obj", child.type); - out(1,") {"); - out(2,"@(@) = obj; return *this;", child.name, par); - out(1,"}"); - }; - // with index or label - if (child.isVector) { - indlab("std::size_t ", "index"); - indlab("std::string &", "label"); - } -} // writeClassSetterChild +// writeClassCtorBody +void writeClassCtorBody( + writer &out, + const std::string &kind, + const std::string &clname, + const std::string &argName +) { + out(1,"{"); + if (printCtorCalls) + out(2,"std::cout << \"ctor: @: @\" << std::endl;", clname, kind); + out(2,"Component::finish(@);", argName); + out(1,"}"); +} -// writeClassSetters -void writeClassSetters(writer &out, const PerClass &per) +// writeClassCtors +void writeClassCtors(writer &out, const PerClass &per) { - out(); - out(1,smallComment); - out(1,"// Setters"); - out(1,"// non-const"); - out(1,"// All return *this"); - out(1,smallComment); + // ------------------------ + // macro + // ------------------------ - // Reminder: - // metadata can have: optional, defaulted (but not vector) - // children can have: optional, vector (but not defaulted) + int count; const int total = per.nfields(); - // metadata - for (const auto &m : per.metadata) { - out(); - out(1,"// @(value)", m.name); - - // special cases: we want to send length, start, and valueType - // to the BodyText base as well - const bool special = - per.isData && - (m.name == "length" || m.name == "start" || m.name == "valueType"); - - // setter - // note that if type is optional, a T can still be sent - out(1,"@ &@(const @ &obj)", per.clname, m.name, m.typeFull); - if (special && m.isDefaulted) - out(2,"{ BodyText::@(content.@ = obj); return *this; }", - m.name, m.name); - if (special && !m.isDefaulted) - out(2,"{ BodyText::@(@() = obj); return *this; }", - m.name, m.name); - if (!special && m.isDefaulted) - out(2,"{ content.@ = obj; return *this; }", - m.name); - if (!special && !m.isDefaulted) - out(2,"{ @() = obj; return *this; }", - m.name); - - // setter, if type is Defaulted - if (m.isDefaulted) { - out(1,"@ &@(const std::optional<@> &obj)", per.clname, m.name, m.type); - special - ? out(2,"{ BodyText::@(content.@ = obj); return *this; }", - m.name, m.name) - : out(2,"{ content.@ = obj; return *this; }", m.name); - } - } + out(); + out(1,"#define GNDSTK_COMPONENT(blockdata) \\"); + out(1,"Component( \\"); + out(2,"blockdata, \\"); + out(2,"this->comment@ \\", std::string(total || per.isDataNode ? "," : "")); + count = 0; + for (const auto &m : per.metadata) + out(2,"this->@@ \\", m.name, + ++count < total || per.isDataNode ? "," : ""); + for (const auto &c : per.children) + out(2,"this->@@ \\", c.name, + ++count < total || per.isDataNode ? "," : ""); + for (const auto &v : per.variants) + out(2,"this->@@ \\", v.name, + ++count < total || per.isDataNode ? "," : ""); + if (per.isDataNode) + out(2,"static_cast(*this) \\"); + out(1,")"); - // children, variants - for (const auto &c : per.children) writeClassSetterChild(out, per, c); - for (const auto &v : per.variants) writeClassSetterChild(out, per, v); + // ------------------------ + // ctor: default + // ------------------------ - // variant alternatives - for (const auto &v : per.variants) { - if (v.isVector) { - // choice is a vector - for (const auto &c : v.children) { - const auto indlab = - [&out,&per,&v,&c](const auto &T, const auto &par) - { - // T par: index or label parameter - out(); - out(1,"// @(@,value)", c.name, par); - out(1,"@ &@(", per.clname, c.name); - out(2,"const @@,", T, par); - out(2,"const std::optional<@> &obj", c.type); - out(1,") {"); - out(2,"if (obj) @(@,obj.value());", v.name, par); - out(2,"return *this;"); - out(1,"}"); - }; - - // with index or label - indlab("std::size_t ", "index"); - indlab("std::string &", "label"); - } - } else { - // choice is a variant - for (const auto &c : v.children) { - out(); - out(1,"// @(value)", c.name); - out(1,"@ &@(const std::optional<@> &obj)", - per.clname, c.name, c.type); - out(2,"{ if (obj) @(obj.value()); return *this; }", v.name); - } - } - } -} // writeClassSetters - - - -// ----------------------------------------------------------------------------- -// writeClassCtor* -// ----------------------------------------------------------------------------- - -// writeClassCtorComponent -void writeClassCtorComponent( - writer &out, const PerClass &per, const bool hasOther -) { - out(2,"Component{"); - out(3, hasOther ? "other" : "BodyText{}", false); - - for (const auto &m : per.metadata) { // metadata - out(","); - out(3,"content.@", m.name, false); - } - for (const auto &c : per.children) { // children - out(","); - out(3,"content.@", c.name, false); - } - for (const auto &v : per.variants) { // variants - out(","); - out(3,"content.@", v.name, false); - } - - out(); - out(2,"}",false); -} // writeClassCtorComponent - - -// writeClassCtorBody -void writeClassCtorBody(writer &out, const std::string &argName) -{ - out(1,"{"); - out(2,"Component::finish(@);", argName); - out(1,"}"); -} // writeClassCtorBody - - -// writeClassCtors -void writeClassCtors(writer &out, const PerClass &per) -{ - // ctor: default out(); out(1,"// default"); out(1,"@() :", per.clname); writeClassCtorComponent(out, per, false); - out(); - writeClassCtorBody(out, ""); - - // ctor: copy - out(); - out(1,"// copy"); - out(1,"@(const @ &other) :", per.clname, per.clname); - writeClassCtorComponent(out, per, true); - out(","); - out(2,"content{other.content}"); - writeClassCtorBody(out, "other"); - - // ctor: move - out(); - out(1,"// move"); - out(1,"@(@ &&other) :", per.clname, per.clname); - writeClassCtorComponent(out, per, true); - out(","); - out(2,"content{std::move(other.content)}"); - writeClassCtorBody(out, "other"); - - // ctor: node - out(); - out(1,"// from node"); - out(1,"@(const Node &node) :", per.clname); - writeClassCtorComponent(out, per, false); - out(); - writeClassCtorBody(out, "node"); + writeClassCtorBody(out, "default", per.clname, ""); // ------------------------ - // ctor: fields + // ctor: from fields // ------------------------ - const auto total = per.nfields(); - if (total != 0) { + if (total > 0) { out(); - out(1,"// from fields"); + + // comment for this constructor + out(1,"// from fields, comment excluded"); + + // informational message, if applicable for (const auto &m : per.metadata) if (m.isDefaulted) { - out(1,"// std::optional replaces Defaulted; " + out(1,"// optional replaces Defaulted; " "this class knows the default(s)"); break; } - // signature, and base constructor call - // Note: we don't need "explicit" unless this constructor can be called - // with one argument. We'll always write it, however, in case someone - // modifies the auto-generated constructor (say, giving its arguments - // defaults) in such a way that is *can* be called with one argument. - // But we'd rather nobody modify the auto-generated classes. - int count = 0; + // signature + count = 0; out(1,"explicit @(", per.clname); - for (const auto &m : per.metadata) - out(2,"const @ &@@", - m.isDefaulted ? "std::optional<" + m.type + ">" : m.typeFull, - m.name, ++count < total ? "," : ""); - for (const auto &c : per.children) - out(2,"const @ &@@", c.typeFull, c.name, ++count < total ? "," : ""); - for (const auto &v : per.variants) - out(2,"const @ &@@", v.typeFull, v.name, ++count < total ? "," : ""); + for (const auto &m : per.metadata) { + out(2,"const wrapper<@>", + m.isDefaulted ? OPTIONAL "<" + m.type + ">" : m.typeFull); + out(3,"&@@@", + m.name, count ? " = {}" : "", count+1 < total ? "," : ""); + count++; + } + for (const auto &c : per.children) { + out(2,"const wrapper<@>", + c.typeFull); + out(3,"&@@@", + c.name, count ? " = {}" : "", count+1 < total ? "," : ""); + count++; + } + for (const auto &v : per.variants) { + out(2,"const wrapper<@>", + v.typeFull); + out(3,"&@@@", + v.name, count ? " = {}" : "", count+1 < total ? "," : ""); + count++; + } + + // base constructor call out(1,") :"); - writeClassCtorComponent(out, per, false); + writeClassCtorComponent(out, per, false, false); // initialize fields out(","); - out(2,"content{"); count = 0; for (const auto &m : per.metadata) - out(3,"@@", - m.isDefaulted - ? "Defaulted<"+m.type+">(defaults."+m.name+","+m.name+")" - : m.name, - ++count < total ? "," : ""); + if (m.isDefaulted) + out(2,"@(this,defaults.@,@)@", + m.name, m.name, m.name, sep(count,total)); + else + out(2,"@(this,@)@", m.name, m.name, sep(count,total)); for (const auto &c : per.children) - out(3,"@@", c.name, ++count < total ? "," : ""); + out(2,"@(this,@)@", c.name, c.name, sep(count,total)); for (const auto &v : per.variants) - out(3,"@@", v.name, ++count < total ? "," : ""); - out(2,"}"); + out(2,"@(this,@)@", v.name, v.name, sep(count,total)); // body - writeClassCtorBody(out, ""); + writeClassCtorBody(out, "fields", per.clname, ""); } + // ------------------------ + // ctor: node + // ------------------------ + + out(); + out(1,"// from node"); + out(1,"explicit @(const Node &node) :", per.clname); + writeClassCtorComponent(out, per, false); + writeClassCtorBody(out, "node", per.clname, "node"); + // ------------------------ // ctor: vector // ------------------------ - if (per.isData) { + if (per.isDataVector && per.elementType == "") { out(); out(1,"// from vector"); out(1,"template>>"); - out(1,"@(const std::vector &vector) :", per.clname); + "std::enable_if_t>>"); + out(1,"explicit @(const std::vector &vector) :", + per.clname); writeClassCtorComponent(out, per, false); + writeClassCtorBody(out, "vector", per.clname, "vector"); + } else if (per.isDataVector) { out(); - writeClassCtorBody(out, "vector"); + out(1,"// from vector<@>", per.elementType); + out(1,"explicit @(const std::vector<@> &vector) :", + per.clname, per.elementType); + writeClassCtorComponent(out, per, false,false); + out(","); + out(2,"DataNode(vector)"); + writeClassCtorBody(out, "vector", per.clname, "vector"); + } else if (per.isDataString) { + // todo + // Perhaps construction from std::string here, as we do with std::vector + // above, but we need to be careful. What if the class has a std::string + // metadatum and no other fields? Then, I think, the constructor created + // here would conflict with the "from fields" constructor. And, actually, + // perhaps this sort of thing can happen in relation to std::vector too. + // With other priorities being more pressing, let's address these concerns + // only if and when necessary. } -} // writeClassCtors + // ------------------------ + // ctor: copy + // ------------------------ + + out(); + out(1,"// copy"); + out(1,"@(const @ &other) :", per.clname, per.clname); + writeClassCtorComponent(out, per, true, false); + out(","); + if (per.isDataNode) + out(2,"DataNode(other),"); + out(2,"comment(this,other.comment)@", std::string(total ? "," : "")); + count = 0; + for (const auto &m : per.metadata) + out(2,"@(this,other.@)@", m.name, m.name, sep(count,total)); + for (const auto &c : per.children) + out(2,"@(this,other.@)@", c.name, c.name, sep(count,total)); + for (const auto &v : per.variants) + out(2,"@(this,other.@)@", v.name, v.name, sep(count,total)); + writeClassCtorBody(out, "copy", per.clname, "other"); + + // ------------------------ + // ctor: move + // ------------------------ + + out(); + out(1,"// move"); + out(1,"@(@ &&other) :", per.clname, per.clname); + writeClassCtorComponent(out, per, true, false); + out(","); + if (per.isDataNode) + out(2,"DataNode(std::move(other)),"); + out(2,"comment(this,std::move(other.comment))@", + std::string(total ? "," : "")); + count = 0; + for (const auto &m : per.metadata) + out(2,"@(this,std::move(other.@))@", m.name, m.name, sep(count,total)); + for (const auto &c : per.children) + out(2,"@(this,std::move(other.@))@", c.name, c.name, sep(count,total)); + for (const auto &v : per.variants) + out(2,"@(this,std::move(other.@))@", v.name, v.name, sep(count,total)); + writeClassCtorBody(out, "move", per.clname, "other"); +} // writeClassCtors // ----------------------------------------------------------------------------- // writeClass // ----------------------------------------------------------------------------- -void writeClass(PerClass &per, const InfoSpecs &specs) +void writeClass( + const InfoSpecs &specs, std::string &title, + const PerClass &per, std::string &code) { // false: no "file was autogenerated" message, because in writeClass we're // writing certain class contents to a string, not writing an entire file. writer out(false); // output: class begin - writeClassPrefix(out,per); + writeClassPrefix(out, per); // output: for the Component base - writeClassForComponent(out,per); + writeClassForComponent(out, per); + + // section: public interface + out(); + out(1,smallComment); + out(1,"// Public interface"); + out(1,smallComment); + out(); + out("public:"); // output: using directives out(); + out(1,"using component_t = Component;"); out(1,"using Component::construct;"); - if (per.isData) - out(1,"using BodyText::operator=;"); + if (per.isDataVector && per.elementType == "") + out(1,"using BlockData::operator=;"); + else if (per.isDataNode) + out(1,"using DataNode::operator=;"); // output: defaults (applicable only to metadata) - out(); - out(1,smallComment); - out(1,"// Relevant defaults"); - out(1,"// FYI for users"); - out(1,smallComment); - out(); - out(1,"static inline const struct Defaults {"); - for (auto &m : per.metadata) + std::size_t ndefaults = 0; + for (const auto &m : per.metadata) if (m.isDefaulted) - out(2,"static inline const @ @ = @;", m.type, m.name, initializer(m)); - out(1,"} defaults;"); + ++ndefaults; + if (ndefaults > 0) { + out(); + out(1,"// defaults"); + out(1,"static inline const struct Defaults {"); + for (const auto &m : per.metadata) + if (m.isDefaulted) + out(2, "static inline const @ @ = @;", + m.type, m.name, initializer(m)); + out(1,"} defaults;"); + } - // output: content (the metadata/children computed earlier) + // section: data members out(); out(1,smallComment); - out(1,"// Raw GNDS content"); + out(1,"// Data members"); out(1,smallComment); + + // output: comment out(); - out(1,"struct {"); - writeClassContentMetadata(out, per); + out(1,"// comment"); + out(1,"Field> comment{this};"); + + // output: fields + writeClassContentMetadata(out, per, title); writeClassContentChildren(out, per); writeClassContentVariants(out, per); - out(1,"} content;"); - // output: getters, setters - if (per.metadata.size() || per.children.size() || per.variants.size()) { - writeClassGetters(out, per); - writeClassSetters(out, per); + // output: data string or vector reference, if applicable + if (per.isDataNode) { + if (per.isDataString) { + out(); + out(1,"// data"); + out(1,"std::string &string = *this;"); + } else { + auto it = nameMap.find(per.elementType); + if (it != nameMap.end()) { + out(); + out(1,"// data"); + out(1,"std::vector<@> &@ = *this;", + it->second.first, it->second.second); + } else { + // This would mean either than our nameMap is missing something that + // it ought to have, or that we're dealing with one of those dynamic + // GNDS valueType-typed vectors, which is probably something we + // should try to avoid dealing with. Perhaps, here, in the event + // that we want anything in such a case, we'd make it a variant & + // to the variant in the base BodyText. + } + } + } + + // output: shortcuts + if (per.name2path.size()) { + out(); + out(1,"// shortcuts"); + out(1,"#define GNDSTK_SHORTCUT(to,name) " + "decltype(to.name) &name = to.name"); + + for (const auto &cut : per.name2path) { + const std::string &name = cut.first; + const std::vector &path = cut.second; + std::string full; + for (const std::string &field : path) + full += field + "()."; + full.pop_back(); // trailing '.' + out(1,"GNDSTK_SHORTCUT(@,@);", full, name); + } + + out(1,"#undef GNDSTK_SHORTCUT"); } // output: constructors out(); out(1,smallComment); - out(1,"// Construction"); + out(1,"// Constructors"); out(1,smallComment); writeClassCtors(out, per); // output: class end - writeClassSuffix(out, per, specs.Version); + writeClassSuffix(out, per, specs); // done - per.code = out.str(); + code = out.str(); } // writeClass - // ----------------------------------------------------------------------------- // Miscellaneous functions for getting JSON content // ----------------------------------------------------------------------------- // readJSONFile -nlohmann::json readJSONFile(const std::string &file, const bool print = false) +orderedJSON readJSONFile(const std::string &file, const bool print = false) { - static const std::string underlineON = "\033[4m"; - static const std::string underlineOFF = "\033[24m"; - - // Depending on call context, we might want to print the file name + // Depending on the call context, we might or might not print the file name if (print) { - std::cout << " "; - std::cout << underlineON << "File:" << underlineOFF << " "; - std::cout << '"' << colors::vivid::green << file << colors::reset << '"'; - std::cout << std::endl; + const std::string f = beginsin(file,"./") ? std::string(&file[2]) : file; + std::cout << color::custom::purple << f << color::reset << std::endl; } std::ifstream ifs(file); @@ -1455,55 +1848,38 @@ nlohmann::json readJSONFile(const std::string &file, const bool print = false) throw std::exception{}; } - nlohmann::json j; + orderedJSON j; ifs >> j; return j; } // readJSONFile // getMetadataJSON -template -auto getMetadataJSON(const nlohmann::json &j) +orderedJSON getMetadataJSON(const orderedJSON &j) { static const std::string metastr = "metadata"; static const std::string attrstr = "attributes"; - const bool meta = j.contains(metastr); const bool attr = j.contains(attrstr); - if constexpr (required) { - assert(meta != attr); // exactly one - return meta ? j[metastr] : j[attrstr]; - } else { - assert(!(meta && attr)); // not both - return std::optional( - meta ? j[metastr] : attr ? j[attrstr] : nlohmann::json{}); - } + assert(!(meta && attr)); // not both + return meta ? j[metastr] : attr ? j[attrstr] : orderedJSON{}; } // getMetadataJSON // getChildrenJSON -template -auto getChildrenJSON(const nlohmann::json &j) +orderedJSON getChildrenJSON(const orderedJSON &j) { static const std::string chldstr = "children"; static const std::string nodestr = "childNodes"; - const bool chld = j.contains(chldstr); const bool node = j.contains(nodestr); - if constexpr (required) { - assert(chld != node); // exactly one - return chld ? j[chldstr] : j[nodestr]; - } else { - assert(!(chld && node)); // not both - return std::optional( - chld ? j[chldstr] : node ? j[nodestr] : nlohmann::json{}); - } + assert(!(chld && node)); // not both + return chld ? j[chldstr] : node ? j[nodestr] : orderedJSON{}; } // getChildrenJSON - // ----------------------------------------------------------------------------- // commandLine and its helper functions // ----------------------------------------------------------------------------- @@ -1511,7 +1887,7 @@ auto getChildrenJSON(const nlohmann::json &j) // readChangesFile void readChangesFile(const std::string &file, InfoSpecs &specs) { - const nlohmann::json jchanges = readJSONFile(file); + const orderedJSON jchanges = readJSONFile(file); using pair = std::pair; // Changes to name? @@ -1521,95 +1897,123 @@ void readChangesFile(const std::string &file, InfoSpecs &specs) specs.mapName.insert(pair(item.key(),item.value())); // Changes to metadata/attributes? - const auto metadata = getMetadataJSON(jchanges); - if (metadata.has_value()) { - // from/to pairs for "type" - if (metadata->contains("type")) - for (const auto &item : (*metadata)["type"].items()) - if (!isComment(item.key())) - specs.mapMetaType.insert(pair(item.key(),item.value())); - // from/to pairs for "default" - if (metadata->contains("default")) - for (const auto &item : (*metadata)["default"].items()) - if (!isComment(item.key())) - specs.mapMetaDefault.insert(pair(item.key(),item.value())); - } + const orderedJSON metadata = getMetadataJSON(jchanges); + + // from/to pairs for "type" + if (metadata.contains("type")) + for (const auto &item : metadata["type"].items()) + if (!isComment(item.key())) + specs.mapMetaType.insert(pair(item.key(),item.value())); + // from/to pairs for "default" + if (metadata.contains("default")) + for (const auto &item : metadata["default"].items()) + if (!isComment(item.key())) + specs.mapMetaDefault.insert(pair(item.key(),item.value())); } // readChangesFile // printSingletons void printSingletons(const std::string &file) { - const nlohmann::json &jfile = readJSONFile(file,true); + const orderedJSON &jfile = readJSONFile(file,true); for (const auto &item : jfile.items()) { - const std::string parent = item.key(); - const nlohmann::json rhs = item.value(); + if (beginsin(item.key(), "//")) + continue; + + const orderedJSON rhs = item.value(); if (!isClass(item)) continue; - const auto metadata = getMetadataJSON(rhs); - const auto children = getChildrenJSON(rhs); + const bool hasdata = + (rhs.contains("string" ) && !rhs["string" ].is_null()) || + (rhs.contains("vector" ) && !rhs["vector" ].is_null()) || + (rhs.contains("bodyText") && !rhs["bodyText"].is_null()); + + const orderedJSON metadata = getMetadataJSON(rhs); + const orderedJSON children = getChildrenJSON(rhs); - if (metadata.size() == 0 && children.size() == 0) - log::info("Class \"{}\" has no metadata and no children", parent); - if (metadata.size() == 0 && children.size() == 1) - log::info("Class \"{}\" has no metadata and just one child", parent); + const std::string parent = item.key(); + if (metadata.size() == 0 && children.size() == 1 && !hasdata) + std::cout + << color::custom::green + << " Entry has no metadata or data, and just one child: " + << color::custom::blue << parent << color::reset << std::endl; + if (metadata.size() == 0 && children.size() == 0 && !hasdata) + std::cout + << color::custom::yellow + << " Entry has no metadata, data, or children: " + << color::custom::blue << parent << color::reset << std::endl; } } // printSingletons // commandLine -// Gather information from the .json file given on the command line +// Gather information from the JSON file given on the command line void commandLine( const int argc, const char *const *const argv, InfoSpecs &specs ) { - // Keys we'll look for - static const std::string input = "JSONDir"; - static const std::string files = "JSONFiles"; - static const std::string output = "GNDSDir"; - static const std::string version = "Version"; - static const std::string changes = "Changes"; - // Usage - if (argc != 2) { + if (argc < 2) { std::cout << "Usage: " << argv[0] << " file.json" << std::endl; exit(EXIT_FAILURE); } // Input file - const nlohmann::json jmain = readJSONFile(argv[1]); + const orderedJSON jmain = readJSONFile(argv[1]); + + // JSON keys we'll look for + static const std::string path = "Path"; + static const std::string project = "Project"; + static const std::string version = "Version"; + static const std::string input = "JSONDir"; + static const std::string files = "JSONFiles"; + static const std::string changes = "Changes"; + + // Need "Version" + if (!jmain.contains(version)) { + log::error("The input JSON file needs {}", version); + throw std::exception{}; + } - // Validate content - if (!(jmain.contains(input) && jmain.contains(output) && - jmain.contains(files) && jmain.contains(version))) { - log::error("The input json file needs {}, {}, {}, and {}", - input, files, output, version); + // Need "JSONFiles" + if (!jmain.contains(files)) { + log::error("The input JSON file needs {}", files); throw std::exception{}; } - // Extract information from the command line .json - specs.JSONDir = jmain[input]; - specs.JSONFiles = std::vector(jmain[files]); - specs.GNDSDir = jmain[output]; - specs.Version = jmain[version]; + // Extract information from the command line JSON file... + // ...these are optional: + specs.Path = jmain.contains(path ) ? jmain[path ] : "."; + specs.Project = jmain.contains(project) ? jmain[project] : "GNDStk"; + specs.JSONDir = jmain.contains(input ) ? jmain[input ] : "."; + // ...these are required: + specs.Version = jmain[version]; + for (const auto &str : jmain[files]) + specs.JSONFiles.push_back(str); + + // Version, with '_'s in place of '.'s specs.VersionUnderscore = replace(specs.Version, '.', '_'); // Prepend the JSON file names with their directory for (std::string &file : specs.JSONFiles) file = specs.JSONDir + '/' + file; - // File names - specs.hppVersion = specs.GNDSDir + "/src/GNDStk/" + specs.Version + ".hpp"; - specs.hppKey = specs.GNDSDir + "/src/GNDStk/" + specs.Version + "/key.hpp"; + // File names... - // Report on "singletons" - if (singletons) { - action("Finding possible simplifications"); - for (const std::string &file : specs.JSONFiles) - printSingletons(file); - } + // For C++ + const std::string cbase = + specs.Path + "/" + specs.Project + "/src/" + specs.Project + "/"; + specs.hppVersion = cbase + specs.Version + ".hpp"; + specs.hppKey = cbase + specs.Version + "/key.hpp"; + + // For the C interface + const std::string cppbase = specs.Path + "/" + specs.Project + "/c/src/"; + specs.hVersion = cppbase + specs.Version + ".h"; + // We don't currently know of anything that we'd have in the following + // file, so we won't create it. But I'll leave this in as a placeholder. + specs.cVersion = cppbase + specs.Version + ".cpp"; // Changes? if (jmain.contains(changes)) @@ -1617,7 +2021,6 @@ void commandLine( } // commandLine - // ----------------------------------------------------------------------------- // preprocess* functions // ----------------------------------------------------------------------------- @@ -1637,44 +2040,83 @@ void preprocessClass( specs.class2nspace.insert(std::make_pair(clname,nsname)); // ------------------------ - // Create directories and - // custom files as needed + // Create directories // ------------------------ - // Given the base GNDS directory and the GNDS version, as obtained earlier - // from the JSON input file to this tool, compute relevant directory names. - const std::string - // For the present namespace: C++ and Python directories. The present - // namespace probably contains multiple classes, so its directories - // may have been created already, but that's fine. - nsdir = specs.GNDSDir + "/src/GNDStk/" + specs.Version + "/" + nsname, - nsdirpy = specs.GNDSDir + "/python/src/" + specs.Version + "/" + nsname, - // For the present class: C++ source and test directories. - clsrc = nsdir + "/" + clname + "/src", - cltest = nsdir + "/" + clname + "/test"; + // For the present namespace: C++, Python, and C directories. The present + // namespace probably contains multiple classes, so these directories may + // have been created already, but that's fine. + const std::string nsdircpp = specs.Path + "/" + specs.Project + + "/src/" + specs.Project + "/" + specs.Version + "/" + nsname; + const std::string nsdirpy = specs.Path + "/" + specs.Project + + "/python/src/" + specs.Version + "/" + nsname; + const std::string nsdirc = specs.Path + "/" + specs.Project + + "/c/src/" + specs.Version + "/" + nsname; + + // For the present class: C++ and C source and test directories. + const std::string clsrccpp = nsdircpp + "/" + clname + "/src"; + const std::string cltestcpp = nsdircpp + "/" + clname + "/test"; + const std::string clsrcc = nsdirc + "/" + clname + "/src"; + const std::string cltestc = nsdirc + "/" + clname + "/test"; // Create the above directories, if (and only if) they don't already exist. - system(("mkdir -p " + nsdir ).data()); - system(("mkdir -p " + nsdirpy).data()); - system(("mkdir -p " + clsrc ).data()); - system(("mkdir -p " + cltest ).data()); + system(("mkdir -p " + nsdircpp ).data()); + system(("mkdir -p " + nsdirpy ).data()); + system(("mkdir -p " + nsdirc ).data()); + system(("mkdir -p " + clsrccpp ).data()); + system(("mkdir -p " + cltestcpp).data()); + system(("mkdir -p " + clsrcc ).data()); + system(("mkdir -p " + cltestc ).data()); + + // ------------------------ + // Create custom files + // ------------------------ // To allow for customization of the present class in the present namespace, - // create a custom.hpp file in the C++ source directory for the class. But - // do so only if the customization file isn't already there, or else we might - // be trashing someone's customization! - const std::string custom = clsrc + "/custom.hpp"; - if (!std::ifstream(custom)) { - std::cout << " No customization file " << custom << "\n"; - std::cout << " ...so, creating a basic one" << std::endl; - - writer out(custom,false); // false: no "file was autogenerated" message + // create certain custom.* files. Do so, however, only where any such file + // isn't already there, or else we might be trashing someone's customization! + + // Below, the "false" parameters in the writer constructions prevent the + // file from getting our "autogenerated, do not modify" admonishment at the + // top. This makes sense, as the customization file are there precisely for + // users to, well, customize. + + // C++ custom.hpp + const std::string customhpp = clsrccpp + "/custom.hpp"; + if (!std::ifstream(customhpp)) { + std::cout + << color::custom::green << " Creating " << clsrccpp + "/" + << color::custom::blue << "custom.hpp" << color::reset << std::endl; + writer out(customhpp,false); // false: no "file was autogenerated" message out(); out(0,"private:"); out(); out(1,"static inline helpMap help = {};"); } + // As above, but for the C interface: create custom.h and custom.cpp if and + // where they don't already exist. + + // C custom.h + const std::string customh = clsrcc + "/custom.h"; + if (!std::ifstream(customh)) { + std::cout + << color::custom::green << " Creating " << clsrcc + "/" + << color::custom::blue << "custom.h" << color::reset << std::endl; + writer out(customh,false); + } + + // C custom.cpp + // Meaning, C++ source for the C interface to call. (That is, this isn't for + // C++ itself; remember that our C++ library is header-only.) + const std::string customcpp = clsrcc + "/custom.cpp"; + if (!std::ifstream(customcpp)) { + std::cout + << color::custom::green << " Creating " << clsrcc + "/" + << color::custom::blue << "custom.cpp" << color::reset << std::endl; + writer out(customcpp,false); + } + // ------------------------ // Create file-name maps // ------------------------ @@ -1688,11 +2130,14 @@ void preprocessClass( // For this namespace::class: // The cpp file for Python // The hpp file for GNDStk + // The C/C++ header, and the C++ backend for the C interface auto cl = specs.class2data.insert( std::make_pair(NamespaceAndClass{nsname,clname}, PerClass{})); assert(cl.second); // should have been inserted - not there already - cl.first->second.cppPython = nsdirpy + "/" + clname + ".python.cpp"; - cl.first->second.hppGNDStk = nsdir + "/" + clname + ".hpp"; + cl.first->second.cppPython = nsdirpy + "/" + clname + ".python.cpp"; + cl.first->second.hppGNDStk = nsdircpp + "/" + clname + ".hpp"; + cl.first->second.headerC = nsdirc + "/" + clname + ".h"; + cl.first->second.sourceC = nsdirc + "/" + clname + ".cpp"; } // preprocessClass @@ -1708,10 +2153,9 @@ void preprocessClass( // names are computed as part of the "information" for the maps just mentioned. void preprocessFiles(InfoSpecs &specs) { - action("Preprocessing input files"); // files for (const std::string &file : specs.JSONFiles) { - const nlohmann::json jmain = readJSONFile(file,true); + const orderedJSON jmain = readJSONFile(file,true); const std::string nsname = getFileNamespace(jmain); // classes in the file for (const auto &cl : jmain.items()) @@ -1720,17 +2164,18 @@ void preprocessFiles(InfoSpecs &specs) } // preprocessFiles - // ----------------------------------------------------------------------------- // validate* // getClass -// getFiles +// getFilesAndClasses // ----------------------------------------------------------------------------- // Helper: validateMetadata -void validateMetadata(const nlohmann::json &metadata) +void validateMetadata(const orderedJSON &metadata) { for (const auto &field : metadata.items()) { + if (beginsin(field.key(), "//")) + continue; assert(field.value().contains("type")); assert(field.value().contains("required")); } @@ -1738,19 +2183,34 @@ void validateMetadata(const nlohmann::json &metadata) // Helper: validateChildren -void validateChildren(const nlohmann::json &children) +void validateChildren(const orderedJSON &children, const PerClass &per) { for (const auto &field : children.items()) { - assert(field.value().contains("occurrence")); + if (beginsin(field.key(), "//")) + continue; assert(field.value().contains("required")); - // Consistency check: certain "occurrence" values imply *not* required. + // Consistency check: certain occurrence values imply *not* required. // Remark: the GNDS manual speaks of "choice2" and "choice2+" options // for occurrence. We're not sure if those will remain in future GNDS // specifications, so we won't worry now about how they might fit in. - const std::string occ = field.value()["occurrence"]; - if (occ == "0+" || occ == "choice" || occ == "choice+") + const std::string times = getTimes(per,field.key(),field.value()); + if (times == "0+" || times == "choice" || times == "choice+") assert(!field.value()["required"]); // not required + + if (debugging) { + const std::string key = field.key(); + const std::string name = field.value().contains("name") + ? std::string(field.value()["name"]) + : key; + std::cout + << "child: " + << std::setw(20) << std::left << per.nsname << " " + << std::setw(48) << std::left << per.clname << " " + << std::setw(48) << std::left << key << " " + << (key == name ? " " : "*") << " " + << std::left << name << std::endl; + } } } @@ -1759,14 +2219,12 @@ void validateChildren(const nlohmann::json &children) void getClass( InfoSpecs &specs, const std::string &nsname, const KeyValue &keyval ) { - const auto &classRHS = keyval.value(); if (!isClass(keyval)) return; const std::string clname = nameClass(keyval,specs); // find in class map const auto it = specs.class2data.find(NamespaceAndClass(nsname,clname)); - assert(it != specs.class2data.end()); PerClass &per = it->second; // collect dependencies, for the present class, as this function proceeds @@ -1776,48 +2234,55 @@ void getClass( // names per.nsname = nsname; per.clname = clname; - per.nameGNDS = nameGNDS(keyval); + per.nameGNDS = nameGNDS(keyval,nsname,true); // metadata/children information - const nlohmann::json attrs = getMetadataJSON(classRHS); - const nlohmann::json elems = getChildrenJSON(classRHS); + const auto &classRHS = keyval.value(); + const orderedJSON attrs = getMetadataJSON(classRHS); + const orderedJSON elems = getChildrenJSON(classRHS); validateMetadata(attrs); - validateChildren(elems); + validateChildren(elems, per); getClassMetadata(attrs, specs, per); getClassChildren(elems, specs, per, dep); getClassVariants(elems, specs, per, dep); // data-node information - static const std::string datastr = "data"; - static const std::string bodystr = "bodyText"; - const bool data = classRHS.contains(datastr) && !classRHS[datastr].is_null(); - const bool body = classRHS.contains(bodystr) && !classRHS[bodystr].is_null(); - assert(!(data && body)); // not both - per.isData = data || body; - per.dataType = data ? classRHS[datastr] : ""; - - // per.code will contain printed C++ code for the class itself - writeClass(per,specs); + const bool + str = classRHS.contains("string" ) && !classRHS["string" ].is_null(), + vec = classRHS.contains("vector" ) && !classRHS["vector" ].is_null(), + body = classRHS.contains("bodyText") && !classRHS["bodyText"].is_null(); + assert(int(str) + int(vec) + int(body) <= 1); // no more than one + + per.isDataString = str; + per.isDataVector = vec || body; + if (vec) { + // A type change, as with metadata, may be warranted here as well + const std::string type = classRHS["vector"]; + const auto it = specs.mapMetaType.find(type); + per.elementType = it == specs.mapMetaType.end() ? type : it->second; + } else + per.elementType = ""; + per.isDataNode = + per.isDataString || (per.isDataVector && per.elementType != ""); + per.cdata = classRHS.contains("cdata") && classRHS["cdata"]; // save dependencies specs.ClassDependenciesRaw.push_back(dep); } // getClass -// getFiles -void getFiles(InfoSpecs &specs) +// getFilesAndClasses +void getFilesAndClasses(InfoSpecs &specs) { - action("Creating classes"); - // files + // each file for (const std::string &file : specs.JSONFiles) { - const nlohmann::json jmain = readJSONFile(file,true); + const orderedJSON jmain = readJSONFile(file); const std::string nsname = getFileNamespace(jmain); - // classes in the file + // each class for (const auto &cl : jmain.items()) getClass(specs, nsname, cl); } -} // getFiles - +} // getFilesAndClasses // ----------------------------------------------------------------------------- @@ -1856,61 +2321,91 @@ void sortDependencies(InfoSpecs &specs) } - // ----------------------------------------------------------------------------- -// Functions for creating output files +// For the C++ header files +// fileGNDStkVersion +// fileGNDStkKey +// fileGNDStkClass // ----------------------------------------------------------------------------- +// ------------------------ // fileGNDStkVersion +// ------------------------ + void fileGNDStkVersion(const InfoSpecs &specs) { - // Create an overarching file for this version - writer out(specs.hppVersion); - out(); - out("#ifndef NJOY_GNDSTK_@", allcaps(specs.VersionUnderscore)); - out("#define NJOY_GNDSTK_@", allcaps(specs.VersionUnderscore)); + // ------------------------ + // Create a C++ header + // for this version + // ------------------------ - std::string nsname_last = ""; - for (auto &c : specs.class2data) { - const std::string nsname = c.first.nsname; - const std::string clname = c.first.clname; - if (nsname != nsname_last) - out(); - nsname_last = nsname; - out("#include \"GNDStk/@/@/@.hpp\"", specs.Version, nsname, clname); + { + writer out(specs.hppVersion); + out(); + out("#ifndef @_@", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); + out("#define @_@", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); + + std::string nsname_last = ""; + for (const auto &c : specs.class2data) { + const std::string nsname = c.first.nsname; + const std::string clname = c.first.clname; + if (nsname != nsname_last) + out(); + nsname_last = nsname; + out("#include \"@/@/@/@.hpp\"", + specs.Project, specs.Version, nsname, clname); + } + + out(); + out("#endif"); } - out(); - out("#include \"GNDStk/@/key.hpp\"", specs.Version); - out(); - out("#endif"); + // ------------------------ + // Create a C/C++ header + // for the C interface + // ------------------------ + + { + writer out(specs.hVersion); + out(); + out(largeComment); + out("// This header file is designed to work with both C and C++"); + out(largeComment); + out(); + out("#ifndef C_INTERFACE_@_@", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); + out("#define C_INTERFACE_@_@", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); + + out(); + out("#include \"GNDStk.h\""); + out(); + out("#ifdef __cplusplus"); + out(1,"// For C++"); + out(1,"#include \"@/@.hpp\"", specs.Project, specs.VersionUnderscore); + out("#endif"); + + std::string nsname_last = ""; + for (const auto &c : specs.class2data) { + const std::string nsname = c.first.nsname; + const std::string clname = c.first.clname; + if (nsname != nsname_last) + out(); + nsname_last = nsname; + out("#include \"@/@/@.h\"", specs.Version, nsname, clname); + } + + out(); + out("#endif"); + } } // fileGNDStkVersion -// fixme Reconsider the arrangement described here... +// ------------------------ // fileGNDStkKey -const std::string file_key_comment = -R"***( -This file contains Meta and Child objects for metadata and child nodes in the -current GNDS version. These may prove to be useful if you wish to use the Core -Interface in conjunction with the autogenerated classes for this GNDS version. - -Within the outer njoy::GNDStk::version namespace below, the remaining namespace -arrangement was chosen to make the use of these objects smooth and logical. - -Meta and Child objects are collectively called "keys." Meta keys are placed -into key::meta. Child keys correspond to autogenerated classes, each of which -is already in some namespace; we thus use theNamespace::key::child::. That way, -an autogenerated class [ns::Foo] has [ns::key::foo] as its Child object, and -a "using namespace ns" allows the class and the Child object to be [Foo] and -[key::foo], respectively. (If we reordered ns:: and key::, that wouldn't work.) - -Within key::, we use meta:: and child:: around Meta and Child objects, just in -case there exist any identical GNDS metadata names and child-node names. (That -can, in fact, happen). The "using namespace meta" and "using namespace child" -directives then make the Meta<> and Child<> objects appear directly in key::, -so that "meta::" and "child::" are needed only to disambiguate identical names. -)***"; +// ------------------------ void fileGNDStkKey(const InfoSpecs &specs) { @@ -1930,7 +2425,7 @@ void fileGNDStkKey(const InfoSpecs &specs) std::multimap> namespace2children; for (const auto &file : specs.JSONFiles) { - const nlohmann::json jmain = readJSONFile(file); + const orderedJSON jmain = readJSONFile(file); auto it = namespace2children.insert( std::make_pair(getFileNamespace(jmain),std::set{})); @@ -1939,14 +2434,17 @@ void fileGNDStkKey(const InfoSpecs &specs) // nodes ==> children it->second.insert(std::make_pair( nameField(node,specs), - nameGNDS (node))); + nameGNDS(node))); // attributes ==> metadata - const auto attrs = getMetadataJSON(node.value()); - for (const auto &attr : attrs.items()) + const orderedJSON attrs = getMetadataJSON(node.value()); + for (const auto &attr : attrs.items()) { + if (beginsin(attr.key(), "//")) + continue; metadata.insert(std::make_pair( nameField(attr,specs), - nameGNDS (attr))); + nameGNDS(attr))); + } } } } @@ -1958,54 +2456,57 @@ void fileGNDStkKey(const InfoSpecs &specs) writer out(specs.hppKey); out(); - out("/*",false); - out(file_key_comment,false); - out("*/"); + out("#ifndef @_@_KEY", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); + out("#define @_@_KEY", + allcaps(specs.Project), allcaps(specs.VersionUnderscore)); out(); - out("#ifndef NJOY_GNDSTK_@_KEY", allcaps(specs.VersionUnderscore)); - out("#define NJOY_GNDSTK_@_KEY", allcaps(specs.VersionUnderscore)); + out("// GNDStk Core Interface"); + out("#include \"GNDStk.hpp\""); out(); - out("namespace njoy {"); - out("namespace GNDStk {"); + if (specs.Project == "GNDStk") // <== use namespace njoy only for this + out("namespace njoy {"); + out("namespace @ {", specs.Project); out("namespace @ {", specs.VersionUnderscore); + out(); + out("using namespace njoy;"); + out("using namespace GNDStk;"); // ------------------------ // Meta<> objects // ------------------------ + section(out,"// meta::"); out(); - out(); - out(largeComment); - out("// key::meta::"); - out(largeComment); - out(); - out("namespace key {"); out("namespace meta {"); if (metadata.size() > 0) { + out(); + out(0,"#define GNDSTK_MAKE_LOOKUP(nameField,nameGNDS) \\"); + out(1, "inline const auto nameField = makeLookup( \\"); + out(2, "[](const auto &obj) -> decltype(obj.nameField()) \\"); + out(2, "{ return obj.nameField(); }, \\"); + out(2, "#nameGNDS \\"); + out(1, ")"); + out(0, "// nameField vs. nameGNDS: for, e.g., Double vs. double in GNDS"); out(); for (const auto &meta : metadata) - out("inline const Meta<> @(\"@\");", meta.first, meta.second); + out("GNDSTK_MAKE_LOOKUP(@,@);", meta.first, meta.second); + out(); + out(0,"#undef GNDSTK_MAKE_LOOKUP"); out(); } out("} // namespace meta"); - out("using namespace meta;"); - out("} // namespace key"); // ------------------------ // Child<> objects // ------------------------ for (const auto &nspace : namespace2children) { - out(); - out(); - out(largeComment); - out("// @::key::child::", nspace.first); - out(largeComment); + section(out, "// @::child::", nspace.first); out(); out("namespace @ {", nspace.first); - out("namespace key {"); out("namespace child {"); const auto &children = nspace.second; @@ -2018,10 +2519,25 @@ void fileGNDStkKey(const InfoSpecs &specs) out("} // namespace child"); out("using namespace child;"); - out("} // namespace key"); out("} // namespace @", nspace.first); } + // ------------------------ + // Using directives + // ------------------------ + + section(out, "// For convenience: using directives"); + out(); + out("namespace key {"); + out(1,"using namespace meta;"); + for (const auto &nspace : namespace2children) + out(1,"using namespace @::child;", nspace.first); + out("} // namespace key"); + out(); + out("using namespace key;"); + for (const auto &nspace : namespace2children) + out("using namespace @;", nspace.first); + // ------------------------ // finish // ------------------------ @@ -2032,62 +2548,1005 @@ void fileGNDStkKey(const InfoSpecs &specs) out(largeComment); out(); out("} // namespace @", specs.VersionUnderscore); - out("} // namespace GNDStk"); - out("} // namespace njoy"); + out("} // namespace @", specs.Project); + if (specs.Project == "GNDStk") // <== end namespace njoy only for this + out("} // namespace njoy"); out(); out("#endif"); } // fileGNDStkKey +// ------------------------ // fileGNDStkClass +// ------------------------ + void fileGNDStkClass( const InfoSpecs &specs, const PerClass &per, const Class2Dependencies &c2d ) { // class-specific hpp file writer out(per.hppGNDStk); const std::string guard = - "NJOY_GNDSTK_" + allcaps(specs.VersionUnderscore) + "_" + - allcaps(per.nsname) + "_" + allcaps(per.clname); + allcaps(specs.Project) + "_" + + allcaps(specs.VersionUnderscore) + "_" + + allcaps(per.nsname) + "_" + + allcaps(per.clname); out(); out("#ifndef @", guard); out("#define @", guard); - out(); - out("// core interface"); - out("#include \"GNDStk.hpp\""); - if (c2d.dependencies.size() > 0) { - out(); - out("// @ dependencies", specs.Version); - for (const auto &dep : c2d.dependencies) - out("#include \"GNDStk/@/@/@.hpp\"", - specs.Version, dep.nsname, dep.clname); - } + out(); + if (c2d.dependencies.size() == 0) // <== otherwise, comes in through deps + out("#include \"@/@/key.hpp\"", specs.Project, specs.Version); + for (const auto &dep : c2d.dependencies) + out("#include \"@/@/@/@.hpp\"", + specs.Project, specs.Version, dep.nsname, dep.clname); out(); - out("namespace njoy {"); - out("namespace GNDStk {"); + if (specs.Project == "GNDStk") + out("namespace njoy {"); + out("namespace @ {", specs.Project); out("namespace @ {", specs.VersionUnderscore); - out(); - out("using namespace njoy::GNDStk::core;"); out(per.code,false); out("} // namespace @", specs.VersionUnderscore); - out("} // namespace GNDStk"); - out("} // namespace njoy"); + out("} // namespace @", specs.Project); + if (specs.Project == "GNDStk") + out("} // namespace njoy"); out(); out("#endif"); } // fileGNDStkClass -// filePythonNamespace -void filePythonNamespace(const InfoSpecs &specs, const PerNamespace &per) +// ----------------------------------------------------------------------------- +// C interface: +// Helpers +// ----------------------------------------------------------------------------- + +// two +// Forward args to two places: header and source +template +void two(writer &hdr, writer &src, Ts &&...args) { - writer out(per.cppPython); - out(); + hdr(std::forward(args)...); + src(std::forward(args)...); +} + +// ext +// For writing (or not writing) 'extern "C"' +template +void ext(writer &hdr, writer &src, const std::string &str, Ts &&...args) +{ + hdr("extern_c "+str, std::forward(args)...); + src( str, std::forward(args)...); +} + +// ppp +// Comment, prefixed in header file with "+++" +template +void ppp(writer &hdr, writer &src, const std::string &str, Ts &&...args) +{ + hdr("// +++ "+str, std::forward(args)...); + src("// " +str, std::forward(args)...); +} +template +void PPP(writer &hdr, writer &src, Ts &&...args) +{ + two(hdr,src); + ppp(hdr,src,std::forward(args)...); +} + +// mmm +// Comment, prefixed in header file with "---" +template +void mmm(writer &hdr, writer &src, const std::string &str, Ts &&...args) +{ + hdr("// --- "+str, std::forward(args)...); + src("// " +str, std::forward(args)...); +} +template +void MMM(writer &hdr, writer &src, Ts &&...args) +{ + two(hdr,src); + mmm(hdr,src,std::forward(args)...); +} + +// sig +// End C interface function signature; style dependent on hadFields bool +void sig(writer &hdr, writer &src, const bool hadFields = false) +{ + // header: end of parameters, semicolon for declaration + hdr(");"); + // source: end of parameters, left brace for definition + src(hadFields ? ") {" : ")\n{"); +} + +// mtype_param +// Get metadata type, for C interface +std::string mtype_param(const InfoMetadata &m) +{ + return m.type == "std::string" + ? "char *const" + : m.type; +} + +// mtype_return +// Get metadata type, for C interface +std::string mtype_return(const InfoMetadata &m) +{ + return m.type == "std::string" + ? "const char *" + : m.type; +} + +// ctype +// Get child-node type, for C interface +std::string ctype(const InfoChildren &c) +{ + // Why not ...2Const... in the first case? See: + // https://stackoverflow.com/questions/5055655 + // and: + // https://c-faq.com/ansi/constmismatch.html + // Remember that we're making C code here, not C++. + return c.isVector + ? "ConstHandle2" + c.plain + " *const" + : "ConstHandle2Const" + c.plain; +} + +// section +template +void section(writer &hdr, writer &src, const std::string &str, Ts &&...args) +{ + two(hdr,src); + two(hdr,src); + two(hdr,src,largeComment); + two(hdr,src,str, std::forward(args)...); + two(hdr,src,largeComment); +} + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceCreate* +// ----------------------------------------------------------------------------- + +// fileCInterfaceCreateParams +void fileCInterfaceCreateParams(writer &hdr, writer &src, const PerClass &per) +{ + int count = 0; + const int total = per.nfields(); + + // metadata + for (const auto &m : per.metadata) { + two(hdr,src); + two(hdr,src,1,"const @ @@", + mtype_param(m), + m.name, + ++count < total ? "," : "", + false); + } + + // children + for (const auto &c : per.children) { + two(hdr,src); + two(hdr,src,1,"@ @@@", + ctype(c), + c.name, + c.isVector ? ", const size_t "+c.name+"Size" : "", + ++count < total ? "," : "", + false + ); + } + + // variants + // todo + + if (total) + two(hdr,src); +} + +// fileCInterfaceCreateCall +void fileCInterfaceCreateCall(writer &hdr, writer &src, const PerClass &per) +{ + // metadata + for (const auto &m : per.metadata) { + src(","); + src(2,"@", m.name, false); + } + + // children + for (const auto &c : per.children) { + src(","); + const std::string Child = c.plain; + const std::string child = c.name; + c.isVector + ? src(2,"std::vector{}", Child, false) + : src(2,"detail::tocpp(@)", Child, child, false); + } + + // variants + // todo + + src(); + src(1,");"); + for (const auto &c : per.children) { + if (!c.isVector) + continue; + const std::string Child = c.plain; + const std::string child = c.name; + src(1,"for (size_t @N = 0; @N < @Size; ++@N)", + Child, Child, child, Child); + src(2,"@@Add(handle, @[@N]);", + per.clname, Child, child, Child); + } + src(1,"return handle;"); + src("}"); +} + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceBasics +// ----------------------------------------------------------------------------- + +void fileCInterfaceBasics(writer &hdr, writer &src, const PerClass &per) +{ + // section comment + section(hdr,src, + "// Basics\n" + "// Create, Assign, Delete"); + + // create: default, const + MMM(hdr,src,"Create, default, const"); + ext(hdr,src,"Handle2Const@", per.clname); + two(hdr,src,"@DefaultConst(", per.clname, false); + sig(hdr,src); + src(1,"return detail::createHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"DefaultConst\");"); + src("}"); + + // create: default, non-const + PPP(hdr,src,"Create, default"); + ext(hdr,src,"Handle2@", per.clname); + two(hdr,src,"@Default(", per.clname, false); + sig(hdr,src); + src(1,"return detail::createHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Default\");"); + src("}"); + + // create: general, const + MMM(hdr,src,"Create, general, const"); + ext(hdr,src,"Handle2Const@", per.clname); + two(hdr,src,"@CreateConst(", per.clname, false); + fileCInterfaceCreateParams(hdr,src,per); + sig(hdr,src, per.nfields() != 0); + src(1,"ConstHandle2@ handle = detail::createHandle(", per.clname); + src(2,"CLASSNAME, CLASSNAME+\"CreateConst\"", false); + fileCInterfaceCreateCall(hdr,src,per); + + // create: general, non-const + PPP(hdr,src,"Create, general"); + ext(hdr,src,"Handle2@", per.clname); + two(hdr,src,"@Create(", per.clname, false); + fileCInterfaceCreateParams(hdr,src,per); + sig(hdr,src, per.nfields() != 0); + src(1,"ConstHandle2@ handle = detail::createHandle(", per.clname); + src(2,"CLASSNAME, CLASSNAME+\"Create\"", false); + fileCInterfaceCreateCall(hdr,src,per); + + // assign + PPP(hdr,src,"Assign"); + ppp(hdr,src,"Use this to assign one handled object to another. " + "Don't assign handles,"); + ppp(hdr,src,"as with to = from. That has a meaning that you probably " + "don't intend."); + ext(hdr,src,"void"); + two(hdr,src,"@Assign(", per.clname, false); + two(hdr,src,"ConstHandle2@ self, ConstHandle2Const@ from", + per.clname, per.clname, false); + sig(hdr,src); + src(1,"detail::assignHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Assign\", self, from);"); + src("}"); + + // delete + PPP(hdr,src,"Delete"); + ppp(hdr,src,"We'll attempt to remove no-longer-used objects " + "automatically, but you"); + ppp(hdr,src,"may improve performance if you delete them when " + "you're done with them."); + ext(hdr,src,"void"); + two(hdr,src,"@Delete(", per.clname, false); + two(hdr,src,"ConstHandle2Const@ self", per.clname, false); + sig(hdr,src); + src(1,"detail::deleteHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Delete\", self);"); + src("}"); +} // fileCInterfaceBasics + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceIO +// ----------------------------------------------------------------------------- + +void fileCInterfaceIO(writer &hdr, writer &src, const PerClass &per) +{ + // section comment + section(hdr,src, + "// I/O\n" + "// Read, Write, Print\n" + "// Each returns 0 if failure, 1 if success."); + + // read from file + PPP(hdr,src,"Read from file"); + ppp(hdr,src,"File can be XML, JSON, or HDF5."); + ppp(hdr,src,"We'll examine the file's contents to determine " + "its type automatically."); + ext(hdr,src,"int"); + two(hdr,src,"@Read(", per.clname, false); + two(hdr,src,"ConstHandle2@ self, const char *const filename", + per.clname, false); + sig(hdr,src); + src(1,"return detail::readHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Read\", self, filename);"); + src("}"); + + // write to file + PPP(hdr,src,"Write to file"); + ppp(hdr,src,"File can be XML, JSON, or HDF5."); + ppp(hdr,src,"We'll use filename's extension to determine " + "the type you want written."); + ext(hdr,src,"int"); + two(hdr,src,"@Write(", per.clname, false); + two(hdr,src,"ConstHandle2Const@ self, const char *const filename", + per.clname, false); + sig(hdr,src); + src(1,"return detail::writeHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Write\", self, filename);"); + src("}"); + + // print + PPP(hdr,src,"Print to standard output, in our prettyprinting format"); + ext(hdr,src,"int"); + two(hdr,src,"@Print(", per.clname, false); + two(hdr,src,"ConstHandle2Const@ self", per.clname, false); + sig(hdr,src); + src(1,"return detail::printHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"Print\", self);"); + src("}"); + + // print, XML + PPP(hdr,src,"Print to standard output, as XML"); + ext(hdr,src,"int"); + two(hdr,src,"@PrintXML(", per.clname, false); + two(hdr,src,"ConstHandle2Const@ self", per.clname, false); + sig(hdr,src); + src(1,"return detail::printHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"PrintXML\", self, \"XML\");"); + src("}"); + + // print, JSON + PPP(hdr,src,"Print to standard output, as JSON"); + ext(hdr,src,"int"); + two(hdr,src,"@PrintJSON(", per.clname, false); + two(hdr,src,"ConstHandle2Const@ self", per.clname, false); + sig(hdr,src); + src(1,"return detail::printHandle"); + src(2,"(CLASSNAME, CLASSNAME+\"PrintJSON\", self, \"JSON\");"); + src("}"); +} // fileCInterfaceIO + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceVector +// ----------------------------------------------------------------------------- + +void fileCInterfaceVector( + writer &hdr, writer &src, + const PerClass &per, const std::string &type, + const bool isSection = true +) { + // section comment + if (isSection) + section(hdr,src,"// Data vector"); + else { + assert(type != ""); + two(hdr,src); + two(hdr,src,smallComment); + two(hdr,src,"// @", type); + two(hdr,src,smallComment); + } + + // dynamic type? + if (type == "") { + // for a C interface, these are probably sufficient + fileCInterfaceVector(hdr,src,per,"int", false); + fileCInterfaceVector(hdr,src,per,"unsigned",false); + fileCInterfaceVector(hdr,src,per,"float", false); + fileCInterfaceVector(hdr,src,per,"double", false); + return; + } + + // Example: + // type: "double" (parameter to the present function) + // Class: "Foobar" (class type; for brevity) + // types: "doubles" + // Types: "Doubles" + const std::string Class = per.clname; + const std::string types = type + 's'; + const std::string Types = capital(type) + 's'; + + PPP(hdr,src,"Clear"); + ext(hdr,src,"void"); + two(hdr,src,"@@Clear(", Class, Types, false); + two(hdr,src,"ConstHandle2@ self", Class, false); + sig(hdr,src); + src(1,"detail::vectorClear"); + src(2,"(CLASSNAME, CLASSNAME+\"@Clear\", self);", Types); + src("}"); + + PPP(hdr,src,"Get size"); + ext(hdr,src,"size_t"); + two(hdr,src,"@@Size(", Class, Types, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::vectorSize"); + src(2,"(CLASSNAME, CLASSNAME+\"@Size\", self);", Types); + src("}"); + + PPP(hdr,src,"Get value"); + ppp(hdr,src,"By index \\in [0,size)"); + ext(hdr,src,"@", type); + two(hdr,src,"@@Get(", Class, Types, false); + two(hdr,src,"ConstHandle2Const@ self, const size_t index", Class, false); + sig(hdr,src); + src(1,"return detail::vectorGet", type); + src(2,"(CLASSNAME, CLASSNAME+\"@Get\", self, index);", Types); + src("}"); + + PPP(hdr,src,"Set value"); + ppp(hdr,src,"By index \\in [0,size)"); + ext(hdr,src,"void"); + two(hdr,src,"@@Set(", Class, Types, false); + two(hdr,src,"ConstHandle2@ self, const size_t index, const @ value", + Class, type, false); + sig(hdr,src); + src(1,"detail::vectorSet", type); + src(2,"(CLASSNAME, CLASSNAME+\"@Set\", self, index, value);", Types); + src("}"); + + MMM(hdr,src,"Get pointer to existing values, const"); + ext(hdr,src,"const @ *", type); + two(hdr,src,"@@GetArrayConst(", Class, Types, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::vectorGet", type); + src(2,"(CLASSNAME, CLASSNAME+\"@GetArrayConst\", self);", Types); + src("}"); + + PPP(hdr,src,"Get pointer to existing values, non-const"); + ext(hdr,src,"@ *", type); + two(hdr,src,"@@GetArray(", Class, Types, false); + two(hdr,src,"ConstHandle2@ self", Class, false); + sig(hdr,src); + src(1,"return detail::vectorGet", type); + src(2,"(CLASSNAME, CLASSNAME+\"@GetArray\", self);", Types); + src("}"); + + PPP(hdr,src,"Set completely new values and size"); + ext(hdr,src,"void"); + two(hdr,src,"@@SetArray(", Class, Types, false); + two(hdr,src,"ConstHandle2@ self, const @ *const values, const size_t size", + Class, type, false); + sig(hdr,src); + src(1,"return detail::vectorSet", type); + src(2,"(CLASSNAME, CLASSNAME+\"@SetArray\", self, size, values);", Types); + src("}"); +} // fileCInterfaceVector + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceMeta +// ----------------------------------------------------------------------------- + +void fileCInterfaceMeta( + writer &hdr, writer &src, + const PerClass &per, const InfoMetadata &m +) { + const std::string Class = per.clname; + const std::string Meta = UpperCamel(m.name); + const std::string meta = m.name; + + // section comment + section(hdr,src,"// Metadatum: @", meta); + + // has + // if (m.isOptional) // <== may or may not want this + { + PPP(hdr,src,"Has"); + ext(hdr,src,"int"); + two(hdr,src,"@@Has(", Class, Meta, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::hasField"); + src(2,"(CLASSNAME, CLASSNAME+\"@Has\", self, extract::@);", Meta, meta); + src("}"); + } + + // get + PPP(hdr,src,"Get"); + ppp(hdr,src,"Returns by value"); + ext(hdr,src,"@", mtype_return(m)); + two(hdr,src,"@@Get(", Class, Meta, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::getField"); + src(2,"(CLASSNAME, CLASSNAME+\"@Get\", self, extract::@);", Meta, meta); + src("}"); + + // set + PPP(hdr,src,"Set"); + ext(hdr,src,"void"); + two(hdr,src,"@@Set(", Class, Meta, false); + two(hdr,src,"ConstHandle2@ self, const @ @", + Class, mtype_param(m), meta, false); + sig(hdr,src); + src(1,"detail::setField"); + src(2,"(CLASSNAME, CLASSNAME+\"@Set\", self, extract::@, @);", + Meta, meta, meta); + src("}"); +} + + +// ----------------------------------------------------------------------------- +// C interface: +// fileCInterfaceChild +// ----------------------------------------------------------------------------- + +void fileCInterfaceChild( + writer &hdr, writer &src, + const InfoSpecs &specs, + const PerClass &per, const InfoChildren &c +) { + const std::string Class = per.clname; + const std::string Child = c.plain; + const std::string child = c.name; + + // section comment + section(hdr,src,"// Child: @", child); + + // has + // if (c.isOptional) // <== may or may not want this + { + PPP(hdr,src,"Has"); + ext(hdr,src,"int"); + two(hdr,src,"@@Has(", Class, Child, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::hasField"); + src(2,"(CLASSNAME, CLASSNAME+\"@Has\", self, extract::@);", Child, child); + src("}"); + } + + // ------------------------ + // scalar case + // ------------------------ + + if (!c.isVector) { + // get, const + MMM(hdr,src,"Get, const"); + ext(hdr,src,"Handle2Const@", Child); + two(hdr,src,"@@GetConst(", Class, Child, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::getField", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@GetConst\", self, extract::@);", + Child, child); + src("}"); + + // get, non-const + PPP(hdr,src,"Get, non-const"); + ext(hdr,src,"Handle2@", Child); + two(hdr,src,"@@Get(", Class, Child, false); + two(hdr,src,"ConstHandle2@ self", Class, false); + sig(hdr,src); + src(1,"return detail::getField", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@Get\", self, extract::@);", Child, child); + src("}"); + + // set + PPP(hdr,src,"Set"); + ext(hdr,src,"void"); + two(hdr,src,"@@Set(", Class, Child, false); + two(hdr,src,"ConstHandle2@ self, ConstHandle2Const@ @", + Class, Child, child, false); + sig(hdr,src); + src(1,"detail::setField", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@Set\", self, extract::@, @);", + Child, child, child); + src("}"); + + return; + } + + // ------------------------ + // vector case + // ------------------------ + + // clear + PPP(hdr,src,"Clear"); + ext(hdr,src,"void"); + two(hdr,src,"@@Clear(", Class, Child, false); + two(hdr,src,"ConstHandle2@ self", Class, false); + sig(hdr,src); + src(1,"detail::clearContainer"); + src(2,"(CLASSNAME, CLASSNAME+\"@Clear\", self, extract::@);", Child, child); + src("}"); + + // size + PPP(hdr,src,"Size"); + ext(hdr,src,"size_t"); + two(hdr,src,"@@Size(", Class, Child, false); + two(hdr,src,"ConstHandle2Const@ self", Class, false); + sig(hdr,src); + src(1,"return detail::sizeOfContainer"); + src(2,"(CLASSNAME, CLASSNAME+\"@Size\", self, extract::@);", Child, child); + src("}"); + + // add + PPP(hdr,src,"Add"); + ext(hdr,src,"void"); + two(hdr,src,"@@Add(", Class, Child, false); + two(hdr,src,"ConstHandle2@ self, ", Class, false); + two(hdr,src,"ConstHandle2Const@ @", Child, child, false); + sig(hdr,src); + src(1,"detail::addToContainer", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@Add\", self, extract::@, @);", + Child, child, child); + src("}"); + + // get, by index, const + MMM(hdr,src,"Get, by index \\in [0,size), const"); + ext(hdr,src,"Handle2Const@", Child); + two(hdr,src,"@@GetConst(", Class, Child, false); + two(hdr,src,"ConstHandle2Const@ self, ", Class, false); + two(hdr,src,"const size_t index_", false); + sig(hdr,src); + src(1,"return detail::getByIndex", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@GetConst\", self, extract::@, index_);", + Child, child); + src("}"); + + // get, by index, non-const + PPP(hdr,src,"Get, by index \\in [0,size), non-const"); + ext(hdr,src,"Handle2@", Child); + two(hdr,src,"@@Get(", Class, Child, false); + two(hdr,src,"ConstHandle2@ self, ", Class, false); + two(hdr,src,"const size_t index_", false); + sig(hdr,src); + src(1,"return detail::getByIndex", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@Get\", self, extract::@, index_);", + Child, child); + src("}"); + + // set, by index + PPP(hdr,src,"Set, by index \\in [0,size)"); + ext(hdr,src,"void"); + two(hdr,src,"@@Set(", Class, Child, false); + two(hdr,src); + two(hdr,src,1,"ConstHandle2@ self,", Class); + two(hdr,src,1,"const size_t index_,"); + two(hdr,src,1,"ConstHandle2Const@ @", Child, child); + sig(hdr,src,true); + src(1,"detail::setByIndex", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@Set\", self, extract::@, index_, @);", + Child, child, child); + src("}"); + + // for this child's metadata: has, get, set + const auto it = specs.class2data.find(NamespaceAndClass(c.ns,c.plain)); + if (it == specs.class2data.end()) { + log::warning( + "Unable to generate C interface has/get/set functions for:\n" + " class: {}::{}\n" + " child: {}::{}\n" + "Child class is unknown, so its metadata for has/get/set are unknown.", + per.nsname, Class, + c.ns, Child + ); + return; + } + + for (const auto &m : it->second.metadata) { + const std::string Meta = UpperCamel(m.name); + const std::string meta = m.name; + + // has, by metadatum + PPP(hdr,src,"Has, by @", meta); + ext(hdr,src,"int"); + two(hdr,src,"@@HasBy@(", Class, Child, Meta, false); + two(hdr,src); + two(hdr,src,1,"ConstHandle2Const@ self,", Class); + two(hdr,src,1,"const @ @", mtype_param(m), meta); + sig(hdr,src,true); + src(1,"return detail::hasByMetadatum"); + src(2,"(CLASSNAME, CLASSNAME+\"@HasBy@\",", Child, Meta); + src(2," self, extract::@, meta::@, @);", child, meta, meta); + src("}"); + + // get, by metadatum, const + MMM(hdr,src,"Get, by @, const", meta); + ext(hdr,src,"Handle2Const@", Child); + two(hdr,src,"@@GetBy@Const(", Class, Child, Meta, false); + two(hdr,src); + two(hdr,src,1,"ConstHandle2Const@ self,", Class); + two(hdr,src,1,"const @ @", mtype_param(m), meta); + sig(hdr,src,true); + src(1,"return detail::getByMetadatum", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@GetBy@Const\",", Child, Meta); + src(2," self, extract::@, meta::@, @);", child, meta, meta); + src("}"); + + // get, by metadatum, non-const + PPP(hdr,src,"Get, by @, non-const", meta); + ext(hdr,src,"Handle2@", Child); + two(hdr,src,"@@GetBy@(", Class, Child, Meta, false); + two(hdr,src); + two(hdr,src,1,"ConstHandle2@ self,", Class); + two(hdr,src,1,"const @ @", mtype_param(m), meta); + sig(hdr,src,true); + src(1,"return detail::getByMetadatum", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@GetBy@\",", Child, Meta); + src(2," self, extract::@, meta::@, @);", child, meta, meta); + src("}"); + + // set, by metadatum + PPP(hdr,src,"Set, by @", meta); + ext(hdr,src,"void"); + two(hdr,src,"@@SetBy@(", Class, Child, Meta, false); + two(hdr,src); + two(hdr,src,1,"ConstHandle2@ self,", Class); + two(hdr,src,1,"const @ @,", mtype_param(m), meta); + two(hdr,src,1,"ConstHandle2Const@ @", Child, child); + sig(hdr,src,true); + src(1,"detail::setByMetadatum", Child); + src(2,"(CLASSNAME, CLASSNAME+\"@SetBy@\",", Child, Meta); + src(2," self, extract::@, meta::@, @, @);", child, meta, meta, child); + src("}"); + } // metadata +} // fileCInterfaceChild + + +// ----------------------------------------------------------------------------- +// For the C interface +// ----------------------------------------------------------------------------- + +// ------------------------ +// fileCInterfaceHeader +// ------------------------ + +void fileCInterfaceHeader( + writer &hdr, const InfoSpecs &specs, + const PerClass &per, const Class2Dependencies &c2d +) { + // Initial remarks + hdr(); + hdr("// Interface for C"); + hdr("// This header file is designed to work with both C and C++"); + hdr("// Function definitions are in this file's .cpp source"); + hdr(); + + // Instructions + hdr(largeComment); + hdr(largeComment); + hdr("// Instructions for Users"); + hdr("//"); + hdr("// Constructs you're MORE likely to care about are preceded with:"); + hdr("// // +++ remark"); + hdr("// Constructs you're LESS likely to care about are preceded with:"); + hdr("// // --- remark"); + hdr("// Anything not marked as above can be ignored by most users."); + hdr("//"); + hdr("// @ is the basic handle type in this file. Example:", per.clname); + hdr("// // Create a default @ object:", per.clname); + hdr("// @ handle = @Default();", per.clname, per.clname); + hdr("// Functions involving @ are declared throughout this file.", + per.clname); + hdr(largeComment); + hdr(largeComment); + + // Preliminaries + section(hdr, "// Preliminaries"); + const std::string guard = + allcaps(specs.Project) + "_" + + allcaps(specs.VersionUnderscore) + "_" + + allcaps(per.nsname) + "_" + + allcaps(per.clname); + + hdr(); + hdr("#ifndef C_INTERFACE_@", guard); + hdr("#define C_INTERFACE_@", guard); + hdr(); + hdr("#include \"GNDStk.h\""); + for (const auto &dep : c2d.dependencies) + hdr("#include \"@/@/@.h\"", specs.Version, dep.nsname, dep.clname); + hdr(); + hdr("#ifdef __cplusplus"); + hdr(1,"#define extern_c extern \"C\""); + hdr("#else"); + hdr(1,"#define extern_c"); + hdr("#endif"); + hdr(); + hdr("// Proxy C struct for the handled C++ class"); + hdr("struct @Class { };", per.clname); + + // Handle types + section(hdr, "// Handle types"); + hdr(); + hdr("// +++ @", per.clname); + hdr("// +++ General handle, suitable for most users. " + "If you're not concerned about"); + hdr("// +++ strict \"const correctness\" in your C code, " + "you can probably use this in"); + hdr("// +++ place of any function parameter of a const-aware handle type."); + hdr("typedef struct @Class *@;", per.clname, per.clname); + hdr(); + hdr("// --- Const-aware handles."); + hdr("typedef const struct @Class *const ConstHandle2Const@;", + per.clname, per.clname); + hdr("typedef struct @Class *const ConstHandle2@;", + per.clname, per.clname); + hdr("typedef const struct @Class * Handle2Const@;", + per.clname, per.clname); + hdr("typedef struct @Class * Handle2@;", + per.clname, per.clname); +} // fileCInterfaceHeader + + +// ------------------------ +// fileCInterfaceSource +// ------------------------ + +void fileCInterfaceSource( + writer &src, const InfoSpecs &specs, + const PerClass &per, const Class2Dependencies &c2d +) { + // includes + src(); + src("#include \"@/@/@/@.hpp\"", + specs.Project, specs.VersionUnderscore, per.nsname, per.clname); + src("#include \"@.h\"", per.clname); + src(); + + // using namespace + src("using namespace njoy::GNDStk;"); + src("using namespace @::@;", specs.Project, specs.VersionUnderscore); + src(); + + // using + src("using C = @Class;", per.clname); + src("using CPP = multigroup::@;", per.clname); + src(); + + // class name + src("static const std::string CLASSNAME = \"@\";", per.clname); + + // extract: namespace begin + if (per.nfields()) { + src(); + src("namespace extract {"); + } + + // extract: metadata + for (const auto &m : per.metadata) + src(1,"static auto @ = [](auto &obj) { return &obj.@; };", + m.name, m.name); + + // extract: children + for (const auto &c : per.children) + src(1,"static auto @ = [](auto &obj) { return &obj.@; };", + c.name, c.name); + + // extract: variants + // todo Determine how the C interface should deal with C++ variants + + // extract: namespace end + if (per.nfields()) src("}"); + + if (c2d.dependencies.size()) + src(); + for (const auto &dep : c2d.dependencies) + src("using CPP@ = @::@;", dep.clname, dep.nsname, dep.clname); +} // fileCInterfaceSource + + +// ------------------------ +// fileCInterfaceCommon +// ------------------------ + +void fileCInterfaceCommon( + writer &hdr, writer &src, + const InfoSpecs &specs, + const PerClass &per, const Class2Dependencies &c2d +) { + // Basics: create, assign, delete + fileCInterfaceBasics(hdr,src, per); + + // IO: read, write, print + fileCInterfaceIO(hdr,src, per); + + // Array support, if BlockData + if (per.isDataVector) + fileCInterfaceVector(hdr,src, per, per.elementType); + + // Functions regarding metadata + for (const auto &m : per.metadata) + fileCInterfaceMeta(hdr,src, per, m); + + // Functions regarding children + for (const auto &c : per.children) + fileCInterfaceChild(hdr,src, specs, per, c); + + // variants + // todo +} // fileCInterfaceCommon + + +// ------------------------ +// fileCInterface +// ------------------------ + +void fileCInterface( + const InfoSpecs &specs, const PerClass &per, const Class2Dependencies &c2d +) { + // header beginning + writer hdr(per.headerC); + fileCInterfaceHeader(hdr, specs, per, c2d); + + // source beginning + writer src(per.sourceC); + fileCInterfaceSource(src, specs, per, c2d); + + // common, or partially common, to both header and source + fileCInterfaceCommon(hdr,src, specs, per, c2d); + + // header: customization #include, then done + section(hdr, "// Custom functionality"); + hdr(); + hdr("#include \"@/@/@/src/custom.h\"", + specs.Version, per.nsname, per.clname); + hdr(); + hdr("#undef extern_c"); + hdr("#endif"); + + // source: customization #include, then done + section(src, "// Custom functionality"); + src(); + src("#include \"@/@/@/src/custom.cpp\"", + specs.Version, per.nsname, per.clname); +} // fileCInterface + + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// For the Python interface +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// filePythonNamespace +// ----------------------------------------------------------------------------- + +void filePythonNamespace(const InfoSpecs &specs, const PerNamespace &per) +{ + writer out(per.cppPython); + out(); out("#include "); out("#include "); out(); - out("namespace python = pybind11;"); + out("namespace py = pybind11;"); out(); out("// @ interface", specs.Version); out("namespace python_@ {", specs.VersionUnderscore); @@ -2095,24 +3554,27 @@ void filePythonNamespace(const InfoSpecs &specs, const PerNamespace &per) out(); out("// @ declarations", per.nsname); out("namespace python_@ {", per.nsname); - for (auto &cl : specs.ClassDependenciesSorted) + for (const auto &cl : specs.ClassDependenciesSorted) if (cl.theClass.nsname == per.nsname) - out(1,"void wrap@(python::module &);", cl.theClass.clname); + out(1,"void wrap@(py::module &);", cl.theClass.clname); out("} // namespace python_@", per.nsname); out(); - out("// @ wrapper", per.nsname); - out("void wrap@(python::module &module)", capital(per.nsname)); + out("// wrapper for @", per.nsname); + out("void wrap@(py::module &module)", capital(per.nsname)); out("{"); out(1,"// create the @ submodule", per.nsname); - out(1,"python::module submodule = module.def_submodule("); + out(1,"py::module submodule = module.def_submodule("); out(2,"\"@\",", per.nsname); - out(2,"\"GNDS @ @\"", specs.Version, per.nsname); + if (specs.Project == "GNDStk") + out(2,"\"GNDS @ @\"", specs.Version, per.nsname); // "GNDS", not "GNDStk" + else + out(2,"\"@ @ @\"", specs.Project, specs.Version, per.nsname); out(1,");"); out(); out(1,"// wrap @ components", per.nsname); - for (auto &cl : specs.ClassDependenciesSorted) + for (const auto &cl : specs.ClassDependenciesSorted) if (cl.theClass.nsname == per.nsname) out(1,"python_@::wrap@(submodule);", per.nsname, cl.theClass.clname); out("};"); @@ -2121,74 +3583,37 @@ void filePythonNamespace(const InfoSpecs &specs, const PerNamespace &per) } // filePythonNamespace +// ----------------------------------------------------------------------------- // filePythonClass +// ----------------------------------------------------------------------------- + void filePythonClass(const InfoSpecs &specs, const PerClass &per) { const std::string &nsname = per.nsname; const std::string &clname = per.clname; writer out(per.cppPython); - static const std::map> map = { - // ---------------------- ----------- ----------------- - // In per.dataType or The A name to use - // in per.metadata's appropriate for the function - // valueType defaultValue C++ type that returns them - // ---------------------- ----------- ----------------- - - // Described in the GNDS manual. - // I'm not sure which of the several types that map to std::string can, - // or would, appear in any GNDS specifications in such a way that we'd - // need it here, but listing all "string-like" types shouldn't hurt. - { "Integer32" , { "int" , "ints" } }, - { "UInteger32" , { "unsigned" , "uints" } }, - { "Float64" , { "double" , "doubles" } }, - { "XMLName" , { "std::string" , "strings" } }, - { "UTF8Text" , { "std::string" , "strings" } }, - { "printableText" , { "std::string" , "strings" } }, - { "quotedText" , { "std::string" , "strings" } }, - { "tdText" , { "std::string" , "strings" } }, - - // Our versions of the above. - { "int" , { "int" , "ints" } }, - { "unsigned" , { "unsigned" , "uints" } }, - { "double" , { "double" , "doubles" } }, - { "string" , { "std::string" , "strings" } }, - { "std::string" , { "std::string" , "strings" } }, - - // Allow other sensible things. - { "char" , { "char" , "chars" } }, - { "signed char" , { "signed char" , "schars" } }, - { "short" , { "short" , "shorts" } }, - { "long" , { "long" , "longs" } }, - { "long long" , { "long long" , "longlongs" } }, - { "unsigned char" , { "unsigned char" , "uchars" } }, - { "unsigned short" , { "unsigned short" , "ushorts" } }, - { "unsigned int" , { "unsigned" , "uints" } }, - { "unsigned long" , { "unsigned long" , "ulongs" } }, - { "unsigned long long" , { "unsigned long long" , "ulonglongs" } }, - { "float" , { "float" , "floats" } }, - { "long double" , { "long double" , "longdoubles" } }, - { "quad" , { "long double" , "quads" } } - }; - - std::vector< std::pair< std::string, std::string > > dataTypesNames; - if (per.isData) { - // try to find per.dataType in the map - auto it = map.find(per.dataType); - if (it != map.end()) { - // this is a node with a fixed data type - dataTypesNames.emplace_back( it->second.first, it->second.second ); - } - else { - // this is a node with a runtime data type: select types to expose - std::array< std::string, 3 > types = { "int", "double", "string" }; - for ( const auto& type : types ) { - it = map.find( type ); - dataTypesNames.emplace_back( it->second.first, it->second.second ); + std::vector> dataTypesNames; + if (per.isDataVector) { + // try to find per.elementType in nameMap + auto it = nameMap.find(per.elementType); + if (it != nameMap.end()) { + // node has a fixed data type + dataTypesNames.emplace_back(it->second.first, it->second.second); + } else { + // node has a runtime data type: select types to expose + static std::array types = { "int", "double", "string" }; + for (const auto &type : types) { + it = nameMap.find(type); + dataTypesNames.emplace_back(it->second.first, it->second.second); } } } + // ------------------------ + // Begin file + // ------------------------ + out(); out("// system includes"); out("#include "); @@ -2196,144 +3621,590 @@ void filePythonClass(const InfoSpecs &specs, const PerClass &per) out(); out("// local includes"); - out("#include \"GNDStk/@/@/@.hpp\"", specs.Version, nsname, clname); + out("#include \"@/@/@/@.hpp\"", + specs.Project, specs.Version, nsname, clname); out("#include \"definitions.hpp\""); out(); out("// namespace aliases"); - out("namespace python = pybind11;"); + out("namespace py = pybind11;"); out(); out("namespace python_@ {", specs.VersionUnderscore); out("namespace python_@ {", nsname); out(); - out("// @ wrapper", clname); - out("void wrap@(python::module &module)", clname); + out("// wrapper for @::@", nsname, clname); + out("void wrap@(py::module &module)", clname); out("{"); - out(1,"using namespace njoy::GNDStk;"); - out(1,"using namespace njoy::GNDStk::@;", specs.VersionUnderscore); + const std::string prefix = specs.Project == "GNDStk" ? "njoy::" : ""; + out(1,"using namespace @@;", + prefix, specs.Project); + out(1,"using namespace @@::@;", + prefix, specs.Project, specs.VersionUnderscore); out(); out(1,"// type aliases"); - out(1,"using Component = @::@;", nsname, clname); + out(1,"using cppCLASS = @::@;", nsname, clname); // using [variant name] = std::variant..., if necessary for (const auto &v : per.variants) { out(1,"using @ = std::variant<", v.type); - int count = 0, total = v.children.size(); + int count = 0; + const int total = v.children.size(); for (const auto &c : v.children) - out(2, "@@", c.type, ++count == total ? "" : ","); + out(2, "@@", c.type, sep(count,total)); out(1,">;"); } out(); - out(1,"// create the component"); - out(1,"python::class_ component("); - out(2,"module,"); - out(2,"\"@\",", clname); - out(2,"Component::documentation().data()"); + out(1,"// create the Python object"); + out(1,"py::class_ object("); + out(2,"module, \"@\",", clname); + out(2,"cppCLASS::component_t::documentation().data()"); out(1,");"); + + // ------------------------ + // py::init<...> + // for construction from + // metadata and children + // ------------------------ + + int count = 0; + const int total = per.nfields(); + out(); - out(1,"// wrap the component"); - out(1,"component"); - - // python::init<...> for attributes and children - out(2,".def("); - out(3,"python::init<"); - int count = 0, total = per.nfields(); - for (auto &m : per.metadata) - out(4,"const @ &@", - m.isDefaulted ? "std::optional<" + m.type + ">" : m.typeFull, - ++count < total ? "," : ""); - for (auto &c : per.children) - out(4,"const @ &@", c.typeFull, ++count < total ? "," : ""); - for (auto &v : per.variants) - out(4,"const @ &@", v.typeFull, ++count < total ? "," : ""); - out(3,">(),"); - for (auto &m : per.metadata) - out(3,"python::arg(\"@\")@,", + out(1,"// constructor: from fields"); + out(1,"object.def("); + out(2,"py::init<"); + { + // init<> arguments + for (const auto &m : per.metadata) + out(3,"const @ &@", + m.isDefaulted ? OPTIONAL "<" + m.type + ">" : m.typeFull, + sep(count,total)); + for (const auto &c : per.children) + out(3,"const @ &@", c.typeFull, sep(count,total)); + for (const auto &v : per.variants) + out(3,"const @ &@", v.typeFull, sep(count,total)); + } + out(2,">(),"); + + for (const auto &m : per.metadata) + out(2,"py::arg(\"@\")@,", namePython(m.name), m.isOptional || m.isDefaulted ? " = std::nullopt" : ""); - for (auto &c : per.children) - out(3,"python::arg(\"@\")@,", namePython(c.name), + for (const auto &c : per.children) + out(2,"py::arg(\"@\")@,", + namePython(c.name), c.isOptional ? " = std::nullopt" : ""); - for (auto &v : per.variants) - out(3,"python::arg(\"@\"),", namePython(v.name)); - out(3,"Component::documentation(\"constructor\").data()"); - out(2,")"); - - // python::init<...> for each data type and name pair - for ( const auto& dataTypeName : dataTypesNames ) { - out(2,".def("); - out(3,"python::init<"); - out(4,"const std::vector<@> &", dataTypeName.first); - out(3,">(),"); - out(3,"python::arg(\"@\"),", dataTypeName.second); - out(3,"Component::documentation(\"constructor\").data()"); - out(2,")"); - } - - // .def_property_readonly... - for (auto &m : per.metadata) { + for (const auto &v : per.variants) + out(2,"py::arg(\"@\"),", + namePython(v.name)); + out(2,"cppCLASS::component_t::documentation(\"constructor\").data()"); + out(1,");"); // object.def( + + // ------------------------ + // py::init<...> + // for construction from + // vector + // ------------------------ + + // vector type[s], as computed above + for (const auto &dataTypeName : dataTypesNames) { + out(); + out(1,"// constructor: from vector"); + out(1,"object.def("); + out(2,"py::init<"); + out(3,"const std::vector<@> &", dataTypeName.first); + out(2,">(),"); + out(2,"py::arg(\"@\"),", dataTypeName.second); + out(2,"cppCLASS::component_t::documentation(\"constructor\").data()"); + out(1,");"); // object.def( + } + + // ------------------------ + // def_property + // metadata + // ------------------------ + + // todo + // We need to ensure that what we're doing, below, works for optional, + // Defaulted, and variant. (At the time of this writing, I'm not using + // Defaulted or variant anywhere in the GNDS 2.0 specs.) + + for (const auto &m : per.metadata) { const auto pyname = namePython(m.name); - out(2,".def_property_readonly("); - out(3,"\"@\",", pyname); + out(); + out(1,"// get/set @", m.name); + out(1,"object.def_property("); + // name + out(2,"\"@\",", pyname); + // get + out(2,"[](const cppCLASS &self) -> decltype(auto)"); + out(2,"{"); + m.isDefaulted + ? out(3,"return self.@().value();", m.name) + : out(3,"return self.@();", m.name); + out(2,"},"); + // set m.isDefaulted - ? out(3,"[](const Component &self) { return self.@().value(); },", - m.name) - : out(3,"&Component::@,", - m.name); - out(3,"Component::documentation(\"@\").data()", pyname); - out(2,")"); + ? out(2,"[](cppCLASS &self, const @ &value)", m.type) + : out(2,"[](cppCLASS &self, const @ &value)", m.typeFull); + out(2,"{"); + out(3,"self.@() = value;", m.name); + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", pyname); + out(1,");"); } - for (auto &c : per.children) { + // ------------------------ + // def_property + // children + // ------------------------ + + for (const auto &c : per.children) { const auto pyname = namePython(c.name); - out(2,".def_property_readonly("); - out(3,"\"@\",", pyname); - out(3,"python::overload_cast<>(&Component::@),", c.name); - out(3,"Component::documentation(\"@\").data()", pyname); - out(2,")"); + out(); + out(1,"// get/set @", c.name); + out(1,"object.def_property("); + // name + out(2,"\"@\",", pyname); + // get + out(2,"[](const cppCLASS &self) -> decltype(auto)"); + out(2,"{"); + out(3,"return self.@();", c.name); + out(2,"},"); + // set + out(2,"[](cppCLASS &self, const @ &value)", c.typeFull); + out(2,"{"); + out(3,"self.@() = value;", c.name); + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", pyname); + out(1,");"); } - for (auto &v : per.variants) { - if (!v.isVector) - for (auto &c : v.children) { + // ------------------------ + // def_property + // variants + // ------------------------ + + for (const auto &v : per.variants) { + if (!v.isVector) { + for (const auto &c : v.children) { const auto pyname = namePython(c.name); - out(2,".def_property_readonly("); - out(3,"\"@\",", pyname); - out(3,"python::overload_cast<>(&Component::@),", c.name); - out(3,"Component::documentation(\"@\").data()", pyname); - out(2,")"); + out(); + out(1,"object.def_property("); + // name + out(2,"\"@\",", pyname); + // get + out(2,"[](const cppCLASS &self) -> decltype(auto)"); + out(2,"{"); + out(3,"return self.@();", c.name); + out(2,"},"); + // set + out(2,"[](cppCLASS &self, const @ &value)", c.type); + out(2,"{"); + out(3,"self.@() = value;", c.name); + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", pyname); + out(1,");"); } + } const auto pyname = namePython(v.name); - out(2,".def_property_readonly("); - out(3,"\"@\",", pyname); - out(3,"python::overload_cast<>(&Component::@),", v.name); - out(3,"Component::documentation(\"@\").data()", pyname); - out(2,")"); + out(); + out(1,"object.def_property("); + // name + out(2,"\"@\",", pyname); + // get + out(2,"[](const cppCLASS &self) -> decltype(auto)"); + out(2,"{"); + out(3,"return self.@();", v.name); + out(2,"},"); + // set + out(2,"[](cppCLASS &self, const @ &value)", v.typeFull); + out(2,"{"); + out(3,"self.@() = value;", v.name); + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", pyname); + out(1,");"); + } + + // ------------------------ + // def_property + // string + // ------------------------ + + if (per.isDataString) { + out(); + out(1,"// get/set data string"); + out(1,"object.def_property("); + out(2,"\"string\","); + out(2,"[](const cppCLASS &self) -> const std::string &"); + out(2,"{"); + out(3,"return self;"); + out(2,"},"); + out(2,"[](cppCLASS &self, const std::string &value)"); + out(2,"{"); + out(3,"self = value;"); + out(2,"},"); + out(2,"cppCLASS::component_t::documentation(\"string\").data()"); + out(1,");"); + } + + // ------------------------ + // def_property + // vector(s) + // ------------------------ + + for (const auto &dataTypeName : dataTypesNames) { + out(); + out(1,"// get/set vector<@>", dataTypeName.first); + out(1,"object.def_property("); + // name + out(2,"\"@\",", dataTypeName.second); + // get + out(2,"[](const cppCLASS &self) -> const std::vector<@> &", + dataTypeName.first); + out(2,"{"); + per.elementType == "" // vector is... + ? out(3,"return self.@();", dataTypeName.second) // ...of dynamic type + : out(3,"return self;"); // ...of a fixed type + out(2,"},"); + // set + out(2,"[](cppCLASS &self, const std::vector<@> &value)", + dataTypeName.first); + out(2,"{"); + per.elementType == "" // vector is... + ? out(3,"self.@() = value;", dataTypeName.second) // ...of dynamic type + : out(3,"self = value;"); // ...of a fixed type + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", + dataTypeName.second); + out(1,");"); } - for ( const auto& dataTypeName : dataTypesNames ) { - out(2,".def_property_readonly("); - out(3,"\"@\",", dataTypeName.second); - out(3,"[] (const Component &self) { return self.@(); },", dataTypeName.second); - out(3,"Component::documentation(\"@\").data()", dataTypeName.second); - out(2,")"); + // ------------------------ + // def_property + // shortcuts + // ------------------------ + + for (const auto &cut : per.name2path) { + const std::string &name = cut.first; + const auto pyname = namePython(name); + out(); + out(1,"// shortcut: get/set @", name); + out(1,"object.def_property("); + // name + out(2,"\"@\",", pyname); + // get + out(2,"[](const cppCLASS &self) -> decltype(auto)"); + out(2,"{"); + out(3,"return self.@();", name); + out(2,"},"); + // set + // todo For the benefit of clarity both here and where the shortcut + // references appear in the generated C++ classes, I suppose we should + // determine the direct type of the referenced object. Note that it will + // be some sort of Field<>, and, because Field<> is defined inside of + // Component<> (intentionally so - see the remarks where class Field + // is defined), we need to realize that Field inside a referencing + // class will have a different meaning than Field in a referenced + // context. We should think about ways to make this clearer in the code. + out(2,"[](cppCLASS &self, const std::decay_t &value)", + name); + out(2,"{"); + out(3,"self.@() = value;", name); + out(2,"},"); + // documentation + out(2,"cppCLASS::component_t::documentation(\"@\").data()", pyname); + out(1,");"); } + // ------------------------ // finish - out(1,";"); + // ------------------------ + out(); - out(1,"// add standard component definitions"); - out(1,"addStandardComponentDefinitions< Component >( component );"); + out(1,"// add standard definitions"); + out(1,"addStandardComponentDefinitions(object);"); out("}"); + out(); out("} // namespace python_@", nsname); out("} // namespace python_@", specs.VersionUnderscore); } // filePythonClass +// ----------------------------------------------------------------------------- +// ShortcutDown +// Helper for the shortcuts() function +// ----------------------------------------------------------------------------- + +void ShortcutDown( + const InfoSpecs &specs, + const InfoChildren &child, + std::map &usednames, + std::vector &path, + std::multimap> &name2path, + std::set &optvec, + std::string &title, // might be modified + int down, + const bool warn, + bool consider // <== we've *not* already gone through an optional or vector? +) { + if (child.isOptional || child.isVector) + consider = false; // at least henceforth, if not already + + const std::string &nsname = child.ns; + const std::string &clname = child.plain; + const auto it = specs.class2data.find(NamespaceAndClass(nsname,clname)); + if (it == specs.class2data.end()) { + // We can't seem to find the namespace::class of the child object we're + // looking at. This is probably more-or-less an error situation, at least + // if somebody created all the children in their generated classes at the + // same time that they created the parent - basically, meaning everything + // was created in a single run of the code generator, which is how we + // intend for it to be used. In any event: right here, in the present + // context, we can't reason about shortcuts through the child if we can't + // find any information *about* the child. So, we'll just return. + return; + } + + for (const auto &grand : it->second.children) { + // grand: an InfoChildren + const auto used = usednames.find(grand.name); + if (used == usednames.end()) { + if (consider) { + // Create a preliminary shortcut, to be used later if, and only if, + // nothing elsewhere introduces a name conflict. If something else + // does, then we'll say, at that point, that the potential shortcut + // is ambiguous. (It would probably create confusion if we somehow + // chose one shortcut path over others, or tried to disambiguate by + // inventing different names based on the same original name.) + name2path.insert(std::make_pair(grand.name,path)); + } else { + // We've gone through an optional or vector, and thus won't ever + // be creating a shortcut to here. However, we'll record the fact + // that something of this name exists, even if only through an + // optional or vector, because such a scenario might be regarded + // as a good reason to *not* shortcut to other same-named objects + // that are otherwise valid for shurtcuts. + optvec.insert(grand.name); + } + } else if (warn && !used->second) { + std::cout + << title << color::custom::faded::yellow + << " Shortcut would conflict with existing field: " + << color::custom::yellow << grand.name + << color::reset << std::endl; + title = ""; + used->second = true; // so, don't report future conflicts w/same name + } + + // Note that we always dig further, regardless of what happened with the + // above conditionals. The current object might or might not, for whatever + // reason or reasons, be something to which we could shortcut. However, + // objects further down could potentially still be shortcut candidates, + // or could prove to be deal breakers for other candidates. + if (--down) { + path.push_back(grand.name); + ShortcutDown( + specs, grand, usednames, path, name2path, + optvec, title, down, warn, consider + ); + path.pop_back(); + } + down++; + } +} + + +// ----------------------------------------------------------------------------- +// shortcuts +// ----------------------------------------------------------------------------- + +void shortcuts(InfoSpecs &specs, int down, const bool warn) +{ + if (down == 1) + return; + + // ------------------------ + // For each class + // ------------------------ + + for (auto &s : specs.class2data) { + // s.first : a NamespaceAndClass + // s.second: a PerClass, which we'll call "current" (the current class) + + // The following, title, simply tells us the namespace::class we're + // currently examining. We'll arrange things so that it isn't printed + // at all (thus reducing/decluttering the code generator's output) if + // there's nothing to say - no shortcuts, no remarks about why some + // shortcut potential didn't pan out. If anything *is* said, title is + // printed and then set to "", so that it isn't needlessly re-printed. + std::string title = + color::custom::faded::purple + s.first.nsname + "::" + + color::custom::purple + s.first.clname + + color::reset + '\n'; + + // ------------------------ + // Existing field names + // in the current class + // ------------------------ + + // The bool is for diagnostic reporting, if we want to report only + // once, per name, about potential shortcut(s) conflicting with it. + std::map usednames; + + // comment; all of our generated classes have this + usednames.insert(std::make_pair("comment",false)); + + // metadata, children, variants + PerClass ¤t = s.second; + for (const auto &m : current.metadata) + usednames.insert(std::make_pair(m.name,false)); + for (const auto &c : current.children) + usednames.insert(std::make_pair(c.name,false)); + for (const auto &v : current.variants) + usednames.insert(std::make_pair(v.name,false)); + + // data (string or vector) + if (current.isDataNode) { + if (current.isDataString) + usednames.insert(std::make_pair("string",false)); + else { + // As in some other new(er) code-generator capabilities, I haven't + // handled the GNDS valueType (basically, dynamic data type) stuff + // here because it's inherently a messy concept and we may be able + // to avoid the need for it. (But possibly todo.) + auto it = nameMap.find(current.elementType); + if (it != nameMap.end()) + usednames.insert(std::make_pair(it->second.second,false)); + } + } + + // ------------------------ + // Visit children + // ------------------------ + + // For each object to which a shortcut may be possible (to be determined, + // based on criteria such as uniqueness), we'll have a map key:value pair. + // The key is the name of the object to which we may shortcut. The value + // is a vector of names, giving the path to the object. Example: say that + // the current class has x, which has y, which has foo. The potential foo + // shortcut would be represented by map key "foo", value {"x","y"}. Note + // that we use a multimap, because something might appear via multiple + // viable paths - without going through any optional, vector, or variant. + // An object of the same name being in multiple paths may mean that we + // won't shortcut to any of them (unless we decide on a reasonable way + // to disambiguate), but we can still use the multimap we'll be computing + // to print informational messages telling users about multuple paths. + std::multimap> name2path; + + // The above will contain key:value pairs for objects that appear to be + // valid for shortcutting - they don't go through optionals or vectors - + // except potentially for ambiguities. We'll also maintain (separately, + // as doing so is cleaner) a set of names that appear through optionals + // and/or vectors. We won't need paths here, as we'd never be using them, + // and also don't need to record names more than once for our purposes + // here (hence a plain set). This set can be used to exclude otherwise + // valid and unambiguous shortcuts, if we regard the existence of another + // object of the same name - even under an optional or a vector - to have + // introduced an ambiguity. todo: Consider variants here too! + std::set optvec; + + // Each "child" in the following is of class InfoChildren + for (const auto &child : current.children) { + // Path down which we're shortcutting + std::vector path; + path.push_back(child.name); + + // The "true" in the following call means we haven't already gone + // through an optional or vector. Which of course we haven't - at + // this point, because this is the initial call into the recursion. + down--; + ShortcutDown( + specs, child, usednames, path, name2path, + optvec, title, down, warn, true + ); + down++; + } + + // ------------------------ + // Identify unique + // shortcuts + // ------------------------ + + using namespace color; + std::set reportedAlready; + + // For each potential shortcut as determined above... + for (const auto &cut : name2path) { + const std::string &name = cut.first; + const std::vector &path = cut.second; + + // If a shortcut of this name would be ambiguous directly - because + // another otherwise viable shortcut of the same name exists - then + // report on this. We arrange to do the reporting just once. + if (name2path.count(name) > 1) { + if (warn && reportedAlready.find(name) == reportedAlready.end()) { + std::cout + << title << " " << custom::faded::yellow + << "Shortcut would be ambiguous: " + << custom::yellow << name << reset << std::endl; + title = ""; + + auto one = name2path.lower_bound(name); + auto end = name2path.upper_bound(name); + while (one != end) { + std::cout << " " << custom::faded::yellow; + for (const std::string &field : one->second) + std::cout << field << '.'; + std::cout << custom::yellow << name << reset << std::endl; + one++; + } + + // So we don't print the above message again, for the duplicates + reportedAlready.insert(name); + } + continue; + } + + // If a shortcut of this name *could* be considered ambiguous because + // the same name also exists beyond an optional or a vector, then the + // following code excludes it from being made into a shortcut. We may + // or may not want to have this condition. Todo: decide on this. + if (optvec.find(name) != optvec.end()) { + if (warn && reportedAlready.find(name) == reportedAlready.end()) { + std::cout + << title << " " << custom::faded::yellow + << "Shortcut would be ambiguous vis-à-vis optional/vector: " + << custom::yellow << name << reset << std::endl; + title = ""; + reportedAlready.insert(name); + } + continue; + } + + // Shortcut! + std::cout << title << custom::blue << " Shortcut: " << custom::green; + title = ""; + for (const std::string &field : path) + std::cout << field << '.'; + std::cout << custom::red << name << reset << std::endl; + + // Remember this shortcut. We'll use it soon, + // when writing code for the current class. + current.name2path.insert(cut); + } + } // each class in which we're looking for shortcuts +} + // ----------------------------------------------------------------------------- // main @@ -2342,41 +4213,105 @@ void filePythonClass(const InfoSpecs &specs, const PerClass &per) int main(const int argc, const char *const *const argv) { // For GNDStk's diagnostics - color = true; + colors = true; + + // ------------------------ + // Read .json + // ------------------------ // READ INFORMATION from the JSON file on the command line + action( + "GNDStk Code Generator", + "Author: Martin Staley", + "Los Alamos National Laboratory" + ); InfoSpecs specs; commandLine(argc, argv, specs); + // ------------------------ + // Simplifications? + // ------------------------ + + // REPORT regarding potential simplifications + if (singletons) { + action("Finding Potential Simplifications"); + for (const std::string &file : specs.JSONFiles) + printSingletons(file); + } + + // ------------------------ + // Preprocessing + // ------------------------ + // PREPROCESS, to get information needed upfront for detailed processing + action("Preprocessing"); preprocessFiles(specs); - - // PRINT CLASS CODE into temporary strings, which are written to the - // class-specific files later, after class dependencies are computed - getFiles(specs); + getFilesAndClasses(specs); // COMPUTE AN ORDERING that respects dependencies sortDependencies(specs); - // GNDStk hpp file for this GNDS version + // ------------------------ + // Shortcuts + // ------------------------ + + // COMPUTE SHORTCUTS + // The boolean tells us whether or not the code should print information + // about potential shortcuts that end up being unused for whatever reason. + // I suppose this should eventually be a command-line argument. + const int levelsDown = argc >= 3 ? atoi(argv[2]) : ShortcutLevels; + if (levelsDown != 1) + action("Computing Shortcuts"); + shortcuts(specs, levelsDown, false); + + // ------------------------ + // C++ + // ------------------------ + + // PRINT CLASS CODE into temporary strings, which are written to the + // class-specific files later, after class dependencies are computed + action("Writing Code: C++"); + for (auto &c : specs.class2data) { + const std::string &nsname = c.first.nsname; + const std::string &clname = c.first.clname; + std::string title = + color::custom::faded::purple + nsname + "::" + + color::custom::purple + clname + color::reset + '\n'; + PerClass &per = c.second; + // after the following, per.code will contain printed + // C++ code for the class itself + writeClass(specs, title, per, per.code); + } + + // Create GNDStk hpp file for this GNDS version fileGNDStkVersion(specs); - // GNDStk hpp file for Meta and Child keys + // Create GNDStk hpp file for Meta and Child keys fileGNDStkKey(specs); - // GNDStk hpp file for each namespace::class - for (const auto &obj : specs.ClassDependenciesSorted) { - auto find = specs.class2data.find(obj.theClass); - assert(find != specs.class2data.end()); - fileGNDStkClass(specs, find->second, obj); - } + // For each namespace::class: create GNDStk hpp file + for (const auto &obj : specs.ClassDependenciesSorted) + fileGNDStkClass(specs, specs.class2data.find(obj.theClass)->second, obj); - // Python cpp file for each namespace - for (auto &obj : specs.namespace2data) - filePythonNamespace(specs, obj.second); + // ------------------------ + // C Interface + // ------------------------ + + // For each namespace::class: create header+source files for the C interface + action("Writing Code: C Interface"); + for (const auto &obj : specs.ClassDependenciesSorted) + fileCInterface(specs, specs.class2data.find(obj.theClass)->second, obj); - // Python cpp file for each namespace::class - for (auto &obj : specs.class2data) + // ------------------------ + // Python Interface + // ------------------------ + + // Create Python cpp file for each namespace + // Create Python cpp file for each namespace::class + action("Writing Code: Python Interface"); + for (const auto &obj : specs.namespace2data) + filePythonNamespace(specs, obj.second); + for (const auto &obj : specs.class2data) filePythonClass(specs, obj.second); std::cout << std::endl; } diff --git a/autogen/prototype.json b/autogen/prototype.json deleted file mode 100644 index 856a88ec1..000000000 --- a/autogen/prototype.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "comment" : [ - "GNDSDir", - " Base GNDStk directory into which the autogenerator tool", - " should place src/GNDStk/version.hpp and src/GNDStk/version/*", - "", - "JSONDir", - " Directory where the listed .json input files are located", - "", - "TO AUTOGENERATE THE PROTOTYPE IN THE REAL GNDStk HIERARCHY", - " Set GNDSDir to .. if you run json2class.exe from within", - " GNDStk/autogen/, where GNDStk/ is the cloned repository", - "", - "Do NOT end the directories (JSONDir and GNDSDir) with a /" - ], - - "GNDSDir": "..", - "Version": "v1.9", - - "JSONDir": "prototype", - "JSONFiles": [ - "generalPurpose.json", - "reactionSuite.json" - ], - "Changes": "changes.json" -} diff --git a/autogen/prototype/.gitignore b/autogen/prototype/.gitignore deleted file mode 100644 index bd541c7e2..000000000 --- a/autogen/prototype/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -python -src diff --git a/autogen/prototype/generalPurpose.json b/autogen/prototype/generalPurpose.json index 0f0456417..a0f41ebc2 100644 --- a/autogen/prototype/generalPurpose.json +++ b/autogen/prototype/generalPurpose.json @@ -33,11 +33,11 @@ }, "children": { "axes": { - "occurrence": "1", + "times": "1", "required": false }, "values": { - "occurrence": "1", + "times": "1", "required": true } } @@ -52,12 +52,12 @@ }, "children": { "axis": { - "occurrence": "choice+", + "times": "choice+", "variant": "axis_grid", "required": false }, "grid": { - "occurrence": "choice+", + "times": "choice+", "variant": "axis_grid", "required": false } @@ -108,12 +108,12 @@ }, "children": { "values": { - "occurrence": "choice", + "times": "choice", "variant": "link_values", "required": false }, "link": { - "occurrence": "choice", + "times": "choice", "variant": "link_values", "required": false } @@ -154,11 +154,11 @@ }, "children": { "axes": { - "occurrence": "1", + "times": "1", "required": false }, "XYs1d": { - "occurrence": "1+", + "times": "1+", "required": true } }, diff --git a/autogen/prototype/proto/c/src/v1.9.h b/autogen/prototype/proto/c/src/v1.9.h new file mode 100644 index 000000000..12c4c688d --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9.h @@ -0,0 +1,32 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// ----------------------------------------------------------------------------- +// This header file is designed to work with both C and C++ +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9 +#define C_INTERFACE_PROTO_V1_9 + +#include "GNDStk.h" + +#ifdef __cplusplus + // For C++ + #include "proto/v1_9.hpp" +#endif + +#include "v1.9/containers/Link.h" +#include "v1.9/containers/XYs1d.h" +#include "v1.9/containers/Axes.h" +#include "v1.9/containers/Axis.h" +#include "v1.9/containers/Grid.h" +#include "v1.9/containers/Values.h" +#include "v1.9/containers/Regions1d.h" + +#include "v1.9/transport/ReactionSuite.h" +#include "v1.9/transport/Reactions.h" +#include "v1.9/transport/Reaction.h" +#include "v1.9/transport/CrossSection.h" + +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axes.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Axes.cpp new file mode 100644 index 000000000..4ce103e20 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Axes.cpp @@ -0,0 +1,175 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Axes.hpp" +#include "Axes.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = AxesClass; +using CPP = multigroup::Axes; + +static const std::string CLASSNAME = "Axes"; + +namespace extract { + static auto href = [](auto &obj) { return &obj.href; }; +} + +using CPPAxis = containers::Axis; +using CPPGrid = containers::Grid; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstAxes +AxesDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Axes +AxesDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstAxes +AxesCreateConst( + const char *const href, +) { + ConstHandle2Axes handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + href + ); + return handle; +} + +// Create, general +Handle2Axes +AxesCreate( + const char *const href, +) { + ConstHandle2Axes handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + href + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +AxesAssign(ConstHandle2Axes self, ConstHandle2ConstAxes from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +AxesDelete(ConstHandle2ConstAxes self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +AxesRead(ConstHandle2Axes self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +AxesWrite(ConstHandle2ConstAxes self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +AxesPrint(ConstHandle2ConstAxes self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +AxesPrintXML(ConstHandle2ConstAxes self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +AxesPrintJSON(ConstHandle2ConstAxes self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: href +// ----------------------------------------------------------------------------- + +// Has +int +AxesHrefHas(ConstHandle2ConstAxes self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"HrefHas", self, extract::href); +} + +// Get +// Returns by value +const char * +AxesHrefGet(ConstHandle2ConstAxes self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"HrefGet", self, extract::href); +} + +// Set +void +AxesHrefSet(ConstHandle2Axes self, const char *const href) +{ + detail::setField + (CLASSNAME, CLASSNAME+"HrefSet", self, extract::href, href); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Axes/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axes.h b/autogen/prototype/proto/c/src/v1.9/containers/Axes.h new file mode 100644 index 000000000..cddc43e82 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Axes.h @@ -0,0 +1,159 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Axes is the basic handle type in this file. Example: +// // Create a default Axes object: +// Axes handle = AxesDefault(); +// Functions involving Axes are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_AXES +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_AXES + +#include "GNDStk.h" +#include "v1.9/containers/Axis.h" +#include "v1.9/containers/Grid.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct AxesClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Axes +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct AxesClass *Axes; + +// --- Const-aware handles. +typedef const struct AxesClass *const ConstHandle2ConstAxes; +typedef struct AxesClass *const ConstHandle2Axes; +typedef const struct AxesClass * Handle2ConstAxes; +typedef struct AxesClass * Handle2Axes; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstAxes +AxesDefaultConst(); + +// +++ Create, default +extern_c Handle2Axes +AxesDefault(); + +// --- Create, general, const +extern_c Handle2ConstAxes +AxesCreateConst( + const char *const href, +); + +// +++ Create, general +extern_c Handle2Axes +AxesCreate( + const char *const href, +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +AxesAssign(ConstHandle2Axes self, ConstHandle2ConstAxes from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +AxesDelete(ConstHandle2ConstAxes self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +AxesRead(ConstHandle2Axes self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +AxesWrite(ConstHandle2ConstAxes self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +AxesPrint(ConstHandle2ConstAxes self); + +// +++ Print to standard output, as XML +extern_c int +AxesPrintXML(ConstHandle2ConstAxes self); + +// +++ Print to standard output, as JSON +extern_c int +AxesPrintJSON(ConstHandle2ConstAxes self); + + +// ----------------------------------------------------------------------------- +// Metadatum: href +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +AxesHrefHas(ConstHandle2ConstAxes self); + +// +++ Get +// +++ Returns by value +extern_c const char * +AxesHrefGet(ConstHandle2ConstAxes self); + +// +++ Set +extern_c void +AxesHrefSet(ConstHandle2Axes self, const char *const href); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Axes/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axes/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Axes/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axes/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Axes/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axis.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Axis.cpp new file mode 100644 index 000000000..1cab66507 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Axis.cpp @@ -0,0 +1,242 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Axis.hpp" +#include "Axis.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = AxisClass; +using CPP = multigroup::Axis; + +static const std::string CLASSNAME = "Axis"; + +namespace extract { + static auto index = [](auto &obj) { return &obj.index; }; + static auto label = [](auto &obj) { return &obj.label; }; + static auto unit = [](auto &obj) { return &obj.unit; }; +} + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstAxis +AxisDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Axis +AxisDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstAxis +AxisCreateConst( + const int index, + const char *const label, + const char *const unit +) { + ConstHandle2Axis handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + index, + label, + unit + ); + return handle; +} + +// Create, general +Handle2Axis +AxisCreate( + const int index, + const char *const label, + const char *const unit +) { + ConstHandle2Axis handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + index, + label, + unit + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +AxisAssign(ConstHandle2Axis self, ConstHandle2ConstAxis from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +AxisDelete(ConstHandle2ConstAxis self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +AxisRead(ConstHandle2Axis self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +AxisWrite(ConstHandle2ConstAxis self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +AxisPrint(ConstHandle2ConstAxis self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +AxisPrintXML(ConstHandle2ConstAxis self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +AxisPrintJSON(ConstHandle2ConstAxis self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// Has +int +AxisIndexHas(ConstHandle2ConstAxis self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"IndexHas", self, extract::index); +} + +// Get +// Returns by value +int +AxisIndexGet(ConstHandle2ConstAxis self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"IndexGet", self, extract::index); +} + +// Set +void +AxisIndexSet(ConstHandle2Axis self, const int index) +{ + detail::setField + (CLASSNAME, CLASSNAME+"IndexSet", self, extract::index, index); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// Has +int +AxisLabelHas(ConstHandle2ConstAxis self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LabelHas", self, extract::label); +} + +// Get +// Returns by value +const char * +AxisLabelGet(ConstHandle2ConstAxis self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LabelGet", self, extract::label); +} + +// Set +void +AxisLabelSet(ConstHandle2Axis self, const char *const label) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LabelSet", self, extract::label, label); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: unit +// ----------------------------------------------------------------------------- + +// Has +int +AxisUnitHas(ConstHandle2ConstAxis self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"UnitHas", self, extract::unit); +} + +// Get +// Returns by value +const char * +AxisUnitGet(ConstHandle2ConstAxis self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"UnitGet", self, extract::unit); +} + +// Set +void +AxisUnitSet(ConstHandle2Axis self, const char *const unit) +{ + detail::setField + (CLASSNAME, CLASSNAME+"UnitSet", self, extract::unit, unit); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Axis/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axis.h b/autogen/prototype/proto/c/src/v1.9/containers/Axis.h new file mode 100644 index 000000000..8a5b3ec95 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Axis.h @@ -0,0 +1,197 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Axis is the basic handle type in this file. Example: +// // Create a default Axis object: +// Axis handle = AxisDefault(); +// Functions involving Axis are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_AXIS +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_AXIS + +#include "GNDStk.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct AxisClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Axis +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct AxisClass *Axis; + +// --- Const-aware handles. +typedef const struct AxisClass *const ConstHandle2ConstAxis; +typedef struct AxisClass *const ConstHandle2Axis; +typedef const struct AxisClass * Handle2ConstAxis; +typedef struct AxisClass * Handle2Axis; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstAxis +AxisDefaultConst(); + +// +++ Create, default +extern_c Handle2Axis +AxisDefault(); + +// --- Create, general, const +extern_c Handle2ConstAxis +AxisCreateConst( + const int index, + const char *const label, + const char *const unit +); + +// +++ Create, general +extern_c Handle2Axis +AxisCreate( + const int index, + const char *const label, + const char *const unit +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +AxisAssign(ConstHandle2Axis self, ConstHandle2ConstAxis from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +AxisDelete(ConstHandle2ConstAxis self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +AxisRead(ConstHandle2Axis self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +AxisWrite(ConstHandle2ConstAxis self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +AxisPrint(ConstHandle2ConstAxis self); + +// +++ Print to standard output, as XML +extern_c int +AxisPrintXML(ConstHandle2ConstAxis self); + +// +++ Print to standard output, as JSON +extern_c int +AxisPrintJSON(ConstHandle2ConstAxis self); + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +AxisIndexHas(ConstHandle2ConstAxis self); + +// +++ Get +// +++ Returns by value +extern_c int +AxisIndexGet(ConstHandle2ConstAxis self); + +// +++ Set +extern_c void +AxisIndexSet(ConstHandle2Axis self, const int index); + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +AxisLabelHas(ConstHandle2ConstAxis self); + +// +++ Get +// +++ Returns by value +extern_c const char * +AxisLabelGet(ConstHandle2ConstAxis self); + +// +++ Set +extern_c void +AxisLabelSet(ConstHandle2Axis self, const char *const label); + + +// ----------------------------------------------------------------------------- +// Metadatum: unit +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +AxisUnitHas(ConstHandle2ConstAxis self); + +// +++ Get +// +++ Returns by value +extern_c const char * +AxisUnitGet(ConstHandle2ConstAxis self); + +// +++ Set +extern_c void +AxisUnitSet(ConstHandle2Axis self, const char *const unit); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Axis/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axis/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Axis/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Axis/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Axis/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Grid.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Grid.cpp new file mode 100644 index 000000000..501862b7b --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Grid.cpp @@ -0,0 +1,315 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Grid.hpp" +#include "Grid.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = GridClass; +using CPP = multigroup::Grid; + +static const std::string CLASSNAME = "Grid"; + +namespace extract { + static auto index = [](auto &obj) { return &obj.index; }; + static auto interpolation = [](auto &obj) { return &obj.interpolation; }; + static auto label = [](auto &obj) { return &obj.label; }; + static auto style = [](auto &obj) { return &obj.style; }; + static auto unit = [](auto &obj) { return &obj.unit; }; +} + +using CPPValues = containers::Values; +using CPPLink = containers::Link; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstGrid +GridDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Grid +GridDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstGrid +GridCreateConst( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const enums::GridStyle style, + const char *const unit, +) { + ConstHandle2Grid handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + index, + interpolation, + label, + style, + unit + ); + return handle; +} + +// Create, general +Handle2Grid +GridCreate( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const enums::GridStyle style, + const char *const unit, +) { + ConstHandle2Grid handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + index, + interpolation, + label, + style, + unit + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +GridAssign(ConstHandle2Grid self, ConstHandle2ConstGrid from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +GridDelete(ConstHandle2ConstGrid self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +GridRead(ConstHandle2Grid self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +GridWrite(ConstHandle2ConstGrid self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +GridPrint(ConstHandle2ConstGrid self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +GridPrintXML(ConstHandle2ConstGrid self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +GridPrintJSON(ConstHandle2ConstGrid self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// Has +int +GridIndexHas(ConstHandle2ConstGrid self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"IndexHas", self, extract::index); +} + +// Get +// Returns by value +int +GridIndexGet(ConstHandle2ConstGrid self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"IndexGet", self, extract::index); +} + +// Set +void +GridIndexSet(ConstHandle2Grid self, const int index) +{ + detail::setField + (CLASSNAME, CLASSNAME+"IndexSet", self, extract::index, index); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: interpolation +// ----------------------------------------------------------------------------- + +// Has +int +GridInterpolationHas(ConstHandle2ConstGrid self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"InterpolationHas", self, extract::interpolation); +} + +// Get +// Returns by value +enums::Interpolation +GridInterpolationGet(ConstHandle2ConstGrid self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"InterpolationGet", self, extract::interpolation); +} + +// Set +void +GridInterpolationSet(ConstHandle2Grid self, const enums::Interpolation interpolation) +{ + detail::setField + (CLASSNAME, CLASSNAME+"InterpolationSet", self, extract::interpolation, interpolation); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// Has +int +GridLabelHas(ConstHandle2ConstGrid self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LabelHas", self, extract::label); +} + +// Get +// Returns by value +const char * +GridLabelGet(ConstHandle2ConstGrid self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LabelGet", self, extract::label); +} + +// Set +void +GridLabelSet(ConstHandle2Grid self, const char *const label) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LabelSet", self, extract::label, label); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: style +// ----------------------------------------------------------------------------- + +// Has +int +GridStyleHas(ConstHandle2ConstGrid self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"StyleHas", self, extract::style); +} + +// Get +// Returns by value +enums::GridStyle +GridStyleGet(ConstHandle2ConstGrid self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"StyleGet", self, extract::style); +} + +// Set +void +GridStyleSet(ConstHandle2Grid self, const enums::GridStyle style) +{ + detail::setField + (CLASSNAME, CLASSNAME+"StyleSet", self, extract::style, style); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: unit +// ----------------------------------------------------------------------------- + +// Has +int +GridUnitHas(ConstHandle2ConstGrid self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"UnitHas", self, extract::unit); +} + +// Get +// Returns by value +const char * +GridUnitGet(ConstHandle2ConstGrid self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"UnitGet", self, extract::unit); +} + +// Set +void +GridUnitSet(ConstHandle2Grid self, const char *const unit) +{ + detail::setField + (CLASSNAME, CLASSNAME+"UnitSet", self, extract::unit, unit); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Grid/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Grid.h b/autogen/prototype/proto/c/src/v1.9/containers/Grid.h new file mode 100644 index 000000000..198302b86 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Grid.h @@ -0,0 +1,239 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Grid is the basic handle type in this file. Example: +// // Create a default Grid object: +// Grid handle = GridDefault(); +// Functions involving Grid are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_GRID +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_GRID + +#include "GNDStk.h" +#include "v1.9/containers/Values.h" +#include "v1.9/containers/Link.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct GridClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Grid +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct GridClass *Grid; + +// --- Const-aware handles. +typedef const struct GridClass *const ConstHandle2ConstGrid; +typedef struct GridClass *const ConstHandle2Grid; +typedef const struct GridClass * Handle2ConstGrid; +typedef struct GridClass * Handle2Grid; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstGrid +GridDefaultConst(); + +// +++ Create, default +extern_c Handle2Grid +GridDefault(); + +// --- Create, general, const +extern_c Handle2ConstGrid +GridCreateConst( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const enums::GridStyle style, + const char *const unit, +); + +// +++ Create, general +extern_c Handle2Grid +GridCreate( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const enums::GridStyle style, + const char *const unit, +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +GridAssign(ConstHandle2Grid self, ConstHandle2ConstGrid from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +GridDelete(ConstHandle2ConstGrid self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +GridRead(ConstHandle2Grid self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +GridWrite(ConstHandle2ConstGrid self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +GridPrint(ConstHandle2ConstGrid self); + +// +++ Print to standard output, as XML +extern_c int +GridPrintXML(ConstHandle2ConstGrid self); + +// +++ Print to standard output, as JSON +extern_c int +GridPrintJSON(ConstHandle2ConstGrid self); + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +GridIndexHas(ConstHandle2ConstGrid self); + +// +++ Get +// +++ Returns by value +extern_c int +GridIndexGet(ConstHandle2ConstGrid self); + +// +++ Set +extern_c void +GridIndexSet(ConstHandle2Grid self, const int index); + + +// ----------------------------------------------------------------------------- +// Metadatum: interpolation +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +GridInterpolationHas(ConstHandle2ConstGrid self); + +// +++ Get +// +++ Returns by value +extern_c enums::Interpolation +GridInterpolationGet(ConstHandle2ConstGrid self); + +// +++ Set +extern_c void +GridInterpolationSet(ConstHandle2Grid self, const enums::Interpolation interpolation); + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +GridLabelHas(ConstHandle2ConstGrid self); + +// +++ Get +// +++ Returns by value +extern_c const char * +GridLabelGet(ConstHandle2ConstGrid self); + +// +++ Set +extern_c void +GridLabelSet(ConstHandle2Grid self, const char *const label); + + +// ----------------------------------------------------------------------------- +// Metadatum: style +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +GridStyleHas(ConstHandle2ConstGrid self); + +// +++ Get +// +++ Returns by value +extern_c enums::GridStyle +GridStyleGet(ConstHandle2ConstGrid self); + +// +++ Set +extern_c void +GridStyleSet(ConstHandle2Grid self, const enums::GridStyle style); + + +// ----------------------------------------------------------------------------- +// Metadatum: unit +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +GridUnitHas(ConstHandle2ConstGrid self); + +// +++ Get +// +++ Returns by value +extern_c const char * +GridUnitGet(ConstHandle2ConstGrid self); + +// +++ Set +extern_c void +GridUnitSet(ConstHandle2Grid self, const char *const unit); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Grid/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Grid/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Grid/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Grid/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Grid/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Link.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Link.cpp new file mode 100644 index 000000000..fcc3f0049 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Link.cpp @@ -0,0 +1,172 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Link.hpp" +#include "Link.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = LinkClass; +using CPP = multigroup::Link; + +static const std::string CLASSNAME = "Link"; + +namespace extract { + static auto href = [](auto &obj) { return &obj.href; }; +} + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstLink +LinkDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Link +LinkDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstLink +LinkCreateConst( + const char *const href +) { + ConstHandle2Link handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + href + ); + return handle; +} + +// Create, general +Handle2Link +LinkCreate( + const char *const href +) { + ConstHandle2Link handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + href + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +LinkAssign(ConstHandle2Link self, ConstHandle2ConstLink from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +LinkDelete(ConstHandle2ConstLink self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +LinkRead(ConstHandle2Link self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +LinkWrite(ConstHandle2ConstLink self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +LinkPrint(ConstHandle2ConstLink self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +LinkPrintXML(ConstHandle2ConstLink self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +LinkPrintJSON(ConstHandle2ConstLink self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: href +// ----------------------------------------------------------------------------- + +// Has +int +LinkHrefHas(ConstHandle2ConstLink self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"HrefHas", self, extract::href); +} + +// Get +// Returns by value +const char * +LinkHrefGet(ConstHandle2ConstLink self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"HrefGet", self, extract::href); +} + +// Set +void +LinkHrefSet(ConstHandle2Link self, const char *const href) +{ + detail::setField + (CLASSNAME, CLASSNAME+"HrefSet", self, extract::href, href); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Link/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Link.h b/autogen/prototype/proto/c/src/v1.9/containers/Link.h new file mode 100644 index 000000000..4f6009662 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Link.h @@ -0,0 +1,157 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Link is the basic handle type in this file. Example: +// // Create a default Link object: +// Link handle = LinkDefault(); +// Functions involving Link are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_LINK +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_LINK + +#include "GNDStk.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct LinkClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Link +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct LinkClass *Link; + +// --- Const-aware handles. +typedef const struct LinkClass *const ConstHandle2ConstLink; +typedef struct LinkClass *const ConstHandle2Link; +typedef const struct LinkClass * Handle2ConstLink; +typedef struct LinkClass * Handle2Link; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstLink +LinkDefaultConst(); + +// +++ Create, default +extern_c Handle2Link +LinkDefault(); + +// --- Create, general, const +extern_c Handle2ConstLink +LinkCreateConst( + const char *const href +); + +// +++ Create, general +extern_c Handle2Link +LinkCreate( + const char *const href +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +LinkAssign(ConstHandle2Link self, ConstHandle2ConstLink from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +LinkDelete(ConstHandle2ConstLink self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +LinkRead(ConstHandle2Link self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +LinkWrite(ConstHandle2ConstLink self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +LinkPrint(ConstHandle2ConstLink self); + +// +++ Print to standard output, as XML +extern_c int +LinkPrintXML(ConstHandle2ConstLink self); + +// +++ Print to standard output, as JSON +extern_c int +LinkPrintJSON(ConstHandle2ConstLink self); + + +// ----------------------------------------------------------------------------- +// Metadatum: href +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +LinkHrefHas(ConstHandle2ConstLink self); + +// +++ Get +// +++ Returns by value +extern_c const char * +LinkHrefGet(ConstHandle2ConstLink self); + +// +++ Set +extern_c void +LinkHrefSet(ConstHandle2Link self, const char *const href); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Link/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Link/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Link/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Link/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Link/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.cpp new file mode 100644 index 000000000..a2dc947e3 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.cpp @@ -0,0 +1,505 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Regions1d.hpp" +#include "Regions1d.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = Regions1dClass; +using CPP = multigroup::Regions1d; + +static const std::string CLASSNAME = "Regions1d"; + +namespace extract { + static auto label = [](auto &obj) { return &obj.label; }; + static auto outerDomainValue = [](auto &obj) { return &obj.outerDomainValue; }; + static auto axes = [](auto &obj) { return &obj.axes; }; + static auto XYs1d = [](auto &obj) { return &obj.XYs1d; }; +} + +using CPPAxes = containers::Axes; +using CPPXYs1d = containers::XYs1d; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstRegions1d +Regions1dDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Regions1d +Regions1dDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstRegions1d +Regions1dCreateConst( + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2XYs1d *const XYs1d, const size_t XYs1dSize +) { + ConstHandle2Regions1d handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + label, + outerDomainValue, + detail::tocpp(axes), + std::vector{} + ); + for (size_t XYs1dN = 0; XYs1dN < XYs1dSize; ++XYs1dN) + Regions1dXYs1dAdd(handle, XYs1d[XYs1dN]); + return handle; +} + +// Create, general +Handle2Regions1d +Regions1dCreate( + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2XYs1d *const XYs1d, const size_t XYs1dSize +) { + ConstHandle2Regions1d handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + label, + outerDomainValue, + detail::tocpp(axes), + std::vector{} + ); + for (size_t XYs1dN = 0; XYs1dN < XYs1dSize; ++XYs1dN) + Regions1dXYs1dAdd(handle, XYs1d[XYs1dN]); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +Regions1dAssign(ConstHandle2Regions1d self, ConstHandle2ConstRegions1d from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +Regions1dDelete(ConstHandle2ConstRegions1d self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +Regions1dRead(ConstHandle2Regions1d self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +Regions1dWrite(ConstHandle2ConstRegions1d self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +Regions1dPrint(ConstHandle2ConstRegions1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +Regions1dPrintXML(ConstHandle2ConstRegions1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +Regions1dPrintJSON(ConstHandle2ConstRegions1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// Has +int +Regions1dLabelHas(ConstHandle2ConstRegions1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LabelHas", self, extract::label); +} + +// Get +// Returns by value +const char * +Regions1dLabelGet(ConstHandle2ConstRegions1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LabelGet", self, extract::label); +} + +// Set +void +Regions1dLabelSet(ConstHandle2Regions1d self, const char *const label) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LabelSet", self, extract::label, label); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: outerDomainValue +// ----------------------------------------------------------------------------- + +// Has +int +Regions1dOuterDomainValueHas(ConstHandle2ConstRegions1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"OuterDomainValueHas", self, extract::outerDomainValue); +} + +// Get +// Returns by value +double +Regions1dOuterDomainValueGet(ConstHandle2ConstRegions1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"OuterDomainValueGet", self, extract::outerDomainValue); +} + +// Set +void +Regions1dOuterDomainValueSet(ConstHandle2Regions1d self, const double outerDomainValue) +{ + detail::setField + (CLASSNAME, CLASSNAME+"OuterDomainValueSet", self, extract::outerDomainValue, outerDomainValue); +} + + +// ----------------------------------------------------------------------------- +// Child: axes +// ----------------------------------------------------------------------------- + +// Has +int +Regions1dAxesHas(ConstHandle2ConstRegions1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"AxesHas", self, extract::axes); +} + +// Get, const +Handle2ConstAxes +Regions1dAxesGetConst(ConstHandle2ConstRegions1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"AxesGetConst", self, extract::axes); +} + +// Get, non-const +Handle2Axes +Regions1dAxesGet(ConstHandle2Regions1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"AxesGet", self, extract::axes); +} + +// Set +void +Regions1dAxesSet(ConstHandle2Regions1d self, ConstHandle2ConstAxes axes) +{ + detail::setField + (CLASSNAME, CLASSNAME+"AxesSet", self, extract::axes, axes); +} + + +// ----------------------------------------------------------------------------- +// Child: XYs1d +// ----------------------------------------------------------------------------- + +// Has +int +Regions1dXYs1dHas(ConstHandle2ConstRegions1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"XYs1dHas", self, extract::XYs1d); +} + +// Clear +void +Regions1dXYs1dClear(ConstHandle2Regions1d self) +{ + detail::clearContainer + (CLASSNAME, CLASSNAME+"XYs1dClear", self, extract::XYs1d); +} + +// Size +size_t +Regions1dXYs1dSize(ConstHandle2ConstRegions1d self) +{ + return detail::sizeOfContainer + (CLASSNAME, CLASSNAME+"XYs1dSize", self, extract::XYs1d); +} + +// Add +void +Regions1dXYs1dAdd(ConstHandle2Regions1d self, ConstHandle2ConstXYs1d XYs1d) +{ + detail::addToContainer + (CLASSNAME, CLASSNAME+"XYs1dAdd", self, extract::XYs1d, XYs1d); +} + +// Get, by index \in [0,size), const +Handle2ConstXYs1d +Regions1dXYs1dGetConst(ConstHandle2ConstRegions1d self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"XYs1dGetConst", self, extract::XYs1d, index_); +} + +// Get, by index \in [0,size), non-const +Handle2XYs1d +Regions1dXYs1dGet(ConstHandle2Regions1d self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"XYs1dGet", self, extract::XYs1d, index_); +} + +// Set, by index \in [0,size) +void +Regions1dXYs1dSet( + ConstHandle2Regions1d self, + const size_t index_, + ConstHandle2ConstXYs1d XYs1d +) { + detail::setByIndex + (CLASSNAME, CLASSNAME+"XYs1dSet", self, extract::XYs1d, index_, XYs1d); +} + +// Has, by index +int +Regions1dXYs1dHasByIndex( + ConstHandle2ConstRegions1d self, + const int index +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dHasByIndex", + self, extract::XYs1d, meta::index, index); +} + +// Get, by index, const +Handle2ConstXYs1d +Regions1dXYs1dGetByIndexConst( + ConstHandle2ConstRegions1d self, + const int index +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByIndexConst", + self, extract::XYs1d, meta::index, index); +} + +// Get, by index, non-const +Handle2XYs1d +Regions1dXYs1dGetByIndex( + ConstHandle2Regions1d self, + const int index +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByIndex", + self, extract::XYs1d, meta::index, index); +} + +// Set, by index +void +Regions1dXYs1dSetByIndex( + ConstHandle2Regions1d self, + const int index, + ConstHandle2ConstXYs1d XYs1d +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dSetByIndex", + self, extract::XYs1d, meta::index, index, XYs1d); +} + +// Has, by interpolation +int +Regions1dXYs1dHasByInterpolation( + ConstHandle2ConstRegions1d self, + const enums::Interpolation interpolation +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dHasByInterpolation", + self, extract::XYs1d, meta::interpolation, interpolation); +} + +// Get, by interpolation, const +Handle2ConstXYs1d +Regions1dXYs1dGetByInterpolationConst( + ConstHandle2ConstRegions1d self, + const enums::Interpolation interpolation +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByInterpolationConst", + self, extract::XYs1d, meta::interpolation, interpolation); +} + +// Get, by interpolation, non-const +Handle2XYs1d +Regions1dXYs1dGetByInterpolation( + ConstHandle2Regions1d self, + const enums::Interpolation interpolation +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByInterpolation", + self, extract::XYs1d, meta::interpolation, interpolation); +} + +// Set, by interpolation +void +Regions1dXYs1dSetByInterpolation( + ConstHandle2Regions1d self, + const enums::Interpolation interpolation, + ConstHandle2ConstXYs1d XYs1d +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dSetByInterpolation", + self, extract::XYs1d, meta::interpolation, interpolation, XYs1d); +} + +// Has, by label +int +Regions1dXYs1dHasByLabel( + ConstHandle2ConstRegions1d self, + const char *const label +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dHasByLabel", + self, extract::XYs1d, meta::label, label); +} + +// Get, by label, const +Handle2ConstXYs1d +Regions1dXYs1dGetByLabelConst( + ConstHandle2ConstRegions1d self, + const char *const label +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByLabelConst", + self, extract::XYs1d, meta::label, label); +} + +// Get, by label, non-const +Handle2XYs1d +Regions1dXYs1dGetByLabel( + ConstHandle2Regions1d self, + const char *const label +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByLabel", + self, extract::XYs1d, meta::label, label); +} + +// Set, by label +void +Regions1dXYs1dSetByLabel( + ConstHandle2Regions1d self, + const char *const label, + ConstHandle2ConstXYs1d XYs1d +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dSetByLabel", + self, extract::XYs1d, meta::label, label, XYs1d); +} + +// Has, by outerDomainValue +int +Regions1dXYs1dHasByOuterDomainValue( + ConstHandle2ConstRegions1d self, + const double outerDomainValue +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dHasByOuterDomainValue", + self, extract::XYs1d, meta::outerDomainValue, outerDomainValue); +} + +// Get, by outerDomainValue, const +Handle2ConstXYs1d +Regions1dXYs1dGetByOuterDomainValueConst( + ConstHandle2ConstRegions1d self, + const double outerDomainValue +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByOuterDomainValueConst", + self, extract::XYs1d, meta::outerDomainValue, outerDomainValue); +} + +// Get, by outerDomainValue, non-const +Handle2XYs1d +Regions1dXYs1dGetByOuterDomainValue( + ConstHandle2Regions1d self, + const double outerDomainValue +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dGetByOuterDomainValue", + self, extract::XYs1d, meta::outerDomainValue, outerDomainValue); +} + +// Set, by outerDomainValue +void +Regions1dXYs1dSetByOuterDomainValue( + ConstHandle2Regions1d self, + const double outerDomainValue, + ConstHandle2ConstXYs1d XYs1d +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"XYs1dSetByOuterDomainValue", + self, extract::XYs1d, meta::outerDomainValue, outerDomainValue, XYs1d); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Regions1d/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.h b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.h new file mode 100644 index 000000000..9996e0839 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d.h @@ -0,0 +1,357 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Regions1d is the basic handle type in this file. Example: +// // Create a default Regions1d object: +// Regions1d handle = Regions1dDefault(); +// Functions involving Regions1d are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_REGIONS1D +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_REGIONS1D + +#include "GNDStk.h" +#include "v1.9/containers/Axes.h" +#include "v1.9/containers/XYs1d.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct Regions1dClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Regions1d +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct Regions1dClass *Regions1d; + +// --- Const-aware handles. +typedef const struct Regions1dClass *const ConstHandle2ConstRegions1d; +typedef struct Regions1dClass *const ConstHandle2Regions1d; +typedef const struct Regions1dClass * Handle2ConstRegions1d; +typedef struct Regions1dClass * Handle2Regions1d; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstRegions1d +Regions1dDefaultConst(); + +// +++ Create, default +extern_c Handle2Regions1d +Regions1dDefault(); + +// --- Create, general, const +extern_c Handle2ConstRegions1d +Regions1dCreateConst( + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2XYs1d *const XYs1d, const size_t XYs1dSize +); + +// +++ Create, general +extern_c Handle2Regions1d +Regions1dCreate( + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2XYs1d *const XYs1d, const size_t XYs1dSize +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +Regions1dAssign(ConstHandle2Regions1d self, ConstHandle2ConstRegions1d from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +Regions1dDelete(ConstHandle2ConstRegions1d self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +Regions1dRead(ConstHandle2Regions1d self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +Regions1dWrite(ConstHandle2ConstRegions1d self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +Regions1dPrint(ConstHandle2ConstRegions1d self); + +// +++ Print to standard output, as XML +extern_c int +Regions1dPrintXML(ConstHandle2ConstRegions1d self); + +// +++ Print to standard output, as JSON +extern_c int +Regions1dPrintJSON(ConstHandle2ConstRegions1d self); + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +Regions1dLabelHas(ConstHandle2ConstRegions1d self); + +// +++ Get +// +++ Returns by value +extern_c const char * +Regions1dLabelGet(ConstHandle2ConstRegions1d self); + +// +++ Set +extern_c void +Regions1dLabelSet(ConstHandle2Regions1d self, const char *const label); + + +// ----------------------------------------------------------------------------- +// Metadatum: outerDomainValue +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +Regions1dOuterDomainValueHas(ConstHandle2ConstRegions1d self); + +// +++ Get +// +++ Returns by value +extern_c double +Regions1dOuterDomainValueGet(ConstHandle2ConstRegions1d self); + +// +++ Set +extern_c void +Regions1dOuterDomainValueSet(ConstHandle2Regions1d self, const double outerDomainValue); + + +// ----------------------------------------------------------------------------- +// Child: axes +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +Regions1dAxesHas(ConstHandle2ConstRegions1d self); + +// --- Get, const +extern_c Handle2ConstAxes +Regions1dAxesGetConst(ConstHandle2ConstRegions1d self); + +// +++ Get, non-const +extern_c Handle2Axes +Regions1dAxesGet(ConstHandle2Regions1d self); + +// +++ Set +extern_c void +Regions1dAxesSet(ConstHandle2Regions1d self, ConstHandle2ConstAxes axes); + + +// ----------------------------------------------------------------------------- +// Child: XYs1d +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +Regions1dXYs1dHas(ConstHandle2ConstRegions1d self); + +// +++ Clear +extern_c void +Regions1dXYs1dClear(ConstHandle2Regions1d self); + +// +++ Size +extern_c size_t +Regions1dXYs1dSize(ConstHandle2ConstRegions1d self); + +// +++ Add +extern_c void +Regions1dXYs1dAdd(ConstHandle2Regions1d self, ConstHandle2ConstXYs1d XYs1d); + +// --- Get, by index \in [0,size), const +extern_c Handle2ConstXYs1d +Regions1dXYs1dGetConst(ConstHandle2ConstRegions1d self, const size_t index_); + +// +++ Get, by index \in [0,size), non-const +extern_c Handle2XYs1d +Regions1dXYs1dGet(ConstHandle2Regions1d self, const size_t index_); + +// +++ Set, by index \in [0,size) +extern_c void +Regions1dXYs1dSet( + ConstHandle2Regions1d self, + const size_t index_, + ConstHandle2ConstXYs1d XYs1d +); + +// +++ Has, by index +extern_c int +Regions1dXYs1dHasByIndex( + ConstHandle2ConstRegions1d self, + const int index +); + +// --- Get, by index, const +extern_c Handle2ConstXYs1d +Regions1dXYs1dGetByIndexConst( + ConstHandle2ConstRegions1d self, + const int index +); + +// +++ Get, by index, non-const +extern_c Handle2XYs1d +Regions1dXYs1dGetByIndex( + ConstHandle2Regions1d self, + const int index +); + +// +++ Set, by index +extern_c void +Regions1dXYs1dSetByIndex( + ConstHandle2Regions1d self, + const int index, + ConstHandle2ConstXYs1d XYs1d +); + +// +++ Has, by interpolation +extern_c int +Regions1dXYs1dHasByInterpolation( + ConstHandle2ConstRegions1d self, + const enums::Interpolation interpolation +); + +// --- Get, by interpolation, const +extern_c Handle2ConstXYs1d +Regions1dXYs1dGetByInterpolationConst( + ConstHandle2ConstRegions1d self, + const enums::Interpolation interpolation +); + +// +++ Get, by interpolation, non-const +extern_c Handle2XYs1d +Regions1dXYs1dGetByInterpolation( + ConstHandle2Regions1d self, + const enums::Interpolation interpolation +); + +// +++ Set, by interpolation +extern_c void +Regions1dXYs1dSetByInterpolation( + ConstHandle2Regions1d self, + const enums::Interpolation interpolation, + ConstHandle2ConstXYs1d XYs1d +); + +// +++ Has, by label +extern_c int +Regions1dXYs1dHasByLabel( + ConstHandle2ConstRegions1d self, + const char *const label +); + +// --- Get, by label, const +extern_c Handle2ConstXYs1d +Regions1dXYs1dGetByLabelConst( + ConstHandle2ConstRegions1d self, + const char *const label +); + +// +++ Get, by label, non-const +extern_c Handle2XYs1d +Regions1dXYs1dGetByLabel( + ConstHandle2Regions1d self, + const char *const label +); + +// +++ Set, by label +extern_c void +Regions1dXYs1dSetByLabel( + ConstHandle2Regions1d self, + const char *const label, + ConstHandle2ConstXYs1d XYs1d +); + +// +++ Has, by outerDomainValue +extern_c int +Regions1dXYs1dHasByOuterDomainValue( + ConstHandle2ConstRegions1d self, + const double outerDomainValue +); + +// --- Get, by outerDomainValue, const +extern_c Handle2ConstXYs1d +Regions1dXYs1dGetByOuterDomainValueConst( + ConstHandle2ConstRegions1d self, + const double outerDomainValue +); + +// +++ Get, by outerDomainValue, non-const +extern_c Handle2XYs1d +Regions1dXYs1dGetByOuterDomainValue( + ConstHandle2Regions1d self, + const double outerDomainValue +); + +// +++ Set, by outerDomainValue +extern_c void +Regions1dXYs1dSetByOuterDomainValue( + ConstHandle2Regions1d self, + const double outerDomainValue, + ConstHandle2ConstXYs1d XYs1d +); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Regions1d/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Regions1d/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Regions1d/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Regions1d/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Values.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Values.cpp new file mode 100644 index 000000000..4e6e86515 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Values.cpp @@ -0,0 +1,495 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/Values.hpp" +#include "Values.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = ValuesClass; +using CPP = multigroup::Values; + +static const std::string CLASSNAME = "Values"; + +namespace extract { + static auto valueType = [](auto &obj) { return &obj.valueType; }; + static auto start = [](auto &obj) { return &obj.start; }; + static auto length = [](auto &obj) { return &obj.length; }; +} + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstValues +ValuesDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Values +ValuesDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstValues +ValuesCreateConst( + const char *const valueType, + const int start, + const int length +) { + ConstHandle2Values handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + valueType, + start, + length + ); + return handle; +} + +// Create, general +Handle2Values +ValuesCreate( + const char *const valueType, + const int start, + const int length +) { + ConstHandle2Values handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + valueType, + start, + length + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +ValuesAssign(ConstHandle2Values self, ConstHandle2ConstValues from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +ValuesDelete(ConstHandle2ConstValues self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +ValuesRead(ConstHandle2Values self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +ValuesWrite(ConstHandle2ConstValues self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +ValuesPrint(ConstHandle2ConstValues self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +ValuesPrintXML(ConstHandle2ConstValues self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +ValuesPrintJSON(ConstHandle2ConstValues self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Data vector +// ----------------------------------------------------------------------------- + +// ------------------------ +// int +// ------------------------ + +// Clear +void +ValuesIntsClear(ConstHandle2Values self) +{ + detail::vectorClear + (CLASSNAME, CLASSNAME+"IntsClear", self); +} + +// Get size +size_t +ValuesIntsSize(ConstHandle2ConstValues self) +{ + return detail::vectorSize + (CLASSNAME, CLASSNAME+"IntsSize", self); +} + +// Get value +// By index \in [0,size) +int +ValuesIntsGet(ConstHandle2ConstValues self, const size_t index) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"IntsGet", self, index); +} + +// Set value +// By index \in [0,size) +void +ValuesIntsSet(ConstHandle2Values self, const size_t index, const int value) +{ + detail::vectorSet + (CLASSNAME, CLASSNAME+"IntsSet", self, index, value); +} + +// Get pointer to existing values, const +const int * +ValuesIntsGetArrayConst(ConstHandle2ConstValues self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"IntsGetArrayConst", self); +} + +// Get pointer to existing values, non-const +int * +ValuesIntsGetArray(ConstHandle2Values self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"IntsGetArray", self); +} + +// Set completely new values and size +void +ValuesIntsSetArray(ConstHandle2Values self, const int *const values, const size_t size) +{ + return detail::vectorSet + (CLASSNAME, CLASSNAME+"IntsSetArray", self, size, values); +} + +// ------------------------ +// unsigned +// ------------------------ + +// Clear +void +ValuesUnsignedsClear(ConstHandle2Values self) +{ + detail::vectorClear + (CLASSNAME, CLASSNAME+"UnsignedsClear", self); +} + +// Get size +size_t +ValuesUnsignedsSize(ConstHandle2ConstValues self) +{ + return detail::vectorSize + (CLASSNAME, CLASSNAME+"UnsignedsSize", self); +} + +// Get value +// By index \in [0,size) +unsigned +ValuesUnsignedsGet(ConstHandle2ConstValues self, const size_t index) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"UnsignedsGet", self, index); +} + +// Set value +// By index \in [0,size) +void +ValuesUnsignedsSet(ConstHandle2Values self, const size_t index, const unsigned value) +{ + detail::vectorSet + (CLASSNAME, CLASSNAME+"UnsignedsSet", self, index, value); +} + +// Get pointer to existing values, const +const unsigned * +ValuesUnsignedsGetArrayConst(ConstHandle2ConstValues self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"UnsignedsGetArrayConst", self); +} + +// Get pointer to existing values, non-const +unsigned * +ValuesUnsignedsGetArray(ConstHandle2Values self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"UnsignedsGetArray", self); +} + +// Set completely new values and size +void +ValuesUnsignedsSetArray(ConstHandle2Values self, const unsigned *const values, const size_t size) +{ + return detail::vectorSet + (CLASSNAME, CLASSNAME+"UnsignedsSetArray", self, size, values); +} + +// ------------------------ +// float +// ------------------------ + +// Clear +void +ValuesFloatsClear(ConstHandle2Values self) +{ + detail::vectorClear + (CLASSNAME, CLASSNAME+"FloatsClear", self); +} + +// Get size +size_t +ValuesFloatsSize(ConstHandle2ConstValues self) +{ + return detail::vectorSize + (CLASSNAME, CLASSNAME+"FloatsSize", self); +} + +// Get value +// By index \in [0,size) +float +ValuesFloatsGet(ConstHandle2ConstValues self, const size_t index) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"FloatsGet", self, index); +} + +// Set value +// By index \in [0,size) +void +ValuesFloatsSet(ConstHandle2Values self, const size_t index, const float value) +{ + detail::vectorSet + (CLASSNAME, CLASSNAME+"FloatsSet", self, index, value); +} + +// Get pointer to existing values, const +const float * +ValuesFloatsGetArrayConst(ConstHandle2ConstValues self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"FloatsGetArrayConst", self); +} + +// Get pointer to existing values, non-const +float * +ValuesFloatsGetArray(ConstHandle2Values self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"FloatsGetArray", self); +} + +// Set completely new values and size +void +ValuesFloatsSetArray(ConstHandle2Values self, const float *const values, const size_t size) +{ + return detail::vectorSet + (CLASSNAME, CLASSNAME+"FloatsSetArray", self, size, values); +} + +// ------------------------ +// double +// ------------------------ + +// Clear +void +ValuesDoublesClear(ConstHandle2Values self) +{ + detail::vectorClear + (CLASSNAME, CLASSNAME+"DoublesClear", self); +} + +// Get size +size_t +ValuesDoublesSize(ConstHandle2ConstValues self) +{ + return detail::vectorSize + (CLASSNAME, CLASSNAME+"DoublesSize", self); +} + +// Get value +// By index \in [0,size) +double +ValuesDoublesGet(ConstHandle2ConstValues self, const size_t index) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGet", self, index); +} + +// Set value +// By index \in [0,size) +void +ValuesDoublesSet(ConstHandle2Values self, const size_t index, const double value) +{ + detail::vectorSet + (CLASSNAME, CLASSNAME+"DoublesSet", self, index, value); +} + +// Get pointer to existing values, const +const double * +ValuesDoublesGetArrayConst(ConstHandle2ConstValues self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGetArrayConst", self); +} + +// Get pointer to existing values, non-const +double * +ValuesDoublesGetArray(ConstHandle2Values self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGetArray", self); +} + +// Set completely new values and size +void +ValuesDoublesSetArray(ConstHandle2Values self, const double *const values, const size_t size) +{ + return detail::vectorSet + (CLASSNAME, CLASSNAME+"DoublesSetArray", self, size, values); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: valueType +// ----------------------------------------------------------------------------- + +// Has +int +ValuesValueTypeHas(ConstHandle2ConstValues self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ValueTypeHas", self, extract::valueType); +} + +// Get +// Returns by value +const char * +ValuesValueTypeGet(ConstHandle2ConstValues self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ValueTypeGet", self, extract::valueType); +} + +// Set +void +ValuesValueTypeSet(ConstHandle2Values self, const char *const valueType) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ValueTypeSet", self, extract::valueType, valueType); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: start +// ----------------------------------------------------------------------------- + +// Has +int +ValuesStartHas(ConstHandle2ConstValues self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"StartHas", self, extract::start); +} + +// Get +// Returns by value +int +ValuesStartGet(ConstHandle2ConstValues self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"StartGet", self, extract::start); +} + +// Set +void +ValuesStartSet(ConstHandle2Values self, const int start) +{ + detail::setField + (CLASSNAME, CLASSNAME+"StartSet", self, extract::start, start); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: length +// ----------------------------------------------------------------------------- + +// Has +int +ValuesLengthHas(ConstHandle2ConstValues self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LengthHas", self, extract::length); +} + +// Get +// Returns by value +int +ValuesLengthGet(ConstHandle2ConstValues self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LengthGet", self, extract::length); +} + +// Set +void +ValuesLengthSet(ConstHandle2Values self, const int length) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LengthSet", self, extract::length, length); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Values/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Values.h b/autogen/prototype/proto/c/src/v1.9/containers/Values.h new file mode 100644 index 000000000..fefc409bb --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/Values.h @@ -0,0 +1,338 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Values is the basic handle type in this file. Example: +// // Create a default Values object: +// Values handle = ValuesDefault(); +// Functions involving Values are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_VALUES +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_VALUES + +#include "GNDStk.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct ValuesClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Values +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct ValuesClass *Values; + +// --- Const-aware handles. +typedef const struct ValuesClass *const ConstHandle2ConstValues; +typedef struct ValuesClass *const ConstHandle2Values; +typedef const struct ValuesClass * Handle2ConstValues; +typedef struct ValuesClass * Handle2Values; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstValues +ValuesDefaultConst(); + +// +++ Create, default +extern_c Handle2Values +ValuesDefault(); + +// --- Create, general, const +extern_c Handle2ConstValues +ValuesCreateConst( + const char *const valueType, + const int start, + const int length +); + +// +++ Create, general +extern_c Handle2Values +ValuesCreate( + const char *const valueType, + const int start, + const int length +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +ValuesAssign(ConstHandle2Values self, ConstHandle2ConstValues from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +ValuesDelete(ConstHandle2ConstValues self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +ValuesRead(ConstHandle2Values self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +ValuesWrite(ConstHandle2ConstValues self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +ValuesPrint(ConstHandle2ConstValues self); + +// +++ Print to standard output, as XML +extern_c int +ValuesPrintXML(ConstHandle2ConstValues self); + +// +++ Print to standard output, as JSON +extern_c int +ValuesPrintJSON(ConstHandle2ConstValues self); + + +// ----------------------------------------------------------------------------- +// Data vector +// ----------------------------------------------------------------------------- + +// ------------------------ +// int +// ------------------------ + +// +++ Clear +extern_c void +ValuesIntsClear(ConstHandle2Values self); + +// +++ Get size +extern_c size_t +ValuesIntsSize(ConstHandle2ConstValues self); + +// +++ Get value +// +++ By index \in [0,size) +extern_c int +ValuesIntsGet(ConstHandle2ConstValues self, const size_t index); + +// +++ Set value +// +++ By index \in [0,size) +extern_c void +ValuesIntsSet(ConstHandle2Values self, const size_t index, const int value); + +// --- Get pointer to existing values, const +extern_c const int * +ValuesIntsGetArrayConst(ConstHandle2ConstValues self); + +// +++ Get pointer to existing values, non-const +extern_c int * +ValuesIntsGetArray(ConstHandle2Values self); + +// +++ Set completely new values and size +extern_c void +ValuesIntsSetArray(ConstHandle2Values self, const int *const values, const size_t size); + +// ------------------------ +// unsigned +// ------------------------ + +// +++ Clear +extern_c void +ValuesUnsignedsClear(ConstHandle2Values self); + +// +++ Get size +extern_c size_t +ValuesUnsignedsSize(ConstHandle2ConstValues self); + +// +++ Get value +// +++ By index \in [0,size) +extern_c unsigned +ValuesUnsignedsGet(ConstHandle2ConstValues self, const size_t index); + +// +++ Set value +// +++ By index \in [0,size) +extern_c void +ValuesUnsignedsSet(ConstHandle2Values self, const size_t index, const unsigned value); + +// --- Get pointer to existing values, const +extern_c const unsigned * +ValuesUnsignedsGetArrayConst(ConstHandle2ConstValues self); + +// +++ Get pointer to existing values, non-const +extern_c unsigned * +ValuesUnsignedsGetArray(ConstHandle2Values self); + +// +++ Set completely new values and size +extern_c void +ValuesUnsignedsSetArray(ConstHandle2Values self, const unsigned *const values, const size_t size); + +// ------------------------ +// float +// ------------------------ + +// +++ Clear +extern_c void +ValuesFloatsClear(ConstHandle2Values self); + +// +++ Get size +extern_c size_t +ValuesFloatsSize(ConstHandle2ConstValues self); + +// +++ Get value +// +++ By index \in [0,size) +extern_c float +ValuesFloatsGet(ConstHandle2ConstValues self, const size_t index); + +// +++ Set value +// +++ By index \in [0,size) +extern_c void +ValuesFloatsSet(ConstHandle2Values self, const size_t index, const float value); + +// --- Get pointer to existing values, const +extern_c const float * +ValuesFloatsGetArrayConst(ConstHandle2ConstValues self); + +// +++ Get pointer to existing values, non-const +extern_c float * +ValuesFloatsGetArray(ConstHandle2Values self); + +// +++ Set completely new values and size +extern_c void +ValuesFloatsSetArray(ConstHandle2Values self, const float *const values, const size_t size); + +// ------------------------ +// double +// ------------------------ + +// +++ Clear +extern_c void +ValuesDoublesClear(ConstHandle2Values self); + +// +++ Get size +extern_c size_t +ValuesDoublesSize(ConstHandle2ConstValues self); + +// +++ Get value +// +++ By index \in [0,size) +extern_c double +ValuesDoublesGet(ConstHandle2ConstValues self, const size_t index); + +// +++ Set value +// +++ By index \in [0,size) +extern_c void +ValuesDoublesSet(ConstHandle2Values self, const size_t index, const double value); + +// --- Get pointer to existing values, const +extern_c const double * +ValuesDoublesGetArrayConst(ConstHandle2ConstValues self); + +// +++ Get pointer to existing values, non-const +extern_c double * +ValuesDoublesGetArray(ConstHandle2Values self); + +// +++ Set completely new values and size +extern_c void +ValuesDoublesSetArray(ConstHandle2Values self, const double *const values, const size_t size); + + +// ----------------------------------------------------------------------------- +// Metadatum: valueType +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ValuesValueTypeHas(ConstHandle2ConstValues self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ValuesValueTypeGet(ConstHandle2ConstValues self); + +// +++ Set +extern_c void +ValuesValueTypeSet(ConstHandle2Values self, const char *const valueType); + + +// ----------------------------------------------------------------------------- +// Metadatum: start +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ValuesStartHas(ConstHandle2ConstValues self); + +// +++ Get +// +++ Returns by value +extern_c int +ValuesStartGet(ConstHandle2ConstValues self); + +// +++ Set +extern_c void +ValuesStartSet(ConstHandle2Values self, const int start); + + +// ----------------------------------------------------------------------------- +// Metadatum: length +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ValuesLengthHas(ConstHandle2ConstValues self); + +// +++ Get +// +++ Returns by value +extern_c int +ValuesLengthGet(ConstHandle2ConstValues self); + +// +++ Set +extern_c void +ValuesLengthSet(ConstHandle2Values self, const int length); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/Values/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Values/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/Values/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/Values/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/Values/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.cpp b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.cpp new file mode 100644 index 000000000..c20b5a6d3 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.cpp @@ -0,0 +1,364 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/containers/XYs1d.hpp" +#include "XYs1d.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = XYs1dClass; +using CPP = multigroup::XYs1d; + +static const std::string CLASSNAME = "XYs1d"; + +namespace extract { + static auto index = [](auto &obj) { return &obj.index; }; + static auto interpolation = [](auto &obj) { return &obj.interpolation; }; + static auto label = [](auto &obj) { return &obj.label; }; + static auto outerDomainValue = [](auto &obj) { return &obj.outerDomainValue; }; + static auto axes = [](auto &obj) { return &obj.axes; }; + static auto values = [](auto &obj) { return &obj.values; }; +} + +using CPPAxes = containers::Axes; +using CPPValues = containers::Values; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstXYs1d +XYs1dDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2XYs1d +XYs1dDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstXYs1d +XYs1dCreateConst( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2ConstValues values +) { + ConstHandle2XYs1d handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + index, + interpolation, + label, + outerDomainValue, + detail::tocpp(axes), + detail::tocpp(values) + ); + return handle; +} + +// Create, general +Handle2XYs1d +XYs1dCreate( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2ConstValues values +) { + ConstHandle2XYs1d handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + index, + interpolation, + label, + outerDomainValue, + detail::tocpp(axes), + detail::tocpp(values) + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +XYs1dAssign(ConstHandle2XYs1d self, ConstHandle2ConstXYs1d from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +XYs1dDelete(ConstHandle2ConstXYs1d self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +XYs1dRead(ConstHandle2XYs1d self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +XYs1dWrite(ConstHandle2ConstXYs1d self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +XYs1dPrint(ConstHandle2ConstXYs1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +XYs1dPrintXML(ConstHandle2ConstXYs1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +XYs1dPrintJSON(ConstHandle2ConstXYs1d self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dIndexHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"IndexHas", self, extract::index); +} + +// Get +// Returns by value +int +XYs1dIndexGet(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"IndexGet", self, extract::index); +} + +// Set +void +XYs1dIndexSet(ConstHandle2XYs1d self, const int index) +{ + detail::setField + (CLASSNAME, CLASSNAME+"IndexSet", self, extract::index, index); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: interpolation +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dInterpolationHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"InterpolationHas", self, extract::interpolation); +} + +// Get +// Returns by value +enums::Interpolation +XYs1dInterpolationGet(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"InterpolationGet", self, extract::interpolation); +} + +// Set +void +XYs1dInterpolationSet(ConstHandle2XYs1d self, const enums::Interpolation interpolation) +{ + detail::setField + (CLASSNAME, CLASSNAME+"InterpolationSet", self, extract::interpolation, interpolation); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dLabelHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LabelHas", self, extract::label); +} + +// Get +// Returns by value +const char * +XYs1dLabelGet(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LabelGet", self, extract::label); +} + +// Set +void +XYs1dLabelSet(ConstHandle2XYs1d self, const char *const label) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LabelSet", self, extract::label, label); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: outerDomainValue +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dOuterDomainValueHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"OuterDomainValueHas", self, extract::outerDomainValue); +} + +// Get +// Returns by value +double +XYs1dOuterDomainValueGet(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"OuterDomainValueGet", self, extract::outerDomainValue); +} + +// Set +void +XYs1dOuterDomainValueSet(ConstHandle2XYs1d self, const double outerDomainValue) +{ + detail::setField + (CLASSNAME, CLASSNAME+"OuterDomainValueSet", self, extract::outerDomainValue, outerDomainValue); +} + + +// ----------------------------------------------------------------------------- +// Child: axes +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dAxesHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"AxesHas", self, extract::axes); +} + +// Get, const +Handle2ConstAxes +XYs1dAxesGetConst(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"AxesGetConst", self, extract::axes); +} + +// Get, non-const +Handle2Axes +XYs1dAxesGet(ConstHandle2XYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"AxesGet", self, extract::axes); +} + +// Set +void +XYs1dAxesSet(ConstHandle2XYs1d self, ConstHandle2ConstAxes axes) +{ + detail::setField + (CLASSNAME, CLASSNAME+"AxesSet", self, extract::axes, axes); +} + + +// ----------------------------------------------------------------------------- +// Child: values +// ----------------------------------------------------------------------------- + +// Has +int +XYs1dValuesHas(ConstHandle2ConstXYs1d self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ValuesHas", self, extract::values); +} + +// Get, const +Handle2ConstValues +XYs1dValuesGetConst(ConstHandle2ConstXYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ValuesGetConst", self, extract::values); +} + +// Get, non-const +Handle2Values +XYs1dValuesGet(ConstHandle2XYs1d self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ValuesGet", self, extract::values); +} + +// Set +void +XYs1dValuesSet(ConstHandle2XYs1d self, ConstHandle2ConstValues values) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ValuesSet", self, extract::values, values); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/XYs1d/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.h b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.h new file mode 100644 index 000000000..609d9b0da --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d.h @@ -0,0 +1,265 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// XYs1d is the basic handle type in this file. Example: +// // Create a default XYs1d object: +// XYs1d handle = XYs1dDefault(); +// Functions involving XYs1d are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_CONTAINERS_XYS1D +#define C_INTERFACE_PROTO_V1_9_CONTAINERS_XYS1D + +#include "GNDStk.h" +#include "v1.9/containers/Axes.h" +#include "v1.9/containers/Values.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct XYs1dClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ XYs1d +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct XYs1dClass *XYs1d; + +// --- Const-aware handles. +typedef const struct XYs1dClass *const ConstHandle2ConstXYs1d; +typedef struct XYs1dClass *const ConstHandle2XYs1d; +typedef const struct XYs1dClass * Handle2ConstXYs1d; +typedef struct XYs1dClass * Handle2XYs1d; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstXYs1d +XYs1dDefaultConst(); + +// +++ Create, default +extern_c Handle2XYs1d +XYs1dDefault(); + +// --- Create, general, const +extern_c Handle2ConstXYs1d +XYs1dCreateConst( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2ConstValues values +); + +// +++ Create, general +extern_c Handle2XYs1d +XYs1dCreate( + const int index, + const enums::Interpolation interpolation, + const char *const label, + const double outerDomainValue, + ConstHandle2ConstAxes axes, + ConstHandle2ConstValues values +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +XYs1dAssign(ConstHandle2XYs1d self, ConstHandle2ConstXYs1d from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +XYs1dDelete(ConstHandle2ConstXYs1d self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +XYs1dRead(ConstHandle2XYs1d self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +XYs1dWrite(ConstHandle2ConstXYs1d self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +XYs1dPrint(ConstHandle2ConstXYs1d self); + +// +++ Print to standard output, as XML +extern_c int +XYs1dPrintXML(ConstHandle2ConstXYs1d self); + +// +++ Print to standard output, as JSON +extern_c int +XYs1dPrintJSON(ConstHandle2ConstXYs1d self); + + +// ----------------------------------------------------------------------------- +// Metadatum: index +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dIndexHas(ConstHandle2ConstXYs1d self); + +// +++ Get +// +++ Returns by value +extern_c int +XYs1dIndexGet(ConstHandle2ConstXYs1d self); + +// +++ Set +extern_c void +XYs1dIndexSet(ConstHandle2XYs1d self, const int index); + + +// ----------------------------------------------------------------------------- +// Metadatum: interpolation +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dInterpolationHas(ConstHandle2ConstXYs1d self); + +// +++ Get +// +++ Returns by value +extern_c enums::Interpolation +XYs1dInterpolationGet(ConstHandle2ConstXYs1d self); + +// +++ Set +extern_c void +XYs1dInterpolationSet(ConstHandle2XYs1d self, const enums::Interpolation interpolation); + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dLabelHas(ConstHandle2ConstXYs1d self); + +// +++ Get +// +++ Returns by value +extern_c const char * +XYs1dLabelGet(ConstHandle2ConstXYs1d self); + +// +++ Set +extern_c void +XYs1dLabelSet(ConstHandle2XYs1d self, const char *const label); + + +// ----------------------------------------------------------------------------- +// Metadatum: outerDomainValue +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dOuterDomainValueHas(ConstHandle2ConstXYs1d self); + +// +++ Get +// +++ Returns by value +extern_c double +XYs1dOuterDomainValueGet(ConstHandle2ConstXYs1d self); + +// +++ Set +extern_c void +XYs1dOuterDomainValueSet(ConstHandle2XYs1d self, const double outerDomainValue); + + +// ----------------------------------------------------------------------------- +// Child: axes +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dAxesHas(ConstHandle2ConstXYs1d self); + +// --- Get, const +extern_c Handle2ConstAxes +XYs1dAxesGetConst(ConstHandle2ConstXYs1d self); + +// +++ Get, non-const +extern_c Handle2Axes +XYs1dAxesGet(ConstHandle2XYs1d self); + +// +++ Set +extern_c void +XYs1dAxesSet(ConstHandle2XYs1d self, ConstHandle2ConstAxes axes); + + +// ----------------------------------------------------------------------------- +// Child: values +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +XYs1dValuesHas(ConstHandle2ConstXYs1d self); + +// --- Get, const +extern_c Handle2ConstValues +XYs1dValuesGetConst(ConstHandle2ConstXYs1d self); + +// +++ Get, non-const +extern_c Handle2Values +XYs1dValuesGet(ConstHandle2XYs1d self); + +// +++ Set +extern_c void +XYs1dValuesSet(ConstHandle2XYs1d self, ConstHandle2ConstValues values); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/containers/XYs1d/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/containers/XYs1d/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/containers/XYs1d/src/custom.h b/autogen/prototype/proto/c/src/v1.9/containers/XYs1d/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.cpp b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.cpp new file mode 100644 index 000000000..39ca6079b --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.cpp @@ -0,0 +1,140 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/transport/CrossSection.hpp" +#include "CrossSection.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = CrossSectionClass; +using CPP = multigroup::CrossSection; + +static const std::string CLASSNAME = "CrossSection"; + +namespace extract { +} + +using CPPXYs1d = containers::XYs1d; +using CPPRegions1d = containers::Regions1d; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstCrossSection +CrossSectionDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2CrossSection +CrossSectionDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstCrossSection +CrossSectionCreateConst( +) { + ConstHandle2CrossSection handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst" + ); + return handle; +} + +// Create, general +Handle2CrossSection +CrossSectionCreate( +) { + ConstHandle2CrossSection handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create" + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +CrossSectionAssign(ConstHandle2CrossSection self, ConstHandle2ConstCrossSection from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +CrossSectionDelete(ConstHandle2ConstCrossSection self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +CrossSectionRead(ConstHandle2CrossSection self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +CrossSectionWrite(ConstHandle2ConstCrossSection self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +CrossSectionPrint(ConstHandle2ConstCrossSection self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +CrossSectionPrintXML(ConstHandle2ConstCrossSection self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +CrossSectionPrintJSON(ConstHandle2ConstCrossSection self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/CrossSection/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.h b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.h new file mode 100644 index 000000000..b4ef0e9c9 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection.h @@ -0,0 +1,139 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// CrossSection is the basic handle type in this file. Example: +// // Create a default CrossSection object: +// CrossSection handle = CrossSectionDefault(); +// Functions involving CrossSection are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_TRANSPORT_CROSSSECTION +#define C_INTERFACE_PROTO_V1_9_TRANSPORT_CROSSSECTION + +#include "GNDStk.h" +#include "v1.9/containers/XYs1d.h" +#include "v1.9/containers/Regions1d.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct CrossSectionClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ CrossSection +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct CrossSectionClass *CrossSection; + +// --- Const-aware handles. +typedef const struct CrossSectionClass *const ConstHandle2ConstCrossSection; +typedef struct CrossSectionClass *const ConstHandle2CrossSection; +typedef const struct CrossSectionClass * Handle2ConstCrossSection; +typedef struct CrossSectionClass * Handle2CrossSection; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstCrossSection +CrossSectionDefaultConst(); + +// +++ Create, default +extern_c Handle2CrossSection +CrossSectionDefault(); + +// --- Create, general, const +extern_c Handle2ConstCrossSection +CrossSectionCreateConst( +); + +// +++ Create, general +extern_c Handle2CrossSection +CrossSectionCreate( +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +CrossSectionAssign(ConstHandle2CrossSection self, ConstHandle2ConstCrossSection from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +CrossSectionDelete(ConstHandle2ConstCrossSection self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +CrossSectionRead(ConstHandle2CrossSection self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +CrossSectionWrite(ConstHandle2ConstCrossSection self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +CrossSectionPrint(ConstHandle2ConstCrossSection self); + +// +++ Print to standard output, as XML +extern_c int +CrossSectionPrintXML(ConstHandle2ConstCrossSection self); + +// +++ Print to standard output, as JSON +extern_c int +CrossSectionPrintJSON(ConstHandle2ConstCrossSection self); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/CrossSection/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/transport/CrossSection/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/CrossSection/src/custom.h b/autogen/prototype/proto/c/src/v1.9/transport/CrossSection/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reaction.cpp b/autogen/prototype/proto/c/src/v1.9/transport/Reaction.cpp new file mode 100644 index 000000000..378e5db3c --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/Reaction.cpp @@ -0,0 +1,286 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/transport/Reaction.hpp" +#include "Reaction.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = ReactionClass; +using CPP = multigroup::Reaction; + +static const std::string CLASSNAME = "Reaction"; + +namespace extract { + static auto ENDF_MT = [](auto &obj) { return &obj.ENDF_MT; }; + static auto fissionGenre = [](auto &obj) { return &obj.fissionGenre; }; + static auto label = [](auto &obj) { return &obj.label; }; + static auto crossSection = [](auto &obj) { return &obj.crossSection; }; +} + +using CPPCrossSection = transport::CrossSection; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstReaction +ReactionDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Reaction +ReactionDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstReaction +ReactionCreateConst( + const int ENDF_MT, + const char *const fissionGenre, + const char *const label, + ConstHandle2ConstCrossSection crossSection +) { + ConstHandle2Reaction handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + ENDF_MT, + fissionGenre, + label, + detail::tocpp(crossSection) + ); + return handle; +} + +// Create, general +Handle2Reaction +ReactionCreate( + const int ENDF_MT, + const char *const fissionGenre, + const char *const label, + ConstHandle2ConstCrossSection crossSection +) { + ConstHandle2Reaction handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + ENDF_MT, + fissionGenre, + label, + detail::tocpp(crossSection) + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +ReactionAssign(ConstHandle2Reaction self, ConstHandle2ConstReaction from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +ReactionDelete(ConstHandle2ConstReaction self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +ReactionRead(ConstHandle2Reaction self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +ReactionWrite(ConstHandle2ConstReaction self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +ReactionPrint(ConstHandle2ConstReaction self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +ReactionPrintXML(ConstHandle2ConstReaction self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +ReactionPrintJSON(ConstHandle2ConstReaction self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: ENDF_MT +// ----------------------------------------------------------------------------- + +// Has +int +ReactionENDFMTHas(ConstHandle2ConstReaction self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ENDFMTHas", self, extract::ENDF_MT); +} + +// Get +// Returns by value +int +ReactionENDFMTGet(ConstHandle2ConstReaction self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ENDFMTGet", self, extract::ENDF_MT); +} + +// Set +void +ReactionENDFMTSet(ConstHandle2Reaction self, const int ENDF_MT) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ENDFMTSet", self, extract::ENDF_MT, ENDF_MT); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: fissionGenre +// ----------------------------------------------------------------------------- + +// Has +int +ReactionFissionGenreHas(ConstHandle2ConstReaction self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"FissionGenreHas", self, extract::fissionGenre); +} + +// Get +// Returns by value +const char * +ReactionFissionGenreGet(ConstHandle2ConstReaction self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"FissionGenreGet", self, extract::fissionGenre); +} + +// Set +void +ReactionFissionGenreSet(ConstHandle2Reaction self, const char *const fissionGenre) +{ + detail::setField + (CLASSNAME, CLASSNAME+"FissionGenreSet", self, extract::fissionGenre, fissionGenre); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// Has +int +ReactionLabelHas(ConstHandle2ConstReaction self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LabelHas", self, extract::label); +} + +// Get +// Returns by value +const char * +ReactionLabelGet(ConstHandle2ConstReaction self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"LabelGet", self, extract::label); +} + +// Set +void +ReactionLabelSet(ConstHandle2Reaction self, const char *const label) +{ + detail::setField + (CLASSNAME, CLASSNAME+"LabelSet", self, extract::label, label); +} + + +// ----------------------------------------------------------------------------- +// Child: crossSection +// ----------------------------------------------------------------------------- + +// Has +int +ReactionCrossSectionHas(ConstHandle2ConstReaction self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"CrossSectionHas", self, extract::crossSection); +} + +// Get, const +Handle2ConstCrossSection +ReactionCrossSectionGetConst(ConstHandle2ConstReaction self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"CrossSectionGetConst", self, extract::crossSection); +} + +// Get, non-const +Handle2CrossSection +ReactionCrossSectionGet(ConstHandle2Reaction self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"CrossSectionGet", self, extract::crossSection); +} + +// Set +void +ReactionCrossSectionSet(ConstHandle2Reaction self, ConstHandle2ConstCrossSection crossSection) +{ + detail::setField + (CLASSNAME, CLASSNAME+"CrossSectionSet", self, extract::crossSection, crossSection); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/Reaction/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reaction.h b/autogen/prototype/proto/c/src/v1.9/transport/Reaction.h new file mode 100644 index 000000000..564b14471 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/Reaction.h @@ -0,0 +1,221 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Reaction is the basic handle type in this file. Example: +// // Create a default Reaction object: +// Reaction handle = ReactionDefault(); +// Functions involving Reaction are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTION +#define C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTION + +#include "GNDStk.h" +#include "v1.9/transport/CrossSection.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct ReactionClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Reaction +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct ReactionClass *Reaction; + +// --- Const-aware handles. +typedef const struct ReactionClass *const ConstHandle2ConstReaction; +typedef struct ReactionClass *const ConstHandle2Reaction; +typedef const struct ReactionClass * Handle2ConstReaction; +typedef struct ReactionClass * Handle2Reaction; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstReaction +ReactionDefaultConst(); + +// +++ Create, default +extern_c Handle2Reaction +ReactionDefault(); + +// --- Create, general, const +extern_c Handle2ConstReaction +ReactionCreateConst( + const int ENDF_MT, + const char *const fissionGenre, + const char *const label, + ConstHandle2ConstCrossSection crossSection +); + +// +++ Create, general +extern_c Handle2Reaction +ReactionCreate( + const int ENDF_MT, + const char *const fissionGenre, + const char *const label, + ConstHandle2ConstCrossSection crossSection +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +ReactionAssign(ConstHandle2Reaction self, ConstHandle2ConstReaction from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +ReactionDelete(ConstHandle2ConstReaction self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +ReactionRead(ConstHandle2Reaction self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +ReactionWrite(ConstHandle2ConstReaction self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +ReactionPrint(ConstHandle2ConstReaction self); + +// +++ Print to standard output, as XML +extern_c int +ReactionPrintXML(ConstHandle2ConstReaction self); + +// +++ Print to standard output, as JSON +extern_c int +ReactionPrintJSON(ConstHandle2ConstReaction self); + + +// ----------------------------------------------------------------------------- +// Metadatum: ENDF_MT +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionENDFMTHas(ConstHandle2ConstReaction self); + +// +++ Get +// +++ Returns by value +extern_c int +ReactionENDFMTGet(ConstHandle2ConstReaction self); + +// +++ Set +extern_c void +ReactionENDFMTSet(ConstHandle2Reaction self, const int ENDF_MT); + + +// ----------------------------------------------------------------------------- +// Metadatum: fissionGenre +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionFissionGenreHas(ConstHandle2ConstReaction self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionFissionGenreGet(ConstHandle2ConstReaction self); + +// +++ Set +extern_c void +ReactionFissionGenreSet(ConstHandle2Reaction self, const char *const fissionGenre); + + +// ----------------------------------------------------------------------------- +// Metadatum: label +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionLabelHas(ConstHandle2ConstReaction self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionLabelGet(ConstHandle2ConstReaction self); + +// +++ Set +extern_c void +ReactionLabelSet(ConstHandle2Reaction self, const char *const label); + + +// ----------------------------------------------------------------------------- +// Child: crossSection +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionCrossSectionHas(ConstHandle2ConstReaction self); + +// --- Get, const +extern_c Handle2ConstCrossSection +ReactionCrossSectionGetConst(ConstHandle2ConstReaction self); + +// +++ Get, non-const +extern_c Handle2CrossSection +ReactionCrossSectionGet(ConstHandle2Reaction self); + +// +++ Set +extern_c void +ReactionCrossSectionSet(ConstHandle2Reaction self, ConstHandle2ConstCrossSection crossSection); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/Reaction/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reaction/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/transport/Reaction/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reaction/src/custom.h b/autogen/prototype/proto/c/src/v1.9/transport/Reaction/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.cpp b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.cpp new file mode 100644 index 000000000..09f1fae15 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.cpp @@ -0,0 +1,391 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/transport/ReactionSuite.hpp" +#include "ReactionSuite.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = ReactionSuiteClass; +using CPP = multigroup::ReactionSuite; + +static const std::string CLASSNAME = "ReactionSuite"; + +namespace extract { + static auto evaluation = [](auto &obj) { return &obj.evaluation; }; + static auto format = [](auto &obj) { return &obj.format; }; + static auto projectile = [](auto &obj) { return &obj.projectile; }; + static auto projectileFrame = [](auto &obj) { return &obj.projectileFrame; }; + static auto target = [](auto &obj) { return &obj.target; }; + static auto interaction = [](auto &obj) { return &obj.interaction; }; + static auto reactions = [](auto &obj) { return &obj.reactions; }; +} + +using CPPReactions = transport::Reactions; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstReactionSuite +ReactionSuiteDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2ReactionSuite +ReactionSuiteDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstReactionSuite +ReactionSuiteCreateConst( + const char *const evaluation, + const char *const format, + const char *const projectile, + const enums::Frame projectileFrame, + const char *const target, + const enums::Interaction interaction, + ConstHandle2ConstReactions reactions +) { + ConstHandle2ReactionSuite handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + evaluation, + format, + projectile, + projectileFrame, + target, + interaction, + detail::tocpp(reactions) + ); + return handle; +} + +// Create, general +Handle2ReactionSuite +ReactionSuiteCreate( + const char *const evaluation, + const char *const format, + const char *const projectile, + const enums::Frame projectileFrame, + const char *const target, + const enums::Interaction interaction, + ConstHandle2ConstReactions reactions +) { + ConstHandle2ReactionSuite handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + evaluation, + format, + projectile, + projectileFrame, + target, + interaction, + detail::tocpp(reactions) + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +ReactionSuiteAssign(ConstHandle2ReactionSuite self, ConstHandle2ConstReactionSuite from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +ReactionSuiteDelete(ConstHandle2ConstReactionSuite self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +ReactionSuiteRead(ConstHandle2ReactionSuite self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +ReactionSuiteWrite(ConstHandle2ConstReactionSuite self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +ReactionSuitePrint(ConstHandle2ConstReactionSuite self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +ReactionSuitePrintXML(ConstHandle2ConstReactionSuite self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +ReactionSuitePrintJSON(ConstHandle2ConstReactionSuite self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: evaluation +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteEvaluationHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"EvaluationHas", self, extract::evaluation); +} + +// Get +// Returns by value +const char * +ReactionSuiteEvaluationGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"EvaluationGet", self, extract::evaluation); +} + +// Set +void +ReactionSuiteEvaluationSet(ConstHandle2ReactionSuite self, const char *const evaluation) +{ + detail::setField + (CLASSNAME, CLASSNAME+"EvaluationSet", self, extract::evaluation, evaluation); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: format +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteFormatHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"FormatHas", self, extract::format); +} + +// Get +// Returns by value +const char * +ReactionSuiteFormatGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"FormatGet", self, extract::format); +} + +// Set +void +ReactionSuiteFormatSet(ConstHandle2ReactionSuite self, const char *const format) +{ + detail::setField + (CLASSNAME, CLASSNAME+"FormatSet", self, extract::format, format); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: projectile +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteProjectileHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ProjectileHas", self, extract::projectile); +} + +// Get +// Returns by value +const char * +ReactionSuiteProjectileGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ProjectileGet", self, extract::projectile); +} + +// Set +void +ReactionSuiteProjectileSet(ConstHandle2ReactionSuite self, const char *const projectile) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ProjectileSet", self, extract::projectile, projectile); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: projectileFrame +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteProjectileFrameHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ProjectileFrameHas", self, extract::projectileFrame); +} + +// Get +// Returns by value +enums::Frame +ReactionSuiteProjectileFrameGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ProjectileFrameGet", self, extract::projectileFrame); +} + +// Set +void +ReactionSuiteProjectileFrameSet(ConstHandle2ReactionSuite self, const enums::Frame projectileFrame) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ProjectileFrameSet", self, extract::projectileFrame, projectileFrame); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: target +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteTargetHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"TargetHas", self, extract::target); +} + +// Get +// Returns by value +const char * +ReactionSuiteTargetGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"TargetGet", self, extract::target); +} + +// Set +void +ReactionSuiteTargetSet(ConstHandle2ReactionSuite self, const char *const target) +{ + detail::setField + (CLASSNAME, CLASSNAME+"TargetSet", self, extract::target, target); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: interaction +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteInteractionHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"InteractionHas", self, extract::interaction); +} + +// Get +// Returns by value +enums::Interaction +ReactionSuiteInteractionGet(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"InteractionGet", self, extract::interaction); +} + +// Set +void +ReactionSuiteInteractionSet(ConstHandle2ReactionSuite self, const enums::Interaction interaction) +{ + detail::setField + (CLASSNAME, CLASSNAME+"InteractionSet", self, extract::interaction, interaction); +} + + +// ----------------------------------------------------------------------------- +// Child: reactions +// ----------------------------------------------------------------------------- + +// Has +int +ReactionSuiteReactionsHas(ConstHandle2ConstReactionSuite self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ReactionsHas", self, extract::reactions); +} + +// Get, const +Handle2ConstReactions +ReactionSuiteReactionsGetConst(ConstHandle2ConstReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ReactionsGetConst", self, extract::reactions); +} + +// Get, non-const +Handle2Reactions +ReactionSuiteReactionsGet(ConstHandle2ReactionSuite self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ReactionsGet", self, extract::reactions); +} + +// Set +void +ReactionSuiteReactionsSet(ConstHandle2ReactionSuite self, ConstHandle2ConstReactions reactions) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ReactionsSet", self, extract::reactions, reactions); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/ReactionSuite/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.h b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.h new file mode 100644 index 000000000..87b16f838 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite.h @@ -0,0 +1,281 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// ReactionSuite is the basic handle type in this file. Example: +// // Create a default ReactionSuite object: +// ReactionSuite handle = ReactionSuiteDefault(); +// Functions involving ReactionSuite are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTIONSUITE +#define C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTIONSUITE + +#include "GNDStk.h" +#include "v1.9/transport/Reactions.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct ReactionSuiteClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ ReactionSuite +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct ReactionSuiteClass *ReactionSuite; + +// --- Const-aware handles. +typedef const struct ReactionSuiteClass *const ConstHandle2ConstReactionSuite; +typedef struct ReactionSuiteClass *const ConstHandle2ReactionSuite; +typedef const struct ReactionSuiteClass * Handle2ConstReactionSuite; +typedef struct ReactionSuiteClass * Handle2ReactionSuite; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstReactionSuite +ReactionSuiteDefaultConst(); + +// +++ Create, default +extern_c Handle2ReactionSuite +ReactionSuiteDefault(); + +// --- Create, general, const +extern_c Handle2ConstReactionSuite +ReactionSuiteCreateConst( + const char *const evaluation, + const char *const format, + const char *const projectile, + const enums::Frame projectileFrame, + const char *const target, + const enums::Interaction interaction, + ConstHandle2ConstReactions reactions +); + +// +++ Create, general +extern_c Handle2ReactionSuite +ReactionSuiteCreate( + const char *const evaluation, + const char *const format, + const char *const projectile, + const enums::Frame projectileFrame, + const char *const target, + const enums::Interaction interaction, + ConstHandle2ConstReactions reactions +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +ReactionSuiteAssign(ConstHandle2ReactionSuite self, ConstHandle2ConstReactionSuite from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +ReactionSuiteDelete(ConstHandle2ConstReactionSuite self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +ReactionSuiteRead(ConstHandle2ReactionSuite self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +ReactionSuiteWrite(ConstHandle2ConstReactionSuite self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +ReactionSuitePrint(ConstHandle2ConstReactionSuite self); + +// +++ Print to standard output, as XML +extern_c int +ReactionSuitePrintXML(ConstHandle2ConstReactionSuite self); + +// +++ Print to standard output, as JSON +extern_c int +ReactionSuitePrintJSON(ConstHandle2ConstReactionSuite self); + + +// ----------------------------------------------------------------------------- +// Metadatum: evaluation +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteEvaluationHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionSuiteEvaluationGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteEvaluationSet(ConstHandle2ReactionSuite self, const char *const evaluation); + + +// ----------------------------------------------------------------------------- +// Metadatum: format +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteFormatHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionSuiteFormatGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteFormatSet(ConstHandle2ReactionSuite self, const char *const format); + + +// ----------------------------------------------------------------------------- +// Metadatum: projectile +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteProjectileHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionSuiteProjectileGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteProjectileSet(ConstHandle2ReactionSuite self, const char *const projectile); + + +// ----------------------------------------------------------------------------- +// Metadatum: projectileFrame +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteProjectileFrameHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c enums::Frame +ReactionSuiteProjectileFrameGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteProjectileFrameSet(ConstHandle2ReactionSuite self, const enums::Frame projectileFrame); + + +// ----------------------------------------------------------------------------- +// Metadatum: target +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteTargetHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ReactionSuiteTargetGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteTargetSet(ConstHandle2ReactionSuite self, const char *const target); + + +// ----------------------------------------------------------------------------- +// Metadatum: interaction +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteInteractionHas(ConstHandle2ConstReactionSuite self); + +// +++ Get +// +++ Returns by value +extern_c enums::Interaction +ReactionSuiteInteractionGet(ConstHandle2ConstReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteInteractionSet(ConstHandle2ReactionSuite self, const enums::Interaction interaction); + + +// ----------------------------------------------------------------------------- +// Child: reactions +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionSuiteReactionsHas(ConstHandle2ConstReactionSuite self); + +// --- Get, const +extern_c Handle2ConstReactions +ReactionSuiteReactionsGetConst(ConstHandle2ConstReactionSuite self); + +// +++ Get, non-const +extern_c Handle2Reactions +ReactionSuiteReactionsGet(ConstHandle2ReactionSuite self); + +// +++ Set +extern_c void +ReactionSuiteReactionsSet(ConstHandle2ReactionSuite self, ConstHandle2ConstReactions reactions); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/ReactionSuite/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite/src/custom.h b/autogen/prototype/proto/c/src/v1.9/transport/ReactionSuite/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reactions.cpp b/autogen/prototype/proto/c/src/v1.9/transport/Reactions.cpp new file mode 100644 index 000000000..f4440c436 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/Reactions.cpp @@ -0,0 +1,347 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "proto/v1_9/transport/Reactions.hpp" +#include "Reactions.h" + +using namespace njoy::GNDStk; +using namespace proto::v1_9; + +using C = ReactionsClass; +using CPP = multigroup::Reactions; + +static const std::string CLASSNAME = "Reactions"; + +namespace extract { + static auto reaction = [](auto &obj) { return &obj.reaction; }; +} + +using CPPReaction = transport::Reaction; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstReactions +ReactionsDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Reactions +ReactionsDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstReactions +ReactionsCreateConst( + ConstHandle2Reaction *const reaction, const size_t reactionSize +) { + ConstHandle2Reactions handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + std::vector{} + ); + for (size_t ReactionN = 0; ReactionN < reactionSize; ++ReactionN) + ReactionsReactionAdd(handle, reaction[ReactionN]); + return handle; +} + +// Create, general +Handle2Reactions +ReactionsCreate( + ConstHandle2Reaction *const reaction, const size_t reactionSize +) { + ConstHandle2Reactions handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + std::vector{} + ); + for (size_t ReactionN = 0; ReactionN < reactionSize; ++ReactionN) + ReactionsReactionAdd(handle, reaction[ReactionN]); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +ReactionsAssign(ConstHandle2Reactions self, ConstHandle2ConstReactions from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +ReactionsDelete(ConstHandle2ConstReactions self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +ReactionsRead(ConstHandle2Reactions self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +ReactionsWrite(ConstHandle2ConstReactions self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +ReactionsPrint(ConstHandle2ConstReactions self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +ReactionsPrintXML(ConstHandle2ConstReactions self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +ReactionsPrintJSON(ConstHandle2ConstReactions self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Child: reaction +// ----------------------------------------------------------------------------- + +// Has +int +ReactionsReactionHas(ConstHandle2ConstReactions self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ReactionHas", self, extract::reaction); +} + +// Clear +void +ReactionsReactionClear(ConstHandle2Reactions self) +{ + detail::clearContainer + (CLASSNAME, CLASSNAME+"ReactionClear", self, extract::reaction); +} + +// Size +size_t +ReactionsReactionSize(ConstHandle2ConstReactions self) +{ + return detail::sizeOfContainer + (CLASSNAME, CLASSNAME+"ReactionSize", self, extract::reaction); +} + +// Add +void +ReactionsReactionAdd(ConstHandle2Reactions self, ConstHandle2ConstReaction reaction) +{ + detail::addToContainer + (CLASSNAME, CLASSNAME+"ReactionAdd", self, extract::reaction, reaction); +} + +// Get, by index \in [0,size), const +Handle2ConstReaction +ReactionsReactionGetConst(ConstHandle2ConstReactions self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"ReactionGetConst", self, extract::reaction, index_); +} + +// Get, by index \in [0,size), non-const +Handle2Reaction +ReactionsReactionGet(ConstHandle2Reactions self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"ReactionGet", self, extract::reaction, index_); +} + +// Set, by index \in [0,size) +void +ReactionsReactionSet( + ConstHandle2Reactions self, + const size_t index_, + ConstHandle2ConstReaction reaction +) { + detail::setByIndex + (CLASSNAME, CLASSNAME+"ReactionSet", self, extract::reaction, index_, reaction); +} + +// Has, by ENDF_MT +int +ReactionsReactionHasByENDFMT( + ConstHandle2ConstReactions self, + const int ENDF_MT +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"ReactionHasByENDFMT", + self, extract::reaction, meta::ENDF_MT, ENDF_MT); +} + +// Get, by ENDF_MT, const +Handle2ConstReaction +ReactionsReactionGetByENDFMTConst( + ConstHandle2ConstReactions self, + const int ENDF_MT +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByENDFMTConst", + self, extract::reaction, meta::ENDF_MT, ENDF_MT); +} + +// Get, by ENDF_MT, non-const +Handle2Reaction +ReactionsReactionGetByENDFMT( + ConstHandle2Reactions self, + const int ENDF_MT +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByENDFMT", + self, extract::reaction, meta::ENDF_MT, ENDF_MT); +} + +// Set, by ENDF_MT +void +ReactionsReactionSetByENDFMT( + ConstHandle2Reactions self, + const int ENDF_MT, + ConstHandle2ConstReaction reaction +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"ReactionSetByENDFMT", + self, extract::reaction, meta::ENDF_MT, ENDF_MT, reaction); +} + +// Has, by fissionGenre +int +ReactionsReactionHasByFissionGenre( + ConstHandle2ConstReactions self, + const char *const fissionGenre +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"ReactionHasByFissionGenre", + self, extract::reaction, meta::fissionGenre, fissionGenre); +} + +// Get, by fissionGenre, const +Handle2ConstReaction +ReactionsReactionGetByFissionGenreConst( + ConstHandle2ConstReactions self, + const char *const fissionGenre +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByFissionGenreConst", + self, extract::reaction, meta::fissionGenre, fissionGenre); +} + +// Get, by fissionGenre, non-const +Handle2Reaction +ReactionsReactionGetByFissionGenre( + ConstHandle2Reactions self, + const char *const fissionGenre +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByFissionGenre", + self, extract::reaction, meta::fissionGenre, fissionGenre); +} + +// Set, by fissionGenre +void +ReactionsReactionSetByFissionGenre( + ConstHandle2Reactions self, + const char *const fissionGenre, + ConstHandle2ConstReaction reaction +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"ReactionSetByFissionGenre", + self, extract::reaction, meta::fissionGenre, fissionGenre, reaction); +} + +// Has, by label +int +ReactionsReactionHasByLabel( + ConstHandle2ConstReactions self, + const char *const label +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"ReactionHasByLabel", + self, extract::reaction, meta::label, label); +} + +// Get, by label, const +Handle2ConstReaction +ReactionsReactionGetByLabelConst( + ConstHandle2ConstReactions self, + const char *const label +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByLabelConst", + self, extract::reaction, meta::label, label); +} + +// Get, by label, non-const +Handle2Reaction +ReactionsReactionGetByLabel( + ConstHandle2Reactions self, + const char *const label +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ReactionGetByLabel", + self, extract::reaction, meta::label, label); +} + +// Set, by label +void +ReactionsReactionSetByLabel( + ConstHandle2Reactions self, + const char *const label, + ConstHandle2ConstReaction reaction +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"ReactionSetByLabel", + self, extract::reaction, meta::label, label, reaction); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/Reactions/src/custom.cpp" diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reactions.h b/autogen/prototype/proto/c/src/v1.9/transport/Reactions.h new file mode 100644 index 000000000..20d9c21d5 --- /dev/null +++ b/autogen/prototype/proto/c/src/v1.9/transport/Reactions.h @@ -0,0 +1,264 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Reactions is the basic handle type in this file. Example: +// // Create a default Reactions object: +// Reactions handle = ReactionsDefault(); +// Functions involving Reactions are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTIONS +#define C_INTERFACE_PROTO_V1_9_TRANSPORT_REACTIONS + +#include "GNDStk.h" +#include "v1.9/transport/Reaction.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct ReactionsClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Reactions +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct ReactionsClass *Reactions; + +// --- Const-aware handles. +typedef const struct ReactionsClass *const ConstHandle2ConstReactions; +typedef struct ReactionsClass *const ConstHandle2Reactions; +typedef const struct ReactionsClass * Handle2ConstReactions; +typedef struct ReactionsClass * Handle2Reactions; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstReactions +ReactionsDefaultConst(); + +// +++ Create, default +extern_c Handle2Reactions +ReactionsDefault(); + +// --- Create, general, const +extern_c Handle2ConstReactions +ReactionsCreateConst( + ConstHandle2Reaction *const reaction, const size_t reactionSize +); + +// +++ Create, general +extern_c Handle2Reactions +ReactionsCreate( + ConstHandle2Reaction *const reaction, const size_t reactionSize +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +ReactionsAssign(ConstHandle2Reactions self, ConstHandle2ConstReactions from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +ReactionsDelete(ConstHandle2ConstReactions self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +ReactionsRead(ConstHandle2Reactions self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +ReactionsWrite(ConstHandle2ConstReactions self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +ReactionsPrint(ConstHandle2ConstReactions self); + +// +++ Print to standard output, as XML +extern_c int +ReactionsPrintXML(ConstHandle2ConstReactions self); + +// +++ Print to standard output, as JSON +extern_c int +ReactionsPrintJSON(ConstHandle2ConstReactions self); + + +// ----------------------------------------------------------------------------- +// Child: reaction +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ReactionsReactionHas(ConstHandle2ConstReactions self); + +// +++ Clear +extern_c void +ReactionsReactionClear(ConstHandle2Reactions self); + +// +++ Size +extern_c size_t +ReactionsReactionSize(ConstHandle2ConstReactions self); + +// +++ Add +extern_c void +ReactionsReactionAdd(ConstHandle2Reactions self, ConstHandle2ConstReaction reaction); + +// --- Get, by index \in [0,size), const +extern_c Handle2ConstReaction +ReactionsReactionGetConst(ConstHandle2ConstReactions self, const size_t index_); + +// +++ Get, by index \in [0,size), non-const +extern_c Handle2Reaction +ReactionsReactionGet(ConstHandle2Reactions self, const size_t index_); + +// +++ Set, by index \in [0,size) +extern_c void +ReactionsReactionSet( + ConstHandle2Reactions self, + const size_t index_, + ConstHandle2ConstReaction reaction +); + +// +++ Has, by ENDF_MT +extern_c int +ReactionsReactionHasByENDFMT( + ConstHandle2ConstReactions self, + const int ENDF_MT +); + +// --- Get, by ENDF_MT, const +extern_c Handle2ConstReaction +ReactionsReactionGetByENDFMTConst( + ConstHandle2ConstReactions self, + const int ENDF_MT +); + +// +++ Get, by ENDF_MT, non-const +extern_c Handle2Reaction +ReactionsReactionGetByENDFMT( + ConstHandle2Reactions self, + const int ENDF_MT +); + +// +++ Set, by ENDF_MT +extern_c void +ReactionsReactionSetByENDFMT( + ConstHandle2Reactions self, + const int ENDF_MT, + ConstHandle2ConstReaction reaction +); + +// +++ Has, by fissionGenre +extern_c int +ReactionsReactionHasByFissionGenre( + ConstHandle2ConstReactions self, + const char *const fissionGenre +); + +// --- Get, by fissionGenre, const +extern_c Handle2ConstReaction +ReactionsReactionGetByFissionGenreConst( + ConstHandle2ConstReactions self, + const char *const fissionGenre +); + +// +++ Get, by fissionGenre, non-const +extern_c Handle2Reaction +ReactionsReactionGetByFissionGenre( + ConstHandle2Reactions self, + const char *const fissionGenre +); + +// +++ Set, by fissionGenre +extern_c void +ReactionsReactionSetByFissionGenre( + ConstHandle2Reactions self, + const char *const fissionGenre, + ConstHandle2ConstReaction reaction +); + +// +++ Has, by label +extern_c int +ReactionsReactionHasByLabel( + ConstHandle2ConstReactions self, + const char *const label +); + +// --- Get, by label, const +extern_c Handle2ConstReaction +ReactionsReactionGetByLabelConst( + ConstHandle2ConstReactions self, + const char *const label +); + +// +++ Get, by label, non-const +extern_c Handle2Reaction +ReactionsReactionGetByLabel( + ConstHandle2Reactions self, + const char *const label +); + +// +++ Set, by label +extern_c void +ReactionsReactionSetByLabel( + ConstHandle2Reactions self, + const char *const label, + ConstHandle2ConstReaction reaction +); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1.9/transport/Reactions/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reactions/src/custom.cpp b/autogen/prototype/proto/c/src/v1.9/transport/Reactions/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/c/src/v1.9/transport/Reactions/src/custom.h b/autogen/prototype/proto/c/src/v1.9/transport/Reactions/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/prototype/proto/python/runtests.sh b/autogen/prototype/proto/python/runtests.sh new file mode 100755 index 000000000..449471762 --- /dev/null +++ b/autogen/prototype/proto/python/runtests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# this script copies the dynamic library for the GNDStk python module +# and runs all the unit tests it can find + +rm GNDStk*.so +cp ../../../../build/GNDStk*.so . +python -m unittest discover -v -p "Test*" diff --git a/autogen/prototype/proto/python/src/v1.9/containers.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers.python.cpp new file mode 100644 index 000000000..e13f37238 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers.python.cpp @@ -0,0 +1,43 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace py = pybind11; + +// v1.9 interface +namespace python_v1_9 { + +// containers declarations +namespace python_containers { + void wrapLink(py::module &); + void wrapAxis(py::module &); + void wrapValues(py::module &); + void wrapGrid(py::module &); + void wrapAxes(py::module &); + void wrapXYs1d(py::module &); + void wrapRegions1d(py::module &); +} // namespace python_containers + +// wrapper for containers +void wrapContainers(py::module &module) +{ + // create the containers submodule + py::module submodule = module.def_submodule( + "containers", + "proto v1.9 containers" + ); + + // wrap containers components + python_containers::wrapLink(submodule); + python_containers::wrapAxis(submodule); + python_containers::wrapValues(submodule); + python_containers::wrapGrid(submodule); + python_containers::wrapAxes(submodule); + python_containers::wrapXYs1d(submodule); + python_containers::wrapRegions1d(submodule); +}; + +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Axes.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Axes.python.cpp new file mode 100644 index 000000000..29e54610e --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Axes.python.cpp @@ -0,0 +1,81 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Axes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Axes +void wrapAxes(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Axes; + using axis_grid_t = std::variant< + containers::Axis, + containers::Grid + >; + + // create the Python object + py::class_ object( + module, "Axes", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::vector & + >(), + py::arg("href") = std::nullopt, + py::arg("axis_grid"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set href + object.def_property( + "href", + [](const cppCLASS &self) -> decltype(auto) + { + return self.href(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.href() = value; + }, + cppCLASS::component_t::documentation("href").data() + ); + + object.def_property( + "axis_grid", + [](const cppCLASS &self) -> decltype(auto) + { + return self.axis_grid(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.axis_grid() = value; + }, + cppCLASS::component_t::documentation("axis_grid").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Axis.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Axis.python.cpp new file mode 100644 index 000000000..6ab3c8bc8 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Axis.python.cpp @@ -0,0 +1,94 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Axis.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Axis +void wrapAxis(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Axis; + + // create the Python object + py::class_ object( + module, "Axis", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + py::arg("index") = std::nullopt, + py::arg("label") = std::nullopt, + py::arg("unit") = std::nullopt, + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set index + object.def_property( + "index", + [](const cppCLASS &self) -> decltype(auto) + { + return self.index(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.index() = value; + }, + cppCLASS::component_t::documentation("index").data() + ); + + // get/set label + object.def_property( + "label", + [](const cppCLASS &self) -> decltype(auto) + { + return self.label(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.label() = value; + }, + cppCLASS::component_t::documentation("label").data() + ); + + // get/set unit + object.def_property( + "unit", + [](const cppCLASS &self) -> decltype(auto) + { + return self.unit(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.unit() = value; + }, + cppCLASS::component_t::documentation("unit").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Grid.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Grid.python.cpp new file mode 100644 index 000000000..dff7a27fc --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Grid.python.cpp @@ -0,0 +1,171 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Grid.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Grid +void wrapGrid(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Grid; + using link_values_t = std::variant< + containers::Values, + containers::Link + >; + + // create the Python object + py::class_ object( + module, "Grid", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const link_values_t & + >(), + py::arg("index") = std::nullopt, + py::arg("interpolation") = std::nullopt, + py::arg("label") = std::nullopt, + py::arg("style") = std::nullopt, + py::arg("unit") = std::nullopt, + py::arg("link_values"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set index + object.def_property( + "index", + [](const cppCLASS &self) -> decltype(auto) + { + return self.index(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.index() = value; + }, + cppCLASS::component_t::documentation("index").data() + ); + + // get/set interpolation + object.def_property( + "interpolation", + [](const cppCLASS &self) -> decltype(auto) + { + return self.interpolation().value(); + }, + [](cppCLASS &self, const enums::Interpolation &value) + { + self.interpolation() = value; + }, + cppCLASS::component_t::documentation("interpolation").data() + ); + + // get/set label + object.def_property( + "label", + [](const cppCLASS &self) -> decltype(auto) + { + return self.label(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.label() = value; + }, + cppCLASS::component_t::documentation("label").data() + ); + + // get/set style + object.def_property( + "style", + [](const cppCLASS &self) -> decltype(auto) + { + return self.style(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.style() = value; + }, + cppCLASS::component_t::documentation("style").data() + ); + + // get/set unit + object.def_property( + "unit", + [](const cppCLASS &self) -> decltype(auto) + { + return self.unit(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.unit() = value; + }, + cppCLASS::component_t::documentation("unit").data() + ); + + object.def_property( + "values", + [](const cppCLASS &self) -> decltype(auto) + { + return self.values(); + }, + [](cppCLASS &self, const containers::Values &value) + { + self.values() = value; + }, + cppCLASS::component_t::documentation("values").data() + ); + + object.def_property( + "link", + [](const cppCLASS &self) -> decltype(auto) + { + return self.link(); + }, + [](cppCLASS &self, const containers::Link &value) + { + self.link() = value; + }, + cppCLASS::component_t::documentation("link").data() + ); + + object.def_property( + "link_values", + [](const cppCLASS &self) -> decltype(auto) + { + return self.link_values(); + }, + [](cppCLASS &self, const link_values_t &value) + { + self.link_values() = value; + }, + cppCLASS::component_t::documentation("link_values").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Link.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Link.python.cpp new file mode 100644 index 000000000..479103d85 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Link.python.cpp @@ -0,0 +1,62 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Link.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Link +void wrapLink(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Link; + + // create the Python object + py::class_ object( + module, "Link", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::string & + >(), + py::arg("href"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set href + object.def_property( + "href", + [](const cppCLASS &self) -> decltype(auto) + { + return self.href(); + }, + [](cppCLASS &self, const std::string &value) + { + self.href() = value; + }, + cppCLASS::component_t::documentation("href").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Regions1d.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Regions1d.python.cpp new file mode 100644 index 000000000..4a363a7a4 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Regions1d.python.cpp @@ -0,0 +1,110 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Regions1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Regions1d +void wrapRegions1d(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Regions1d; + + // create the Python object + py::class_ object( + module, "Regions1d", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::vector & + >(), + py::arg("label") = std::nullopt, + py::arg("outer_domain_value") = std::nullopt, + py::arg("axes") = std::nullopt, + py::arg("xys1d"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set label + object.def_property( + "label", + [](const cppCLASS &self) -> decltype(auto) + { + return self.label(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.label() = value; + }, + cppCLASS::component_t::documentation("label").data() + ); + + // get/set outerDomainValue + object.def_property( + "outer_domain_value", + [](const cppCLASS &self) -> decltype(auto) + { + return self.outerDomainValue(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.outerDomainValue() = value; + }, + cppCLASS::component_t::documentation("outer_domain_value").data() + ); + + // get/set axes + object.def_property( + "axes", + [](const cppCLASS &self) -> decltype(auto) + { + return self.axes(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.axes() = value; + }, + cppCLASS::component_t::documentation("axes").data() + ); + + // get/set XYs1d + object.def_property( + "xys1d", + [](const cppCLASS &self) -> decltype(auto) + { + return self.XYs1d(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.XYs1d() = value; + }, + cppCLASS::component_t::documentation("xys1d").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/Values.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/Values.python.cpp new file mode 100644 index 000000000..476f0a667 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/Values.python.cpp @@ -0,0 +1,163 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/Values.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::Values +void wrapValues(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::Values; + + // create the Python object + py::class_ object( + module, "Values", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + py::arg("value_type") = std::nullopt, + py::arg("start") = std::nullopt, + py::arg("length") = std::nullopt, + cppCLASS::component_t::documentation("constructor").data() + ); + + // constructor: from vector + object.def( + py::init< + const std::vector & + >(), + py::arg("ints"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // constructor: from vector + object.def( + py::init< + const std::vector & + >(), + py::arg("doubles"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // constructor: from vector + object.def( + py::init< + const std::vector & + >(), + py::arg("strings"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set valueType + object.def_property( + "value_type", + [](const cppCLASS &self) -> decltype(auto) + { + return self.valueType().value(); + }, + [](cppCLASS &self, const std::string &value) + { + self.valueType() = value; + }, + cppCLASS::component_t::documentation("value_type").data() + ); + + // get/set start + object.def_property( + "start", + [](const cppCLASS &self) -> decltype(auto) + { + return self.start().value(); + }, + [](cppCLASS &self, const int &value) + { + self.start() = value; + }, + cppCLASS::component_t::documentation("start").data() + ); + + // get/set length + object.def_property( + "length", + [](const cppCLASS &self) -> decltype(auto) + { + return self.length(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.length() = value; + }, + cppCLASS::component_t::documentation("length").data() + ); + + // get/set vector + object.def_property( + "ints", + [](const cppCLASS &self) -> const std::vector & + { + return self.ints(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.ints() = value; + }, + cppCLASS::component_t::documentation("ints").data() + ); + + // get/set vector + object.def_property( + "doubles", + [](const cppCLASS &self) -> const std::vector & + { + return self.doubles(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.doubles() = value; + }, + cppCLASS::component_t::documentation("doubles").data() + ); + + // get/set vector + object.def_property( + "strings", + [](const cppCLASS &self) -> const std::vector & + { + return self.strings(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.strings() = value; + }, + cppCLASS::component_t::documentation("strings").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/containers/XYs1d.python.cpp b/autogen/prototype/proto/python/src/v1.9/containers/XYs1d.python.cpp new file mode 100644 index 000000000..61f2a6b03 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/containers/XYs1d.python.cpp @@ -0,0 +1,142 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/containers/XYs1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_containers { + +// wrapper for containers::XYs1d +void wrapXYs1d(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = containers::XYs1d; + + // create the Python object + py::class_ object( + module, "XYs1d", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Values & + >(), + py::arg("index") = std::nullopt, + py::arg("interpolation") = std::nullopt, + py::arg("label") = std::nullopt, + py::arg("outer_domain_value") = std::nullopt, + py::arg("axes") = std::nullopt, + py::arg("values"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set index + object.def_property( + "index", + [](const cppCLASS &self) -> decltype(auto) + { + return self.index(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.index() = value; + }, + cppCLASS::component_t::documentation("index").data() + ); + + // get/set interpolation + object.def_property( + "interpolation", + [](const cppCLASS &self) -> decltype(auto) + { + return self.interpolation().value(); + }, + [](cppCLASS &self, const enums::Interpolation &value) + { + self.interpolation() = value; + }, + cppCLASS::component_t::documentation("interpolation").data() + ); + + // get/set label + object.def_property( + "label", + [](const cppCLASS &self) -> decltype(auto) + { + return self.label(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.label() = value; + }, + cppCLASS::component_t::documentation("label").data() + ); + + // get/set outerDomainValue + object.def_property( + "outer_domain_value", + [](const cppCLASS &self) -> decltype(auto) + { + return self.outerDomainValue(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.outerDomainValue() = value; + }, + cppCLASS::component_t::documentation("outer_domain_value").data() + ); + + // get/set axes + object.def_property( + "axes", + [](const cppCLASS &self) -> decltype(auto) + { + return self.axes(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.axes() = value; + }, + cppCLASS::component_t::documentation("axes").data() + ); + + // get/set values + object.def_property( + "values", + [](const cppCLASS &self) -> decltype(auto) + { + return self.values(); + }, + [](cppCLASS &self, const containers::Values &value) + { + self.values() = value; + }, + cppCLASS::component_t::documentation("values").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_containers +} // namespace python_v1_9 diff --git a/python/src/v1.9/GNDS.python.cpp b/autogen/prototype/proto/python/src/v1.9/proto.python.cpp similarity index 100% rename from python/src/v1.9/GNDS.python.cpp rename to autogen/prototype/proto/python/src/v1.9/proto.python.cpp diff --git a/autogen/prototype/proto/python/src/v1.9/transport.python.cpp b/autogen/prototype/proto/python/src/v1.9/transport.python.cpp new file mode 100644 index 000000000..165343a14 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/transport.python.cpp @@ -0,0 +1,37 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace py = pybind11; + +// v1.9 interface +namespace python_v1_9 { + +// transport declarations +namespace python_transport { + void wrapCrossSection(py::module &); + void wrapReaction(py::module &); + void wrapReactions(py::module &); + void wrapReactionSuite(py::module &); +} // namespace python_transport + +// wrapper for transport +void wrapTransport(py::module &module) +{ + // create the transport submodule + py::module submodule = module.def_submodule( + "transport", + "proto v1.9 transport" + ); + + // wrap transport components + python_transport::wrapCrossSection(submodule); + python_transport::wrapReaction(submodule); + python_transport::wrapReactions(submodule); + python_transport::wrapReactionSuite(submodule); +}; + +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/transport/CrossSection.python.cpp b/autogen/prototype/proto/python/src/v1.9/transport/CrossSection.python.cpp new file mode 100644 index 000000000..41d3b3e37 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/transport/CrossSection.python.cpp @@ -0,0 +1,65 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/transport/CrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_transport { + +// wrapper for transport::CrossSection +void wrapCrossSection(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = transport::CrossSection; + using XYs1d_regions1d_t = std::variant< + containers::XYs1d, + containers::Regions1d + >; + + // create the Python object + py::class_ object( + module, "CrossSection", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::vector & + >(), + py::arg("xys1d_regions1d"), + cppCLASS::component_t::documentation("constructor").data() + ); + + object.def_property( + "xys1d_regions1d", + [](const cppCLASS &self) -> decltype(auto) + { + return self.XYs1d_regions1d(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.XYs1d_regions1d() = value; + }, + cppCLASS::component_t::documentation("xys1d_regions1d").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_transport +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/transport/Reaction.python.cpp b/autogen/prototype/proto/python/src/v1.9/transport/Reaction.python.cpp new file mode 100644 index 000000000..7da7ab35c --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/transport/Reaction.python.cpp @@ -0,0 +1,110 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/transport/Reaction.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_transport { + +// wrapper for transport::Reaction +void wrapReaction(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = transport::Reaction; + + // create the Python object + py::class_ object( + module, "Reaction", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const int &, + const std::optional &, + const std::string &, + const transport::CrossSection & + >(), + py::arg("endf_mt"), + py::arg("fission_genre") = std::nullopt, + py::arg("label"), + py::arg("cross_section"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set ENDF_MT + object.def_property( + "endf_mt", + [](const cppCLASS &self) -> decltype(auto) + { + return self.ENDF_MT(); + }, + [](cppCLASS &self, const int &value) + { + self.ENDF_MT() = value; + }, + cppCLASS::component_t::documentation("endf_mt").data() + ); + + // get/set fissionGenre + object.def_property( + "fission_genre", + [](const cppCLASS &self) -> decltype(auto) + { + return self.fissionGenre(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.fissionGenre() = value; + }, + cppCLASS::component_t::documentation("fission_genre").data() + ); + + // get/set label + object.def_property( + "label", + [](const cppCLASS &self) -> decltype(auto) + { + return self.label(); + }, + [](cppCLASS &self, const std::string &value) + { + self.label() = value; + }, + cppCLASS::component_t::documentation("label").data() + ); + + // get/set crossSection + object.def_property( + "cross_section", + [](const cppCLASS &self) -> decltype(auto) + { + return self.crossSection(); + }, + [](cppCLASS &self, const transport::CrossSection &value) + { + self.crossSection() = value; + }, + cppCLASS::component_t::documentation("cross_section").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_transport +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/transport/ReactionSuite.python.cpp b/autogen/prototype/proto/python/src/v1.9/transport/ReactionSuite.python.cpp new file mode 100644 index 000000000..e06f243b9 --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/transport/ReactionSuite.python.cpp @@ -0,0 +1,158 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/transport/ReactionSuite.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_transport { + +// wrapper for transport::ReactionSuite +void wrapReactionSuite(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = transport::ReactionSuite; + + // create the Python object + py::class_ object( + module, "ReactionSuite", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::string &, + const std::string &, + const std::string &, + const enums::Frame &, + const std::string &, + const std::optional &, + const std::optional & + >(), + py::arg("evaluation"), + py::arg("format"), + py::arg("projectile"), + py::arg("projectile_frame"), + py::arg("target"), + py::arg("interaction") = std::nullopt, + py::arg("reactions") = std::nullopt, + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set evaluation + object.def_property( + "evaluation", + [](const cppCLASS &self) -> decltype(auto) + { + return self.evaluation(); + }, + [](cppCLASS &self, const std::string &value) + { + self.evaluation() = value; + }, + cppCLASS::component_t::documentation("evaluation").data() + ); + + // get/set format + object.def_property( + "format", + [](const cppCLASS &self) -> decltype(auto) + { + return self.format(); + }, + [](cppCLASS &self, const std::string &value) + { + self.format() = value; + }, + cppCLASS::component_t::documentation("format").data() + ); + + // get/set projectile + object.def_property( + "projectile", + [](const cppCLASS &self) -> decltype(auto) + { + return self.projectile(); + }, + [](cppCLASS &self, const std::string &value) + { + self.projectile() = value; + }, + cppCLASS::component_t::documentation("projectile").data() + ); + + // get/set projectileFrame + object.def_property( + "projectile_frame", + [](const cppCLASS &self) -> decltype(auto) + { + return self.projectileFrame(); + }, + [](cppCLASS &self, const enums::Frame &value) + { + self.projectileFrame() = value; + }, + cppCLASS::component_t::documentation("projectile_frame").data() + ); + + // get/set target + object.def_property( + "target", + [](const cppCLASS &self) -> decltype(auto) + { + return self.target(); + }, + [](cppCLASS &self, const std::string &value) + { + self.target() = value; + }, + cppCLASS::component_t::documentation("target").data() + ); + + // get/set interaction + object.def_property( + "interaction", + [](const cppCLASS &self) -> decltype(auto) + { + return self.interaction(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.interaction() = value; + }, + cppCLASS::component_t::documentation("interaction").data() + ); + + // get/set reactions + object.def_property( + "reactions", + [](const cppCLASS &self) -> decltype(auto) + { + return self.reactions(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.reactions() = value; + }, + cppCLASS::component_t::documentation("reactions").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_transport +} // namespace python_v1_9 diff --git a/autogen/prototype/proto/python/src/v1.9/transport/Reactions.python.cpp b/autogen/prototype/proto/python/src/v1.9/transport/Reactions.python.cpp new file mode 100644 index 000000000..25cc19c9f --- /dev/null +++ b/autogen/prototype/proto/python/src/v1.9/transport/Reactions.python.cpp @@ -0,0 +1,62 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "proto/v1.9/transport/Reactions.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1_9 { +namespace python_transport { + +// wrapper for transport::Reactions +void wrapReactions(py::module &module) +{ + using namespace proto; + using namespace proto::v1_9; + + // type aliases + using cppCLASS = transport::Reactions; + + // create the Python object + py::class_ object( + module, "Reactions", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::vector & + >(), + py::arg("reaction"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set reaction + object.def_property( + "reaction", + [](const cppCLASS &self) -> decltype(auto) + { + return self.reaction(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.reaction() = value; + }, + cppCLASS::component_t::documentation("reaction").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_transport +} // namespace python_v1_9 diff --git a/python/test/v1_9/__init__.py b/autogen/prototype/proto/python/test/v1.9/__init__.py similarity index 100% rename from python/test/v1_9/__init__.py rename to autogen/prototype/proto/python/test/v1.9/__init__.py diff --git a/autogen/prototype/proto/python/test/v1.9/__init__.pyc b/autogen/prototype/proto/python/test/v1.9/__init__.pyc new file mode 100644 index 000000000..fdd90207b Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/__init__.pyc differ diff --git a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Axis.py b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.py similarity index 89% rename from python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Axis.py rename to autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.py index 4969f1ff9..6fc894786 100644 --- a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Axis.py +++ b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.py @@ -9,7 +9,7 @@ class Test_GNDStk_v1_9_containers_Axis( unittest.TestCase ) : """Unit test for the Section class.""" - chunk = ( '\n' ) + chunk = ( '' ) wrong = ( '' ) def test_component( self ) : @@ -32,17 +32,17 @@ def verify_chunk( self, chunk ) : # verify string self.assertEqual( self.chunk, chunk.to_xml_string() ) - # the data is given explicitly + # the data are given explicitly chunk = Axis( index = 1, label = 'energy_in', unit = 'eV' ) verify_chunk( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Axis.from_string( self.chunk ) verify_chunk( self, chunk ) - # the data is copied + # the data are copied copy = Axis( chunk ) verify_chunk( self, copy ) diff --git a/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.pyc b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.pyc new file mode 100644 index 000000000..55dc979f1 Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Axis.pyc differ diff --git a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Grid.py b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.py similarity index 87% rename from python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Grid.py rename to autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.py index 133fdd77a..ed102cbc4 100644 --- a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Grid.py +++ b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.py @@ -12,14 +12,14 @@ class Test_GNDStk_v1_9_containers_Grid( unittest.TestCase ) : """Unit test for the Section class.""" chunk = ( '\n' - ' 1e-05 2e+07\n' - '\n' ) + ' 1e-05 2e+07\n' + '' ) chunkWithLink = ( '\n' ' \n' - '\n' ) + '' ) wrong = ( '\n' - ' 1e-05 2e+07\n' - '\n' ) + ' 1e-05 2e+07\n' + '' ) def test_component( self ) : @@ -57,19 +57,19 @@ def verify_chunk( self, chunk ) : # verify string self.assertEqual( self.chunk, chunk.to_xml_string() ) - # the data is given explicitly + # the data are given explicitly chunk = Grid( index = 2, label = "row_energy_bounds", unit = "eV", style = GridStyle.boundaries, link_values = Values( [ 1e-5, 2e7 ] ) ) verify_chunk( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Grid.from_string( self.chunk ) verify_chunk( self, chunk ) - # the data is copied + # the data are copied copy = Grid( chunk ) verify_chunk( self, copy ) diff --git a/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.pyc b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.pyc new file mode 100644 index 000000000..07eb98480 Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Grid.pyc differ diff --git a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Link.py b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.py similarity index 84% rename from python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Link.py rename to autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.py index 9e28cc6ac..65a2fc61b 100644 --- a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Link.py +++ b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.py @@ -9,8 +9,8 @@ class Test_GNDStk_v1_9_containers_Link( unittest.TestCase ) : """Unit test for the Section class.""" - chunk = ( '\n' ) - wrong = ( '\n' ) + chunk = ( '' ) + wrong = ( '' ) def test_component( self ) : @@ -22,17 +22,17 @@ def verify_chunk( self, chunk ) : # verify string self.assertEqual( self.chunk, chunk.to_xml_string() ) - # the data is given explicitly + # the data are given explicitly chunk = Link( href = '../../grid[@index=\'2\']/values' ) verify_chunk( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Link.from_string( self.chunk ) verify_chunk( self, chunk ) - # the data is copied + # the data are copied copy = Link( chunk ) verify_chunk( self, copy ) diff --git a/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.pyc b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.pyc new file mode 100644 index 000000000..abb7681c7 Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Link.pyc differ diff --git a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Values.py b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.py similarity index 80% rename from python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Values.py rename to autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.py index 117ea1178..a64ae9db4 100644 --- a/python/test/v1_9/containers/Test_GNDStk_v1_9_containers_Values.py +++ b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.py @@ -9,10 +9,10 @@ class Test_GNDStk_v1_9_containers_Values( unittest.TestCase ) : """Unit test for the Section class.""" - chunk_doubles = ( '2500 8.9172 2550 8.9155\n' ) - chunk_ints = ( '2500 9 2550 9\n' ) - chunk_strings = ( '2500 8.9172 2550 8.9155\n' ) - wrong = ( '2500 8.9172 2550 8.9155\n' ) + chunk_doubles = ( '2500 8.9172 2550 8.9155' ) + chunk_ints = ( '2500 9 2550 9' ) + chunk_strings = ( '2500 8.9172 2550 8.9155' ) + wrong = ( '2500 8.9172 2550 8.9155' ) def test_component( self ) : @@ -67,47 +67,47 @@ def verify_chunk_strings( self, chunk ) : # verify string self.assertEqual( self.chunk_strings, chunk.to_xml_string() ) - # the data is given explicitly (doubles) + # the data are given explicitly (doubles) chunk = Values( doubles = [ 2500., 8.9172, 2550., 8.9155 ] ) verify_chunk_doubles( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Values.from_string( self.chunk_doubles ) verify_chunk_doubles( self, chunk ) - # the data is copied + # the data are copied copy = Values( chunk ) verify_chunk_doubles( self, copy ) - # the data is given explicitly (ints) + # the data are given explicitly (ints) chunk = Values( ints = [ 2500, 9, 2550, 9 ] ) verify_chunk_ints( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Values.from_string( self.chunk_ints ) verify_chunk_ints( self, chunk ) - # the data is copied + # the data are copied copy = Values( chunk ) verify_chunk_ints( self, copy ) - # the data is given explicitly (strings) + # the data are given explicitly (strings) chunk = Values( strings = [ "2500", "8.9172", "2550", "8.9155" ] ) verify_chunk_strings( self, chunk ) - # the data is read from a string + # the data are read from a string chunk = Values.from_string( self.chunk_strings ) verify_chunk_strings( self, chunk ) - # the data is copied + # the data are copied copy = Values( chunk ) verify_chunk_strings( self, copy ) diff --git a/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.pyc b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.pyc new file mode 100644 index 000000000..30a1fd54f Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/containers/Test_GNDStk_v1_9_containers_Values.pyc differ diff --git a/python/test/v1_9/containers/__init__.py b/autogen/prototype/proto/python/test/v1.9/containers/__init__.py similarity index 100% rename from python/test/v1_9/containers/__init__.py rename to autogen/prototype/proto/python/test/v1.9/containers/__init__.py diff --git a/autogen/prototype/proto/python/test/v1.9/containers/__init__.pyc b/autogen/prototype/proto/python/test/v1.9/containers/__init__.pyc new file mode 100644 index 000000000..56255e4e3 Binary files /dev/null and b/autogen/prototype/proto/python/test/v1.9/containers/__init__.pyc differ diff --git a/autogen/prototype/proto/src/proto/v1.9.hpp b/autogen/prototype/proto/src/proto/v1.9.hpp new file mode 100644 index 000000000..21ba864aa --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9.hpp @@ -0,0 +1,21 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9 +#define PROTO_V1_9 + +#include "proto/v1.9/containers/Link.hpp" +#include "proto/v1.9/containers/XYs1d.hpp" +#include "proto/v1.9/containers/Axes.hpp" +#include "proto/v1.9/containers/Axis.hpp" +#include "proto/v1.9/containers/Grid.hpp" +#include "proto/v1.9/containers/Values.hpp" +#include "proto/v1.9/containers/Regions1d.hpp" + +#include "proto/v1.9/transport/ReactionSuite.hpp" +#include "proto/v1.9/transport/Reactions.hpp" +#include "proto/v1.9/transport/Reaction.hpp" +#include "proto/v1.9/transport/CrossSection.hpp" + +#endif diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Axes.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axes.hpp new file mode 100644 index 000000000..b9293a85b --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Axes.hpp @@ -0,0 +1,205 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_AXES +#define PROTO_V1_9_CONTAINERS_AXES + +#include "proto/v1.9/containers/Axis.hpp" +#include "proto/v1.9/containers/Grid.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Axes +// ----------------------------------------------------------------------------- + +class Axes : + public Component +{ + friend class Component; + + using axis_grid_t = std::variant< + containers::Axis, + containers::Grid + >; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Axes"; } + static auto NODENAME() { return "axes"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("href") | + + // children + axis_grid_t{} + / ++(Child<>("axis") || Child<>("grid")) + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "href", + "axis_grid" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "href", + "axis_grid" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + href{this}; + + // children - variant + Field> + axis_grid{this}; + FieldPart axis{axis_grid}; + FieldPart grid{axis_grid}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->href, \ + this->axis_grid \ + ) + + // default + Axes() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Axes( + const wrapper> + &href, + const wrapper> + &axis_grid = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + href(this,href), + axis_grid(this,axis_grid) + { + Component::finish(); + } + + // from node + explicit Axes(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Axes(const Axes &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + href(this,other.href), + axis_grid(this,other.axis_grid) + { + Component::finish(other); + } + + // move + Axes(Axes &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + href(this,std::move(other.href)), + axis_grid(this,std::move(other.axis_grid)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Axes &operator=(const Axes &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + href = other.href; + axis_grid = other.axis_grid; + } + return *this; + } + + // move + Axes &operator=(Axes &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + href = std::move(other.href); + axis_grid = std::move(other.axis_grid); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Axes/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Axes + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/containers/Axes/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axes/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/containers/Axes/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Axes/src/custom.hpp diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Axes/test/Axes.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axes/test/Axes.test.cpp new file mode 100644 index 000000000..ffa2a2ae5 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Axes/test/Axes.test.cpp @@ -0,0 +1,330 @@ + +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "proto/v1.9/containers/Axes.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using namespace proto; + +using Axes = v1_9::containers::Axes; +using Axis = v1_9::containers::Axis; +using Grid = v1_9::containers::Grid; +using Values = v1_9::containers::Values; +using Link = v1_9::containers::Link; + +std::string chunk(); +void verifyChunk( const Axes& ); +std::string invalidName(); + +SCENARIO( "Axes" ) { + njoy::GNDStk::sort = true; + + GIVEN( "valid data for the component" ) { + + std::string string = chunk(); + + WHEN( "autogenerated constructor: the data are given explicitly" ) { + + std::vector< std::variant< Axis, Grid > > axis = { + + Axis( 1, "energy_in", "eV" ), + Axis( 0, "radius", "fm" ) + }; + + using agvector = std::vector>; + + THEN ( "Various getters work as expected" ) { + { + const Axes a1(std::nullopt, agvector{Axis(1)}); + Axes a2(std::nullopt, agvector{Axis(2)}); + const Axis *ptr1 = a1.axis.ptr(1); + Axis *ptr2 = a2.axis.ptr(2); + CHECK(ptr1 != nullptr); + CHECK(ptr2 != nullptr); + + const Axes a3(std::nullopt, agvector{Grid(1)}); + Axes a4(std::nullopt, agvector{Grid(2)}); + const Grid *ptr3 = a3.grid.ptr(1); + Grid *ptr4 = a4.grid.ptr(2); + CHECK(ptr3 != nullptr); + CHECK(ptr4 != nullptr); + } + + { + const Axes a1(std::nullopt, agvector{Axis(1)}); + Axes a2(std::nullopt, agvector{Axis(2)}); + const Grid *ptr1 = a1.grid.ptr(1); + Grid *ptr2 = a2.grid.ptr(2); + CHECK(ptr1 == nullptr); + CHECK(ptr2 == nullptr); + + const Axes a3(std::nullopt, agvector{Grid(1)}); + Axes a4(std::nullopt, agvector{Grid(2)}); + const Axis *ptr3 = a3.axis.ptr(1); + Axis *ptr4 = a4.axis.ptr(2); + CHECK(ptr3 == nullptr); + CHECK(ptr4 == nullptr); + } + } + + Axes chunk( std::nullopt, axis ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + + WHEN( "the data are constructed from a node" ) { + + Node node; + node << chunk(); + Axes chunk( node ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "a valid component instance" ) { + + WHEN( "the component is copied" ) { + + Node node; + node << chunk(); + Axes chunk( node ); + + // copy constructor + Axes copy( chunk ); + + // copy assignment + Axes assign; + assign = chunk; + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( copy ); + verifyChunk( assign ); + } // THEN + } // WHEN + + WHEN( "the data are moved" ) { + + Node node; + node << chunk(); + Axes chunk( node ); + Axes chunk2( node ); + + // move constructor + Axes move( std::move( chunk ) ); + + // move assignment + Axes assign; + assign = std::move( chunk2 ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( move ); + verifyChunk( assign ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data" ) { + + WHEN( "when the wrong node is used" ) { + + Node node; + node << invalidName(); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( Axes( node ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return +R"***( + + +)***"; +} + +void verifyChunk( const Axes& component ) { + + CHECK( std::nullopt == component.href() ); + + CHECK( 2 == component.axis_grid().size() ); + CHECK( 2 == component.size() ); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // indexing into the vector and accessing the variant directly + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + decltype(auto) axis_i0 = std::get< Axis >( component.axis_grid()[0] ); + + CHECK( std::nullopt != axis_i0.index() ); + CHECK( std::nullopt != axis_i0.label() ); + CHECK( std::nullopt != axis_i0.unit() ); + + CHECK( 0 == axis_i0.index().value() ); + CHECK( "radius" == axis_i0.label().value() ); + CHECK( "fm" == axis_i0.unit().value() ); + + decltype(auto) axis_i1 = std::get< Axis >( component.axis_grid()[1] ); + + CHECK( std::nullopt != axis_i1.index() ); + CHECK( std::nullopt != axis_i1.label() ); + CHECK( std::nullopt != axis_i1.unit() ); + + CHECK( 1 == axis_i1.index().value() ); + CHECK( "energy_in" == axis_i1.label().value() ); + CHECK( "eV" == axis_i1.unit().value() ); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // using the index based axis_grid getter and accessing the variant directly + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + decltype(auto) axis_ii0 = std::get< Axis >( component.axis_grid( 0 ) ); + + CHECK( std::nullopt != axis_ii0.index() ); + CHECK( std::nullopt != axis_ii0.label() ); + CHECK( std::nullopt != axis_ii0.unit() ); + + CHECK( 0 == axis_ii0.index().value() ); + CHECK( "radius" == axis_ii0.label().value() ); + CHECK( "fm" == axis_ii0.unit().value() ); + + decltype(auto) axis_ii1 = std::get< Axis >( component.axis_grid( 1 ) ); + + CHECK( std::nullopt != axis_ii1.index() ); + CHECK( std::nullopt != axis_ii1.label() ); + CHECK( std::nullopt != axis_ii1.unit() ); + + CHECK( 1 == axis_ii1.index().value() ); + CHECK( "energy_in" == axis_ii1.label().value() ); + CHECK( "eV" == axis_ii1.unit().value() ); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // using the label based axis_grid getter and accessing the variant directly + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + decltype(auto) axis_iii0 = std::get< Axis >(component.axis_grid("radius")); + + CHECK( std::nullopt != axis_iii0.index() ); + CHECK( std::nullopt != axis_iii0.label() ); + CHECK( std::nullopt != axis_iii0.unit() ); + + CHECK( 0 == axis_iii0.index().value() ); + CHECK( "radius" == axis_iii0.label().value() ); + CHECK( "fm" == axis_iii0.unit().value() ); + + decltype(auto) axis_iii1 = std::get< Axis >(component.axis_grid("energy_in")); + + CHECK( std::nullopt != axis_iii1.index() ); + CHECK( std::nullopt != axis_iii1.label() ); + CHECK( std::nullopt != axis_iii1.unit() ); + + CHECK( 1 == axis_iii1.index().value() ); + CHECK( "energy_in" == axis_iii1.label().value() ); + CHECK( "eV" == axis_iii1.unit().value() ); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // using the index based axis getter + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + CHECK(component.axis(has(v1_9::index(0)))); + CHECK(component.axis.has(v1_9::index(0))); + CHECK(component.axis_grid.has(v1_9::index)); + CHECK(component.axis_grid.has(v1_9::index(0))); + decltype(auto) axis_iv0 = component.axis( 0 ); + + CHECK( std::nullopt != axis_iv0.index() ); + CHECK( std::nullopt != axis_iv0.label() ); + CHECK( std::nullopt != axis_iv0.unit() ); + + CHECK( 0 == axis_iv0.index().value() ); + CHECK( "radius" == axis_iv0.label().value() ); + CHECK( "fm" == axis_iv0.unit().value() ); + + CHECK(component.axis(has(v1_9::index(1)))); + CHECK(component.axis.has(v1_9::index(1)) ); + CHECK(component.axis_grid.has(v1_9::index)); + CHECK(component.axis_grid.has(v1_9::index(1))); + decltype(auto) axis_iv1 = component.axis( 1 ); + + CHECK( std::nullopt != axis_iv1.index() ); + CHECK( std::nullopt != axis_iv1.label() ); + CHECK( std::nullopt != axis_iv1.unit() ); + + CHECK( 1 == axis_iv1.index().value() ); + CHECK( "energy_in" == axis_iv1.label().value() ); + CHECK( "eV" == axis_iv1.unit().value() ); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // using the label based axis getter + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + CHECK(component.axis(has(v1_9::label("radius")))); + CHECK(component.axis.has(v1_9::label("radius"))); + CHECK(component.axis_grid.has(v1_9::label)); + CHECK(component.axis_grid.has(v1_9::label("radius"))); + decltype(auto) axis_v0 = component.axis( "radius" ); + + CHECK( std::nullopt != axis_v0.index() ); + CHECK( std::nullopt != axis_v0.label() ); + CHECK( std::nullopt != axis_v0.unit() ); + + CHECK( 0 == axis_v0.index().value() ); + CHECK( "radius" == axis_v0.label().value() ); + CHECK( "fm" == axis_v0.unit().value() ); + + CHECK(component.axis(has(v1_9::label("energy_in")))); + CHECK(component.axis.has(v1_9::label("energy_in"))); + CHECK(component.axis_grid.has(v1_9::label)); + CHECK(component.axis_grid.has(v1_9::label("energy_in"))); + decltype(auto) axis_v1 = component.axis( "energy_in" ); + + CHECK( std::nullopt != axis_v1.index() ); + CHECK( std::nullopt != axis_v1.label() ); + CHECK( std::nullopt != axis_v1.unit() ); + + CHECK( 1 == axis_v1.index().value() ); + CHECK( "energy_in" == axis_v1.label().value() ); + CHECK( "eV" == axis_v1.unit().value() ); +} + +std::string invalidName() { + + // wrong name for the node + return +R"***( + + )***"; +} diff --git a/src/GNDStk/v1.9/containers/Axes/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Axes/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Axes/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Axes/test/CMakeLists.txt diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Axis.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axis.hpp new file mode 100644 index 000000000..94f78889c --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Axis.hpp @@ -0,0 +1,207 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_AXIS +#define PROTO_V1_9_CONTAINERS_AXIS + +#include "proto/v1.9/key.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Axis +// ----------------------------------------------------------------------------- + +class Axis : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Axis"; } + static auto NODENAME() { return "axis"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("index") | + std::optional{} + / Meta<>("label") | + std::optional{} + / Meta<>("unit") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "index", + "label", + "unit" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "index", + "label", + "unit" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + index{this}; + Field> + label{this}; + Field> + unit{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->index, \ + this->label, \ + this->unit \ + ) + + // default + Axis() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Axis( + const wrapper> + &index, + const wrapper> + &label = {}, + const wrapper> + &unit = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + index(this,index), + label(this,label), + unit(this,unit) + { + Component::finish(); + } + + // from node + explicit Axis(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Axis(const Axis &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + index(this,other.index), + label(this,other.label), + unit(this,other.unit) + { + Component::finish(other); + } + + // move + Axis(Axis &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + index(this,std::move(other.index)), + label(this,std::move(other.label)), + unit(this,std::move(other.unit)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Axis &operator=(const Axis &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + index = other.index; + label = other.label; + unit = other.unit; + } + return *this; + } + + // move + Axis &operator=(Axis &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + index = std::move(other.index); + label = std::move(other.label); + unit = std::move(other.unit); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Axis/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Axis + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Axis/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axis/src/custom.hpp new file mode 100644 index 000000000..94ea19739 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Axis/src/custom.hpp @@ -0,0 +1,30 @@ + +private: + +static inline helpMap help = { + + { + "", + "A GNDS 1.9 basic container component: " + "an axis with an index, label and\n" + "optional unit\n\n" + "This component in used in the axes node, " + "which in turn is used in most\n" + "functional containers." + }, + + { + "constructor", + "Initialise the axis component\n\n" + "Arguments:\n" + " self the axis component\n" + " index the index of the axis component\n" + " label the label of the axis component\n" + " unit the unit of the axis component\n" + }, + + { "index", "The index of the axis component" }, + { "label", "The label of the axis component" }, + { "unit", "The unit of the axis component" } + +}; diff --git a/src/GNDStk/v1.9/containers/Axis/test/Axis.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Axis/test/Axis.test.cpp similarity index 88% rename from src/GNDStk/v1.9/containers/Axis/test/Axis.test.cpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Axis/test/Axis.test.cpp index dd5adb194..878d83299 100644 --- a/src/GNDStk/v1.9/containers/Axis/test/Axis.test.cpp +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Axis/test/Axis.test.cpp @@ -1,12 +1,15 @@ + #define CATCH_CONFIG_MAIN #include "catch.hpp" -#include "GNDStk/v1.9/containers/Axis.hpp" +#include "proto/v1.9/containers/Axis.hpp" // other includes // convenience typedefs using namespace njoy::GNDStk; +using namespace proto; + using Axis = v1_9::containers::Axis; std::string chunk(); @@ -19,9 +22,9 @@ SCENARIO( "Axis" ) { std::string string = chunk(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { - unsigned int index = 1; + unsigned index = 1; std::string label = "energy_in"; std::string unit = "eV"; @@ -41,7 +44,7 @@ SCENARIO( "Axis" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunk(); @@ -84,7 +87,7 @@ SCENARIO( "Axis" ) { } // THEN } // WHEN - WHEN( "the data is moved" ) { + WHEN( "the data are moved" ) { Node node; node << chunk(); @@ -124,8 +127,7 @@ SCENARIO( "Axis" ) { std::string chunk() { return -R"***( -)***"; +R"***()***"; } void verifyChunk( const Axis& component ) { @@ -147,6 +149,5 @@ std::string invalidName() { // wrong name for the node return -R"***( -)***"; +R"***()***"; } diff --git a/src/GNDStk/v1.9/containers/Axis/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Axis/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Axis/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Axis/test/CMakeLists.txt diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Grid.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Grid.hpp new file mode 100644 index 000000000..390294922 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Grid.hpp @@ -0,0 +1,267 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_GRID +#define PROTO_V1_9_CONTAINERS_GRID + +#include "proto/v1.9/containers/Values.hpp" +#include "proto/v1.9/containers/Link.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Grid +// ----------------------------------------------------------------------------- + +class Grid : + public Component +{ + friend class Component; + + using link_values_t = std::variant< + containers::Values, + containers::Link + >; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Grid"; } + static auto NODENAME() { return "grid"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("index") | + Defaulted{enums::Interpolation::linlin} + / Meta<>("interpolation") | + std::optional{} + / Meta<>("label") | + std::optional{} + / Meta<>("style") | + std::optional{} + / Meta<>("unit") | + + // children + link_values_t{} + / --(Child<>("values") || Child<>("link")) + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "index", + "interpolation", + "label", + "style", + "unit", + "link_values" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "index", + "interpolation", + "label", + "style", + "unit", + "link_values" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // defaults + static inline const struct Defaults { + static inline const enums::Interpolation interpolation = enums::Interpolation::linlin; + } defaults; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + index{this}; + Field> + interpolation{this,defaults.interpolation}; + Field> + label{this}; + Field> + style{this}; + Field> + unit{this}; + + // children - variant + Field + link_values{this}; + FieldPart values{link_values}; + FieldPart link{link_values}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->index, \ + this->interpolation, \ + this->label, \ + this->style, \ + this->unit, \ + this->link_values \ + ) + + // default + Grid() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + // optional replaces Defaulted; this class knows the default(s) + explicit Grid( + const wrapper> + &index, + const wrapper> + &interpolation = {}, + const wrapper> + &label = {}, + const wrapper> + &style = {}, + const wrapper> + &unit = {}, + const wrapper + &link_values = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + index(this,index), + interpolation(this,defaults.interpolation,interpolation), + label(this,label), + style(this,style), + unit(this,unit), + link_values(this,link_values) + { + Component::finish(); + } + + // from node + explicit Grid(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Grid(const Grid &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + index(this,other.index), + interpolation(this,other.interpolation), + label(this,other.label), + style(this,other.style), + unit(this,other.unit), + link_values(this,other.link_values) + { + Component::finish(other); + } + + // move + Grid(Grid &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + index(this,std::move(other.index)), + interpolation(this,std::move(other.interpolation)), + label(this,std::move(other.label)), + style(this,std::move(other.style)), + unit(this,std::move(other.unit)), + link_values(this,std::move(other.link_values)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Grid &operator=(const Grid &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + index = other.index; + interpolation = other.interpolation; + label = other.label; + style = other.style; + unit = other.unit; + link_values = other.link_values; + } + return *this; + } + + // move + Grid &operator=(Grid &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + index = std::move(other.index); + interpolation = std::move(other.interpolation); + label = std::move(other.label); + style = std::move(other.style); + unit = std::move(other.unit); + link_values = std::move(other.link_values); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Grid/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Grid + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/containers/Grid/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Grid/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/containers/Grid/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Grid/src/custom.hpp diff --git a/src/GNDStk/v1.9/containers/Grid/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Grid/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Grid/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Grid/test/CMakeLists.txt diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Grid/test/Grid.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Grid/test/Grid.test.cpp new file mode 100644 index 000000000..1a98ebcec --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Grid/test/Grid.test.cpp @@ -0,0 +1,310 @@ + +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "proto/v1.9/containers/Grid.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using namespace proto; + +using Values = v1_9::containers::Values; +using Link = v1_9::containers::Link; +using Grid = v1_9::containers::Grid; + +std::string chunk(); +void verifyChunk( const Grid& ); +std::string chunkWithLink(); +void verifyChunkWithLink( const Grid& ); +std::string invalidName(); + +SCENARIO( "Grid" ) { + + GIVEN( "valid data for the component with a Values component" ) { + + std::string string = chunk(); + + WHEN( "autogenerated constructor: the data are given explicitly" ) { + + unsigned index = 2; + std::string label = "row_energy_bounds"; + std::string unit = "eV"; + enums::GridStyle style = enums::GridStyle::boundaries; + std::vector< double > values = { 1e-5, 2e7 }; + + THEN ( "Various getters work as expected" ) { + { + const Grid g1(index,std::nullopt,label,style,unit,Values(values)); + Grid g2(index,std::nullopt,label,style,unit,Values(values)); + const Values *ptr1 = g1.values.ptr(); + Values *ptr2 = g2.values.ptr(); + CHECK(ptr1 != nullptr); + CHECK(ptr2 != nullptr); + + const Grid g3(index,std::nullopt,label,style,unit,Link("mylink")); + Grid g4(index,std::nullopt,label,style,unit,Link("mylink")); + const Link *ptr3 = g3.link.ptr(); + Link *ptr4 = g4.link.ptr(); + CHECK(ptr3 != nullptr); + CHECK(ptr4 != nullptr); + } + + { + const Grid g1(index,std::nullopt,label,style,unit,Values(values)); + Grid g2(index,std::nullopt,label,style,unit,Values(values)); + const Values *ptr1 = g1.values; + Values *ptr2 = g2.values; + const Values &ref1 = g1.values; + Values &ref2 = g2.values; + CHECK(ptr1 != nullptr); + CHECK(ptr2 != nullptr); + + const Grid g3(index,std::nullopt,label,style,unit,Link("mylink")); + Grid g4(index,std::nullopt,label,style,unit,Link("mylink")); + const Link *ptr3 = g3.link; + Link *ptr4 = g4.link; + const Link &ref3 = g3.link; + Link &ref4 = g4.link; + CHECK(ptr3 != nullptr); + CHECK(ptr4 != nullptr); + } + + { + const Grid g1(index,std::nullopt,label,style,unit,Values(values)); + Grid g2(index,std::nullopt,label,style,unit,Values(values)); + const Link *ptr1 = g1.link.ptr(); + Link *ptr2 = g2.link.ptr(); + CHECK(ptr1 == nullptr); + CHECK(ptr2 == nullptr); + + const Grid g3(index,std::nullopt,label,style,unit,Link("mylink")); + Grid g4(index,std::nullopt,label,style,unit,Link("mylink")); + const Values *ptr3 = g3.values.ptr(); + Values *ptr4 = g4.values.ptr(); + CHECK(ptr3 == nullptr); + CHECK(ptr4 == nullptr); + } + } + + Grid chunk( index, std::nullopt, label, style, unit, Values( values ) ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + + WHEN( "the data are constructed from a node" ) { + + Node node; + node << chunk(); + Grid chunk( node ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "valid data for the component with a Link component" ) { + + std::string string = chunkWithLink(); + + WHEN( "autogenerated constructor: the data are given explicitly" ) { + + unsigned index = 1; + std::string label = "column_energy_bounds"; + std::string unit = "eV"; + enums::GridStyle style = enums::GridStyle::link; + std::string href = "../../grid[@index='2']/values"; + + Grid chunk( index, std::nullopt, label, style, unit, + Link( href ) ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunkWithLink( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + + WHEN( "the data are constructed from a node" ) { + + Node node; + node << chunkWithLink(); + Grid chunk( node ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunkWithLink( chunk ); + } // THEN + + THEN( "it can be written in XML" ) { + + std::ostringstream out; + XML( Node( chunk ) ).write( out, false ); + + CHECK( out.str() == string ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "a valid component instance" ) { + + WHEN( "the component is copied" ) { + + Node node; + node << chunk(); + Grid chunk( node ); + + // copy constructor + Grid copy( chunk ); + + // copy assignment + Grid assign; + assign = chunk; + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( copy ); + verifyChunk( assign ); + } // THEN + } // WHEN + + WHEN( "the data are moved" ) { + + Node node; + node << chunk(); + Grid chunk( node ); + Grid chunk2( node ); + + // move constructor + Grid move( std::move( chunk ) ); + + // move assignment + Grid assign; + assign = std::move( chunk2 ); + + THEN( "the component can be constructed and members can be tested" ) { + + verifyChunk( move ); + verifyChunk( assign ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data" ) { + + WHEN( "when the wrong node is used" ) { + + Node node; + node << invalidName(); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( Grid( node ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return +R"***( + 1e-05 2e+07 +)***"; +} + +void verifyChunk( const Grid& component ) { + + CHECK( std::nullopt != component.index() ); + CHECK( std::nullopt != component.label() ); + CHECK( std::nullopt != component.style() ); + CHECK( std::nullopt != component.unit() ); + + CHECK( 2 == component.index().value() ); + CHECK( "row_energy_bounds" == component.label().value() ); + CHECK( "eV" == component.unit().value() ); + CHECK( enums::GridStyle::boundaries == component.style().value() ); + + CHECK( 2 == component.index() ); + CHECK( "row_energy_bounds" == component.label() ); + CHECK( "eV" == component.unit() ); + CHECK( enums::GridStyle::boundaries == component.style() ); + + decltype(auto) values = std::get< Values >( component.link_values() ); + CHECK( 2 == values.length() ); + CHECK( 0 == values.start() ); + CHECK( "Float64" == values.valueType().value() ); + + CHECK( 2 == values.size() ); + CHECK( 2 == values.doubles().size() ); + + CHECK( 1e-5 == Approx( values.doubles()[0] ) ); + CHECK( 2e+7 == Approx( values.doubles()[1] ) ); +} + +std::string chunkWithLink() { + + return +R"***( + +)***"; +} + +void verifyChunkWithLink( const Grid& component ) { + + CHECK( std::nullopt != component.index() ); + CHECK( std::nullopt != component.label() ); + CHECK( std::nullopt != component.style() ); + CHECK( std::nullopt != component.unit() ); + + CHECK( 1 == component.index().value() ); + CHECK( "column_energy_bounds" == component.label().value() ); + CHECK( "eV" == component.unit().value() ); + CHECK( enums::GridStyle::link == component.style().value() ); + + CHECK( 1 == component.index() ); + CHECK( "column_energy_bounds" == component.label() ); + CHECK( "eV" == component.unit() ); + CHECK( enums::GridStyle::link == component.style() ); + + decltype(auto) link = std::get< Link >( component.link_values() ); + CHECK( "../../grid[@index='2']/values" == link.href() ); +} + +std::string invalidName() { + + // wrong name for the node + return +R"***( + +)***"; +} diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Link.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Link.hpp new file mode 100644 index 000000000..58bb142a1 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Link.hpp @@ -0,0 +1,179 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_LINK +#define PROTO_V1_9_CONTAINERS_LINK + +#include "proto/v1.9/key.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Link +// ----------------------------------------------------------------------------- + +class Link : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Link"; } + static auto NODENAME() { return "link"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::string{} + / Meta<>("href") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "href" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "href" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + href{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->href \ + ) + + // default + Link() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Link( + const wrapper + &href + ) : + GNDSTK_COMPONENT(BlockData{}), + href(this,href) + { + Component::finish(); + } + + // from node + explicit Link(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Link(const Link &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + href(this,other.href) + { + Component::finish(other); + } + + // move + Link(Link &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + href(this,std::move(other.href)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Link &operator=(const Link &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + href = other.href; + } + return *this; + } + + // move + Link &operator=(Link &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + href = std::move(other.href); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Link/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Link + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/containers/Link/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Link/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/containers/Link/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Link/src/custom.hpp diff --git a/src/GNDStk/v1.9/containers/Link/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Link/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Link/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Link/test/CMakeLists.txt diff --git a/src/GNDStk/v1.9/containers/Link/test/Link.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Link/test/Link.test.cpp similarity index 87% rename from src/GNDStk/v1.9/containers/Link/test/Link.test.cpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Link/test/Link.test.cpp index a0c5d544c..c1534e6c5 100644 --- a/src/GNDStk/v1.9/containers/Link/test/Link.test.cpp +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Link/test/Link.test.cpp @@ -1,12 +1,15 @@ + #define CATCH_CONFIG_MAIN #include "catch.hpp" -#include "GNDStk/v1.9/containers/Link.hpp" +#include "proto/v1.9/containers/Link.hpp" // other includes // convenience typedefs using namespace njoy::GNDStk; +using namespace proto; + using Link = v1_9::containers::Link; std::string chunk(); @@ -19,7 +22,7 @@ SCENARIO( "Link" ) { std::string string = chunk(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { std::string href = "../../grid[@index='2']/values"; @@ -39,7 +42,7 @@ SCENARIO( "Link" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunk(); @@ -82,7 +85,7 @@ SCENARIO( "Link" ) { } // THEN } // WHEN - WHEN( "the data is moved" ) { + WHEN( "the data are moved" ) { Node node; node << chunk(); @@ -122,8 +125,7 @@ SCENARIO( "Link" ) { std::string chunk() { return -R"***( -)***"; +R"***()***"; } void verifyChunk( const Link& component ) { @@ -135,6 +137,5 @@ std::string invalidName() { // wrong name for the node return -R"***( -)***"; +R"***()***"; } diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d.hpp new file mode 100644 index 000000000..94561816f --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d.hpp @@ -0,0 +1,226 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_REGIONS1D +#define PROTO_V1_9_CONTAINERS_REGIONS1D + +#include "proto/v1.9/containers/Axes.hpp" +#include "proto/v1.9/containers/XYs1d.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Regions1d +// ----------------------------------------------------------------------------- + +class Regions1d : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Regions1d"; } + static auto NODENAME() { return "regions1d"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("label") | + std::optional{} + / Meta<>("outerDomainValue") | + + // children + --Child> + ("axes") | + ++Child + ("XYs1d") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "label", + "outerDomainValue", + "axes", + "XYs1d" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "label", + "outer_domain_value", + "axes", + "xys1d" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + label{this}; + Field> + outerDomainValue{this}; + + // children + Field> + axes{this}; + Field> + XYs1d{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->label, \ + this->outerDomainValue, \ + this->axes, \ + this->XYs1d \ + ) + + // default + Regions1d() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Regions1d( + const wrapper> + &label, + const wrapper> + &outerDomainValue = {}, + const wrapper> + &axes = {}, + const wrapper> + &XYs1d = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + label(this,label), + outerDomainValue(this,outerDomainValue), + axes(this,axes), + XYs1d(this,XYs1d) + { + Component::finish(); + } + + // from node + explicit Regions1d(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Regions1d(const Regions1d &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + label(this,other.label), + outerDomainValue(this,other.outerDomainValue), + axes(this,other.axes), + XYs1d(this,other.XYs1d) + { + Component::finish(other); + } + + // move + Regions1d(Regions1d &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + label(this,std::move(other.label)), + outerDomainValue(this,std::move(other.outerDomainValue)), + axes(this,std::move(other.axes)), + XYs1d(this,std::move(other.XYs1d)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Regions1d &operator=(const Regions1d &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + label = other.label; + outerDomainValue = other.outerDomainValue; + axes = other.axes; + XYs1d = other.XYs1d; + } + return *this; + } + + // move + Regions1d &operator=(Regions1d &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + label = std::move(other.label); + outerDomainValue = std::move(other.outerDomainValue); + axes = std::move(other.axes); + XYs1d = std::move(other.XYs1d); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Regions1d/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Regions1d + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/containers/Regions1d/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/containers/Regions1d/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/src/custom.hpp diff --git a/src/GNDStk/v1.9/containers/Regions1d/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Regions1d/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test/CMakeLists.txt diff --git a/src/GNDStk/v1.9/containers/Regions1d/test/Regions1d.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test/Regions1d.test.cpp similarity index 83% rename from src/GNDStk/v1.9/containers/Regions1d/test/Regions1d.test.cpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test/Regions1d.test.cpp index f8d93ec35..3175fa715 100644 --- a/src/GNDStk/v1.9/containers/Regions1d/test/Regions1d.test.cpp +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test/Regions1d.test.cpp @@ -1,12 +1,15 @@ + #define CATCH_CONFIG_MAIN #include "catch.hpp" -#include "GNDStk/v1.9/containers/Regions1d.hpp" +#include "proto/v1.9/containers/Regions1d.hpp" // other includes // convenience typedefs using namespace njoy::GNDStk; +using namespace proto; + using Regions1d = v1_9::containers::Regions1d; using XYs1d = v1_9::containers::XYs1d; using Axes = v1_9::containers::Axes; @@ -20,29 +23,32 @@ void verifyChunk( const Regions1d& ); std::string invalidName(); SCENARIO( "Regions1d" ) { + njoy::GNDStk::sort = true; GIVEN( "valid data for the component" ) { std::string string = chunk(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { Regions1d chunk( - std::nullopt, // optional label - std::nullopt, // optional outer domain value + std::nullopt, // optional label + std::nullopt, // optional outer domain value + Axes( std::nullopt, + std::vector< std::variant< Axis, Grid > >{ + Axis( 1, "energy_in", "eV" ), + Axis( 0, "crossSection", "b" ) } ), // optional axes std::vector< XYs1d >{ XYs1d( 0, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - Values( std::vector< double >{ 0.0253, 4.34057, 30000, 1.62386 } ) ), + Values( std::vector< double >{ + 0.0253, 4.34057, 30000, 1.62386 } ) ), XYs1d( 1, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - Values( std::vector< double >{ 30000, 1.65691, 2e+7, 2.35696 } ) ) - }, // vector of 1D functions - Axes( std::nullopt, - std::vector< std::variant< Axis, Grid > >{ - Axis( 1, "energy_in", "eV" ), - Axis( 0, "crossSection", "b" ) } ) // optional axes + Values( std::vector< double >{ + 30000, 1.65691, 2e+7, 2.35696 } ) ) + } // vector of 1D functions ); THEN( "the component can be constructed and members can be tested" ) { @@ -59,7 +65,7 @@ SCENARIO( "Regions1d" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunk(); @@ -102,7 +108,7 @@ SCENARIO( "Regions1d" ) { } // THEN } // WHEN - WHEN( "the data is moved" ) { + WHEN( "the data are moved" ) { Node node; node << chunk(); @@ -143,18 +149,17 @@ std::string chunk() { return R"***( - - 0.0253 4.34057 30000 1.62386 - - - 30000 1.65691 2e+07 2.35696 - - -)***"; + + 0.0253 4.34057 30000 1.62386 + + + 30000 1.65691 2e+07 2.35696 + +)***"; } void verifyChunk( const Regions1d& component ) { @@ -166,7 +171,8 @@ void verifyChunk( const Regions1d& component ) { // axes data CHECK( 2 == component.axes().value().axis_grid().size() ); - decltype(auto) axis0 = std::get< Axis >( component.axes().value().axis_grid()[0] ); + decltype(auto) axis0 = + std::get< Axis >( component.axes().value().axis_grid()[0] ); CHECK( std::nullopt != axis0.index() ); CHECK( std::nullopt != axis0.label() ); CHECK( std::nullopt != axis0.unit() ); @@ -174,7 +180,8 @@ void verifyChunk( const Regions1d& component ) { CHECK( "crossSection" == axis0.label().value() ); CHECK( "b" == axis0.unit().value() ); - decltype(auto) axis1 = std::get< Axis >( component.axes().value().axis_grid()[1] ); + decltype(auto) axis1 = + std::get< Axis >( component.axes().value().axis_grid()[1] ); CHECK( std::nullopt != axis1.index() ); CHECK( std::nullopt != axis1.label() ); CHECK( std::nullopt != axis1.unit() ); @@ -224,15 +231,14 @@ std::string invalidName() { return R"***( - 0.0253 4.34057 30000 1.62386 + 0.0253 4.34057 30000 1.62386 - 30000 1.65691 2e+07 2.35696 + 30000 1.65691 2e+07 2.35696 - -)***"; +)***"; } diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Values.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Values.hpp new file mode 100644 index 000000000..c6c59fa6b --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Values.hpp @@ -0,0 +1,223 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_VALUES +#define PROTO_V1_9_CONTAINERS_VALUES + +#include "proto/v1.9/key.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class Values +// ----------------------------------------------------------------------------- + +class Values : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "Values"; } + static auto NODENAME() { return "values"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + Defaulted{"double"} + / Meta<>("valueType") | + Defaulted{0} + / Meta<>("start") | + std::optional{} + / Meta<>("length") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "valueType", + "start", + "length" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "value_type", + "start", + "length" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + using BlockData::operator=; + + // defaults + static inline const struct Defaults { + static inline const std::string valueType = "double"; + static inline const int start = 0; + } defaults; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + mutable Field> + valueType{this,defaults.valueType}; + mutable Field> + start{this,defaults.start}; + mutable Field> + length{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->valueType, \ + this->start, \ + this->length \ + ) + + // default + Values() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + // optional replaces Defaulted; this class knows the default(s) + explicit Values( + const wrapper> + &valueType, + const wrapper> + &start = {}, + const wrapper> + &length = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + valueType(this,defaults.valueType,valueType), + start(this,defaults.start,start), + length(this,length) + { + Component::finish(); + } + + // from node + explicit Values(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // from vector + template>> + explicit Values(const std::vector &vector) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(vector); + } + + // copy + Values(const Values &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + valueType(this,other.valueType), + start(this,other.start), + length(this,other.length) + { + Component::finish(other); + } + + // move + Values(Values &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + valueType(this,std::move(other.valueType)), + start(this,std::move(other.start)), + length(this,std::move(other.length)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Values &operator=(const Values &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + valueType = other.valueType; + start = other.start; + length = other.length; + } + return *this; + } + + // move + Values &operator=(Values &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + valueType = std::move(other.valueType); + start = std::move(other.start); + length = std::move(other.length); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/Values/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Values + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/Values/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/Values/src/custom.hpp new file mode 100644 index 000000000..ccf86f6b5 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Values/src/custom.hpp @@ -0,0 +1,54 @@ +private: + + static inline helpMap help = { + + { "", "A GNDS basic component: a list of values\n\n" + "This component is used in the nodes like XYs1D or the grid node." }, + { "constructor", "Initialise the values component\n\n" + "Arguments:\n" + " self the values component\n" + " values the values\n" + " start the starting index of the values\n" + " value_type the value type\n" }, + { "length", "The length of the values" }, + { "start", "The starting index of the values (default = 0)" }, + { "value_type", "The value type (default = 'Float64')" }, + { "doubles", "The underlying values" } + }; + + /** + * Custom construct function + */ + void construct() { + + if ( this->length() != std::nullopt ) { + + if ( this->length() != this->size() + this->start() ) { + + log::error( "Inconsistent size for \"values\" array" ); + log::info( "start: {}", this->start() ); + log::info( "length: {}", this->length().value() ); + log::info( "number of values: {}", this->size() ); + throw std::exception(); + } + } + } + +public: + + template < typename T, + typename = std::enable_if_t< + detail::isAlternative< T, VariantOfScalars > > > + Values( const std::optional< int >& length, + const std::optional< int >& start, + const std::optional< std::string >& valueType, + const std::vector< T >& values ) : + GNDSTK_COMPONENT(BlockData{}), + valueType(this,defaults.valueType,valueType), + start(this,defaults.start,start), + length(this,length) + { + + *this = values; + Component::finish(); // ensure that construct() gets called + } diff --git a/src/GNDStk/v1.9/containers/Values/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/Values/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/Values/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/Values/test/CMakeLists.txt diff --git a/src/GNDStk/v1.9/containers/Values/test/Values.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/Values/test/Values.test.cpp similarity index 87% rename from src/GNDStk/v1.9/containers/Values/test/Values.test.cpp rename to autogen/prototype/proto/src/proto/v1.9/containers/Values/test/Values.test.cpp index d8e132d5d..d2912e4a7 100644 --- a/src/GNDStk/v1.9/containers/Values/test/Values.test.cpp +++ b/autogen/prototype/proto/src/proto/v1.9/containers/Values/test/Values.test.cpp @@ -1,12 +1,15 @@ + #define CATCH_CONFIG_MAIN #include "catch.hpp" -#include "GNDStk/v1.9/containers/Values.hpp" +#include "proto/v1.9/containers/Values.hpp" // other includes // convenience typedefs using namespace njoy::GNDStk; +using namespace proto; + using Values = v1_9::containers::Values; std::string chunk(); @@ -23,7 +26,7 @@ SCENARIO( "Values" ) { std::string string = chunk(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { std::vector< double > values = { 2500., 8.9172, 2550., 8.9155 }; @@ -43,7 +46,7 @@ SCENARIO( "Values" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunk(); @@ -68,7 +71,7 @@ SCENARIO( "Values" ) { std::string string = chunkInts(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { std::vector< Integer32 > values = { 2500, 9, 2550, 9 }; @@ -88,7 +91,7 @@ SCENARIO( "Values" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunkInts(); @@ -113,7 +116,7 @@ SCENARIO( "Values" ) { std::string string = chunkStrings(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { std::vector< UTF8Text > values = { "2500", "8.9172", "2550", "8.9155" }; @@ -133,7 +136,7 @@ SCENARIO( "Values" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunkStrings(); @@ -176,7 +179,7 @@ SCENARIO( "Values" ) { } // THEN } // WHEN - WHEN( "the data is moved" ) { + WHEN( "the data are moved" ) { Node node; node << chunk(); @@ -216,8 +219,7 @@ SCENARIO( "Values" ) { std::string chunk() { return -R"***(2500 8.9172 2550 8.9155 -)***"; +R"***(2500 8.9172 2550 8.9155)***"; } void verifyChunk( const Values& component ) { @@ -238,8 +240,7 @@ void verifyChunk( const Values& component ) { std::string chunkInts() { return -R"***(2500 9 2550 9 -)***"; +R"***(2500 9 2550 9)***"; } void verifyChunkInts( const Values& component ) { @@ -260,8 +261,7 @@ void verifyChunkInts( const Values& component ) { std::string chunkStrings() { return -R"***(2500 8.9172 2550 8.9155 -)***"; +R"***(2500 8.9172 2550 8.9155)***"; } void verifyChunkStrings( const Values& component ) { @@ -283,6 +283,5 @@ std::string invalidName() { // wrong name for the node return -R"***(2500 8.9172 2550 8.9155 -)***"; +R"***(2500 8.9172 2550 8.9155)***"; } diff --git a/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d.hpp new file mode 100644 index 000000000..2b3937b9c --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d.hpp @@ -0,0 +1,260 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_CONTAINERS_XYS1D +#define PROTO_V1_9_CONTAINERS_XYS1D + +#include "proto/v1.9/containers/Axes.hpp" +#include "proto/v1.9/containers/Values.hpp" + +namespace proto { +namespace v1_9 { +namespace containers { + +// ----------------------------------------------------------------------------- +// containers:: +// class XYs1d +// ----------------------------------------------------------------------------- + +class XYs1d : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "containers"; } + static auto CLASS() { return "XYs1d"; } + static auto NODENAME() { return "XYs1d"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("index") | + Defaulted{enums::Interpolation::linlin} + / Meta<>("interpolation") | + std::optional{} + / Meta<>("label") | + std::optional{} + / Meta<>("outerDomainValue") | + + // children + --Child> + ("axes") | + --Child + ("values") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "index", + "interpolation", + "label", + "outerDomainValue", + "axes", + "values" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "index", + "interpolation", + "label", + "outer_domain_value", + "axes", + "values" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // defaults + static inline const struct Defaults { + static inline const enums::Interpolation interpolation = enums::Interpolation::linlin; + } defaults; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + index{this}; + Field> + interpolation{this,defaults.interpolation}; + Field> + label{this}; + Field> + outerDomainValue{this}; + + // children + Field> + axes{this}; + Field + values{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->index, \ + this->interpolation, \ + this->label, \ + this->outerDomainValue, \ + this->axes, \ + this->values \ + ) + + // default + XYs1d() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + // optional replaces Defaulted; this class knows the default(s) + explicit XYs1d( + const wrapper> + &index, + const wrapper> + &interpolation = {}, + const wrapper> + &label = {}, + const wrapper> + &outerDomainValue = {}, + const wrapper> + &axes = {}, + const wrapper + &values = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + index(this,index), + interpolation(this,defaults.interpolation,interpolation), + label(this,label), + outerDomainValue(this,outerDomainValue), + axes(this,axes), + values(this,values) + { + Component::finish(); + } + + // from node + explicit XYs1d(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + XYs1d(const XYs1d &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + index(this,other.index), + interpolation(this,other.interpolation), + label(this,other.label), + outerDomainValue(this,other.outerDomainValue), + axes(this,other.axes), + values(this,other.values) + { + Component::finish(other); + } + + // move + XYs1d(XYs1d &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + index(this,std::move(other.index)), + interpolation(this,std::move(other.interpolation)), + label(this,std::move(other.label)), + outerDomainValue(this,std::move(other.outerDomainValue)), + axes(this,std::move(other.axes)), + values(this,std::move(other.values)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + XYs1d &operator=(const XYs1d &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + index = other.index; + interpolation = other.interpolation; + label = other.label; + outerDomainValue = other.outerDomainValue; + axes = other.axes; + values = other.values; + } + return *this; + } + + // move + XYs1d &operator=(XYs1d &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + index = std::move(other.index); + interpolation = std::move(other.interpolation); + label = std::move(other.label); + outerDomainValue = std::move(other.outerDomainValue); + axes = std::move(other.axes); + values = std::move(other.values); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/containers/XYs1d/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class XYs1d + +} // namespace containers +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/containers/XYs1d/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/containers/XYs1d/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/src/custom.hpp diff --git a/src/GNDStk/v1.9/containers/XYs1d/test/CMakeLists.txt b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test/CMakeLists.txt similarity index 100% rename from src/GNDStk/v1.9/containers/XYs1d/test/CMakeLists.txt rename to autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test/CMakeLists.txt diff --git a/src/GNDStk/v1.9/containers/XYs1d/test/XYs1d.test.cpp b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test/XYs1d.test.cpp similarity index 87% rename from src/GNDStk/v1.9/containers/XYs1d/test/XYs1d.test.cpp rename to autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test/XYs1d.test.cpp index 05c427b6a..1429a2a15 100644 --- a/src/GNDStk/v1.9/containers/XYs1d/test/XYs1d.test.cpp +++ b/autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test/XYs1d.test.cpp @@ -1,12 +1,15 @@ + #define CATCH_CONFIG_MAIN #include "catch.hpp" -#include "GNDStk/v1.9/containers/XYs1d.hpp" +#include "proto/v1.9/containers/XYs1d.hpp" // other includes // convenience typedefs using namespace njoy::GNDStk; +using namespace proto; + using XYs1d = v1_9::containers::XYs1d; using Axes = v1_9::containers::Axes; using Axis = v1_9::containers::Axis; @@ -19,19 +22,21 @@ void verifyChunk( const XYs1d& ); std::string invalidName(); SCENARIO( "XYs1d" ) { + njoy::GNDStk::sort = true; GIVEN( "valid data for the component" ) { std::string string = chunk(); - WHEN( "autogenerated constructor: the data is given explicitly" ) { + WHEN( "autogenerated constructor: the data are given explicitly" ) { XYs1d chunk( std::nullopt, std::nullopt, std::nullopt, std::nullopt, Axes( std::nullopt, std::vector< std::variant< Axis, Grid > >{ Axis( 1, "energy_in", "eV" ), Axis( 0, "crossSection", "b" ) } ), - Values( std::vector< double >{ 1e-05, 1., 2.53e-2, 2., 2.5e+3, 3. } ) ); + Values( std::vector< double > + { 1e-05, 1., 2.53e-2, 2., 2.5e+3, 3. } ) ); THEN( "the component can be constructed and members can be tested" ) { @@ -47,7 +52,7 @@ SCENARIO( "XYs1d" ) { } // THEN } // WHEN - WHEN( "the data is constructed from a node" ) { + WHEN( "the data are constructed from a node" ) { Node node; node << chunk(); @@ -90,7 +95,7 @@ SCENARIO( "XYs1d" ) { } // THEN } // WHEN - WHEN( "the data is moved" ) { + WHEN( "the data are moved" ) { Node node; node << chunk(); @@ -135,9 +140,8 @@ R"***( - 1e-05 1 0.0253 2 2500 3 - -)***"; + 1e-05 1 0.0253 2 2500 3 +)***"; } void verifyChunk( const XYs1d& component ) { @@ -150,7 +154,8 @@ void verifyChunk( const XYs1d& component ) { CHECK( enums::Interpolation::linlin == component.interpolation() ); // axes data - decltype(auto) axis0 = std::get< Axis >( component.axes().value().axis_grid()[0] ); + decltype(auto) axis0 = + std::get< Axis >( component.axes().value().axis_grid()[0] ); CHECK( std::nullopt != axis0.index() ); CHECK( std::nullopt != axis0.label() ); @@ -160,7 +165,8 @@ void verifyChunk( const XYs1d& component ) { CHECK( "crossSection" == axis0.label().value() ); CHECK( "b" == axis0.unit().value() ); - decltype(auto) axis1 = std::get< Axis >( component.axes().value().axis_grid()[1] ); + decltype(auto) axis1 = + std::get< Axis >( component.axes().value().axis_grid()[1] ); CHECK( std::nullopt != axis1.index() ); CHECK( std::nullopt != axis1.label() ); @@ -196,6 +202,5 @@ R"***( 1e-05 1. 2.53e-2 2. 2.5e+3 3. - -)***"; +)***"; } diff --git a/autogen/prototype/proto/src/proto/v1.9/key.hpp b/autogen/prototype/proto/src/proto/v1.9/key.hpp new file mode 100644 index 000000000..5e7c10c73 --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/key.hpp @@ -0,0 +1,114 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_KEY +#define PROTO_V1_9_KEY + +// GNDStk Core Interface +#include "GNDStk.hpp" + +namespace proto { +namespace v1_9 { + +using namespace njoy; +using namespace GNDStk; + + +// ----------------------------------------------------------------------------- +// meta:: +// ----------------------------------------------------------------------------- + +namespace meta { + +#define GNDSTK_MAKE_LOOKUP(nameField,nameGNDS) \ + inline const auto nameField = makeLookup( \ + [](const auto &obj) -> decltype(obj.nameField()) \ + { return obj.nameField(); }, \ + #nameGNDS \ + ) +// nameField vs. nameGNDS: for, e.g., Double vs. double in GNDS + +GNDSTK_MAKE_LOOKUP(ENDF_MT,ENDF_MT); +GNDSTK_MAKE_LOOKUP(evaluation,evaluation); +GNDSTK_MAKE_LOOKUP(fissionGenre,fissionGenre); +GNDSTK_MAKE_LOOKUP(format,format); +GNDSTK_MAKE_LOOKUP(href,href); +GNDSTK_MAKE_LOOKUP(index,index); +GNDSTK_MAKE_LOOKUP(interaction,interaction); +GNDSTK_MAKE_LOOKUP(interpolation,interpolation); +GNDSTK_MAKE_LOOKUP(label,label); +GNDSTK_MAKE_LOOKUP(length,length); +GNDSTK_MAKE_LOOKUP(outerDomainValue,outerDomainValue); +GNDSTK_MAKE_LOOKUP(projectile,projectile); +GNDSTK_MAKE_LOOKUP(projectileFrame,projectileFrame); +GNDSTK_MAKE_LOOKUP(start,start); +GNDSTK_MAKE_LOOKUP(style,style); +GNDSTK_MAKE_LOOKUP(target,target); +GNDSTK_MAKE_LOOKUP(unit,unit); +GNDSTK_MAKE_LOOKUP(valueType,valueType); + +#undef GNDSTK_MAKE_LOOKUP + +} // namespace meta + + +// ----------------------------------------------------------------------------- +// containers::child:: +// ----------------------------------------------------------------------------- + +namespace containers { +namespace child { + +inline const Child<> XYs1d("XYs1d"); +inline const Child<> axes("axes"); +inline const Child<> axis("axis"); +inline const Child<> grid("grid"); +inline const Child<> link("link"); +inline const Child<> regions1d("regions1d"); +inline const Child<> values("values"); + +} // namespace child +using namespace child; +} // namespace containers + + +// ----------------------------------------------------------------------------- +// transport::child:: +// ----------------------------------------------------------------------------- + +namespace transport { +namespace child { + +inline const Child<> crossSection("crossSection"); +inline const Child<> reaction("reaction"); +inline const Child<> reactionSuite("reactionSuite"); +inline const Child<> reactions("reactions"); + +} // namespace child +using namespace child; +} // namespace transport + + +// ----------------------------------------------------------------------------- +// For convenience: using directives +// ----------------------------------------------------------------------------- + +namespace key { + using namespace meta; + using namespace containers::child; + using namespace transport::child; +} // namespace key + +using namespace key; +using namespace containers; +using namespace transport; + + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/autogen/prototype/proto/src/proto/v1.9/transport/CrossSection.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/CrossSection.hpp new file mode 100644 index 000000000..f4914035b --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/transport/CrossSection.hpp @@ -0,0 +1,187 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_TRANSPORT_CROSSSECTION +#define PROTO_V1_9_TRANSPORT_CROSSSECTION + +#include "proto/v1.9/containers/XYs1d.hpp" +#include "proto/v1.9/containers/Regions1d.hpp" + +namespace proto { +namespace v1_9 { +namespace transport { + +// ----------------------------------------------------------------------------- +// transport:: +// class CrossSection +// ----------------------------------------------------------------------------- + +class CrossSection : + public Component +{ + friend class Component; + + using XYs1d_regions1d_t = std::variant< + containers::XYs1d, + containers::Regions1d + >; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "transport"; } + static auto CLASS() { return "CrossSection"; } + static auto NODENAME() { return "crossSection"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // children + XYs1d_regions1d_t{} + / ++(Child<>("XYs1d") || Child<>("regions1d")) + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "XYs1d_regions1d" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "xys1d_regions1d" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // children - variant + Field> + XYs1d_regions1d{this}; + FieldPart XYs1d{XYs1d_regions1d}; + FieldPart regions1d{XYs1d_regions1d}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->XYs1d_regions1d \ + ) + + // default + CrossSection() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit CrossSection( + const wrapper> + &XYs1d_regions1d + ) : + GNDSTK_COMPONENT(BlockData{}), + XYs1d_regions1d(this,XYs1d_regions1d) + { + Component::finish(); + } + + // from node + explicit CrossSection(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + CrossSection(const CrossSection &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + XYs1d_regions1d(this,other.XYs1d_regions1d) + { + Component::finish(other); + } + + // move + CrossSection(CrossSection &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + XYs1d_regions1d(this,std::move(other.XYs1d_regions1d)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + CrossSection &operator=(const CrossSection &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + XYs1d_regions1d = other.XYs1d_regions1d; + } + return *this; + } + + // move + CrossSection &operator=(CrossSection &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + XYs1d_regions1d = std::move(other.XYs1d_regions1d); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/transport/CrossSection/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class CrossSection + +} // namespace transport +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/transport/CrossSection/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/CrossSection/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/transport/CrossSection/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/transport/CrossSection/src/custom.hpp diff --git a/autogen/prototype/proto/src/proto/v1.9/transport/Reaction.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/Reaction.hpp new file mode 100644 index 000000000..749405b8c --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/transport/Reaction.hpp @@ -0,0 +1,225 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_TRANSPORT_REACTION +#define PROTO_V1_9_TRANSPORT_REACTION + +#include "proto/v1.9/transport/CrossSection.hpp" + +namespace proto { +namespace v1_9 { +namespace transport { + +// ----------------------------------------------------------------------------- +// transport:: +// class Reaction +// ----------------------------------------------------------------------------- + +class Reaction : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "transport"; } + static auto CLASS() { return "Reaction"; } + static auto NODENAME() { return "reaction"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + int{} + / Meta<>("ENDF_MT") | + std::optional{} + / Meta<>("fissionGenre") | + std::string{} + / Meta<>("label") | + + // children + --Child + ("crossSection") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "ENDF_MT", + "fissionGenre", + "label", + "crossSection" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "endf_mt", + "fission_genre", + "label", + "cross_section" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + ENDF_MT{this}; + Field> + fissionGenre{this}; + Field + label{this}; + + // children + Field + crossSection{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->ENDF_MT, \ + this->fissionGenre, \ + this->label, \ + this->crossSection \ + ) + + // default + Reaction() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Reaction( + const wrapper + &ENDF_MT, + const wrapper> + &fissionGenre = {}, + const wrapper + &label = {}, + const wrapper + &crossSection = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + ENDF_MT(this,ENDF_MT), + fissionGenre(this,fissionGenre), + label(this,label), + crossSection(this,crossSection) + { + Component::finish(); + } + + // from node + explicit Reaction(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Reaction(const Reaction &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + ENDF_MT(this,other.ENDF_MT), + fissionGenre(this,other.fissionGenre), + label(this,other.label), + crossSection(this,other.crossSection) + { + Component::finish(other); + } + + // move + Reaction(Reaction &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + ENDF_MT(this,std::move(other.ENDF_MT)), + fissionGenre(this,std::move(other.fissionGenre)), + label(this,std::move(other.label)), + crossSection(this,std::move(other.crossSection)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Reaction &operator=(const Reaction &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + ENDF_MT = other.ENDF_MT; + fissionGenre = other.fissionGenre; + label = other.label; + crossSection = other.crossSection; + } + return *this; + } + + // move + Reaction &operator=(Reaction &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + ENDF_MT = std::move(other.ENDF_MT); + fissionGenre = std::move(other.fissionGenre); + label = std::move(other.label); + crossSection = std::move(other.crossSection); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/transport/Reaction/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Reaction + +} // namespace transport +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/transport/Reaction/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/Reaction/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/transport/Reaction/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/transport/Reaction/src/custom.hpp diff --git a/autogen/prototype/proto/src/proto/v1.9/transport/ReactionSuite.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/ReactionSuite.hpp new file mode 100644 index 000000000..74bb5ccda --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/transport/ReactionSuite.hpp @@ -0,0 +1,267 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_TRANSPORT_REACTIONSUITE +#define PROTO_V1_9_TRANSPORT_REACTIONSUITE + +#include "proto/v1.9/transport/Reactions.hpp" + +namespace proto { +namespace v1_9 { +namespace transport { + +// ----------------------------------------------------------------------------- +// transport:: +// class ReactionSuite +// ----------------------------------------------------------------------------- + +class ReactionSuite : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "transport"; } + static auto CLASS() { return "ReactionSuite"; } + static auto NODENAME() { return "reactionSuite"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::string{} + / Meta<>("evaluation") | + std::string{} + / Meta<>("format") | + std::string{} + / Meta<>("projectile") | + enums::Frame{} + / Meta<>("projectileFrame") | + std::string{} + / Meta<>("target") | + std::optional{} + / Meta<>("interaction") | + + // children + --Child> + ("reactions") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "evaluation", + "format", + "projectile", + "projectileFrame", + "target", + "interaction", + "reactions" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "evaluation", + "format", + "projectile", + "projectile_frame", + "target", + "interaction", + "reactions" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + evaluation{this}; + Field + format{this}; + Field + projectile{this}; + Field + projectileFrame{this}; + Field + target{this}; + Field> + interaction{this}; + + // children + Field> + reactions{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->evaluation, \ + this->format, \ + this->projectile, \ + this->projectileFrame, \ + this->target, \ + this->interaction, \ + this->reactions \ + ) + + // default + ReactionSuite() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit ReactionSuite( + const wrapper + &evaluation, + const wrapper + &format = {}, + const wrapper + &projectile = {}, + const wrapper + &projectileFrame = {}, + const wrapper + &target = {}, + const wrapper> + &interaction = {}, + const wrapper> + &reactions = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + evaluation(this,evaluation), + format(this,format), + projectile(this,projectile), + projectileFrame(this,projectileFrame), + target(this,target), + interaction(this,interaction), + reactions(this,reactions) + { + Component::finish(); + } + + // from node + explicit ReactionSuite(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + ReactionSuite(const ReactionSuite &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + evaluation(this,other.evaluation), + format(this,other.format), + projectile(this,other.projectile), + projectileFrame(this,other.projectileFrame), + target(this,other.target), + interaction(this,other.interaction), + reactions(this,other.reactions) + { + Component::finish(other); + } + + // move + ReactionSuite(ReactionSuite &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + evaluation(this,std::move(other.evaluation)), + format(this,std::move(other.format)), + projectile(this,std::move(other.projectile)), + projectileFrame(this,std::move(other.projectileFrame)), + target(this,std::move(other.target)), + interaction(this,std::move(other.interaction)), + reactions(this,std::move(other.reactions)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + ReactionSuite &operator=(const ReactionSuite &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + evaluation = other.evaluation; + format = other.format; + projectile = other.projectile; + projectileFrame = other.projectileFrame; + target = other.target; + interaction = other.interaction; + reactions = other.reactions; + } + return *this; + } + + // move + ReactionSuite &operator=(ReactionSuite &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + evaluation = std::move(other.evaluation); + format = std::move(other.format); + projectile = std::move(other.projectile); + projectileFrame = std::move(other.projectileFrame); + target = std::move(other.target); + interaction = std::move(other.interaction); + reactions = std::move(other.reactions); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/transport/ReactionSuite/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class ReactionSuite + +} // namespace transport +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/transport/ReactionSuite/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/ReactionSuite/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/transport/ReactionSuite/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/transport/ReactionSuite/src/custom.hpp diff --git a/autogen/prototype/proto/src/proto/v1.9/transport/Reactions.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/Reactions.hpp new file mode 100644 index 000000000..5d538bebe --- /dev/null +++ b/autogen/prototype/proto/src/proto/v1.9/transport/Reactions.hpp @@ -0,0 +1,179 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef PROTO_V1_9_TRANSPORT_REACTIONS +#define PROTO_V1_9_TRANSPORT_REACTIONS + +#include "proto/v1.9/transport/Reaction.hpp" + +namespace proto { +namespace v1_9 { +namespace transport { + +// ----------------------------------------------------------------------------- +// transport:: +// class Reactions +// ----------------------------------------------------------------------------- + +class Reactions : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "transport"; } + static auto CLASS() { return "Reactions"; } + static auto NODENAME() { return "reactions"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // children + ++Child + ("reaction") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "reaction" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "reaction" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // children + Field> + reaction{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->reaction \ + ) + + // default + Reactions() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Reactions( + const wrapper> + &reaction + ) : + GNDSTK_COMPONENT(BlockData{}), + reaction(this,reaction) + { + Component::finish(); + } + + // from node + explicit Reactions(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Reactions(const Reactions &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + reaction(this,other.reaction) + { + Component::finish(other); + } + + // move + Reactions(Reactions &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + reaction(this,std::move(other.reaction)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Reactions &operator=(const Reactions &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + reaction = other.reaction; + } + return *this; + } + + // move + Reactions &operator=(Reactions &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + reaction = std::move(other.reaction); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "proto/v1.9/transport/Reactions/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Reactions + +} // namespace transport +} // namespace v1_9 +} // namespace proto + +#endif diff --git a/src/GNDStk/v1.9/transport/Reactions/src/custom.hpp b/autogen/prototype/proto/src/proto/v1.9/transport/Reactions/src/custom.hpp similarity index 100% rename from src/GNDStk/v1.9/transport/Reactions/src/custom.hpp rename to autogen/prototype/proto/src/proto/v1.9/transport/Reactions/src/custom.hpp diff --git a/autogen/prototype/prototype.json b/autogen/prototype/prototype.json new file mode 100644 index 000000000..138df990b --- /dev/null +++ b/autogen/prototype/prototype.json @@ -0,0 +1,36 @@ +{ + "remark" : [ + "Path", + " Path to the Project directory.", + " Optional (defaults to .).", + "", + "Project", + " Base project directory into which the code generator should", + " place files. IMPORTANT: this should be a **plain** name only,", + " without any directory path. Use Path for that, if it's needed.", + " Optional (defaults to GNDStk).", + "", + "Version", + " Version number for this project.", + "", + "JSONDir", + " Directory in which the .json input files are located.", + "", + "JSONFiles", + " The .json input files.", + "", + "Do NOT end directories with a /" + ], + + "Path": ".", + "Project": "proto", + "Version": "v1.9", + + "JSONDir": ".", + "JSONFiles": [ + "generalPurpose.json", + "reactionSuite.json" + ], + + "Changes": "../changes.json" +} diff --git a/autogen/prototype/reactionSuite.json b/autogen/prototype/reactionSuite.json index 56280918b..814478bae 100644 --- a/autogen/prototype/reactionSuite.json +++ b/autogen/prototype/reactionSuite.json @@ -30,7 +30,7 @@ }, "children": { "reactions": { - "occurrence": "1", + "times": "1", "required": false } } @@ -40,7 +40,7 @@ "metadata": {}, "children": { "reaction": { - "occurrence": "1+", + "times": "1+", "required": true } } @@ -63,7 +63,7 @@ }, "children": { "crossSection": { - "occurrence": "1", + "times": "1", "required": true } } @@ -73,12 +73,12 @@ "metadata": {}, "children": { "XYs1d": { - "occurrence": "choice+", + "times": "choice+", "variant": "XYs1d_regions1d", "required": false }, "regions1d": { - "occurrence": "choice+", + "times": "choice+", "variant": "XYs1d_regions1d", "required": false } diff --git a/autogen/simple/.gitignore b/autogen/simple/.gitignore new file mode 100644 index 000000000..ad858e531 --- /dev/null +++ b/autogen/simple/.gitignore @@ -0,0 +1,20 @@ + +[0-9] +*.o +*~ + +*.h +*.hh +*.cc + +*.exe + +file.h5 +file.json +file.xml +out +foobar.xml +foobar.json +foobar.h5 +m +j diff --git a/autogen/simple/clean b/autogen/simple/clean new file mode 100755 index 000000000..a4eb9d408 --- /dev/null +++ b/autogen/simple/clean @@ -0,0 +1,3 @@ +#!/bin/bash + +/bin/rm -f *.o *.exe out *~ diff --git a/autogen/simple/compile-c b/autogen/simple/compile-c new file mode 100755 index 000000000..d6e8efc30 --- /dev/null +++ b/autogen/simple/compile-c @@ -0,0 +1,47 @@ +#!/bin/bash + +# C++ compilation command +COMPILE=" + clang++ -std=c++17 + -I../../../GNDStk/src + -I../../../GNDStk/c/src + -Imulti/src + -Imulti/c/src + -I../../../GNDStk/build/_deps/pugixml-adapter-src/src/src + -I../../../GNDStk/build/_deps/hdf5-src/include + -I../../../GNDStk/build/_deps/json-src/include + -I../../../GNDStk/build/_deps/json-src/include/nlohmann + -I../../../GNDStk/build/_deps/log-src/src + -I../../../GNDStk/build/_deps/spdlog-src/include + -I/usr/include/hdf5/serial + -DHIGHFIVE_USE_BOOST=OFF + -L/usr/lib/x86_64-linux-gnu/hdf5/serial + -lhdf5 + -fno-show-column + -Wno-unused-command-line-argument + -Wall -Wextra -Wpedantic " + +# pugixml +if [ ! -f "pugixml.o" ]; then + $COMPILE ../../../GNDStk/build/_deps/pugixml-adapter-src/src/src/pugixml.cpp -c & +fi + +# Compile C++ +$COMPILE -c ../../../GNDStk/c/src/GNDStk.cpp & +$COMPILE -c multi/c/src/v1/multigroup/Foobar.cpp & +$COMPILE -c multi/c/src/v1/multigroup/Isotope.cpp & +$COMPILE -c multi/c/src/v1/multigroup/Element.cpp & +$COMPILE -c multi/c/src/v1/multigroup/Library.cpp & +$COMPILE -c multi/c/src/v1/multigroup/Multigroup.cpp & + +wait $(jobs -p) + +# Compile C +clang \ + -I../../../GNDStk/c/src \ + -Imulti/c/src \ + example-01.c \ + *.o \ + -L/usr/lib/x86_64-linux-gnu/hdf5/serial \ + -lstdc++ -lm -lhdf5 \ + -o c.exe diff --git a/autogen/simple/compile-cpp b/autogen/simple/compile-cpp new file mode 100755 index 000000000..7411e1bba --- /dev/null +++ b/autogen/simple/compile-cpp @@ -0,0 +1,31 @@ +#!/bin/bash + +# C++ compilation command +COMPILE=" + clang++ -std=c++17 + -I../../../GNDStk/src + -Imulti/src + -I../../../GNDStk/build/_deps/pugixml-adapter-src/src/src + -I../../../GNDStk/build/_deps/hdf5-src/include + -I../../../GNDStk/build/_deps/json-src/include + -I../../../GNDStk/build/_deps/json-src/include/nlohmann + -I../../../GNDStk/build/_deps/log-src/src + -I../../../GNDStk/build/_deps/spdlog-src/include + -I/usr/include/hdf5/serial + -DHIGHFIVE_USE_BOOST=OFF + -L/usr/lib/x86_64-linux-gnu/hdf5/serial + -lhdf5 + -fno-show-column + -Wno-unused-command-line-argument + -Wall -Wextra -Wpedantic " + +# pugixml +if [ ! -f "pugixml.o" ]; then +$COMPILE ../../../GNDStk/build/_deps/pugixml-adapter-src/src/src/pugixml.cpp -c +fi + +# Compile +$COMPILE example-01.cpp pugixml.o -o cpp-01.exe & +$COMPILE example-02.cpp pugixml.o -o cpp-02.exe & + +wait $(jobs -p) diff --git a/autogen/simple/example-01.c b/autogen/simple/example-01.c new file mode 100644 index 000000000..78b4712ee --- /dev/null +++ b/autogen/simple/example-01.c @@ -0,0 +1,17 @@ + +#include +#include "v1.h" + +int main() +{ + // colored diagnostics and prettyprinting + color(1); + + Foobar one = FoobarDefault(); + Foobar two = FoobarDefault(); + + FoobarAssign(one,two); + FoobarPrint(one); + FoobarPrintXML(one); + FoobarPrintJSON(one); +} diff --git a/autogen/simple/example-01.cpp b/autogen/simple/example-01.cpp new file mode 100644 index 000000000..f9afcc1b5 --- /dev/null +++ b/autogen/simple/example-01.cpp @@ -0,0 +1,73 @@ + +#include "multi/v1.hpp" +using namespace multi::v1; + +int main() +{ + colors = true; + + // Make some elements. We can make elements ("outer + // objects") first, then add isotopes ("inner objects"). + Element H ("H", 1); + Element He("He",2); + Element Li("Li",3); + Element Be("Be",4); + + // Add some isotopes. With this short notation, we + // get vector push_back()s into an Element's vector + // of Isotopes. + H += Isotope(1); + H += Isotope(2); + H += Isotope(3); + + He += Isotope(3); + He += Isotope(4); + // ... + + // for fun... + He.isotope.replace(mass_number(4),Isotope(4)); + He. replace(mass_number(4),Isotope(4)); + + He.foobar = Foobar{}; + + // Make a couple of libraries. Here, we'll give them + // (vectors of) elements immediately. (Alternatively, + // those could have been added later, like we did for + // adding isotopes above.) + Library first("first library", {H,He}); + Library second("second library", {Li,Be}); + + // Make a multigroup object. + Multigroup multi("projectile name", {first,second}); + + // Example: use a basic getter to get the vector of + // elements from the second library. Getters are + // flexible (the good) but mean we have to require + // the "()" syntax (the ugly). :-/ + std::vector elems = second.element(); + assert(elems[0].symbol() == "Li"); + assert(elems[1].symbol() == "Be"); + + // Example: look stuff up by metadatum value. + Isotope deu = H.isotope(mass_number(2)); + Isotope tri = H.isotope(mass_number(3)); + + // If we instead write isotope() with no arguments + // to the getter, we get a vector of Isotope objects. + std::vector iso = H.isotope(); + + // Slightly fancier lookup, starting all the way up + // at the Multigroup object. + Isotope i = + multi.library(name("first library")) + .element(symbol("He")) + .isotope(mass_number(3)); + + // Write as XML, JSON, and HDF5. + multi.write("file.xml"); + multi.write("file.json"); + multi.write("file.h5"); + + // Prettyprint. + multi.print(); +} diff --git a/autogen/simple/example-02.cpp b/autogen/simple/example-02.cpp new file mode 100644 index 000000000..42d409b21 --- /dev/null +++ b/autogen/simple/example-02.cpp @@ -0,0 +1,35 @@ + +#include "multi/v1.hpp" +using namespace multi::v1; + +int main() +{ + colors = true; + + // Try a Foobar all by itself + { + Foobar f(std::vector{ 1, 2, 3, 4, 5 }); + f.write("foobar.xml"); + f.write("foobar.json"); + f.write("foobar.h5"); + f.print(); + + // read from xml + std::cout << "\nTrying to read XML:" << std::endl; + f.read("foobar.xml"); + std::cout << "Back from XML:" << std::endl; + f.print(); + + // read from json + std::cout << "\nTrying to read JSON:" << std::endl; + f.read("foobar.json"); + std::cout << "Back from JSON:" << std::endl; + f.print(); + + // read from h5 + std::cout << "\nTrying to read H5:" << std::endl; + f.read("foobar.h5"); + std::cout << "Back from H5:" << std::endl; + f.print(); + } +} diff --git a/autogen/simple/multi-classes.json b/autogen/simple/multi-classes.json new file mode 100644 index 000000000..26e44cda9 --- /dev/null +++ b/autogen/simple/multi-classes.json @@ -0,0 +1,76 @@ +{ + "namespace": "multigroup", + + "multigroup": { + "metadata": { + "projectile": { + "type": "string", + "required": true + } + }, + "children": { + "library": { + "times": "1+", + "required": true + } + } + }, + + "library": { + "metadata": { + "name": { + "type": "string", + "required": true + } + }, + "children": { + "element": { + "times": "1+", + "required": true + } + } + }, + + + "element": { + "metadata": { + "symbol": { + "type": "string", + "required": false + }, + "atomic_number": { + "type": "int", + "required": true + } + }, + "children": { + "isotope": { + "times": "1+", + "required": true + }, + "foobar": { + "times": "1", + "required": false + } + } + }, + + "isotope": { + "metadata": { + "mass_number": { + "type": "int", + "required": true + } + } + }, + + "foobar": { + "metadata": { + "value": { + "type": "string", + "required": true + } + }, + "vector": "double" + } +} diff --git a/autogen/simple/multi.json b/autogen/simple/multi.json new file mode 100644 index 000000000..f7f5dbbf0 --- /dev/null +++ b/autogen/simple/multi.json @@ -0,0 +1,9 @@ +{ + "Project": "multi", + "Version": "v1", + + "JSONDir": ".", + "JSONFiles": [ + "multi-classes.json" + ] +} diff --git a/autogen/simple/multi/c/src/v1.cpp b/autogen/simple/multi/c/src/v1.cpp new file mode 100644 index 000000000..3980cc696 --- /dev/null +++ b/autogen/simple/multi/c/src/v1.cpp @@ -0,0 +1,2 @@ + +#include "v1.h" diff --git a/autogen/simple/multi/c/src/v1.h b/autogen/simple/multi/c/src/v1.h new file mode 100644 index 000000000..d69c0f08b --- /dev/null +++ b/autogen/simple/multi/c/src/v1.h @@ -0,0 +1,25 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// ----------------------------------------------------------------------------- +// This header file is designed to work with both C and C++ +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1 +#define C_INTERFACE_MULTI_V1 + +#include "GNDStk.h" + +#ifdef __cplusplus + // For C++ + #include "multi/v1.hpp" +#endif + +#include "v1/multigroup/Multigroup.h" +#include "v1/multigroup/Library.h" +#include "v1/multigroup/Element.h" +#include "v1/multigroup/Isotope.h" +#include "v1/multigroup/Foobar.h" + +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Element.cpp b/autogen/simple/multi/c/src/v1/multigroup/Element.cpp new file mode 100644 index 000000000..bd84e5162 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Element.cpp @@ -0,0 +1,370 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "multi/v1/multigroup/Element.hpp" +#include "Element.h" + +using namespace njoy::GNDStk; +using namespace multi::v1; + +using C = ElementClass; +using CPP = multigroup::Element; + +static const std::string CLASSNAME = "Element"; + +namespace extract { + static auto symbol = [](auto &obj) { return &obj.symbol; }; + static auto atomic_number = [](auto &obj) { return &obj.atomic_number; }; + static auto isotope = [](auto &obj) { return &obj.isotope; }; + static auto foobar = [](auto &obj) { return &obj.foobar; }; +} + +using CPPIsotope = multigroup::Isotope; +using CPPFoobar = multigroup::Foobar; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstElement +ElementDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Element +ElementDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstElement +ElementCreateConst( + const char *const symbol, + const int atomic_number, + ConstHandle2Isotope *const isotope, const size_t isotopeSize, + ConstHandle2ConstFoobar foobar +) { + ConstHandle2Element handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + symbol, + atomic_number, + std::vector{}, + detail::tocpp(foobar) + ); + for (size_t IsotopeN = 0; IsotopeN < isotopeSize; ++IsotopeN) + ElementIsotopeAdd(handle, isotope[IsotopeN]); + return handle; +} + +// Create, general +Handle2Element +ElementCreate( + const char *const symbol, + const int atomic_number, + ConstHandle2Isotope *const isotope, const size_t isotopeSize, + ConstHandle2ConstFoobar foobar +) { + ConstHandle2Element handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + symbol, + atomic_number, + std::vector{}, + detail::tocpp(foobar) + ); + for (size_t IsotopeN = 0; IsotopeN < isotopeSize; ++IsotopeN) + ElementIsotopeAdd(handle, isotope[IsotopeN]); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +ElementAssign(ConstHandle2Element self, ConstHandle2ConstElement from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +ElementDelete(ConstHandle2ConstElement self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +ElementRead(ConstHandle2Element self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +ElementWrite(ConstHandle2ConstElement self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +ElementPrint(ConstHandle2ConstElement self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +ElementPrintXML(ConstHandle2ConstElement self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +ElementPrintJSON(ConstHandle2ConstElement self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: symbol +// ----------------------------------------------------------------------------- + +// Has +int +ElementSymbolHas(ConstHandle2ConstElement self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"SymbolHas", self, extract::symbol); +} + +// Get +// Returns by value +const char * +ElementSymbolGet(ConstHandle2ConstElement self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"SymbolGet", self, extract::symbol); +} + +// Set +void +ElementSymbolSet(ConstHandle2Element self, const char *const symbol) +{ + detail::setField + (CLASSNAME, CLASSNAME+"SymbolSet", self, extract::symbol, symbol); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: atomic_number +// ----------------------------------------------------------------------------- + +// Has +int +ElementAtomicNumberHas(ConstHandle2ConstElement self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"AtomicNumberHas", self, extract::atomic_number); +} + +// Get +// Returns by value +int +ElementAtomicNumberGet(ConstHandle2ConstElement self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"AtomicNumberGet", self, extract::atomic_number); +} + +// Set +void +ElementAtomicNumberSet(ConstHandle2Element self, const int atomic_number) +{ + detail::setField + (CLASSNAME, CLASSNAME+"AtomicNumberSet", self, extract::atomic_number, atomic_number); +} + + +// ----------------------------------------------------------------------------- +// Child: isotope +// ----------------------------------------------------------------------------- + +// Has +int +ElementIsotopeHas(ConstHandle2ConstElement self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"IsotopeHas", self, extract::isotope); +} + +// Clear +void +ElementIsotopeClear(ConstHandle2Element self) +{ + detail::clearContainer + (CLASSNAME, CLASSNAME+"IsotopeClear", self, extract::isotope); +} + +// Size +size_t +ElementIsotopeSize(ConstHandle2ConstElement self) +{ + return detail::sizeOfContainer + (CLASSNAME, CLASSNAME+"IsotopeSize", self, extract::isotope); +} + +// Add +void +ElementIsotopeAdd(ConstHandle2Element self, ConstHandle2ConstIsotope isotope) +{ + detail::addToContainer + (CLASSNAME, CLASSNAME+"IsotopeAdd", self, extract::isotope, isotope); +} + +// Get, by index \in [0,size), const +Handle2ConstIsotope +ElementIsotopeGetConst(ConstHandle2ConstElement self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"IsotopeGetConst", self, extract::isotope, index_); +} + +// Get, by index \in [0,size), non-const +Handle2Isotope +ElementIsotopeGet(ConstHandle2Element self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"IsotopeGet", self, extract::isotope, index_); +} + +// Set, by index \in [0,size) +void +ElementIsotopeSet( + ConstHandle2Element self, + const size_t index_, + ConstHandle2ConstIsotope isotope +) { + detail::setByIndex + (CLASSNAME, CLASSNAME+"IsotopeSet", self, extract::isotope, index_, isotope); +} + +// Has, by mass_number +int +ElementIsotopeHasByMassNumber( + ConstHandle2ConstElement self, + const int mass_number +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"IsotopeHasByMassNumber", + self, extract::isotope, meta::mass_number, mass_number); +} + +// Get, by mass_number, const +Handle2ConstIsotope +ElementIsotopeGetByMassNumberConst( + ConstHandle2ConstElement self, + const int mass_number +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"IsotopeGetByMassNumberConst", + self, extract::isotope, meta::mass_number, mass_number); +} + +// Get, by mass_number, non-const +Handle2Isotope +ElementIsotopeGetByMassNumber( + ConstHandle2Element self, + const int mass_number +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"IsotopeGetByMassNumber", + self, extract::isotope, meta::mass_number, mass_number); +} + +// Set, by mass_number +void +ElementIsotopeSetByMassNumber( + ConstHandle2Element self, + const int mass_number, + ConstHandle2ConstIsotope isotope +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"IsotopeSetByMassNumber", + self, extract::isotope, meta::mass_number, mass_number, isotope); +} + + +// ----------------------------------------------------------------------------- +// Child: foobar +// ----------------------------------------------------------------------------- + +// Has +int +ElementFoobarHas(ConstHandle2ConstElement self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"FoobarHas", self, extract::foobar); +} + +// Get, const +Handle2ConstFoobar +ElementFoobarGetConst(ConstHandle2ConstElement self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"FoobarGetConst", self, extract::foobar); +} + +// Get, non-const +Handle2Foobar +ElementFoobarGet(ConstHandle2Element self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"FoobarGet", self, extract::foobar); +} + +// Set +void +ElementFoobarSet(ConstHandle2Element self, ConstHandle2ConstFoobar foobar) +{ + detail::setField + (CLASSNAME, CLASSNAME+"FoobarSet", self, extract::foobar, foobar); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Element/src/custom.cpp" diff --git a/autogen/simple/multi/c/src/v1/multigroup/Element.h b/autogen/simple/multi/c/src/v1/multigroup/Element.h new file mode 100644 index 000000000..88b21a3a9 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Element.h @@ -0,0 +1,270 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Element is the basic handle type in this file. Example: +// // Create a default Element object: +// Element handle = ElementDefault(); +// Functions involving Element are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1_MULTIGROUP_ELEMENT +#define C_INTERFACE_MULTI_V1_MULTIGROUP_ELEMENT + +#include "GNDStk.h" +#include "v1/multigroup/Isotope.h" +#include "v1/multigroup/Foobar.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct ElementClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Element +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct ElementClass *Element; + +// --- Const-aware handles. +typedef const struct ElementClass *const ConstHandle2ConstElement; +typedef struct ElementClass *const ConstHandle2Element; +typedef const struct ElementClass * Handle2ConstElement; +typedef struct ElementClass * Handle2Element; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstElement +ElementDefaultConst(); + +// +++ Create, default +extern_c Handle2Element +ElementDefault(); + +// --- Create, general, const +extern_c Handle2ConstElement +ElementCreateConst( + const char *const symbol, + const int atomic_number, + ConstHandle2Isotope *const isotope, const size_t isotopeSize, + ConstHandle2ConstFoobar foobar +); + +// +++ Create, general +extern_c Handle2Element +ElementCreate( + const char *const symbol, + const int atomic_number, + ConstHandle2Isotope *const isotope, const size_t isotopeSize, + ConstHandle2ConstFoobar foobar +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +ElementAssign(ConstHandle2Element self, ConstHandle2ConstElement from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +ElementDelete(ConstHandle2ConstElement self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +ElementRead(ConstHandle2Element self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +ElementWrite(ConstHandle2ConstElement self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +ElementPrint(ConstHandle2ConstElement self); + +// +++ Print to standard output, as XML +extern_c int +ElementPrintXML(ConstHandle2ConstElement self); + +// +++ Print to standard output, as JSON +extern_c int +ElementPrintJSON(ConstHandle2ConstElement self); + + +// ----------------------------------------------------------------------------- +// Metadatum: symbol +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ElementSymbolHas(ConstHandle2ConstElement self); + +// +++ Get +// +++ Returns by value +extern_c const char * +ElementSymbolGet(ConstHandle2ConstElement self); + +// +++ Set +extern_c void +ElementSymbolSet(ConstHandle2Element self, const char *const symbol); + + +// ----------------------------------------------------------------------------- +// Metadatum: atomic_number +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ElementAtomicNumberHas(ConstHandle2ConstElement self); + +// +++ Get +// +++ Returns by value +extern_c int +ElementAtomicNumberGet(ConstHandle2ConstElement self); + +// +++ Set +extern_c void +ElementAtomicNumberSet(ConstHandle2Element self, const int atomic_number); + + +// ----------------------------------------------------------------------------- +// Child: isotope +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ElementIsotopeHas(ConstHandle2ConstElement self); + +// +++ Clear +extern_c void +ElementIsotopeClear(ConstHandle2Element self); + +// +++ Size +extern_c size_t +ElementIsotopeSize(ConstHandle2ConstElement self); + +// +++ Add +extern_c void +ElementIsotopeAdd(ConstHandle2Element self, ConstHandle2ConstIsotope isotope); + +// --- Get, by index \in [0,size), const +extern_c Handle2ConstIsotope +ElementIsotopeGetConst(ConstHandle2ConstElement self, const size_t index_); + +// +++ Get, by index \in [0,size), non-const +extern_c Handle2Isotope +ElementIsotopeGet(ConstHandle2Element self, const size_t index_); + +// +++ Set, by index \in [0,size) +extern_c void +ElementIsotopeSet( + ConstHandle2Element self, + const size_t index_, + ConstHandle2ConstIsotope isotope +); + +// +++ Has, by mass_number +extern_c int +ElementIsotopeHasByMassNumber( + ConstHandle2ConstElement self, + const int mass_number +); + +// --- Get, by mass_number, const +extern_c Handle2ConstIsotope +ElementIsotopeGetByMassNumberConst( + ConstHandle2ConstElement self, + const int mass_number +); + +// +++ Get, by mass_number, non-const +extern_c Handle2Isotope +ElementIsotopeGetByMassNumber( + ConstHandle2Element self, + const int mass_number +); + +// +++ Set, by mass_number +extern_c void +ElementIsotopeSetByMassNumber( + ConstHandle2Element self, + const int mass_number, + ConstHandle2ConstIsotope isotope +); + + +// ----------------------------------------------------------------------------- +// Child: foobar +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +ElementFoobarHas(ConstHandle2ConstElement self); + +// --- Get, const +extern_c Handle2ConstFoobar +ElementFoobarGetConst(ConstHandle2ConstElement self); + +// +++ Get, non-const +extern_c Handle2Foobar +ElementFoobarGet(ConstHandle2Element self); + +// +++ Set +extern_c void +ElementFoobarSet(ConstHandle2Element self, ConstHandle2ConstFoobar foobar); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Element/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Element/src/custom.cpp b/autogen/simple/multi/c/src/v1/multigroup/Element/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Element/src/custom.h b/autogen/simple/multi/c/src/v1/multigroup/Element/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Foobar.cpp b/autogen/simple/multi/c/src/v1/multigroup/Foobar.cpp new file mode 100644 index 000000000..2fc58121c --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Foobar.cpp @@ -0,0 +1,235 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "multi/v1/multigroup/Foobar.hpp" +#include "Foobar.h" + +using namespace njoy::GNDStk; +using namespace multi::v1; + +using C = FoobarClass; +using CPP = multigroup::Foobar; + +static const std::string CLASSNAME = "Foobar"; + +namespace extract { + static auto value = [](auto &obj) { return &obj.value; }; +} + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstFoobar +FoobarDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Foobar +FoobarDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstFoobar +FoobarCreateConst( + const char *const value +) { + ConstHandle2Foobar handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + value + ); + return handle; +} + +// Create, general +Handle2Foobar +FoobarCreate( + const char *const value +) { + ConstHandle2Foobar handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + value + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +FoobarAssign(ConstHandle2Foobar self, ConstHandle2ConstFoobar from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +FoobarDelete(ConstHandle2ConstFoobar self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +FoobarRead(ConstHandle2Foobar self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +FoobarWrite(ConstHandle2ConstFoobar self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +FoobarPrint(ConstHandle2ConstFoobar self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +FoobarPrintXML(ConstHandle2ConstFoobar self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +FoobarPrintJSON(ConstHandle2ConstFoobar self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Data vector +// ----------------------------------------------------------------------------- + +// Clear +void +FoobarDoublesClear(ConstHandle2Foobar self) +{ + detail::vectorClear + (CLASSNAME, CLASSNAME+"DoublesClear", self); +} + +// Get size +size_t +FoobarDoublesSize(ConstHandle2ConstFoobar self) +{ + return detail::vectorSize + (CLASSNAME, CLASSNAME+"DoublesSize", self); +} + +// Get value +// By index \in [0,size) +double +FoobarDoublesGet(ConstHandle2ConstFoobar self, const size_t index) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGet", self, index); +} + +// Set value +// By index \in [0,size) +void +FoobarDoublesSet(ConstHandle2Foobar self, const size_t index, const double value) +{ + detail::vectorSet + (CLASSNAME, CLASSNAME+"DoublesSet", self, index, value); +} + +// Get pointer to existing values, const +const double * +FoobarDoublesGetArrayConst(ConstHandle2ConstFoobar self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGetArrayConst", self); +} + +// Get pointer to existing values, non-const +double * +FoobarDoublesGetArray(ConstHandle2Foobar self) +{ + return detail::vectorGet + (CLASSNAME, CLASSNAME+"DoublesGetArray", self); +} + +// Set completely new values and size +void +FoobarDoublesSetArray(ConstHandle2Foobar self, const double *const values, const size_t size) +{ + return detail::vectorSet + (CLASSNAME, CLASSNAME+"DoublesSetArray", self, size, values); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: value +// ----------------------------------------------------------------------------- + +// Has +int +FoobarValueHas(ConstHandle2ConstFoobar self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ValueHas", self, extract::value); +} + +// Get +// Returns by value +const char * +FoobarValueGet(ConstHandle2ConstFoobar self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ValueGet", self, extract::value); +} + +// Set +void +FoobarValueSet(ConstHandle2Foobar self, const char *const value) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ValueSet", self, extract::value, value); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Foobar/src/custom.cpp" diff --git a/autogen/simple/multi/c/src/v1/multigroup/Foobar.h b/autogen/simple/multi/c/src/v1/multigroup/Foobar.h new file mode 100644 index 000000000..b43064d75 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Foobar.h @@ -0,0 +1,192 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Foobar is the basic handle type in this file. Example: +// // Create a default Foobar object: +// Foobar handle = FoobarDefault(); +// Functions involving Foobar are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1_MULTIGROUP_FOOBAR +#define C_INTERFACE_MULTI_V1_MULTIGROUP_FOOBAR + +#include "GNDStk.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct FoobarClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Foobar +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct FoobarClass *Foobar; + +// --- Const-aware handles. +typedef const struct FoobarClass *const ConstHandle2ConstFoobar; +typedef struct FoobarClass *const ConstHandle2Foobar; +typedef const struct FoobarClass * Handle2ConstFoobar; +typedef struct FoobarClass * Handle2Foobar; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstFoobar +FoobarDefaultConst(); + +// +++ Create, default +extern_c Handle2Foobar +FoobarDefault(); + +// --- Create, general, const +extern_c Handle2ConstFoobar +FoobarCreateConst( + const char *const value +); + +// +++ Create, general +extern_c Handle2Foobar +FoobarCreate( + const char *const value +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +FoobarAssign(ConstHandle2Foobar self, ConstHandle2ConstFoobar from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +FoobarDelete(ConstHandle2ConstFoobar self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +FoobarRead(ConstHandle2Foobar self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +FoobarWrite(ConstHandle2ConstFoobar self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +FoobarPrint(ConstHandle2ConstFoobar self); + +// +++ Print to standard output, as XML +extern_c int +FoobarPrintXML(ConstHandle2ConstFoobar self); + +// +++ Print to standard output, as JSON +extern_c int +FoobarPrintJSON(ConstHandle2ConstFoobar self); + + +// ----------------------------------------------------------------------------- +// Data vector +// ----------------------------------------------------------------------------- + +// +++ Clear +extern_c void +FoobarDoublesClear(ConstHandle2Foobar self); + +// +++ Get size +extern_c size_t +FoobarDoublesSize(ConstHandle2ConstFoobar self); + +// +++ Get value +// +++ By index \in [0,size) +extern_c double +FoobarDoublesGet(ConstHandle2ConstFoobar self, const size_t index); + +// +++ Set value +// +++ By index \in [0,size) +extern_c void +FoobarDoublesSet(ConstHandle2Foobar self, const size_t index, const double value); + +// --- Get pointer to existing values, const +extern_c const double * +FoobarDoublesGetArrayConst(ConstHandle2ConstFoobar self); + +// +++ Get pointer to existing values, non-const +extern_c double * +FoobarDoublesGetArray(ConstHandle2Foobar self); + +// +++ Set completely new values and size +extern_c void +FoobarDoublesSetArray(ConstHandle2Foobar self, const double *const values, const size_t size); + + +// ----------------------------------------------------------------------------- +// Metadatum: value +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +FoobarValueHas(ConstHandle2ConstFoobar self); + +// +++ Get +// +++ Returns by value +extern_c const char * +FoobarValueGet(ConstHandle2ConstFoobar self); + +// +++ Set +extern_c void +FoobarValueSet(ConstHandle2Foobar self, const char *const value); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Foobar/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Foobar/src/custom.cpp b/autogen/simple/multi/c/src/v1/multigroup/Foobar/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Foobar/src/custom.h b/autogen/simple/multi/c/src/v1/multigroup/Foobar/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Isotope.cpp b/autogen/simple/multi/c/src/v1/multigroup/Isotope.cpp new file mode 100644 index 000000000..6da318dae --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Isotope.cpp @@ -0,0 +1,172 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "multi/v1/multigroup/Isotope.hpp" +#include "Isotope.h" + +using namespace njoy::GNDStk; +using namespace multi::v1; + +using C = IsotopeClass; +using CPP = multigroup::Isotope; + +static const std::string CLASSNAME = "Isotope"; + +namespace extract { + static auto mass_number = [](auto &obj) { return &obj.mass_number; }; +} + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstIsotope +IsotopeDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Isotope +IsotopeDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstIsotope +IsotopeCreateConst( + const int mass_number +) { + ConstHandle2Isotope handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + mass_number + ); + return handle; +} + +// Create, general +Handle2Isotope +IsotopeCreate( + const int mass_number +) { + ConstHandle2Isotope handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + mass_number + ); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +IsotopeAssign(ConstHandle2Isotope self, ConstHandle2ConstIsotope from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +IsotopeDelete(ConstHandle2ConstIsotope self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +IsotopeRead(ConstHandle2Isotope self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +IsotopeWrite(ConstHandle2ConstIsotope self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +IsotopePrint(ConstHandle2ConstIsotope self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +IsotopePrintXML(ConstHandle2ConstIsotope self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +IsotopePrintJSON(ConstHandle2ConstIsotope self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: mass_number +// ----------------------------------------------------------------------------- + +// Has +int +IsotopeMassNumberHas(ConstHandle2ConstIsotope self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"MassNumberHas", self, extract::mass_number); +} + +// Get +// Returns by value +int +IsotopeMassNumberGet(ConstHandle2ConstIsotope self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"MassNumberGet", self, extract::mass_number); +} + +// Set +void +IsotopeMassNumberSet(ConstHandle2Isotope self, const int mass_number) +{ + detail::setField + (CLASSNAME, CLASSNAME+"MassNumberSet", self, extract::mass_number, mass_number); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Isotope/src/custom.cpp" diff --git a/autogen/simple/multi/c/src/v1/multigroup/Isotope.h b/autogen/simple/multi/c/src/v1/multigroup/Isotope.h new file mode 100644 index 000000000..6544101df --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Isotope.h @@ -0,0 +1,157 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Isotope is the basic handle type in this file. Example: +// // Create a default Isotope object: +// Isotope handle = IsotopeDefault(); +// Functions involving Isotope are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1_MULTIGROUP_ISOTOPE +#define C_INTERFACE_MULTI_V1_MULTIGROUP_ISOTOPE + +#include "GNDStk.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct IsotopeClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Isotope +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct IsotopeClass *Isotope; + +// --- Const-aware handles. +typedef const struct IsotopeClass *const ConstHandle2ConstIsotope; +typedef struct IsotopeClass *const ConstHandle2Isotope; +typedef const struct IsotopeClass * Handle2ConstIsotope; +typedef struct IsotopeClass * Handle2Isotope; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstIsotope +IsotopeDefaultConst(); + +// +++ Create, default +extern_c Handle2Isotope +IsotopeDefault(); + +// --- Create, general, const +extern_c Handle2ConstIsotope +IsotopeCreateConst( + const int mass_number +); + +// +++ Create, general +extern_c Handle2Isotope +IsotopeCreate( + const int mass_number +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +IsotopeAssign(ConstHandle2Isotope self, ConstHandle2ConstIsotope from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +IsotopeDelete(ConstHandle2ConstIsotope self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +IsotopeRead(ConstHandle2Isotope self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +IsotopeWrite(ConstHandle2ConstIsotope self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +IsotopePrint(ConstHandle2ConstIsotope self); + +// +++ Print to standard output, as XML +extern_c int +IsotopePrintXML(ConstHandle2ConstIsotope self); + +// +++ Print to standard output, as JSON +extern_c int +IsotopePrintJSON(ConstHandle2ConstIsotope self); + + +// ----------------------------------------------------------------------------- +// Metadatum: mass_number +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +IsotopeMassNumberHas(ConstHandle2ConstIsotope self); + +// +++ Get +// +++ Returns by value +extern_c int +IsotopeMassNumberGet(ConstHandle2ConstIsotope self); + +// +++ Set +extern_c void +IsotopeMassNumberSet(ConstHandle2Isotope self, const int mass_number); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Isotope/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Isotope/src/custom.cpp b/autogen/simple/multi/c/src/v1/multigroup/Isotope/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Isotope/src/custom.h b/autogen/simple/multi/c/src/v1/multigroup/Isotope/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Library.cpp b/autogen/simple/multi/c/src/v1/multigroup/Library.cpp new file mode 100644 index 000000000..eeb3c46d1 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Library.cpp @@ -0,0 +1,337 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "multi/v1/multigroup/Library.hpp" +#include "Library.h" + +using namespace njoy::GNDStk; +using namespace multi::v1; + +using C = LibraryClass; +using CPP = multigroup::Library; + +static const std::string CLASSNAME = "Library"; + +namespace extract { + static auto name = [](auto &obj) { return &obj.name; }; + static auto element = [](auto &obj) { return &obj.element; }; +} + +using CPPElement = multigroup::Element; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstLibrary +LibraryDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Library +LibraryDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstLibrary +LibraryCreateConst( + const char *const name, + ConstHandle2Element *const element, const size_t elementSize +) { + ConstHandle2Library handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + name, + std::vector{} + ); + for (size_t ElementN = 0; ElementN < elementSize; ++ElementN) + LibraryElementAdd(handle, element[ElementN]); + return handle; +} + +// Create, general +Handle2Library +LibraryCreate( + const char *const name, + ConstHandle2Element *const element, const size_t elementSize +) { + ConstHandle2Library handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + name, + std::vector{} + ); + for (size_t ElementN = 0; ElementN < elementSize; ++ElementN) + LibraryElementAdd(handle, element[ElementN]); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +LibraryAssign(ConstHandle2Library self, ConstHandle2ConstLibrary from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +LibraryDelete(ConstHandle2ConstLibrary self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +LibraryRead(ConstHandle2Library self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +LibraryWrite(ConstHandle2ConstLibrary self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +LibraryPrint(ConstHandle2ConstLibrary self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +LibraryPrintXML(ConstHandle2ConstLibrary self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +LibraryPrintJSON(ConstHandle2ConstLibrary self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: name +// ----------------------------------------------------------------------------- + +// Has +int +LibraryNameHas(ConstHandle2ConstLibrary self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"NameHas", self, extract::name); +} + +// Get +// Returns by value +const char * +LibraryNameGet(ConstHandle2ConstLibrary self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"NameGet", self, extract::name); +} + +// Set +void +LibraryNameSet(ConstHandle2Library self, const char *const name) +{ + detail::setField + (CLASSNAME, CLASSNAME+"NameSet", self, extract::name, name); +} + + +// ----------------------------------------------------------------------------- +// Child: element +// ----------------------------------------------------------------------------- + +// Has +int +LibraryElementHas(ConstHandle2ConstLibrary self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ElementHas", self, extract::element); +} + +// Clear +void +LibraryElementClear(ConstHandle2Library self) +{ + detail::clearContainer + (CLASSNAME, CLASSNAME+"ElementClear", self, extract::element); +} + +// Size +size_t +LibraryElementSize(ConstHandle2ConstLibrary self) +{ + return detail::sizeOfContainer + (CLASSNAME, CLASSNAME+"ElementSize", self, extract::element); +} + +// Add +void +LibraryElementAdd(ConstHandle2Library self, ConstHandle2ConstElement element) +{ + detail::addToContainer + (CLASSNAME, CLASSNAME+"ElementAdd", self, extract::element, element); +} + +// Get, by index \in [0,size), const +Handle2ConstElement +LibraryElementGetConst(ConstHandle2ConstLibrary self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"ElementGetConst", self, extract::element, index_); +} + +// Get, by index \in [0,size), non-const +Handle2Element +LibraryElementGet(ConstHandle2Library self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"ElementGet", self, extract::element, index_); +} + +// Set, by index \in [0,size) +void +LibraryElementSet( + ConstHandle2Library self, + const size_t index_, + ConstHandle2ConstElement element +) { + detail::setByIndex + (CLASSNAME, CLASSNAME+"ElementSet", self, extract::element, index_, element); +} + +// Has, by symbol +int +LibraryElementHasBySymbol( + ConstHandle2ConstLibrary self, + const char *const symbol +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"ElementHasBySymbol", + self, extract::element, meta::symbol, symbol); +} + +// Get, by symbol, const +Handle2ConstElement +LibraryElementGetBySymbolConst( + ConstHandle2ConstLibrary self, + const char *const symbol +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ElementGetBySymbolConst", + self, extract::element, meta::symbol, symbol); +} + +// Get, by symbol, non-const +Handle2Element +LibraryElementGetBySymbol( + ConstHandle2Library self, + const char *const symbol +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ElementGetBySymbol", + self, extract::element, meta::symbol, symbol); +} + +// Set, by symbol +void +LibraryElementSetBySymbol( + ConstHandle2Library self, + const char *const symbol, + ConstHandle2ConstElement element +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"ElementSetBySymbol", + self, extract::element, meta::symbol, symbol, element); +} + +// Has, by atomic_number +int +LibraryElementHasByAtomicNumber( + ConstHandle2ConstLibrary self, + const int atomic_number +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"ElementHasByAtomicNumber", + self, extract::element, meta::atomic_number, atomic_number); +} + +// Get, by atomic_number, const +Handle2ConstElement +LibraryElementGetByAtomicNumberConst( + ConstHandle2ConstLibrary self, + const int atomic_number +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ElementGetByAtomicNumberConst", + self, extract::element, meta::atomic_number, atomic_number); +} + +// Get, by atomic_number, non-const +Handle2Element +LibraryElementGetByAtomicNumber( + ConstHandle2Library self, + const int atomic_number +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"ElementGetByAtomicNumber", + self, extract::element, meta::atomic_number, atomic_number); +} + +// Set, by atomic_number +void +LibraryElementSetByAtomicNumber( + ConstHandle2Library self, + const int atomic_number, + ConstHandle2ConstElement element +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"ElementSetByAtomicNumber", + self, extract::element, meta::atomic_number, atomic_number, element); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Library/src/custom.cpp" diff --git a/autogen/simple/multi/c/src/v1/multigroup/Library.h b/autogen/simple/multi/c/src/v1/multigroup/Library.h new file mode 100644 index 000000000..d9fa18fb7 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Library.h @@ -0,0 +1,255 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Library is the basic handle type in this file. Example: +// // Create a default Library object: +// Library handle = LibraryDefault(); +// Functions involving Library are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1_MULTIGROUP_LIBRARY +#define C_INTERFACE_MULTI_V1_MULTIGROUP_LIBRARY + +#include "GNDStk.h" +#include "v1/multigroup/Element.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct LibraryClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Library +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct LibraryClass *Library; + +// --- Const-aware handles. +typedef const struct LibraryClass *const ConstHandle2ConstLibrary; +typedef struct LibraryClass *const ConstHandle2Library; +typedef const struct LibraryClass * Handle2ConstLibrary; +typedef struct LibraryClass * Handle2Library; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstLibrary +LibraryDefaultConst(); + +// +++ Create, default +extern_c Handle2Library +LibraryDefault(); + +// --- Create, general, const +extern_c Handle2ConstLibrary +LibraryCreateConst( + const char *const name, + ConstHandle2Element *const element, const size_t elementSize +); + +// +++ Create, general +extern_c Handle2Library +LibraryCreate( + const char *const name, + ConstHandle2Element *const element, const size_t elementSize +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +LibraryAssign(ConstHandle2Library self, ConstHandle2ConstLibrary from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +LibraryDelete(ConstHandle2ConstLibrary self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +LibraryRead(ConstHandle2Library self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +LibraryWrite(ConstHandle2ConstLibrary self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +LibraryPrint(ConstHandle2ConstLibrary self); + +// +++ Print to standard output, as XML +extern_c int +LibraryPrintXML(ConstHandle2ConstLibrary self); + +// +++ Print to standard output, as JSON +extern_c int +LibraryPrintJSON(ConstHandle2ConstLibrary self); + + +// ----------------------------------------------------------------------------- +// Metadatum: name +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +LibraryNameHas(ConstHandle2ConstLibrary self); + +// +++ Get +// +++ Returns by value +extern_c const char * +LibraryNameGet(ConstHandle2ConstLibrary self); + +// +++ Set +extern_c void +LibraryNameSet(ConstHandle2Library self, const char *const name); + + +// ----------------------------------------------------------------------------- +// Child: element +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +LibraryElementHas(ConstHandle2ConstLibrary self); + +// +++ Clear +extern_c void +LibraryElementClear(ConstHandle2Library self); + +// +++ Size +extern_c size_t +LibraryElementSize(ConstHandle2ConstLibrary self); + +// +++ Add +extern_c void +LibraryElementAdd(ConstHandle2Library self, ConstHandle2ConstElement element); + +// --- Get, by index \in [0,size), const +extern_c Handle2ConstElement +LibraryElementGetConst(ConstHandle2ConstLibrary self, const size_t index_); + +// +++ Get, by index \in [0,size), non-const +extern_c Handle2Element +LibraryElementGet(ConstHandle2Library self, const size_t index_); + +// +++ Set, by index \in [0,size) +extern_c void +LibraryElementSet( + ConstHandle2Library self, + const size_t index_, + ConstHandle2ConstElement element +); + +// +++ Has, by symbol +extern_c int +LibraryElementHasBySymbol( + ConstHandle2ConstLibrary self, + const char *const symbol +); + +// --- Get, by symbol, const +extern_c Handle2ConstElement +LibraryElementGetBySymbolConst( + ConstHandle2ConstLibrary self, + const char *const symbol +); + +// +++ Get, by symbol, non-const +extern_c Handle2Element +LibraryElementGetBySymbol( + ConstHandle2Library self, + const char *const symbol +); + +// +++ Set, by symbol +extern_c void +LibraryElementSetBySymbol( + ConstHandle2Library self, + const char *const symbol, + ConstHandle2ConstElement element +); + +// +++ Has, by atomic_number +extern_c int +LibraryElementHasByAtomicNumber( + ConstHandle2ConstLibrary self, + const int atomic_number +); + +// --- Get, by atomic_number, const +extern_c Handle2ConstElement +LibraryElementGetByAtomicNumberConst( + ConstHandle2ConstLibrary self, + const int atomic_number +); + +// +++ Get, by atomic_number, non-const +extern_c Handle2Element +LibraryElementGetByAtomicNumber( + ConstHandle2Library self, + const int atomic_number +); + +// +++ Set, by atomic_number +extern_c void +LibraryElementSetByAtomicNumber( + ConstHandle2Library self, + const int atomic_number, + ConstHandle2ConstElement element +); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Library/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Library/src/custom.cpp b/autogen/simple/multi/c/src/v1/multigroup/Library/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Library/src/custom.h b/autogen/simple/multi/c/src/v1/multigroup/Library/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Multigroup.cpp b/autogen/simple/multi/c/src/v1/multigroup/Multigroup.cpp new file mode 100644 index 000000000..95a2844c8 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Multigroup.cpp @@ -0,0 +1,292 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include "multi/v1/multigroup/Multigroup.hpp" +#include "Multigroup.h" + +using namespace njoy::GNDStk; +using namespace multi::v1; + +using C = MultigroupClass; +using CPP = multigroup::Multigroup; + +static const std::string CLASSNAME = "Multigroup"; + +namespace extract { + static auto projectile = [](auto &obj) { return &obj.projectile; }; + static auto library = [](auto &obj) { return &obj.library; }; +} + +using CPPLibrary = multigroup::Library; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// Create, default, const +Handle2ConstMultigroup +MultigroupDefaultConst() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"DefaultConst"); +} + +// Create, default +Handle2Multigroup +MultigroupDefault() +{ + return detail::createHandle + (CLASSNAME, CLASSNAME+"Default"); +} + +// Create, general, const +Handle2ConstMultigroup +MultigroupCreateConst( + const char *const projectile, + ConstHandle2Library *const library, const size_t librarySize +) { + ConstHandle2Multigroup handle = detail::createHandle( + CLASSNAME, CLASSNAME+"CreateConst", + projectile, + std::vector{} + ); + for (size_t LibraryN = 0; LibraryN < librarySize; ++LibraryN) + MultigroupLibraryAdd(handle, library[LibraryN]); + return handle; +} + +// Create, general +Handle2Multigroup +MultigroupCreate( + const char *const projectile, + ConstHandle2Library *const library, const size_t librarySize +) { + ConstHandle2Multigroup handle = detail::createHandle( + CLASSNAME, CLASSNAME+"Create", + projectile, + std::vector{} + ); + for (size_t LibraryN = 0; LibraryN < librarySize; ++LibraryN) + MultigroupLibraryAdd(handle, library[LibraryN]); + return handle; +} + +// Assign +// Use this to assign one handled object to another. Don't assign handles, +// as with to = from. That has a meaning that you probably don't intend. +void +MultigroupAssign(ConstHandle2Multigroup self, ConstHandle2ConstMultigroup from) +{ + detail::assignHandle + (CLASSNAME, CLASSNAME+"Assign", self, from); +} + +// Delete +// We'll attempt to remove no-longer-used objects automatically, but you +// may improve performance if you delete them when you're done with them. +void +MultigroupDelete(ConstHandle2ConstMultigroup self) +{ + detail::deleteHandle + (CLASSNAME, CLASSNAME+"Delete", self); +} + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// Read from file +// File can be XML, JSON, or HDF5. +// We'll examine the file's contents to determine its type automatically. +int +MultigroupRead(ConstHandle2Multigroup self, const char *const filename) +{ + return detail::readHandle + (CLASSNAME, CLASSNAME+"Read", self, filename); +} + +// Write to file +// File can be XML, JSON, or HDF5. +// We'll use filename's extension to determine the type you want written. +int +MultigroupWrite(ConstHandle2ConstMultigroup self, const char *const filename) +{ + return detail::writeHandle + (CLASSNAME, CLASSNAME+"Write", self, filename); +} + +// Print to standard output, in our prettyprinting format +int +MultigroupPrint(ConstHandle2ConstMultigroup self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"Print", self); +} + +// Print to standard output, as XML +int +MultigroupPrintXML(ConstHandle2ConstMultigroup self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintXML", self, "XML"); +} + +// Print to standard output, as JSON +int +MultigroupPrintJSON(ConstHandle2ConstMultigroup self) +{ + return detail::printHandle + (CLASSNAME, CLASSNAME+"PrintJSON", self, "JSON"); +} + + +// ----------------------------------------------------------------------------- +// Metadatum: projectile +// ----------------------------------------------------------------------------- + +// Has +int +MultigroupProjectileHas(ConstHandle2ConstMultigroup self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"ProjectileHas", self, extract::projectile); +} + +// Get +// Returns by value +const char * +MultigroupProjectileGet(ConstHandle2ConstMultigroup self) +{ + return detail::getField + (CLASSNAME, CLASSNAME+"ProjectileGet", self, extract::projectile); +} + +// Set +void +MultigroupProjectileSet(ConstHandle2Multigroup self, const char *const projectile) +{ + detail::setField + (CLASSNAME, CLASSNAME+"ProjectileSet", self, extract::projectile, projectile); +} + + +// ----------------------------------------------------------------------------- +// Child: library +// ----------------------------------------------------------------------------- + +// Has +int +MultigroupLibraryHas(ConstHandle2ConstMultigroup self) +{ + return detail::hasField + (CLASSNAME, CLASSNAME+"LibraryHas", self, extract::library); +} + +// Clear +void +MultigroupLibraryClear(ConstHandle2Multigroup self) +{ + detail::clearContainer + (CLASSNAME, CLASSNAME+"LibraryClear", self, extract::library); +} + +// Size +size_t +MultigroupLibrarySize(ConstHandle2ConstMultigroup self) +{ + return detail::sizeOfContainer + (CLASSNAME, CLASSNAME+"LibrarySize", self, extract::library); +} + +// Add +void +MultigroupLibraryAdd(ConstHandle2Multigroup self, ConstHandle2ConstLibrary library) +{ + detail::addToContainer + (CLASSNAME, CLASSNAME+"LibraryAdd", self, extract::library, library); +} + +// Get, by index \in [0,size), const +Handle2ConstLibrary +MultigroupLibraryGetConst(ConstHandle2ConstMultigroup self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"LibraryGetConst", self, extract::library, index_); +} + +// Get, by index \in [0,size), non-const +Handle2Library +MultigroupLibraryGet(ConstHandle2Multigroup self, const size_t index_) +{ + return detail::getByIndex + (CLASSNAME, CLASSNAME+"LibraryGet", self, extract::library, index_); +} + +// Set, by index \in [0,size) +void +MultigroupLibrarySet( + ConstHandle2Multigroup self, + const size_t index_, + ConstHandle2ConstLibrary library +) { + detail::setByIndex + (CLASSNAME, CLASSNAME+"LibrarySet", self, extract::library, index_, library); +} + +// Has, by name +int +MultigroupLibraryHasByName( + ConstHandle2ConstMultigroup self, + const char *const name +) { + return detail::hasByMetadatum + (CLASSNAME, CLASSNAME+"LibraryHasByName", + self, extract::library, meta::name, name); +} + +// Get, by name, const +Handle2ConstLibrary +MultigroupLibraryGetByNameConst( + ConstHandle2ConstMultigroup self, + const char *const name +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"LibraryGetByNameConst", + self, extract::library, meta::name, name); +} + +// Get, by name, non-const +Handle2Library +MultigroupLibraryGetByName( + ConstHandle2Multigroup self, + const char *const name +) { + return detail::getByMetadatum + (CLASSNAME, CLASSNAME+"LibraryGetByName", + self, extract::library, meta::name, name); +} + +// Set, by name +void +MultigroupLibrarySetByName( + ConstHandle2Multigroup self, + const char *const name, + ConstHandle2ConstLibrary library +) { + detail::setByMetadatum + (CLASSNAME, CLASSNAME+"LibrarySetByName", + self, extract::library, meta::name, name, library); +} + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Multigroup/src/custom.cpp" diff --git a/autogen/simple/multi/c/src/v1/multigroup/Multigroup.h b/autogen/simple/multi/c/src/v1/multigroup/Multigroup.h new file mode 100644 index 000000000..4c4ac5aa6 --- /dev/null +++ b/autogen/simple/multi/c/src/v1/multigroup/Multigroup.h @@ -0,0 +1,226 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// Interface for C +// This header file is designed to work with both C and C++ +// Function definitions are in this file's .cpp source + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// Instructions for Users +// +// Constructs you're MORE likely to care about are preceded with: +// // +++ remark +// Constructs you're LESS likely to care about are preceded with: +// // --- remark +// Anything not marked as above can be ignored by most users. +// +// Multigroup is the basic handle type in this file. Example: +// // Create a default Multigroup object: +// Multigroup handle = MultigroupDefault(); +// Functions involving Multigroup are declared throughout this file. +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Preliminaries +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_MULTI_V1_MULTIGROUP_MULTIGROUP +#define C_INTERFACE_MULTI_V1_MULTIGROUP_MULTIGROUP + +#include "GNDStk.h" +#include "v1/multigroup/Library.h" + +#ifdef __cplusplus + #define extern_c extern "C" +#else + #define extern_c +#endif + +// Proxy C struct for the handled C++ class +struct MultigroupClass { }; + + +// ----------------------------------------------------------------------------- +// Handle types +// ----------------------------------------------------------------------------- + +// +++ Multigroup +// +++ General handle, suitable for most users. If you're not concerned about +// +++ strict "const correctness" in your C code, you can probably use this in +// +++ place of any function parameter of a const-aware handle type. +typedef struct MultigroupClass *Multigroup; + +// --- Const-aware handles. +typedef const struct MultigroupClass *const ConstHandle2ConstMultigroup; +typedef struct MultigroupClass *const ConstHandle2Multigroup; +typedef const struct MultigroupClass * Handle2ConstMultigroup; +typedef struct MultigroupClass * Handle2Multigroup; + + +// ----------------------------------------------------------------------------- +// Basics +// Create, Assign, Delete +// ----------------------------------------------------------------------------- + +// --- Create, default, const +extern_c Handle2ConstMultigroup +MultigroupDefaultConst(); + +// +++ Create, default +extern_c Handle2Multigroup +MultigroupDefault(); + +// --- Create, general, const +extern_c Handle2ConstMultigroup +MultigroupCreateConst( + const char *const projectile, + ConstHandle2Library *const library, const size_t librarySize +); + +// +++ Create, general +extern_c Handle2Multigroup +MultigroupCreate( + const char *const projectile, + ConstHandle2Library *const library, const size_t librarySize +); + +// +++ Assign +// +++ Use this to assign one handled object to another. Don't assign handles, +// +++ as with to = from. That has a meaning that you probably don't intend. +extern_c void +MultigroupAssign(ConstHandle2Multigroup self, ConstHandle2ConstMultigroup from); + +// +++ Delete +// +++ We'll attempt to remove no-longer-used objects automatically, but you +// +++ may improve performance if you delete them when you're done with them. +extern_c void +MultigroupDelete(ConstHandle2ConstMultigroup self); + + +// ----------------------------------------------------------------------------- +// I/O +// Read, Write, Print +// Each returns 0 if failure, 1 if success. +// ----------------------------------------------------------------------------- + +// +++ Read from file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll examine the file's contents to determine its type automatically. +extern_c int +MultigroupRead(ConstHandle2Multigroup self, const char *const filename); + +// +++ Write to file +// +++ File can be XML, JSON, or HDF5. +// +++ We'll use filename's extension to determine the type you want written. +extern_c int +MultigroupWrite(ConstHandle2ConstMultigroup self, const char *const filename); + +// +++ Print to standard output, in our prettyprinting format +extern_c int +MultigroupPrint(ConstHandle2ConstMultigroup self); + +// +++ Print to standard output, as XML +extern_c int +MultigroupPrintXML(ConstHandle2ConstMultigroup self); + +// +++ Print to standard output, as JSON +extern_c int +MultigroupPrintJSON(ConstHandle2ConstMultigroup self); + + +// ----------------------------------------------------------------------------- +// Metadatum: projectile +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +MultigroupProjectileHas(ConstHandle2ConstMultigroup self); + +// +++ Get +// +++ Returns by value +extern_c const char * +MultigroupProjectileGet(ConstHandle2ConstMultigroup self); + +// +++ Set +extern_c void +MultigroupProjectileSet(ConstHandle2Multigroup self, const char *const projectile); + + +// ----------------------------------------------------------------------------- +// Child: library +// ----------------------------------------------------------------------------- + +// +++ Has +extern_c int +MultigroupLibraryHas(ConstHandle2ConstMultigroup self); + +// +++ Clear +extern_c void +MultigroupLibraryClear(ConstHandle2Multigroup self); + +// +++ Size +extern_c size_t +MultigroupLibrarySize(ConstHandle2ConstMultigroup self); + +// +++ Add +extern_c void +MultigroupLibraryAdd(ConstHandle2Multigroup self, ConstHandle2ConstLibrary library); + +// --- Get, by index \in [0,size), const +extern_c Handle2ConstLibrary +MultigroupLibraryGetConst(ConstHandle2ConstMultigroup self, const size_t index_); + +// +++ Get, by index \in [0,size), non-const +extern_c Handle2Library +MultigroupLibraryGet(ConstHandle2Multigroup self, const size_t index_); + +// +++ Set, by index \in [0,size) +extern_c void +MultigroupLibrarySet( + ConstHandle2Multigroup self, + const size_t index_, + ConstHandle2ConstLibrary library +); + +// +++ Has, by name +extern_c int +MultigroupLibraryHasByName( + ConstHandle2ConstMultigroup self, + const char *const name +); + +// --- Get, by name, const +extern_c Handle2ConstLibrary +MultigroupLibraryGetByNameConst( + ConstHandle2ConstMultigroup self, + const char *const name +); + +// +++ Get, by name, non-const +extern_c Handle2Library +MultigroupLibraryGetByName( + ConstHandle2Multigroup self, + const char *const name +); + +// +++ Set, by name +extern_c void +MultigroupLibrarySetByName( + ConstHandle2Multigroup self, + const char *const name, + ConstHandle2ConstLibrary library +); + + +// ----------------------------------------------------------------------------- +// Custom functionality +// ----------------------------------------------------------------------------- + +#include "v1/multigroup/Multigroup/src/custom.h" + +#undef extern_c +#endif diff --git a/autogen/simple/multi/c/src/v1/multigroup/Multigroup/src/custom.cpp b/autogen/simple/multi/c/src/v1/multigroup/Multigroup/src/custom.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/c/src/v1/multigroup/Multigroup/src/custom.h b/autogen/simple/multi/c/src/v1/multigroup/Multigroup/src/custom.h new file mode 100644 index 000000000..e69de29bb diff --git a/autogen/simple/multi/python/src/v1/multigroup.python.cpp b/autogen/simple/multi/python/src/v1/multigroup.python.cpp new file mode 100644 index 000000000..485934881 --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup.python.cpp @@ -0,0 +1,39 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace py = pybind11; + +// v1 interface +namespace python_v1 { + +// multigroup declarations +namespace python_multigroup { + void wrapIsotope(py::module &); + void wrapFoobar(py::module &); + void wrapElement(py::module &); + void wrapLibrary(py::module &); + void wrapMultigroup(py::module &); +} // namespace python_multigroup + +// wrapper for multigroup +void wrapMultigroup(py::module &module) +{ + // create the multigroup submodule + py::module submodule = module.def_submodule( + "multigroup", + "multi v1 multigroup" + ); + + // wrap multigroup components + python_multigroup::wrapIsotope(submodule); + python_multigroup::wrapFoobar(submodule); + python_multigroup::wrapElement(submodule); + python_multigroup::wrapLibrary(submodule); + python_multigroup::wrapMultigroup(submodule); +}; + +} // namespace python_v1 diff --git a/autogen/simple/multi/python/src/v1/multigroup/Element.python.cpp b/autogen/simple/multi/python/src/v1/multigroup/Element.python.cpp new file mode 100644 index 000000000..ff70f49a2 --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup/Element.python.cpp @@ -0,0 +1,110 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "multi/v1/multigroup/Element.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1 { +namespace python_multigroup { + +// wrapper for multigroup::Element +void wrapElement(py::module &module) +{ + using namespace multi; + using namespace multi::v1; + + // type aliases + using cppCLASS = multigroup::Element; + + // create the Python object + py::class_ object( + module, "Element", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::optional &, + const int &, + const std::vector &, + const std::optional & + >(), + py::arg("symbol") = std::nullopt, + py::arg("atomic_number"), + py::arg("isotope"), + py::arg("foobar") = std::nullopt, + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set symbol + object.def_property( + "symbol", + [](const cppCLASS &self) -> decltype(auto) + { + return self.symbol(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.symbol() = value; + }, + cppCLASS::component_t::documentation("symbol").data() + ); + + // get/set atomic_number + object.def_property( + "atomic_number", + [](const cppCLASS &self) -> decltype(auto) + { + return self.atomic_number(); + }, + [](cppCLASS &self, const int &value) + { + self.atomic_number() = value; + }, + cppCLASS::component_t::documentation("atomic_number").data() + ); + + // get/set isotope + object.def_property( + "isotope", + [](const cppCLASS &self) -> decltype(auto) + { + return self.isotope(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.isotope() = value; + }, + cppCLASS::component_t::documentation("isotope").data() + ); + + // get/set foobar + object.def_property( + "foobar", + [](const cppCLASS &self) -> decltype(auto) + { + return self.foobar(); + }, + [](cppCLASS &self, const std::optional &value) + { + self.foobar() = value; + }, + cppCLASS::component_t::documentation("foobar").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_multigroup +} // namespace python_v1 diff --git a/autogen/simple/multi/python/src/v1/multigroup/Foobar.python.cpp b/autogen/simple/multi/python/src/v1/multigroup/Foobar.python.cpp new file mode 100644 index 000000000..b0dc32357 --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup/Foobar.python.cpp @@ -0,0 +1,85 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "multi/v1/multigroup/Foobar.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1 { +namespace python_multigroup { + +// wrapper for multigroup::Foobar +void wrapFoobar(py::module &module) +{ + using namespace multi; + using namespace multi::v1; + + // type aliases + using cppCLASS = multigroup::Foobar; + + // create the Python object + py::class_ object( + module, "Foobar", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::string & + >(), + py::arg("value"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // constructor: from vector + object.def( + py::init< + const std::vector & + >(), + py::arg("doubles"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set value + object.def_property( + "value", + [](const cppCLASS &self) -> decltype(auto) + { + return self.value(); + }, + [](cppCLASS &self, const std::string &value) + { + self.value() = value; + }, + cppCLASS::component_t::documentation("value").data() + ); + + // get/set vector + object.def_property( + "doubles", + [](const cppCLASS &self) -> const std::vector & + { + return self; + }, + [](cppCLASS &self, const std::vector &value) + { + self = value; + }, + cppCLASS::component_t::documentation("doubles").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_multigroup +} // namespace python_v1 diff --git a/autogen/simple/multi/python/src/v1/multigroup/Isotope.python.cpp b/autogen/simple/multi/python/src/v1/multigroup/Isotope.python.cpp new file mode 100644 index 000000000..94d87904f --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup/Isotope.python.cpp @@ -0,0 +1,62 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "multi/v1/multigroup/Isotope.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1 { +namespace python_multigroup { + +// wrapper for multigroup::Isotope +void wrapIsotope(py::module &module) +{ + using namespace multi; + using namespace multi::v1; + + // type aliases + using cppCLASS = multigroup::Isotope; + + // create the Python object + py::class_ object( + module, "Isotope", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const int & + >(), + py::arg("mass_number"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set mass_number + object.def_property( + "mass_number", + [](const cppCLASS &self) -> decltype(auto) + { + return self.mass_number(); + }, + [](cppCLASS &self, const int &value) + { + self.mass_number() = value; + }, + cppCLASS::component_t::documentation("mass_number").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_multigroup +} // namespace python_v1 diff --git a/autogen/simple/multi/python/src/v1/multigroup/Library.python.cpp b/autogen/simple/multi/python/src/v1/multigroup/Library.python.cpp new file mode 100644 index 000000000..0db032a07 --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup/Library.python.cpp @@ -0,0 +1,78 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "multi/v1/multigroup/Library.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1 { +namespace python_multigroup { + +// wrapper for multigroup::Library +void wrapLibrary(py::module &module) +{ + using namespace multi; + using namespace multi::v1; + + // type aliases + using cppCLASS = multigroup::Library; + + // create the Python object + py::class_ object( + module, "Library", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::string &, + const std::vector & + >(), + py::arg("name"), + py::arg("element"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set name + object.def_property( + "name", + [](const cppCLASS &self) -> decltype(auto) + { + return self.name(); + }, + [](cppCLASS &self, const std::string &value) + { + self.name() = value; + }, + cppCLASS::component_t::documentation("name").data() + ); + + // get/set element + object.def_property( + "element", + [](const cppCLASS &self) -> decltype(auto) + { + return self.element(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.element() = value; + }, + cppCLASS::component_t::documentation("element").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_multigroup +} // namespace python_v1 diff --git a/autogen/simple/multi/python/src/v1/multigroup/Multigroup.python.cpp b/autogen/simple/multi/python/src/v1/multigroup/Multigroup.python.cpp new file mode 100644 index 000000000..4332e2906 --- /dev/null +++ b/autogen/simple/multi/python/src/v1/multigroup/Multigroup.python.cpp @@ -0,0 +1,78 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "multi/v1/multigroup/Multigroup.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace py = pybind11; + +namespace python_v1 { +namespace python_multigroup { + +// wrapper for multigroup::Multigroup +void wrapMultigroup(py::module &module) +{ + using namespace multi; + using namespace multi::v1; + + // type aliases + using cppCLASS = multigroup::Multigroup; + + // create the Python object + py::class_ object( + module, "Multigroup", + cppCLASS::component_t::documentation().data() + ); + + // constructor: from fields + object.def( + py::init< + const std::string &, + const std::vector & + >(), + py::arg("projectile"), + py::arg("library"), + cppCLASS::component_t::documentation("constructor").data() + ); + + // get/set projectile + object.def_property( + "projectile", + [](const cppCLASS &self) -> decltype(auto) + { + return self.projectile(); + }, + [](cppCLASS &self, const std::string &value) + { + self.projectile() = value; + }, + cppCLASS::component_t::documentation("projectile").data() + ); + + // get/set library + object.def_property( + "library", + [](const cppCLASS &self) -> decltype(auto) + { + return self.library(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.library() = value; + }, + cppCLASS::component_t::documentation("library").data() + ); + + // add standard definitions + addStandardComponentDefinitions(object); +} + +} // namespace python_multigroup +} // namespace python_v1 diff --git a/autogen/simple/multi/src/multi/v1.hpp b/autogen/simple/multi/src/multi/v1.hpp new file mode 100644 index 000000000..12086f923 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1.hpp @@ -0,0 +1,14 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1 +#define MULTI_V1 + +#include "multi/v1/multigroup/Multigroup.hpp" +#include "multi/v1/multigroup/Library.hpp" +#include "multi/v1/multigroup/Element.hpp" +#include "multi/v1/multigroup/Isotope.hpp" +#include "multi/v1/multigroup/Foobar.hpp" + +#endif diff --git a/autogen/simple/multi/src/multi/v1/key.hpp b/autogen/simple/multi/src/multi/v1/key.hpp new file mode 100644 index 000000000..b80466c22 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/key.hpp @@ -0,0 +1,81 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_KEY +#define MULTI_V1_KEY + +// GNDStk Core Interface +#include "GNDStk.hpp" + +namespace multi { +namespace v1 { + +using namespace njoy; +using namespace GNDStk; + + +// ----------------------------------------------------------------------------- +// meta:: +// ----------------------------------------------------------------------------- + +namespace meta { + +#define GNDSTK_MAKE_LOOKUP(nameField,nameGNDS) \ + inline const auto nameField = makeLookup( \ + [](const auto &obj) -> decltype(obj.nameField()) \ + { return obj.nameField(); }, \ + #nameGNDS \ + ) +// nameField vs. nameGNDS: for, e.g., Double vs. double in GNDS + +GNDSTK_MAKE_LOOKUP(atomic_number,atomic_number); +GNDSTK_MAKE_LOOKUP(mass_number,mass_number); +GNDSTK_MAKE_LOOKUP(name,name); +GNDSTK_MAKE_LOOKUP(projectile,projectile); +GNDSTK_MAKE_LOOKUP(symbol,symbol); +GNDSTK_MAKE_LOOKUP(value,value); + +#undef GNDSTK_MAKE_LOOKUP + +} // namespace meta + + +// ----------------------------------------------------------------------------- +// multigroup::child:: +// ----------------------------------------------------------------------------- + +namespace multigroup { +namespace child { + +inline const Child<> element("element"); +inline const Child<> foobar("foobar"); +inline const Child<> isotope("isotope"); +inline const Child<> library("library"); +inline const Child<> multigroup("multigroup"); + +} // namespace child +using namespace child; +} // namespace multigroup + + +// ----------------------------------------------------------------------------- +// For convenience: using directives +// ----------------------------------------------------------------------------- + +namespace key { + using namespace meta; + using namespace multigroup::child; +} // namespace key + +using namespace key; +using namespace multigroup; + + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Element.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Element.hpp new file mode 100644 index 000000000..87d4f3a40 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Element.hpp @@ -0,0 +1,226 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_MULTIGROUP_ELEMENT +#define MULTI_V1_MULTIGROUP_ELEMENT + +#include "multi/v1/multigroup/Isotope.hpp" +#include "multi/v1/multigroup/Foobar.hpp" + +namespace multi { +namespace v1 { +namespace multigroup { + +// ----------------------------------------------------------------------------- +// multigroup:: +// class Element +// ----------------------------------------------------------------------------- + +class Element : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "multigroup"; } + static auto CLASS() { return "Element"; } + static auto NODENAME() { return "element"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::optional{} + / Meta<>("symbol") | + int{} + / Meta<>("atomic_number") | + + // children + ++Child + ("isotope") | + --Child> + ("foobar") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "symbol", + "atomic_number", + "isotope", + "foobar" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "symbol", + "atomic_number", + "isotope", + "foobar" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field> + symbol{this}; + Field + atomic_number{this}; + + // children + Field> + isotope{this}; + Field> + foobar{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->symbol, \ + this->atomic_number, \ + this->isotope, \ + this->foobar \ + ) + + // default + Element() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Element( + const wrapper> + &symbol, + const wrapper + &atomic_number = {}, + const wrapper> + &isotope = {}, + const wrapper> + &foobar = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + symbol(this,symbol), + atomic_number(this,atomic_number), + isotope(this,isotope), + foobar(this,foobar) + { + Component::finish(); + } + + // from node + explicit Element(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Element(const Element &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + symbol(this,other.symbol), + atomic_number(this,other.atomic_number), + isotope(this,other.isotope), + foobar(this,other.foobar) + { + Component::finish(other); + } + + // move + Element(Element &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + symbol(this,std::move(other.symbol)), + atomic_number(this,std::move(other.atomic_number)), + isotope(this,std::move(other.isotope)), + foobar(this,std::move(other.foobar)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Element &operator=(const Element &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + symbol = other.symbol; + atomic_number = other.atomic_number; + isotope = other.isotope; + foobar = other.foobar; + } + return *this; + } + + // move + Element &operator=(Element &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + symbol = std::move(other.symbol); + atomic_number = std::move(other.atomic_number); + isotope = std::move(other.isotope); + foobar = std::move(other.foobar); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "multi/v1/multigroup/Element/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Element + +} // namespace multigroup +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Element/src/custom.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Element/src/custom.hpp new file mode 100644 index 000000000..b944fbfe2 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Element/src/custom.hpp @@ -0,0 +1,28 @@ + +private: + + static inline helpMap help = {}; + +public: + + // Custom 2-argument print() function. + // In order to be called by Component::print(), this function must be public, + // and must have the exact signature shown here, including both the constness + // of the second parameter, and of the function itself. + std::ostream &print(std::ostream &os, const int level) const + { + // When Component::print() calls a custom print() that takes indentation + // level (as opposed to a custom print() that takes only a std::ostream), + // it assumes that the custom print() takes care of its own indentation. + // So, prefer this print() over a std::ostream-only print() - for which + // Component::print() indents as it believes is appropriate - ONLY if you + // wish to do something nonstandard with indentation. + + // Here, we'll indent as GNDStk does: using GNDStk::indent*level spaces. + // GNDStk::indentTo() creates an appropriate std::string for that purpose. + os << indentTo(level) << "*** Custom Element print(), line 1\n"; + os << indentTo(level) << "*** Custom Element print(), line 2\n"; + os << indentTo(level) << "*** Custom Element print(), line 3"; + + return os; + } diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Foobar.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Foobar.hpp new file mode 100644 index 000000000..5efdf776b --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Foobar.hpp @@ -0,0 +1,202 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_MULTIGROUP_FOOBAR +#define MULTI_V1_MULTIGROUP_FOOBAR + +#include "multi/v1/key.hpp" + +namespace multi { +namespace v1 { +namespace multigroup { + +// ----------------------------------------------------------------------------- +// multigroup:: +// class Foobar +// ----------------------------------------------------------------------------- + +class Foobar : + public Component, + public DataNode,false> +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "multigroup"; } + static auto CLASS() { return "Foobar"; } + static auto NODENAME() { return "foobar"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::string{} + / Meta<>("value") | + + // data + --Child(special::self) / DataConverter{} + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "value", + "doubles" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "value", + "doubles" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + using DataNode::operator=; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + value{this}; + + // data + std::vector &doubles = *this; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->value, \ + static_cast(*this) \ + ) + + // default + Foobar() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Foobar( + const wrapper + &value + ) : + GNDSTK_COMPONENT(BlockData{}), + value(this,value) + { + Component::finish(); + } + + // from node + explicit Foobar(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // from vector + explicit Foobar(const std::vector &vector) : + GNDSTK_COMPONENT(BlockData{}), + DataNode(vector) + { + Component::finish(vector); + } + + // copy + Foobar(const Foobar &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + DataNode(other), + comment(this,other.comment), + value(this,other.value) + { + Component::finish(other); + } + + // move + Foobar(Foobar &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + DataNode(std::move(other)), + comment(this,std::move(other.comment)), + value(this,std::move(other.value)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Foobar &operator=(const Foobar &other) + { + if (this != &other) { + Component::operator=(other); + DataNode::operator=(other); + comment = other.comment; + value = other.value; + } + return *this; + } + + // move + Foobar &operator=(Foobar &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + DataNode::operator=(std::move(other)); + comment = std::move(other.comment); + value = std::move(other.value); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "multi/v1/multigroup/Foobar/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Foobar + +} // namespace multigroup +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Foobar/src/custom.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Foobar/src/custom.hpp new file mode 100644 index 000000000..9bf4b251a --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Foobar/src/custom.hpp @@ -0,0 +1,4 @@ + +private: + + static inline helpMap help = {}; diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Isotope.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Isotope.hpp new file mode 100644 index 000000000..0955a30f9 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Isotope.hpp @@ -0,0 +1,179 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_MULTIGROUP_ISOTOPE +#define MULTI_V1_MULTIGROUP_ISOTOPE + +#include "multi/v1/key.hpp" + +namespace multi { +namespace v1 { +namespace multigroup { + +// ----------------------------------------------------------------------------- +// multigroup:: +// class Isotope +// ----------------------------------------------------------------------------- + +class Isotope : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "multigroup"; } + static auto CLASS() { return "Isotope"; } + static auto NODENAME() { return "isotope"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + int{} + / Meta<>("mass_number") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "mass_number" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "mass_number" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + mass_number{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->mass_number \ + ) + + // default + Isotope() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Isotope( + const wrapper + &mass_number + ) : + GNDSTK_COMPONENT(BlockData{}), + mass_number(this,mass_number) + { + Component::finish(); + } + + // from node + explicit Isotope(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Isotope(const Isotope &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + mass_number(this,other.mass_number) + { + Component::finish(other); + } + + // move + Isotope(Isotope &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + mass_number(this,std::move(other.mass_number)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Isotope &operator=(const Isotope &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + mass_number = other.mass_number; + } + return *this; + } + + // move + Isotope &operator=(Isotope &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + mass_number = std::move(other.mass_number); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "multi/v1/multigroup/Isotope/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Isotope + +} // namespace multigroup +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Isotope/src/custom.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Isotope/src/custom.hpp new file mode 100644 index 000000000..758ac991d --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Isotope/src/custom.hpp @@ -0,0 +1,25 @@ + +private: + + static inline helpMap help = {}; + +public: + + // If a custom 1-argument print() function *and* a custom 2-argument print() + // function are both given, and both with the correct signature, then + // Component::print() will call the 2-argument version, and ignore the other. + + std::ostream &print(std::ostream &os) const + { + assert(false); // shouldn't happen, because the below print() is used! + return os; + } + + std::ostream &print(std::ostream &os, const int level) const + { + os << indentTo(level) << "*** Custom Isotope print(), line 1\n"; + os << indentTo(level) << "*** Custom Isotope print(), line 2\n"; + os << indentTo(level) << "*** Custom Isotope print(), line 3"; + + return os; + } diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Library.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Library.hpp new file mode 100644 index 000000000..2b7178136 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Library.hpp @@ -0,0 +1,197 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_MULTIGROUP_LIBRARY +#define MULTI_V1_MULTIGROUP_LIBRARY + +#include "multi/v1/multigroup/Element.hpp" + +namespace multi { +namespace v1 { +namespace multigroup { + +// ----------------------------------------------------------------------------- +// multigroup:: +// class Library +// ----------------------------------------------------------------------------- + +class Library : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "multigroup"; } + static auto CLASS() { return "Library"; } + static auto NODENAME() { return "library"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::string{} + / Meta<>("name") | + + // children + ++Child + ("element") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "name", + "element" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "name", + "element" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + name{this}; + + // children + Field> + element{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->name, \ + this->element \ + ) + + // default + Library() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Library( + const wrapper + &name, + const wrapper> + &element = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + name(this,name), + element(this,element) + { + Component::finish(); + } + + // from node + explicit Library(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Library(const Library &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + name(this,other.name), + element(this,other.element) + { + Component::finish(other); + } + + // move + Library(Library &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + name(this,std::move(other.name)), + element(this,std::move(other.element)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Library &operator=(const Library &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + name = other.name; + element = other.element; + } + return *this; + } + + // move + Library &operator=(Library &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + name = std::move(other.name); + element = std::move(other.element); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "multi/v1/multigroup/Library/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Library + +} // namespace multigroup +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Library/src/custom.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Library/src/custom.hpp new file mode 100644 index 000000000..3382adeec --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Library/src/custom.hpp @@ -0,0 +1,19 @@ + +private: + + static inline helpMap help = {}; + +public: + + // Custom 1-argument print() function. + // In order to be called by Component::print(), this function must be public, + // and must have the exact signature shown here, including the constness of + // the function itself. + std::ostream &print(std::ostream &os) const + { + os << "*** Custom Library print(), line 1\n"; + os << "*** Custom Library print(), line 2\n"; + os << "*** Custom Library print(), line 3"; + + return os; + } diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Multigroup.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Multigroup.hpp new file mode 100644 index 000000000..a540ee2f8 --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Multigroup.hpp @@ -0,0 +1,197 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef MULTI_V1_MULTIGROUP_MULTIGROUP +#define MULTI_V1_MULTIGROUP_MULTIGROUP + +#include "multi/v1/multigroup/Library.hpp" + +namespace multi { +namespace v1 { +namespace multigroup { + +// ----------------------------------------------------------------------------- +// multigroup:: +// class Multigroup +// ----------------------------------------------------------------------------- + +class Multigroup : + public Component +{ + friend class Component; + + // ------------------------ + // For Component + // ------------------------ + + // Names: this namespace and class, and original nodes (as in XML <...>) + static auto NAMESPACE() { return "multigroup"; } + static auto CLASS() { return "Multigroup"; } + static auto NODENAME() { return "multigroup"; } + + // Core Interface multi-query to transfer information to/from core Nodes + static auto KEYS() + { + return + // comment + ++Child(special::comment) / CommentConverter{} | + + // metadata + std::string{} + / Meta<>("projectile") | + + // children + ++Child + ("library") + ; + } + + // Data member names. Usually - but not necessarily - the same as the node + // names appearing in KEYS(). These are used by Component's prettyprinter. + static const auto &FIELDNAMES() + { + static const std::vector names = { + "comment", + "projectile", + "library" + }; + return names; + } + + // Data member names, as they'll be presented in the Python bindings. + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "comment", + "projectile", + "library" + }; + return names; + } + + // ------------------------ + // Public interface + // ------------------------ + +public: + + using component_t = Component; + using Component::construct; + + // ------------------------ + // Data members + // ------------------------ + + // comment + Field> comment{this}; + + // metadata + Field + projectile{this}; + + // children + Field> + library{this}; + + // ------------------------ + // Constructors + // ------------------------ + + #define GNDSTK_COMPONENT(blockdata) \ + Component( \ + blockdata, \ + this->comment, \ + this->projectile, \ + this->library \ + ) + + // default + Multigroup() : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(); + } + + // from fields, comment excluded + explicit Multigroup( + const wrapper + &projectile, + const wrapper> + &library = {} + ) : + GNDSTK_COMPONENT(BlockData{}), + projectile(this,projectile), + library(this,library) + { + Component::finish(); + } + + // from node + explicit Multigroup(const Node &node) : + GNDSTK_COMPONENT(BlockData{}) + { + Component::finish(node); + } + + // copy + Multigroup(const Multigroup &other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,other.comment), + projectile(this,other.projectile), + library(this,other.library) + { + Component::finish(other); + } + + // move + Multigroup(Multigroup &&other) : + GNDSTK_COMPONENT(other.baseBlockData()), + comment(this,std::move(other.comment)), + projectile(this,std::move(other.projectile)), + library(this,std::move(other.library)) + { + Component::finish(other); + } + + // ------------------------ + // Assignment operators + // ------------------------ + + // copy + Multigroup &operator=(const Multigroup &other) + { + if (this != &other) { + Component::operator=(other); + comment = other.comment; + projectile = other.projectile; + library = other.library; + } + return *this; + } + + // move + Multigroup &operator=(Multigroup &&other) + { + if (this != &other) { + Component::operator=(std::move(other)); + comment = std::move(other.comment); + projectile = std::move(other.projectile); + library = std::move(other.library); + } + return *this; + } + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "multi/v1/multigroup/Multigroup/src/custom.hpp" + #undef GNDSTK_COMPONENT +}; // class Multigroup + +} // namespace multigroup +} // namespace v1 +} // namespace multi + +#endif diff --git a/autogen/simple/multi/src/multi/v1/multigroup/Multigroup/src/custom.hpp b/autogen/simple/multi/src/multi/v1/multigroup/Multigroup/src/custom.hpp new file mode 100644 index 000000000..9bf4b251a --- /dev/null +++ b/autogen/simple/multi/src/multi/v1/multigroup/Multigroup/src/custom.hpp @@ -0,0 +1,4 @@ + +private: + + static inline helpMap help = {}; diff --git a/autogen/v1.9/summary_basic.json b/autogen/v1.9/summary_basic.json index a3f4f65c2..3efc842da 100644 --- a/autogen/v1.9/summary_basic.json +++ b/autogen/v1.9/summary_basic.json @@ -160,7 +160,7 @@ "description": "This represents the allowed set and sequence of characters that represent the Boolean \\attrval{true} and \\attrval{false} values in general-purpose data containers.", "name": "Boolean", "allowedValueDescription": "The allowed strings are `true' and `false'. For a table cell, the allowed values are `\\texttt{}' and `\\texttt{}'.", - "comment": "the standard XML attribute value representation for Boolean values true and false are `true' and `false' respectively.", + "remark": "the standard XML attribute value representation for Boolean values true and false are `true' and `false' respectively.", "C_equivalent": "bool"}, "whiteSpace": { @@ -210,7 +210,7 @@ "description": "Floating point number that can be stored at reduced precision", "name": "Float32", "allowedValueDescription": "n/a", - "comment": "Since only ASCII representation of data types is being considered here, and since Float32 is a subset of Float64, this is probably not needed.", + "remark": "Since only ASCII representation of data types is being considered here, and since Float32 is a subset of Float64, this is probably not needed.", "implementationStatus": "Not implemented as of GNDS-1.9"}, "Integer64": { @@ -227,7 +227,7 @@ "\\noindent with the restriction that the value shall be in the range ", "[\\textbf{Integer64\\_Min}, \\textbf{Integer64\\_Max}]."], "C_equivalent": "int64\\_t", - "comment": "Currently not needed so not defined.", + "remark": "Currently not needed so not defined.", "implementationStatus": "Not implemented as of GNDS-1.9"}, "Hexadecimal": { @@ -235,7 +235,7 @@ "description": "Typical hexadecimal number", "name": "Hexadecimal", "allowedValueDescription": "n/a", - "comment": "Currently not needed so not defined.", + "remark": "Currently not needed so not defined.", "implementationStatus": "Not implemented as of GNDS-1.9"}, "Octal": { @@ -243,6 +243,6 @@ "description": "Typical octal number", "name": "Octal", "allowedValueDescription": "n/a", - "comment": "Currently not needed so not defined.", + "remark": "Currently not needed so not defined.", "implementationStatus": "Not implemented as of GNDS-1.9"} } diff --git a/autogen/v1.9/summary_documentation.json b/autogen/v1.9/summary_documentation.json index 393100fc7..fd3d5f64e 100644 --- a/autogen/v1.9/summary_documentation.json +++ b/autogen/v1.9/summary_documentation.json @@ -176,7 +176,7 @@ }, "affiliations": { "__class__": "nodes.ChildNode", - "description": "Institutional affilation(s) of the author", + "description": "Institutional affiliation(s) of the author", "name": "affiliations", "occurrence": "1", "required": false @@ -240,7 +240,7 @@ "affiliation": { "__class__": "nodes.ChildNode", "description": "Each affiliation is described in an \\element{affiliation} element.", - "name": "affilation", + "name": "affiliation", "occurrence": "1+", "required": true } diff --git a/autogen/v1.9.json b/autogen/v1.9/v1.9.json similarity index 85% rename from autogen/v1.9.json rename to autogen/v1.9/v1.9.json index 87bde7140..c178ac324 100644 --- a/autogen/v1.9.json +++ b/autogen/v1.9/v1.9.json @@ -1,5 +1,9 @@ { - "JSONDir": "v1.9", + "Path": ".", + "Project": "GNDStk", + "Version": "v1.9", + + "JSONDir": ".", "JSONFiles": [ "summary_abstract.json", "summary_appData.json", @@ -19,7 +23,5 @@ "summary_tsl.json" ], - "GNDSDir": "test", - "Version": "v1.9", - "Changes": "changes.json" + "Changes": "../changes.json" } diff --git a/c/src/GNDStk.cpp b/c/src/GNDStk.cpp new file mode 100644 index 000000000..e365193f6 --- /dev/null +++ b/c/src/GNDStk.cpp @@ -0,0 +1,85 @@ + +// ----------------------------------------------------------------------------- +// Interface for C +// Definitions +// ----------------------------------------------------------------------------- + +#include "GNDStk.h" + + +// ----------------------------------------------------------------------------- +// Some basic flags +// In C++, these are available via inline variables. +// For C, we make them functions. +// ----------------------------------------------------------------------------- + +// ------------------------ +// General +// ------------------------ + +void indent(const int value) +{ + njoy::GNDStk::indent = value; +} + +void align(const int value) +{ + njoy::GNDStk::align = bool(value); +} + +void colors(const int value) +{ + njoy::GNDStk::colors = bool(value); +} + +// ------------------------ +// Re: Component printing +// ------------------------ + +void comments(const int value) +{ + njoy::GNDStk::comments = bool(value); +} + +void columns(const long value) +{ + njoy::GNDStk::columns = value; +} + +void elements(const long value) +{ + njoy::GNDStk::elements = value; +} + +// ------------------------ +// Re: GNDStk diagnostics +// ------------------------ + +void notes(const int value) +{ + njoy::GNDStk::notes = bool(value); +} + +void warnings(const int value) +{ + njoy::GNDStk::warnings = bool(value); +} + +void debug(const int value) +{ + njoy::GNDStk::debug = bool(value); +} + +void context(const int value) +{ + njoy::GNDStk::context = bool(value); +} + +// ------------------------ +// Re: OpenMP +// ------------------------ + +void threads(const int value) +{ + njoy::GNDStk::threads = value; +} diff --git a/c/src/GNDStk.h b/c/src/GNDStk.h new file mode 100644 index 000000000..288be3862 --- /dev/null +++ b/c/src/GNDStk.h @@ -0,0 +1,55 @@ + +// ----------------------------------------------------------------------------- +// Interface for C +// Declarations +// ----------------------------------------------------------------------------- + +#ifndef C_INTERFACE_GNDSTK +#define C_INTERFACE_GNDSTK + +// This file works in both C++ and C +#ifdef __cplusplus + // For C++ + #include "GNDStk.hpp" + #define extern_C extern "C" +#else + // For C + #define extern_C +#endif + + +// ----------------------------------------------------------------------------- +// Function declarations +// Definitions are in this file's .cpp +// ----------------------------------------------------------------------------- + +extern_C void indent(const int); +extern_C void align(const int); +extern_C void color(const int); + +extern_C void comments(const int); +extern_C void columns(const long); +extern_C void elements(const long); + +extern_C void note(const int); +extern_C void warning(const int); +extern_C void debug(const int); +extern_C void context(const int); + +extern_C void threads(const int); + +// todo +// Obviously, we'll want much more here. I'll probably add additional +// C-style interfaces to GNDStk's C++ code gradually, as we discover what +// our C language users want. Note that we're speaking here about the C +// interface to the overarching GNDStk library, not a C interface to some +// particular set of generated C++ classes that somebody might have created +// with our code generator. Those C interfaces are (or will be) created +// automatically, by the code generator, just as the C++ classes are. + + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +#undef extern_C +#endif diff --git a/cmake/GNDStk_dependencies.cmake b/cmake/GNDStk_dependencies.cmake index 46c409ac9..a355119b4 100644 --- a/cmake/GNDStk_dependencies.cmake +++ b/cmake/GNDStk_dependencies.cmake @@ -10,28 +10,28 @@ include( FetchContent ) # Declare project dependencies ######################################################################## -FetchContent_Declare( catch-adapter - GIT_REPOSITORY http://github.com/njoy/catch-adapter - GIT_TAG origin/master - GIT_SHALLOW TRUE +FetchContent_Declare(catch-adapter + GIT_REPOSITORY http://github.com/njoy/catch-adapter + GIT_TAG origin/master + GIT_SHALLOW TRUE ) -FetchContent_Declare( Log - GIT_REPOSITORY http://github.com/njoy/Log - GIT_TAG origin/build/fetchcontent - GIT_SHALLOW TRUE +FetchContent_Declare(Log + GIT_REPOSITORY http://github.com/njoy/Log + GIT_TAG origin/master + GIT_SHALLOW TRUE ) -FetchContent_Declare( pugixml-adapter - GIT_REPOSITORY http://github.com/njoy/pugixml-adapter - GIT_TAG origin/master - GIT_SHALLOW TRUE +FetchContent_Declare(pugixml-adapter + GIT_REPOSITORY http://github.com/njoy/pugixml-adapter + GIT_TAG origin/master + GIT_SHALLOW TRUE ) FetchContent_Declare(json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.7.3 - GIT_SHALLOW true + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG origin/master + GIT_SHALLOW TRUE ) FetchContent_GetProperties(json) @@ -41,10 +41,19 @@ if(NOT json_POPULATED) add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL) endif() -FetchContent_Declare( pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.6.1 - GIT_SHALLOW TRUE +FetchContent_Declare(hdf5 + GIT_REPOSITORY https://github.com/BlueBrain/HighFive.git + GIT_TAG v2.3.1 + GIT_SHALLOW TRUE + ) +set( HIGHFIVE_USE_BOOST OFF CACHE INTERNAL "" ) +set( HIGHFIVE_UNIT_TESTS OFF CACHE INTERNAL "" ) +set( HIGHFIVE_EXAMPLES OFF CACHE INTERNAL "" ) + +FetchContent_Declare(pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11 + GIT_TAG v2.6.1 + GIT_SHALLOW TRUE ) @@ -57,5 +66,6 @@ FetchContent_MakeAvailable( Log pugixml-adapter json + hdf5 pybind11 ) diff --git a/cmake/unit_testing.cmake b/cmake/unit_testing.cmake index bf5bacd44..9573a46de 100644 --- a/cmake/unit_testing.cmake +++ b/cmake/unit_testing.cmake @@ -10,7 +10,6 @@ enable_testing() # Unit testing directories ####################################################################### -add_subdirectory( src/GNDStk/test ) add_subdirectory( src/GNDStk/Defaulted/test ) add_subdirectory( src/GNDStk/Tree/test ) add_subdirectory( src/GNDStk/type2string/test ) @@ -20,28 +19,37 @@ add_subdirectory( src/GNDStk/string2type/test ) add_subdirectory( src/GNDStk/Meta/test ) add_subdirectory( src/GNDStk/XML/test ) add_subdirectory( src/GNDStk/JSON/test ) +add_subdirectory( src/GNDStk/HDF5/test ) add_subdirectory( src/GNDStk/Node/test ) -add_subdirectory( src/GNDStk/keyword/test ) add_subdirectory( src/GNDStk/Child/test ) add_subdirectory( src/GNDStk/convert/test ) add_subdirectory( src/GNDStk/utility/test ) add_subdirectory( src/GNDStk/Component/test ) -add_subdirectory( src/GNDStk/BodyText/test ) +add_subdirectory( src/GNDStk/BlockData/test ) add_subdirectory( src/GNDStk/precision/test ) -add_subdirectory( src/GNDStk/enums/Encoding/test ) +add_subdirectory( src/GNDStk/enums/DateType/test ) +add_subdirectory( src/GNDStk/enums/ContributorType/test ) +add_subdirectory( src/GNDStk/enums/RelationType/test ) +add_subdirectory( src/GNDStk/enums/Parity/test ) add_subdirectory( src/GNDStk/enums/Frame/test ) +add_subdirectory( src/GNDStk/enums/Interpolation/test ) +add_subdirectory( src/GNDStk/enums/InterpolationQualifier/test ) +add_subdirectory( src/GNDStk/enums/HashAlgorithm/test ) +add_subdirectory( src/GNDStk/enums/DecayType/test ) add_subdirectory( src/GNDStk/enums/GridStyle/test ) +add_subdirectory( src/GNDStk/enums/BoundaryCondition/test ) + +add_subdirectory( src/GNDStk/enums/Encoding/test ) add_subdirectory( src/GNDStk/enums/Interaction/test ) -add_subdirectory( src/GNDStk/enums/Interpolation/test ) add_subdirectory( src/GNDStk/enums/StorageOrder/test ) add_subdirectory( src/GNDStk/enums/units/Energy/test ) add_subdirectory( src/GNDStk/enums/units/Length/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Values/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Axis/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Link/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Grid/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Axes/test ) -add_subdirectory( src/GNDStk/v1.9/containers/XYs1d/test ) -add_subdirectory( src/GNDStk/v1.9/containers/Regions1d/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Values/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Axis/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Link/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Grid/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Axes/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/XYs1d/test ) +add_subdirectory( autogen/prototype/proto/src/proto/v1.9/containers/Regions1d/test ) diff --git a/docs/build.rst b/docs/build.rst index 89d8e30de..0d4848f59 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -78,7 +78,7 @@ it depends -- automatically. The *bad* news is that the download may, for the same reason, take quite some time. Resist the temptation to terminate the command, perhaps believing that your computer has hung, and consider starting ``cmake ..`` before lunch hour if you have a slow Internet connection. The main -culprit appears to be the "nlohmann json" library, +culprit appears to be the `nlohmann/json` library, https://github.com/nlohmann/json. An excellent library, by all accounts, and invaluable as the workhorse for GNDStk's JSON capabilities; but responsible, at the time of the writing, for over 400MB -- about 95% -- of diff --git a/docs/files/code-tables/node-add-child.cc b/docs/files/code-tables/node-add-child.cc index 820bb982b..97dd3372c 100644 --- a/docs/files/code-tables/node-add-child.cc +++ b/docs/files/code-tables/node-add-child.cc @@ -1,6 +1,6 @@ // string -Node &add( const string &name = "" ); +Node &add( const string &name = emptyNodeName ); // value Node &add( const T &val ); diff --git a/docs/files/code-tables/node-multi.cc b/docs/files/code-tables/node-multi.cc index 9b3fe048a..2d9090a6e 100644 --- a/docs/files/code-tables/node-multi.cc +++ b/docs/files/code-tables/node-multi.cc @@ -1,3 +1,3 @@ -auto operator()( const KeywordTup &kwds ) const; -auto operator()( const KeywordTup &kwds ); +auto operator()( const KeyTuple &keytup ) const; +auto operator()( const KeyTuple &keytup ); diff --git a/docs/primer.rst b/docs/primer.rst index 724fb8f2b..d759fd35b 100644 --- a/docs/primer.rst +++ b/docs/primer.rst @@ -207,7 +207,7 @@ Here's a simple code that reads the XML format GNDS file named Obviously, but worth a reminder, this assumes that the file resides right there, in the directory from which this code is run. If it doesn't, include a suitable -absolute or relative path in the file name string. We, and no doubt everyone +absolute or relative path in the file name. We, and no doubt everyone reading this, have probably made this mistake often enough over the years. ``Tree`` is GNDStk's data structure for holding an entire GNDS hierarchy, a.k.a. @@ -259,11 +259,9 @@ explicitly, and can either be something from GNDStk's ``FileType`` enumerator: :language: cpp or can be a direct string: ``"xml"``, etc. A direct string is shorter and -slightly easier to type -- but, if mistyped, would lead to a run-time error, +slightly easier to type -- but, if mistyped, would lead to a runtime error, not a compile-time error, if that matters to you in this simple context. -**HDF5 is not supported at this time!** Just XML and JSON. - *You should seldom, if ever, need to provide the second argument*. Absent the second argument, **GNDStk determines the file type automatically**, and we doubt that you'll have any objections to that. If you do choose provide the second @@ -276,9 +274,9 @@ as we attempt to read the file pursuant to the (incorrect) forced format. GNDStk uses the "file magic number," not the file name, to determine file type automatically. The file magic number really means the first byte, or bytes, -of the file. XML files always begin with a ``<`` character. HDF files (not -supported yet) begin with ASCII 137 and a few other specific bytes. If the -first byte is neither of those values, then GNDStk assumes JSON format. +of the file. XML files always begin with a ``<`` character. HDF5 files begin +with ASCII 137 and a few other specific bytes. If the first byte is neither +of those values, then GNDStk assumes JSON format. A nice thing about using the file magic number, not the file name, is that it works for ``std::istream``, for which a "file name" isn't even available. @@ -325,7 +323,7 @@ then GNDStk will write file ``pu239.xml`` in JSON format, as you asked for in the second argument, but will warn that the file extension is inconsistent with the format you asked for. -What if the file name extension isn't given, or isn't recognized, *and* a format +What if the file extension isn't given, or isn't recognized, *and* a format isn't forced with a second argument? That is, what if we wrote, for example, ``pu239.write("pu239")``? In that case, ``write`` writes the ``Tree`` into a simple output format that we created largely for debugging purposes. You @@ -406,7 +404,7 @@ Several remarks are in order here. The comparison operator for ``Tree`` compares the two GNDS trees in an *order-agnostic* manner. GNDS fundamentally provides data in two places: nodes (think XML "elements") in its overall tree structure, and metadata (think XML -"attributes"). The GNDS standard does not, however, consider ordering to be +attributes). The GNDS standard does not, however, consider ordering to be important. One tree node's child nodes or metadata, anywhere or everywhere throughout the entire tree structure, could be reordered arbitrarily, but if each remains equivalent -- in the same respect that we consider two mathematical @@ -492,14 +490,31 @@ with what XML is able to represent. the node. For example, in HDF5 the attribute ``nodeIndex`` could be added to each child in a group. -For (1), GNDStk does the first suggested action: it groups all of a node's -attributes under a child node called ``attributes``. We consider that to be -cleaner than using an ``_attr`` suffix. - -For (2), GNDStk does exactly as illustrated: multiple elements of the same name -are suffixed with ``0``, ``1``, etc. And, then, a JSON name/value pair with the -name ``nodeName``, as suggested, is created in order to preserve the original -*unsuffixed* element's name. +For (1), GNDStk does largely the first suggested action (which we think is +somewhat cleaner than using an ``_attr`` suffix), but with a slight twist, +along with our preferred terminology of ``metadata`` in place of ``attributes``. +It groups a node's metadata -- attributes -- under a child node +called ``#metadata``. + +The ``#`` prefix is something we use in node names throughout GNDStk, +if and where +the nodes so named represent special things -- with special meaning, and needing +special treatment. The extra character allows special nodes to be identified +easily, in both the GNDStk code base itself or in files produced by GNDStk. +Moreover, one could imagine that a future GNDS version might -- just might -- +have a normal node with the name ``metadata``, or with some other name that +we might wish to use for a special purpose. If and where such situations occur, +our use of a special prefix character allows for an unambiguous interpretation. +(As an aside: in principle, we'd have preferred to use the S-like dollar sign, +``$``, to inside S for "special" node. Unfortunately, ``$`` has a particular +meaning in the C++ regular-expression library. As such, ``$`` is unsuitable +for use in identifying special nodes, as our various node-finding capabilities +support the use of regular expressions.) + +For (2), GNDStk does as suggested, except again with the ``#`` terminology as +described above, and an all-lowercase name. Multiple elements of the same name +are suffixed with ``0``, ``1``, etc. Then, a JSON name/value pair with the +name ``#nodename`` is created. Its value preserves the original element's name. For (3), GNDStk does nothing in particular right now. Our understanding of GNDS is that it's designed so that elements -- nodes -- can appear in any order. @@ -509,7 +524,7 @@ GNDS file that we've been using for our examples: .. literalinclude:: tutorial/xml-axes-fragment.xml :language: xml -Those ``axis`` child nodes already contain a 0-based ``index`` attribute, so +Those ``axis`` child nodes already contain a 0-based ``index`` metadatum, so perhaps the specification's admonishment #3 is something we can consider to have been satisfied already by whomever has created an existing, valid GNDS file (so that no further treatment is required); or something that *we* must satisfy if @@ -549,8 +564,8 @@ node. (Valid GNDS top-level nodes, per the standard, are ``reactionSuite``, about it for now. Naturally, GNDStk reverses the modifications when we *read* from a JSON file -into our internal format. Specifically: values in an ``attributes`` block are -transformed into metadata in the enclosing node, and values from ``nodeName`` +into our internal format. Specifically: values in a ``#metadata`` block are +transformed into metadata in the enclosing node, and values from ``#nodename`` name/value pairs replace index-suffixed names. At this time, GNDStk provides no other options, such as the ``_attr`` suffix @@ -560,7 +575,7 @@ We're not aware, at the time of this writing, of the existence any official JSON-format GNDS files. If and when such files come into existence, and if such files use a different scheme than we do for addressing the issues described above, then we'll provide capabilities at least for reading those -files, and perhaps for writing them in that manner as well. +files, and perhaps for writing files in that manner as well. @@ -770,7 +785,7 @@ the top of the ``n-094_Pu_239.xml`` GNDS file: :language: xml Here, an outer ``evaluated`` node (XML "element") contains four metadata -key/value pairs (XML "attributes") and two child elements. The first child +key/value pairs (XML attributes) and two child elements. The first child element, ``temperature``, contains two metadata pairs but no further child nodes. The second child element, ``projectileEnergyDomain``, contains three metadata pairs but no further child nodes. diff --git a/docs/ref-core.rst b/docs/ref-core.rst index 76058e2da..a427144bd 100644 --- a/docs/ref-core.rst +++ b/docs/ref-core.rst @@ -28,5 +28,5 @@ Child ======================================== ======================================== -KeywordTup +KeyTuple ======================================== diff --git a/docs/tutorial/employees.json b/docs/tutorial/employees.json index 37bb8442b..98371f024 100644 --- a/docs/tutorial/employees.json +++ b/docs/tutorial/employees.json @@ -2,30 +2,30 @@ "employees": { "employee0": { "name": { - "attributes": { + "#metadata": { "first": "Doc", "last": "Jones" } }, - "nodeName": "employee" + "#nodename": "employee" }, "employee1": { "name": { - "attributes": { + "#metadata": { "first": "Grumpy", "last": "Smith" } }, - "nodeName": "employee" + "#nodename": "employee" }, "employee2": { "name": { - "attributes": { + "#metadata": { "first": "Happy", "last": "Earp" } }, - "nodeName": "employee" + "#nodename": "employee" } } -} \ No newline at end of file +} diff --git a/docs/tutorial/file-types.hpp b/docs/tutorial/file-types.hpp index df64dc575..1106d833b 100644 --- a/docs/tutorial/file-types.hpp +++ b/docs/tutorial/file-types.hpp @@ -1,6 +1,6 @@ enum class FileType { - null, // Default, automagick, etc. - tree, // <== DON't use this for reading; just writing + guess, // Default, automagick, etc. + debug, // <== DON't use this for reading; just writing // Generally use one of these: xml, XML = xml, json, JSON = json, diff --git a/python/runtests.sh b/python/runtests.sh index c94247071..7a7dd0fa5 100755 --- a/python/runtests.sh +++ b/python/runtests.sh @@ -1,8 +1,8 @@ #!/bin/bash -# this script copies the dynamic library for the GNDStk python module -# and runs all the unit tests it can find +# This script copies the dynamic library for the GNDStk python module +# and runs all the unit tests it can find. -rm GNDStk.*.so -cp ../build/GNDStk.*.so . +rm GNDStk*.so +cp ../build/GNDStk*.so . python -m unittest discover -v -p "Test*" diff --git a/python/src/BoundaryCondition.python.cpp b/python/src/BoundaryCondition.python.cpp new file mode 100644 index 000000000..cee60c334 --- /dev/null +++ b/python/src/BoundaryCondition.python.cpp @@ -0,0 +1,37 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapBoundaryCondition( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::BoundaryCondition; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "BoundaryCondition", + "Enumeration class giving acceptable boundary condition values", + python::arithmetic() + ); + + // wrap the component + component + .value( "EliminateShiftFunction", Component::EliminateShiftFunction ) + .value( "NegativeOrbitalMomentum", Component::NegativeOrbitalMomentum ) + .value( "Brune", Component::Brune ) + .value( "Given", Component::Given ); +} + +} // namespace core diff --git a/python/src/ContributorType.python.cpp b/python/src/ContributorType.python.cpp new file mode 100644 index 000000000..23e12e45a --- /dev/null +++ b/python/src/ContributorType.python.cpp @@ -0,0 +1,54 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapContributorType( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::ContributorType; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "ContributorType", + "Enumeration class giving acceptable contributor type values", + python::arithmetic() + ); + + // wrap the component + component + .value( "ContactPerson", Component::ContactPerson ) + .value( "DataCollector", Component::DataCollector ) + .value( "DataCurator", Component::DataCurator ) + .value( "DataManager", Component::DataManager ) + .value( "Distributor", Component::Distributor ) + .value( "Editor", Component::Editor ) + .value( "HostingInstitution", Component::HostingInstitution ) + .value( "Producer", Component::Producer ) + .value( "ProjectLeader", Component::ProjectLeader ) + .value( "ProjectManager", Component::ProjectManager ) + .value( "ProjectMember", Component::ProjectMember ) + .value( "RegistrationAgency", Component::RegistrationAgency ) + .value( "RegistrationAuthority", Component::RegistrationAuthority ) + .value( "RelatedPerson", Component::RelatedPerson ) + .value( "Researcher", Component::Researcher ) + .value( "ResearchGroup", Component::ResearchGroup ) + .value( "RightsHolder", Component::RightsHolder ) + .value( "Sponsor", Component::Sponsor ) + .value( "Supervisor", Component::Supervisor ) + .value( "WorkPackageLeader", Component::WorkPackageLeader ) + .value( "Other", Component::Other ); +} + +} // namespace core diff --git a/python/src/DateType.python.cpp b/python/src/DateType.python.cpp new file mode 100644 index 000000000..8d3d7964f --- /dev/null +++ b/python/src/DateType.python.cpp @@ -0,0 +1,43 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapDateType( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::DateType; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "DateType", + "Enumeration class giving acceptable date type values", + python::arithmetic() + ); + + // wrap the component + component + .value( "accepted", Component::accepted ) + .value( "available", Component::available ) + .value( "copyrighted", Component::copyrighted ) + .value( "collected", Component::collected ) + .value( "created", Component::created ) + .value( "issued", Component::issued ) + .value( "submitted", Component::submitted ) + .value( "updated", Component::updated ) + .value( "valid", Component::valid ) + .value( "withdrawn", Component::withdrawn ); +} + +} // namespace core diff --git a/python/src/DecayType.python.cpp b/python/src/DecayType.python.cpp new file mode 100644 index 000000000..19d837a40 --- /dev/null +++ b/python/src/DecayType.python.cpp @@ -0,0 +1,45 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapDecayType( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::DecayType; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "DecayType", + "Enumeration class giving acceptable decay type values", + python::arithmetic() + ); + + // wrap the component + component + .value( "SF", Component::SpontaneousFission ) + .value( "beta-", Component::BetaMinus ) + .value( "beta+", Component::BetaPlus ) + .value( "EC", Component::ElectronCapture ) + .value( "electroMagnetic", Component::ElectroMagnetic ) + .value( "IT", Component::IsomericTransition ) + .value( "n", Component::Neutron ) + .value( "p", Component::Proton ) + .value( "d", Component::Deuteron ) + .value( "t", Component::Triton ) + .value( "alpha", Component::Alpha ) + .value( "atomicRelaxation", Component::AtomicRelaxation ); +} + +} // namespace core diff --git a/python/src/Frame.python.cpp b/python/src/Frame.python.cpp new file mode 100644 index 000000000..8585f03f8 --- /dev/null +++ b/python/src/Frame.python.cpp @@ -0,0 +1,35 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapFrame( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::Frame; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "Frame", + "Enumeration class giving acceptable reference frame values", + python::arithmetic() + ); + + // wrap the component + component + .value( "lab", Component::lab ) + .value( "centerOfMass", Component::centerOfMass ); +} + +} // namespace core diff --git a/python/src/GNDStk.python.cpp b/python/src/GNDStk.python.cpp index 2a0ec7ad4..a14c0bbd4 100644 --- a/python/src/GNDStk.python.cpp +++ b/python/src/GNDStk.python.cpp @@ -1,25 +1,35 @@ + // system includes #include #include -// other includes +// local includes +#include "GNDStk.hpp" // namespace aliases namespace python = pybind11; // core interface declarations namespace core { + void wrapNode( python::module& ); - void wrapNode( python::module& ); - - void wrapGridStyle( python::module& ); - void wrapInterpolation( python::module& ); + void wrapContributorType( python::module& ); + void wrapDateType( python::module& ); + void wrapDecayType( python::module& ); + void wrapFrame( python::module& ); + void wrapGridStyle( python::module& ); + void wrapHashAlgorithm( python::module& ); + void wrapInteraction( python::module& ); + void wrapInterpolation( python::module& ); + void wrapInterpolationQualifier( python::module& ); + void wrapParity( python::module& ); + void wrapRelationType( python::module& ); + void wrapBoundaryCondition( python::module& ); } -// v1.9 interface declarations -namespace python_v1_9 { - - void wrapGNDS( python::module& ); +// v2.0 interface declarations +namespace python_v2_0 { + void wrapGNDS( python::module& ); } /** @@ -29,21 +39,64 @@ namespace python_v1_9 { * set on the PROPERTIES OUTPUT_NAME in the CMakeLists.txt file. */ PYBIND11_MODULE( GNDStk, module ) { + // create the core submodule + python::module submodule = module.def_submodule( + "core", + "core - GNDS core interface components" + ); + + // wrap core components (in the core module) + core::wrapNode( submodule ); + + // enumerations (in the GNDStk module) + core::wrapContributorType( module ); + core::wrapDateType( module ); + core::wrapDecayType( module ); + core::wrapFrame( module ); + core::wrapGridStyle( module ); + core::wrapHashAlgorithm( module ); + core::wrapInteraction( module ); + core::wrapInterpolation( module ); + core::wrapInterpolationQualifier( module ); + core::wrapParity( module ); + core::wrapRelationType( module ); + core::wrapBoundaryCondition( module ); + + // v2.0 components (in the v2_0 module, created in this function) + python_v2_0::wrapGNDS( module ); - // create the core submodule - python::module submodule = module.def_submodule( + // ------------------------ + // general settings + // ------------------------ - "core", - "core - GNDS core interface components" - ); + struct settings { }; + python::class_ obj(module,"settings"); - // wrap core components (in the core module) - core::wrapNode( submodule ); + // get/set colors + obj.def_property_static( + "colors", + [](python::object) + { + return njoy::GNDStk::colors; + }, + [](python::object, const bool &value) + { + njoy::GNDStk::colors = value; + } + ); - // enumerations (in the GNDStk module) - core::wrapGridStyle( module ); - core::wrapInterpolation( module ); + // get/set shades + obj.def_property_static( + "shades", + [](python::object) + { + return njoy::GNDStk::shades; + }, + [](python::object, const bool &value) + { + njoy::GNDStk::shades = value; + } + ); - // v1.9 components (in the v1_9 module, created in this function) - python_v1_9::wrapGNDS( module ); + // zzz Martin: put lots more here, after figuring out what they should be } diff --git a/python/src/HashAlgorithm.python.cpp b/python/src/HashAlgorithm.python.cpp new file mode 100644 index 000000000..e453fb3f9 --- /dev/null +++ b/python/src/HashAlgorithm.python.cpp @@ -0,0 +1,35 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapHashAlgorithm( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::HashAlgorithm; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "HashAlgorithm", + "Enumeration class giving acceptable hash algorithm values", + python::arithmetic() + ); + + // wrap the component + component + .value( "md5", Component::md5 ) + .value( "sha1", Component::sha1 ); +} + +} // namespace core diff --git a/python/src/Interaction.python.cpp b/python/src/Interaction.python.cpp new file mode 100644 index 000000000..693f60f45 --- /dev/null +++ b/python/src/Interaction.python.cpp @@ -0,0 +1,36 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapInteraction( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::Interaction; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "Interaction", + "Enumeration class giving acceptable interaction type values", + python::arithmetic() + ); + + // wrap the component + component + .value( "nuclear", Component::nuclear ) + .value( "atomic", Component::atomic ) + .value( "thermalNeutronScatteringLaw", Component::thermalNeutronScatteringLaw ); +} + +} // namespace core diff --git a/python/src/InterpolationQualifier.python.cpp b/python/src/InterpolationQualifier.python.cpp new file mode 100644 index 000000000..ef1148e6f --- /dev/null +++ b/python/src/InterpolationQualifier.python.cpp @@ -0,0 +1,37 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapInterpolationQualifier( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::InterpolationQualifier; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "InterpolationQualifier", + "Enumeration class giving acceptable interpolation qualifier values", + python::arithmetic() + ); + + // wrap the component + component + .value( "direct", Component::direct ) + .value( "unitBase", Component::unitBase ) + .value( "correspondingEnergies", Component::correspondingEnergies ) + .value( "correspondingPoints", Component::correspondingPoints ); +} + +} // namespace core diff --git a/python/src/Parity.python.cpp b/python/src/Parity.python.cpp new file mode 100644 index 000000000..001109c90 --- /dev/null +++ b/python/src/Parity.python.cpp @@ -0,0 +1,35 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapParity( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::Parity; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "Parity", + "Enumeration class giving acceptable parity values", + python::arithmetic() + ); + + // wrap the component + component + .value( "minus", Component::minus ) + .value( "plus", Component::plus ); +} + +} // namespace core diff --git a/python/src/RelationType.python.cpp b/python/src/RelationType.python.cpp new file mode 100644 index 000000000..068442a18 --- /dev/null +++ b/python/src/RelationType.python.cpp @@ -0,0 +1,67 @@ +// system includes +#include +#include + +// local includes +#include "GNDStk.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace core { + +void wrapRelationType( python::module& module ) { + + // type aliases + using Component = njoy::GNDStk::enums::RelationType; + + // wrap views created by this component + + // create the component + python::enum_< Component > component( + + module, + "RelationType", + "Enumeration class giving acceptable relation type values", + python::arithmetic() + ); + + // wrap the component + component + .value( "IsCitedBy", Component::IsCitedBy ) + .value( "Cites", Component::Cites ) + .value( "IsSupplementTo", Component::IsSupplementTo ) + .value( "IsSupplementedBy", Component::IsSupplementedBy ) + .value( "IsContinuedBy", Component::IsContinuedBy ) + .value( "Continues", Component::Continues ) + .value( "Describes", Component::Describes ) + .value( "IsDescribedBy", Component::IsDescribedBy ) + .value( "HasMetadata", Component::HasMetadata ) + .value( "IsMetadataFor", Component::IsMetadataFor ) + .value( "HasVersion", Component::HasVersion ) + .value( "IsVersionOf", Component::IsVersionOf ) + .value( "IsNewVersionOf", Component::IsNewVersionOf ) + .value( "IsPreviousVersionOf", Component::IsPreviousVersionOf ) + .value( "IsPartOf", Component::IsPartOf ) + .value( "HasPart", Component::HasPart ) + .value( "IsPublishedIn", Component::IsPublishedIn ) + .value( "IsReferencedBy", Component::IsReferencedBy ) + .value( "References", Component::References ) + .value( "IsDocumentedBy", Component::IsDocumentedBy ) + .value( "Documents", Component::Documents ) + .value( "IsCompiledBy", Component::IsCompiledBy ) + .value( "Compiles", Component::Compiles ) + .value( "IsVariantFormOf", Component::IsVariantFormOf ) + .value( "IsOriginalFormOf", Component::IsOriginalFormOf ) + .value( "IsIdenticalTo", Component::IsIdenticalTo ) + .value( "IsReviewedBy", Component::IsReviewedBy ) + .value( "Reviews", Component::Reviews ) + .value( "IsDerivedFrom", Component::IsDerivedFrom ) + .value( "IsSourceOf", Component::IsSourceOf ) + .value( "IsRequiredBy", Component::IsRequiredBy ) + .value( "Requires", Component::Requires ) + .value( "Obsoletes", Component::Obsoletes ) + .value( "IsObsoletedBy", Component::IsObsoletedBy ); +} + +} // namespace core diff --git a/python/src/core/Node.python.cpp b/python/src/core/Node.python.cpp index ff2e7f377..c554d4c8d 100644 --- a/python/src/core/Node.python.cpp +++ b/python/src/core/Node.python.cpp @@ -1,3 +1,4 @@ + // system includes #include #include @@ -10,148 +11,151 @@ namespace python = pybind11; namespace core { - void wrapNode( python::module& module ) { - - // type aliases - using Component = njoy::GNDStk::core::Node; - using ConstRefComponent = std::reference_wrapper< const Component >; - - // create the core component - python::class_< Component > component( +void wrapNode(python::module &module) +{ + // type aliases + using Component = njoy::GNDStk::Node; + using RefConstComponent = std::reference_wrapper< const Component >; + // create the core component + python::class_< Component > component( module, "Node", "GNDS core node" - ); - - // wrap the core component - component - // add the default Node constructor to the python class - .def( - - python::init<>(), - "Initialise an empty node\n\n" - "Arguments:\n" - " self the node" - ) - // add the Node constructor using a string argument to the python class - .def( - - python::init< const std::string& >(), - python::arg( "name" ), - "Initialise the node with its name\n\n" - "Arguments:\n" - " self the node\n" - " name the name of the node" - ) - // add the copy constructor to the python class - .def( - - python::init< const Component& >(), - python::arg( "name" ), - "Initialise the node with a copy of a node\n\n" - "Arguments:\n" - " self the node\n" - " copy the node to be copied" - ) - // add a public member/field with read only access - // you can use def_readwrite to make it read/write - .def_readonly( - - "name", - &Component::name, - "The name of the node" - ) - .def_readonly( - - "metadata", - &Component::metadata, - "The metadata of the node" - ) - .def_property_readonly( - - "children", - // we cannot expose a vector of unique pointers, so we need to transform - // them into a vector of references first (since this is readonly, we use - // const references) - [] ( const Component& self ) -> std::vector< ConstRefComponent > { - - std::vector< ConstRefComponent > children; - for (auto& pointer : self.children ) { - - children.push_back( std::cref( *pointer ) ); - } - return children; - }, - "The children of the node" - ) - .def( - - "add", - // we need to define one of these for every type we want to use since - // python does not have a concept of templates - [] ( Component& self, const std::string& name, const std::string& value ) - { return self.add( name, value ); }, - python::arg( "name" ), python::arg( "value" ), - "Add the name,value pair as metadata to the node.\n\n" - "Arguments:\n" - " name the name of the metadata\n" - " value the value of the metadata\n" - ) // add a public member function - .def( - - "add", - // we need to define one of these for every type we want to use since - // python does not have a concept of templates - [] ( Component& self, const std::string& name, int value ) - { return self.add( name, value ); }, - python::arg( "name" ), python::arg( "value" ), - "Add the name,value pair as metadata to the node.\n\n" - "Arguments:\n" - " name the name of the metadata\n" - " value the value of the metadata\n" - ) // add a public member function - .def( - - "add", - // we need to define one of these for every type we want to use since - // python does not have a concept of templates - [] ( Component& self, const std::string& name, double value ) - { return self.add( name, value ); }, - python::arg( "name" ), python::arg( "value" ), - "Add the name,value pair as metadata to the node.\n\n" - "Arguments:\n" - " name the name of the metadata\n" - " value the value of the metadata\n" - ) // add a public member function - .def( - - "empty", - &Component::empty, - "Return whether or not the node is empty" - ) - // add a public member function - .def( - - "clear", - &Component::clear, - "Clear the content of the node and return the resulting empty node" - ) - // add a new custom function - .def( - - "to_string", - [] ( const Component& self ) -> std::string { - - if ( !self.empty() ) { - - std::ostringstream out; - self.write( out ); - return out.str(); - } - return ""; - }, - "Return a string representation of the node" - ); - } -} + ); + + // wrap the core component + component + // add the default Node constructor to the python class + .def( + python::init<>(), + "Initialise an empty node\n\n" + "Arguments:\n" + " self the node" + ) + + // add the Node constructor using a string argument to the python class + .def( + python::init(), + python::arg("name"), + "Initialise the node with its name\n\n" + "Arguments:\n" + " self the node\n" + " name the name of the node" + ) + + // add the copy constructor to the python class + .def( + python::init(), + python::arg("name"), + "Initialise the node with a copy of a node\n\n" + "Arguments:\n" + " self the node\n" + " copy the node to be copied" + ) + + // add a public member/field with read only access + // you can use def_readwrite to make it read/write + .def_readonly( + "name", + &Component::name, + "The name of the node" + ) + + .def_readonly( + "metadata", + &Component::metadata, + "The metadata of the node" + ) + + .def_property_readonly( + "children", + // we cannot expose a vector of unique pointers, so we need + // to transform them into a vector of references first (since + // this is readonly, we use const references) + [] (const Component &self) -> std::vector + { + std::vector children; + for (auto &pointer : self.children) + children.push_back(std::cref(*pointer)); + return children; + }, + "The children of the node" + ) + + .def( + "add", + // we need to define one of these for every type we want to use since + // python does not have a concept of templates + [] (Component &self, const std::string &name, const std::string &value) + { + return self.add(name,value); + }, + python::arg("name"), python::arg("value"), + "Add the name,value pair as metadata to the node.\n\n" + "Arguments:\n" + " name the name of the metadata\n" + " value the value of the metadata\n" + ) + + // add a public member function + .def( + "add", + // we need to define one of these for every type we want to use since + // python does not have a concept of templates + [] (Component &self, const std::string &name, int value) + { + return self.add(name,value); + }, + python::arg("name"), python::arg("value"), + "Add the name,value pair as metadata to the node.\n\n" + "Arguments:\n" + " name the name of the metadata\n" + " value the value of the metadata\n" + ) + + // add a public member function + .def( + "add", + // we need to define one of these for every type we want to use since + // python does not have a concept of templates + [] (Component &self, const std::string &name, double value) + { + return self.add(name,value); + }, + python::arg("name"), python::arg("value"), + "Add the name,value pair as metadata to the node.\n\n" + "Arguments:\n" + " name the name of the metadata\n" + " value the value of the metadata\n" + ) // add a public member function + + .def( + "empty", + &Component::empty, + "Return whether or not the node is empty" + ) + + // add a public member function + .def( + "clear", + &Component::clear, + "Clear the content of the node and return the resulting empty node" + ) + + // add a new custom function + .def( + "to_string", + [] (const Component &self) -> std::string + { + if (self.empty()) + return ""; + std::ostringstream oss; + self.write(oss); + return oss.str(); + }, + "Return a string representation of the node" + ); +} // void wrapNode + +} // namespace core diff --git a/python/src/definitions.hpp b/python/src/definitions.hpp index 230bd1d99..9014abf25 100644 --- a/python/src/definitions.hpp +++ b/python/src/definitions.hpp @@ -1,3 +1,4 @@ + #ifndef NJOY_GNDSTK_PYTHON_DEFINITIONS #define NJOY_GNDSTK_PYTHON_DEFINITIONS @@ -9,79 +10,287 @@ #include "GNDStk.hpp" // namespace aliases -namespace python = pybind11; +namespace py = pybind11; /** - * @brief Add standard component definitions + * @brief Add standard definitions for classes derived from GNDStk::Component. * - * This adds the following standard properties/functions: - * init (copy), from_string + * This adds standard properties and functions for generated classes. * - * @param[in] component the component to which the definitions have to be added + * @param[in] object The Python object to which definitions should be added. */ -template < typename Component, typename PythonClass > -void addStandardComponentDefinitions( PythonClass& component ) { - - component - .def( - - python::init< const Component& >(), - python::arg( "component" ), - "Initialise the component with another instance\n\n" - "Arguments:\n" - " self the component\n" - " file the component to be copied" - ) - .def_static( - - "from_string", - [] ( const std::string& string ) -> Component { - - using namespace njoy::GNDStk::core; - - Node node; - node << string; - - return Component( node ); - }, - python::arg( "string" ), - "Read the component from an XML or json string\n\n" - "An exception is raised if something goes wrong while reading the\n" - "component\n\n" - "Arguments:\n" - " string the string representing the component" - ) - .def( - - "to_xml_string", - [] ( const Component& self ) -> std::string { - - using namespace njoy::GNDStk::core; - - std::ostringstream out; - XML( Node( self ) ).write( out, false ); - - return out.str(); - }, - "Write the component to an XML formatted string\n\n" - "Arguments:\n" - " self the component" - ) - .def( - - "to_xml_file", - [] ( const Component& self, const std::string& fileName ) { - - using namespace njoy::GNDStk::core; - - XML( Node( self ) ).write( fileName ); - }, - python::arg( "file_name" ), - "Write the component to an XML file\n\n" - "Arguments:\n" - " self the component\n" - " file_name the name of the XML file" - ); +template +void addStandardComponentDefinitions(pyCLASS &object) +{ + // ------------------------ + // Constructors + // ------------------------ + + // constructor: default + object.def( + py::init<>(), + "Initialise the object with its default contents.\n\n" + "Arguments:\n" + " self The object." + ); + + // constructor: copy + object.def( + py::init(), + py::arg("from"), + "Initialise the object with another instance.\n\n" + "Arguments:\n" + " self The object.\n" + " from The object to be copied from." + ); + + // ------------------------ + // Get/set comment + // ------------------------ + + // get/set comment + object.def_property( + "comment", + [](const cppCLASS &self) -> decltype(auto) + { + return self.comment(); + }, + [](cppCLASS &self, const std::vector &value) + { + self.comment() = value; + }, + "Array of comments to appear at the beginning of the node." + ); + + // ------------------------ + // Re: input from string; + // the type (XML, JSON, or + // HDF5) is auto-determined + // ------------------------ + + // from_string + object.def( + "from_string", + [](cppCLASS &self, const std::string &string) + { + self << string; + }, + py::arg("string"), + "Read the object from an XML, JSON, or HDF5 string.\n" + "An exception is raised if something fails during the read.\n\n" + "Arguments:\n" + " string The string representing the object." + ); + + // ------------------------ + // re: XML + // ------------------------ + + // to_xml_string + object.def( + "to_xml_string", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"xml"); + return oss.str(); + }, + "Write the object to an XML formatted string.\n\n" + "Arguments:\n" + " self The object." + ); + + // to_xml_file + object.def( + "to_xml_file", + [](const cppCLASS &self, const std::string &filename) + { + self.write(filename,"xml"); + }, + py::arg("file"), + "Write the object to an XML file.\n\n" + "Arguments:\n" + " self The object.\n" + " file The name of the XML file." + ); + + // ------------------------ + // re: JSON + // ------------------------ + + // to_json_string + object.def( + "to_json_string", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"json"); + return oss.str(); + }, + "Write the object to a JSON formatted string.\n\n" + "Arguments:\n" + " self The object." + ); + + // to_json_file + object.def( + "to_json_file", + [](const cppCLASS &self, const std::string &filename) + { + self.write(filename,"json"); + }, + py::arg("file"), + "Write the object to a JSON file.\n\n" + "Arguments:\n" + " self The object.\n" + " file The name of the JSON file." + ); + + // ------------------------ + // re: HDF5 + // ------------------------ + + // to_hdf5_string + object.def( + "to_hdf5_string", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"hdf5"); + return oss.str(); + }, + "Write the object to an HDF5 formatted string.\n\n" + "Arguments:\n" + " self The object." + ); + + // to_hdf5_file + object.def( + "to_hdf5_file", + [](const cppCLASS &self, const std::string &filename) + { + self.write(filename,"hdf5"); + }, + py::arg("file"), + "Write the object to an HDF5 file.\n\n" + "Arguments:\n" + " self The object.\n" + " file The name of the HDF5 file." + ); + + // ------------------------ + // for printing + // ------------------------ + + // These use GNDStk::Component's prettyprinter + + // prettyprint: for Python's __repr__ + object.def( + "__repr__", + [](const cppCLASS &self) -> decltype(auto) + { + njoy::GNDStk::printMode = njoy::GNDStk::PrintMode::python; + std::ostringstream oss; + self.print(oss,0); + return oss.str(); + } + ); + + // prettyprint: into string + object.def( + "print", + [](const cppCLASS &self) -> decltype(auto) + { + njoy::GNDStk::printMode = njoy::GNDStk::PrintMode::python; + std::ostringstream oss; + self.print(oss,0); + return oss.str(); + } + ); + + // ------------------------ + // write into string, as + // XML, JSON, HDF5, or our + // internal debug format + // ------------------------ + + // write into string, as XML + object.def( + "xml", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"xml"); + return oss.str(); + } + ); + + // write into string, as JSON + object.def( + "json", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"json"); + return oss.str(); + } + ); + + // write into string, as HDF5 + object.def( + "hdf5", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"hdf5"); + return oss.str(); + } + ); + + // write into string, in our internal debug format + object.def( + "debug", + [](const cppCLASS &self) -> decltype(auto) + { + std::ostringstream oss; + self.write(oss,"debug"); + return oss.str(); + } + ); + + // ------------------------ + // read/write from/to file + // ------------------------ + + // read + object.def( + "read", + [](cppCLASS &self, const std::string &filename) + { + self.read(filename); + }, + py::arg("file"), + "Read the object from a file. " + "The file's type will be determined from its contents.\n\n" + "Arguments:\n" + " self The object.\n" + " file The name of the file." + ); + + // write + object.def( + "write", + [](const cppCLASS &self, const std::string &filename) + { + self.write(filename); + }, + py::arg("file"), + "Write the object to a file. " + "The file's type will be determined from its extension.\n\n" + "Arguments:\n" + " self The object.\n" + " file The name of the file." + ); } #endif diff --git a/python/src/v1.9/containers.python.cpp b/python/src/v1.9/containers.python.cpp deleted file mode 100644 index 31ab9e593..000000000 --- a/python/src/v1.9/containers.python.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#include -#include - -namespace python = pybind11; - -// v1.9 interface -namespace python_v1_9 { - -// containers declarations -namespace python_containers { - void wrapAxis(python::module &); - void wrapLink(python::module &); - void wrapValues(python::module &); - void wrapGrid(python::module &); - void wrapAxes(python::module &); - void wrapXYs1d(python::module &); - void wrapRegions1d(python::module &); -} // namespace python_containers - -// containers wrapper -void wrapContainers(python::module &module) -{ - // create the containers submodule - python::module submodule = module.def_submodule( - "containers", - "GNDS v1.9 containers" - ); - - // wrap containers components - python_containers::wrapAxis(submodule); - python_containers::wrapLink(submodule); - python_containers::wrapValues(submodule); - python_containers::wrapGrid(submodule); - python_containers::wrapAxes(submodule); - python_containers::wrapXYs1d(submodule); - python_containers::wrapRegions1d(submodule); -}; - -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Axes.python.cpp b/python/src/v1.9/containers/Axes.python.cpp deleted file mode 100644 index b3bebd4f9..000000000 --- a/python/src/v1.9/containers/Axes.python.cpp +++ /dev/null @@ -1,67 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Axes.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Axes wrapper -void wrapAxes(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Axes; - using axis_grid_t = std::variant< - containers::Axis, - containers::Grid - >; - - // create the component - python::class_ component( - module, - "Axes", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::vector & - >(), - python::arg("href") = std::nullopt, - python::arg("axis_grid"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "href", - &Component::href, - Component::documentation("href").data() - ) - .def_property_readonly( - "axis_grid", - python::overload_cast<>(&Component::axis_grid), - Component::documentation("axis_grid").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Axis.python.cpp b/python/src/v1.9/containers/Axis.python.cpp deleted file mode 100644 index 9fe2bd62f..000000000 --- a/python/src/v1.9/containers/Axis.python.cpp +++ /dev/null @@ -1,70 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Axis.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Axis wrapper -void wrapAxis(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Axis; - - // create the component - python::class_ component( - module, - "Axis", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::optional &, - const std::optional & - >(), - python::arg("index") = std::nullopt, - python::arg("label") = std::nullopt, - python::arg("unit") = std::nullopt, - Component::documentation("constructor").data() - ) - .def_property_readonly( - "index", - &Component::index, - Component::documentation("index").data() - ) - .def_property_readonly( - "label", - &Component::label, - Component::documentation("label").data() - ) - .def_property_readonly( - "unit", - &Component::unit, - Component::documentation("unit").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Grid.python.cpp b/python/src/v1.9/containers/Grid.python.cpp deleted file mode 100644 index e8556d74e..000000000 --- a/python/src/v1.9/containers/Grid.python.cpp +++ /dev/null @@ -1,105 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Grid.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Grid wrapper -void wrapGrid(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Grid; - using link_values_t = std::variant< - containers::Link, - containers::Values - >; - - // create the component - python::class_ component( - module, - "Grid", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::optional &, - const std::optional &, - const std::optional &, - const std::optional &, - const link_values_t & - >(), - python::arg("index") = std::nullopt, - python::arg("interpolation") = std::nullopt, - python::arg("label") = std::nullopt, - python::arg("style") = std::nullopt, - python::arg("unit") = std::nullopt, - python::arg("link_values"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "index", - &Component::index, - Component::documentation("index").data() - ) - .def_property_readonly( - "interpolation", - [](const Component &self) { return self.interpolation().value(); }, - Component::documentation("interpolation").data() - ) - .def_property_readonly( - "label", - &Component::label, - Component::documentation("label").data() - ) - .def_property_readonly( - "style", - &Component::style, - Component::documentation("style").data() - ) - .def_property_readonly( - "unit", - &Component::unit, - Component::documentation("unit").data() - ) - .def_property_readonly( - "link", - python::overload_cast<>(&Component::link), - Component::documentation("link").data() - ) - .def_property_readonly( - "values", - python::overload_cast<>(&Component::values), - Component::documentation("values").data() - ) - .def_property_readonly( - "link_values", - python::overload_cast<>(&Component::link_values), - Component::documentation("link_values").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Link.python.cpp b/python/src/v1.9/containers/Link.python.cpp deleted file mode 100644 index fd9ea1411..000000000 --- a/python/src/v1.9/containers/Link.python.cpp +++ /dev/null @@ -1,56 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Link.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Link wrapper -void wrapLink(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Link; - - // create the component - python::class_ component( - module, - "Link", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::string & - >(), - python::arg("href"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "href", - &Component::href, - Component::documentation("href").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Regions1d.python.cpp b/python/src/v1.9/containers/Regions1d.python.cpp deleted file mode 100644 index 35ab3052f..000000000 --- a/python/src/v1.9/containers/Regions1d.python.cpp +++ /dev/null @@ -1,77 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Regions1d.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Regions1d wrapper -void wrapRegions1d(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Regions1d; - - // create the component - python::class_ component( - module, - "Regions1d", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::optional &, - const std::vector &, - const std::optional & - >(), - python::arg("label") = std::nullopt, - python::arg("outer_domain_value") = std::nullopt, - python::arg("xys1d"), - python::arg("axes") = std::nullopt, - Component::documentation("constructor").data() - ) - .def_property_readonly( - "label", - &Component::label, - Component::documentation("label").data() - ) - .def_property_readonly( - "outer_domain_value", - &Component::outerDomainValue, - Component::documentation("outer_domain_value").data() - ) - .def_property_readonly( - "xys1d", - python::overload_cast<>(&Component::XYs1d), - Component::documentation("xys1d").data() - ) - .def_property_readonly( - "axes", - python::overload_cast<>(&Component::axes), - Component::documentation("axes").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/Values.python.cpp b/python/src/v1.9/containers/Values.python.cpp deleted file mode 100644 index b9c28e406..000000000 --- a/python/src/v1.9/containers/Values.python.cpp +++ /dev/null @@ -1,106 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/Values.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// Values wrapper -void wrapValues(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::Values; - - // create the component - python::class_ component( - module, - "Values", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::optional &, - const std::optional & - >(), - python::arg("length") = std::nullopt, - python::arg("start") = std::nullopt, - python::arg("value_type") = std::nullopt, - Component::documentation("constructor").data() - ) - .def( - python::init< - const std::vector & - >(), - python::arg("ints"), - Component::documentation("constructor").data() - ) - .def( - python::init< - const std::vector & - >(), - python::arg("doubles"), - Component::documentation("constructor").data() - ) - .def( - python::init< - const std::vector & - >(), - python::arg("strings"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "length", - &Component::length, - Component::documentation("length").data() - ) - .def_property_readonly( - "start", - [](const Component &self) { return self.start().value(); }, - Component::documentation("start").data() - ) - .def_property_readonly( - "value_type", - [](const Component &self) { return self.valueType().value(); }, - Component::documentation("value_type").data() - ) - .def_property_readonly( - "ints", - [] (const Component &self) { return self.ints(); }, - Component::documentation("ints").data() - ) - .def_property_readonly( - "doubles", - [] (const Component &self) { return self.doubles(); }, - Component::documentation("doubles").data() - ) - .def_property_readonly( - "strings", - [] (const Component &self) { return self.strings(); }, - Component::documentation("strings").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/containers/XYs1d.python.cpp b/python/src/v1.9/containers/XYs1d.python.cpp deleted file mode 100644 index 9f231399f..000000000 --- a/python/src/v1.9/containers/XYs1d.python.cpp +++ /dev/null @@ -1,91 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/containers/XYs1d.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_containers { - -// XYs1d wrapper -void wrapXYs1d(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = containers::XYs1d; - - // create the component - python::class_ component( - module, - "XYs1d", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::optional &, - const std::optional &, - const std::optional &, - const std::optional &, - const std::optional &, - const containers::Values & - >(), - python::arg("index") = std::nullopt, - python::arg("interpolation") = std::nullopt, - python::arg("label") = std::nullopt, - python::arg("outer_domain_value") = std::nullopt, - python::arg("axes") = std::nullopt, - python::arg("values"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "index", - &Component::index, - Component::documentation("index").data() - ) - .def_property_readonly( - "interpolation", - [](const Component &self) { return self.interpolation().value(); }, - Component::documentation("interpolation").data() - ) - .def_property_readonly( - "label", - &Component::label, - Component::documentation("label").data() - ) - .def_property_readonly( - "outer_domain_value", - &Component::outerDomainValue, - Component::documentation("outer_domain_value").data() - ) - .def_property_readonly( - "axes", - python::overload_cast<>(&Component::axes), - Component::documentation("axes").data() - ) - .def_property_readonly( - "values", - python::overload_cast<>(&Component::values), - Component::documentation("values").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_containers -} // namespace python_v1_9 diff --git a/python/src/v1.9/transport.python.cpp b/python/src/v1.9/transport.python.cpp deleted file mode 100644 index 631a859bf..000000000 --- a/python/src/v1.9/transport.python.cpp +++ /dev/null @@ -1,37 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#include -#include - -namespace python = pybind11; - -// v1.9 interface -namespace python_v1_9 { - -// transport declarations -namespace python_transport { - void wrapCrossSection(python::module &); - void wrapReaction(python::module &); - void wrapReactions(python::module &); - void wrapReactionSuite(python::module &); -} // namespace python_transport - -// transport wrapper -void wrapTransport(python::module &module) -{ - // create the transport submodule - python::module submodule = module.def_submodule( - "transport", - "GNDS v1.9 transport" - ); - - // wrap transport components - python_transport::wrapCrossSection(submodule); - python_transport::wrapReaction(submodule); - python_transport::wrapReactions(submodule); - python_transport::wrapReactionSuite(submodule); -}; - -} // namespace python_v1_9 diff --git a/python/src/v1.9/transport/CrossSection.python.cpp b/python/src/v1.9/transport/CrossSection.python.cpp deleted file mode 100644 index 4bb4c39c2..000000000 --- a/python/src/v1.9/transport/CrossSection.python.cpp +++ /dev/null @@ -1,60 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/transport/CrossSection.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_transport { - -// CrossSection wrapper -void wrapCrossSection(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = transport::CrossSection; - using XYs1d_regions1d_t = std::variant< - containers::XYs1d, - containers::Regions1d - >; - - // create the component - python::class_ component( - module, - "CrossSection", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::vector & - >(), - python::arg("xys1d_regions1d"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "xys1d_regions1d", - python::overload_cast<>(&Component::XYs1d_regions1d), - Component::documentation("xys1d_regions1d").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_transport -} // namespace python_v1_9 diff --git a/python/src/v1.9/transport/Reaction.python.cpp b/python/src/v1.9/transport/Reaction.python.cpp deleted file mode 100644 index c034610a2..000000000 --- a/python/src/v1.9/transport/Reaction.python.cpp +++ /dev/null @@ -1,77 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/transport/Reaction.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_transport { - -// Reaction wrapper -void wrapReaction(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = transport::Reaction; - - // create the component - python::class_ component( - module, - "Reaction", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const int &, - const std::optional &, - const std::string &, - const transport::CrossSection & - >(), - python::arg("endf_mt"), - python::arg("fission_genre") = std::nullopt, - python::arg("label"), - python::arg("cross_section"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "endf_mt", - &Component::ENDF_MT, - Component::documentation("endf_mt").data() - ) - .def_property_readonly( - "fission_genre", - &Component::fissionGenre, - Component::documentation("fission_genre").data() - ) - .def_property_readonly( - "label", - &Component::label, - Component::documentation("label").data() - ) - .def_property_readonly( - "cross_section", - python::overload_cast<>(&Component::crossSection), - Component::documentation("cross_section").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_transport -} // namespace python_v1_9 diff --git a/python/src/v1.9/transport/ReactionSuite.python.cpp b/python/src/v1.9/transport/ReactionSuite.python.cpp deleted file mode 100644 index 664310fc2..000000000 --- a/python/src/v1.9/transport/ReactionSuite.python.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/transport/ReactionSuite.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_transport { - -// ReactionSuite wrapper -void wrapReactionSuite(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = transport::ReactionSuite; - - // create the component - python::class_ component( - module, - "ReactionSuite", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::string &, - const std::string &, - const std::optional &, - const std::string &, - const enums::Frame &, - const std::string &, - const std::optional & - >(), - python::arg("evaluation"), - python::arg("format"), - python::arg("interaction") = std::nullopt, - python::arg("projectile"), - python::arg("projectile_frame"), - python::arg("target"), - python::arg("reactions") = std::nullopt, - Component::documentation("constructor").data() - ) - .def_property_readonly( - "evaluation", - &Component::evaluation, - Component::documentation("evaluation").data() - ) - .def_property_readonly( - "format", - &Component::format, - Component::documentation("format").data() - ) - .def_property_readonly( - "interaction", - &Component::interaction, - Component::documentation("interaction").data() - ) - .def_property_readonly( - "projectile", - &Component::projectile, - Component::documentation("projectile").data() - ) - .def_property_readonly( - "projectile_frame", - &Component::projectileFrame, - Component::documentation("projectile_frame").data() - ) - .def_property_readonly( - "target", - &Component::target, - Component::documentation("target").data() - ) - .def_property_readonly( - "reactions", - python::overload_cast<>(&Component::reactions), - Component::documentation("reactions").data() - ) - .def_static( - - "from_file", - [] ( const std::string& filename ) -> Component { - - using namespace njoy::GNDStk::core; - Tree tree( filename ); - - return Component( tree( child::reactionSuite ) ); - }, - python::arg( "filename" ), - "Read a reaction suite from an XML or json file\n\n" - "An exception is raised if something goes wrong while reading the\n" - "component\n\n" - "Arguments:\n" - " filename the name of the file" - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_transport -} // namespace python_v1_9 diff --git a/python/src/v1.9/transport/Reactions.python.cpp b/python/src/v1.9/transport/Reactions.python.cpp deleted file mode 100644 index a32c28b59..000000000 --- a/python/src/v1.9/transport/Reactions.python.cpp +++ /dev/null @@ -1,56 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -// system includes -#include -#include - -// local includes -#include "GNDStk/v1.9/transport/Reactions.hpp" -#include "definitions.hpp" - -// namespace aliases -namespace python = pybind11; - -namespace python_v1_9 { -namespace python_transport { - -// Reactions wrapper -void wrapReactions(python::module &module) -{ - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::v1_9; - - // type aliases - using Component = transport::Reactions; - - // create the component - python::class_ component( - module, - "Reactions", - Component::documentation().data() - ); - - // wrap the component - component - .def( - python::init< - const std::vector & - >(), - python::arg("reaction"), - Component::documentation("constructor").data() - ) - .def_property_readonly( - "reaction", - python::overload_cast<>(&Component::reaction), - Component::documentation("reaction").data() - ) - ; - - // add standard component definitions - addStandardComponentDefinitions< Component >( component ); -} - -} // namespace python_transport -} // namespace python_v1_9 diff --git a/python/src/v2.0/GNDS.python.cpp b/python/src/v2.0/GNDS.python.cpp new file mode 100644 index 000000000..9c72193e8 --- /dev/null +++ b/python/src/v2.0/GNDS.python.cpp @@ -0,0 +1,29 @@ + +// system includes +#include +#include + +// namespace aliases +namespace python = pybind11; + +// v2.0 interface declarations +namespace python_v2_0 { + void wrapG2d( python::module& ); + void wrapG3d( python::module& ); + void wrapGeneral( python::module& ); + void wrapReduced( python::module& ); + void wrapTop( python::module& ); + + void wrapGNDS( python::module& module ) { + // create the core submodule + python::module submodule = module.def_submodule( + "v2_0", + "GNDS 2.0 standard components" + ); + python_v2_0::wrapG2d( submodule ); + python_v2_0::wrapG3d( submodule ); + python_v2_0::wrapGeneral( submodule ); + python_v2_0::wrapReduced( submodule ); + python_v2_0::wrapTop( submodule ); + } +} // v2_0 namespace diff --git a/python/src/v2.0/abstract.python.cpp b/python/src/v2.0/abstract.python.cpp new file mode 100644 index 000000000..b159ad793 --- /dev/null +++ b/python/src/v2.0/abstract.python.cpp @@ -0,0 +1,37 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// abstract declarations +namespace python_abstract { + void wrapFunctional(python::module &); + void wrapLabel(python::module &); + void wrapPhysicalQuantity(python::module &); + void wrapText(python::module &); +} // namespace python_abstract + +// abstract wrapper +void wrapAbstract(python::module &module) +{ + // create the abstract submodule + python::module submodule = module.def_submodule( + "abstract", + "GNDS v2.0 abstract" + ); + + // wrap abstract components + python_abstract::wrapFunctional(submodule); + python_abstract::wrapLabel(submodule); + python_abstract::wrapPhysicalQuantity(submodule); + python_abstract::wrapText(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/abstract/Functional.python.cpp b/python/src/v2.0/abstract/Functional.python.cpp new file mode 100644 index 000000000..39dd179ba --- /dev/null +++ b/python/src/v2.0/abstract/Functional.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/abstract/Functional.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_abstract { + +// Functional wrapper +void wrapFunctional(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = abstract::Functional; + using _t = std::variant< + abstract::Functional, + containers::Values + >; + + // create the component + python::class_ component( + module, + "Functional", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const containers::Axes &, + const std::optional &, + const _t & + >(), + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes"), + python::arg("uncertainty") = std::nullopt, + python::arg("_functionalvalues"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "uncertainty", + python::overload_cast<>(&Component::uncertainty), + Component::documentation("uncertainty").data() + ) + .def_property_readonly( + "functional", + python::overload_cast<>(&Component::functional), + Component::documentation("functional").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + .def_property_readonly( + "_functionalvalues", + python::overload_cast<>(&Component::_functionalvalues), + Component::documentation("_functionalvalues").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_abstract +} // namespace python_v2_0 diff --git a/python/src/v2.0/abstract/Label.python.cpp b/python/src/v2.0/abstract/Label.python.cpp new file mode 100644 index 000000000..5c9a2d544 --- /dev/null +++ b/python/src/v2.0/abstract/Label.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/abstract/Label.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_abstract { + +// Label wrapper +void wrapLabel(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = abstract::Label; + + // create the component + python::class_ component( + module, + "Label", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName & + >(), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_abstract +} // namespace python_v2_0 diff --git a/python/src/v2.0/abstract/PhysicalQuantity.python.cpp b/python/src/v2.0/abstract/PhysicalQuantity.python.cpp new file mode 100644 index 000000000..722a31ca3 --- /dev/null +++ b/python/src/v2.0/abstract/PhysicalQuantity.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/abstract/PhysicalQuantity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_abstract { + +// PhysicalQuantity wrapper +void wrapPhysicalQuantity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = abstract::PhysicalQuantity; + + // create the component + python::class_ component( + module, + "PhysicalQuantity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("label"), + python::arg("unit") = std::nullopt, + python::arg("value"), + python::arg("documentation") = std::nullopt, + python::arg("uncertainty") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "uncertainty", + python::overload_cast<>(&Component::uncertainty), + Component::documentation("uncertainty").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_abstract +} // namespace python_v2_0 diff --git a/python/src/v2.0/abstract/Text.python.cpp b/python/src/v2.0/abstract/Text.python.cpp new file mode 100644 index 000000000..fdca89ed1 --- /dev/null +++ b/python/src/v2.0/abstract/Text.python.cpp @@ -0,0 +1,106 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/abstract/Text.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_abstract { + +// Text wrapper +void wrapText(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = abstract::Text; + + // create the component + python::class_ component( + module, + "Text", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("encoding") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("markup") = std::nullopt, + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("ints"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("doubles"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("strings"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "encoding", + [](const Component &self) { return self.encoding().value(); }, + Component::documentation("encoding").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "markup", + [](const Component &self) { return self.markup().value(); }, + Component::documentation("markup").data() + ) + .def_property_readonly( + "ints", + [] (const Component &self) { return self.ints(); }, + Component::documentation("ints").data() + ) + .def_property_readonly( + "doubles", + [] (const Component &self) { return self.doubles(); }, + Component::documentation("doubles").data() + ) + .def_property_readonly( + "strings", + [] (const Component &self) { return self.strings(); }, + Component::documentation("strings").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_abstract +} // namespace python_v2_0 diff --git a/python/src/v2.0/appData.python.cpp b/python/src/v2.0/appData.python.cpp new file mode 100644 index 000000000..d666c02a2 --- /dev/null +++ b/python/src/v2.0/appData.python.cpp @@ -0,0 +1,37 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// appData declarations +namespace python_appData { + void wrapConversion(python::module &); + void wrapENDFconversionFlags(python::module &); + void wrapInstitution(python::module &); + void wrapApplicationData(python::module &); +} // namespace python_appData + +// appData wrapper +void wrapAppData(python::module &module) +{ + // create the appData submodule + python::module submodule = module.def_submodule( + "appData", + "GNDS v2.0 appData" + ); + + // wrap appData components + python_appData::wrapConversion(submodule); + python_appData::wrapENDFconversionFlags(submodule); + python_appData::wrapInstitution(submodule); + python_appData::wrapApplicationData(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/appData/ApplicationData.python.cpp b/python/src/v2.0/appData/ApplicationData.python.cpp new file mode 100644 index 000000000..e7750a1b8 --- /dev/null +++ b/python/src/v2.0/appData/ApplicationData.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/appData/ApplicationData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_appData { + +// ApplicationData wrapper +void wrapApplicationData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = appData::ApplicationData; + + // create the component + python::class_ component( + module, + "ApplicationData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("institution") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "institution", + python::overload_cast<>(&Component::institution), + Component::documentation("institution").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_appData +} // namespace python_v2_0 diff --git a/python/src/v2.0/appData/Conversion.python.cpp b/python/src/v2.0/appData/Conversion.python.cpp new file mode 100644 index 000000000..613eb720f --- /dev/null +++ b/python/src/v2.0/appData/Conversion.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/appData/Conversion.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_appData { + +// Conversion wrapper +void wrapConversion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = appData::Conversion; + + // create the component + python::class_ component( + module, + "Conversion", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("flags") = std::nullopt, + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "flags", + &Component::flags, + Component::documentation("flags").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_appData +} // namespace python_v2_0 diff --git a/python/src/v2.0/appData/ENDFconversionFlags.python.cpp b/python/src/v2.0/appData/ENDFconversionFlags.python.cpp new file mode 100644 index 000000000..81c47b7ef --- /dev/null +++ b/python/src/v2.0/appData/ENDFconversionFlags.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/appData/ENDFconversionFlags.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_appData { + +// ENDFconversionFlags wrapper +void wrapENDFconversionFlags(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = appData::ENDFconversionFlags; + + // create the component + python::class_ component( + module, + "ENDFconversionFlags", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("conversion") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "conversion", + python::overload_cast<>(&Component::conversion), + Component::documentation("conversion").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_appData +} // namespace python_v2_0 diff --git a/python/src/v2.0/appData/Institution.python.cpp b/python/src/v2.0/appData/Institution.python.cpp new file mode 100644 index 000000000..c40959734 --- /dev/null +++ b/python/src/v2.0/appData/Institution.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/appData/Institution.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_appData { + +// Institution wrapper +void wrapInstitution(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = appData::Institution; + + // create the component + python::class_ component( + module, + "Institution", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("label") = std::nullopt, + python::arg("endfconversion_flags") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "endfconversion_flags", + python::overload_cast<>(&Component::ENDFconversionFlags), + Component::documentation("endfconversion_flags").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_appData +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic.python.cpp b/python/src/v2.0/atomic.python.cpp new file mode 100644 index 000000000..f3df7e33d --- /dev/null +++ b/python/src/v2.0/atomic.python.cpp @@ -0,0 +1,41 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// atomic declarations +namespace python_atomic { + void wrapFormFactor(python::module &); + void wrapImaginaryAnomalousFactor(python::module &); + void wrapRealAnomalousFactor(python::module &); + void wrapCoherentPhotonScattering(python::module &); + void wrapScatteringFactor(python::module &); + void wrapIncoherentPhotonScattering(python::module &); +} // namespace python_atomic + +// atomic wrapper +void wrapAtomic(python::module &module) +{ + // create the atomic submodule + python::module submodule = module.def_submodule( + "atomic", + "GNDS v2.0 atomic" + ); + + // wrap atomic components + python_atomic::wrapFormFactor(submodule); + python_atomic::wrapImaginaryAnomalousFactor(submodule); + python_atomic::wrapRealAnomalousFactor(submodule); + python_atomic::wrapCoherentPhotonScattering(submodule); + python_atomic::wrapScatteringFactor(submodule); + python_atomic::wrapIncoherentPhotonScattering(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/CoherentPhotonScattering.python.cpp b/python/src/v2.0/atomic/CoherentPhotonScattering.python.cpp new file mode 100644 index 000000000..3a5eea3f7 --- /dev/null +++ b/python/src/v2.0/atomic/CoherentPhotonScattering.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/CoherentPhotonScattering.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// CoherentPhotonScattering wrapper +void wrapCoherentPhotonScattering(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::CoherentPhotonScattering; + + // create the component + python::class_ component( + module, + "CoherentPhotonScattering", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const enums::Frame &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("pid") = std::nullopt, + python::arg("product_frame"), + python::arg("form_factor") = std::nullopt, + python::arg("imaginary_anomalous_factor") = std::nullopt, + python::arg("real_anomalous_factor") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "form_factor", + python::overload_cast<>(&Component::formFactor), + Component::documentation("form_factor").data() + ) + .def_property_readonly( + "imaginary_anomalous_factor", + python::overload_cast<>(&Component::imaginaryAnomalousFactor), + Component::documentation("imaginary_anomalous_factor").data() + ) + .def_property_readonly( + "real_anomalous_factor", + python::overload_cast<>(&Component::realAnomalousFactor), + Component::documentation("real_anomalous_factor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/FormFactor.python.cpp b/python/src/v2.0/atomic/FormFactor.python.cpp new file mode 100644 index 000000000..b07a2bd47 --- /dev/null +++ b/python/src/v2.0/atomic/FormFactor.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/FormFactor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// FormFactor wrapper +void wrapFormFactor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::FormFactor; + + // create the component + python::class_ component( + module, + "FormFactor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/ImaginaryAnomalousFactor.python.cpp b/python/src/v2.0/atomic/ImaginaryAnomalousFactor.python.cpp new file mode 100644 index 000000000..89b16ac22 --- /dev/null +++ b/python/src/v2.0/atomic/ImaginaryAnomalousFactor.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/ImaginaryAnomalousFactor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// ImaginaryAnomalousFactor wrapper +void wrapImaginaryAnomalousFactor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::ImaginaryAnomalousFactor; + + // create the component + python::class_ component( + module, + "ImaginaryAnomalousFactor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/IncoherentPhotonScattering.python.cpp b/python/src/v2.0/atomic/IncoherentPhotonScattering.python.cpp new file mode 100644 index 000000000..55582d6e3 --- /dev/null +++ b/python/src/v2.0/atomic/IncoherentPhotonScattering.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/IncoherentPhotonScattering.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// IncoherentPhotonScattering wrapper +void wrapIncoherentPhotonScattering(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::IncoherentPhotonScattering; + + // create the component + python::class_ component( + module, + "IncoherentPhotonScattering", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const enums::Frame &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("pid") = std::nullopt, + python::arg("product_frame"), + python::arg("scattering_factor") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "scattering_factor", + python::overload_cast<>(&Component::scatteringFactor), + Component::documentation("scattering_factor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/RealAnomalousFactor.python.cpp b/python/src/v2.0/atomic/RealAnomalousFactor.python.cpp new file mode 100644 index 000000000..86d6a902f --- /dev/null +++ b/python/src/v2.0/atomic/RealAnomalousFactor.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/RealAnomalousFactor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// RealAnomalousFactor wrapper +void wrapRealAnomalousFactor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::RealAnomalousFactor; + + // create the component + python::class_ component( + module, + "RealAnomalousFactor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/atomic/ScatteringFactor.python.cpp b/python/src/v2.0/atomic/ScatteringFactor.python.cpp new file mode 100644 index 000000000..44236cddc --- /dev/null +++ b/python/src/v2.0/atomic/ScatteringFactor.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/atomic/ScatteringFactor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_atomic { + +// ScatteringFactor wrapper +void wrapScatteringFactor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = atomic::ScatteringFactor; + + // create the component + python::class_ component( + module, + "ScatteringFactor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_atomic +} // namespace python_v2_0 diff --git a/python/src/v2.0/common.python.cpp b/python/src/v2.0/common.python.cpp new file mode 100644 index 000000000..268e13fcc --- /dev/null +++ b/python/src/v2.0/common.python.cpp @@ -0,0 +1,47 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// common declarations +namespace python_common { + void wrapQ(python::module &); + void wrapEnergy(python::module &); + void wrapExternalFile(python::module &); + void wrapExternalFiles(python::module &); + void wrapMass(python::module &); + void wrapProbability(python::module &); + void wrapProduct(python::module &); + void wrapProducts(python::module &); + void wrapTemperature(python::module &); +} // namespace python_common + +// common wrapper +void wrapCommon(python::module &module) +{ + // create the common submodule + python::module submodule = module.def_submodule( + "common", + "GNDS v2.0 common" + ); + + // wrap common components + python_common::wrapQ(submodule); + python_common::wrapEnergy(submodule); + python_common::wrapExternalFile(submodule); + python_common::wrapExternalFiles(submodule); + python_common::wrapMass(submodule); + python_common::wrapProbability(submodule); + python_common::wrapProduct(submodule); + python_common::wrapProducts(submodule); + python_common::wrapTemperature(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Energy.python.cpp b/python/src/v2.0/common/Energy.python.cpp new file mode 100644 index 000000000..763197fb2 --- /dev/null +++ b/python/src/v2.0/common/Energy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Energy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Energy wrapper +void wrapEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Energy; + + // create the component + python::class_ component( + module, + "Energy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/ExternalFile.python.cpp b/python/src/v2.0/common/ExternalFile.python.cpp new file mode 100644 index 000000000..e441778ed --- /dev/null +++ b/python/src/v2.0/common/ExternalFile.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/ExternalFile.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// ExternalFile wrapper +void wrapExternalFile(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::ExternalFile; + + // create the component + python::class_ component( + module, + "ExternalFile", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const XMLName &, + const XMLName & + >(), + python::arg("algorithm") = std::nullopt, + python::arg("checksum") = std::nullopt, + python::arg("label"), + python::arg("path"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "algorithm", + &Component::algorithm, + Component::documentation("algorithm").data() + ) + .def_property_readonly( + "checksum", + &Component::checksum, + Component::documentation("checksum").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "path", + &Component::path, + Component::documentation("path").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/ExternalFiles.python.cpp b/python/src/v2.0/common/ExternalFiles.python.cpp new file mode 100644 index 000000000..a07d48218 --- /dev/null +++ b/python/src/v2.0/common/ExternalFiles.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/ExternalFiles.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// ExternalFiles wrapper +void wrapExternalFiles(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::ExternalFiles; + + // create the component + python::class_ component( + module, + "ExternalFiles", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("external_file"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "external_file", + python::overload_cast<>(&Component::externalFile), + Component::documentation("external_file").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Mass.python.cpp b/python/src/v2.0/common/Mass.python.cpp new file mode 100644 index 000000000..a39795673 --- /dev/null +++ b/python/src/v2.0/common/Mass.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Mass.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Mass wrapper +void wrapMass(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Mass; + + // create the component + python::class_ component( + module, + "Mass", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Probability.python.cpp b/python/src/v2.0/common/Probability.python.cpp new file mode 100644 index 000000000..eaa4a8398 --- /dev/null +++ b/python/src/v2.0/common/Probability.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Probability.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Probability wrapper +void wrapProbability(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Probability; + + // create the component + python::class_ component( + module, + "Probability", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("double") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Product.python.cpp b/python/src/v2.0/common/Product.python.cpp new file mode 100644 index 000000000..3033c0de9 --- /dev/null +++ b/python/src/v2.0/common/Product.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Product.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Product wrapper +void wrapProduct(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Product; + + // create the component + python::class_ component( + module, + "Product", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const transport::Distribution &, + const transport::Multiplicity &, + const std::optional & + >(), + python::arg("label"), + python::arg("pid"), + python::arg("distribution"), + python::arg("multiplicity"), + python::arg("output_channel") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "distribution", + python::overload_cast<>(&Component::distribution), + Component::documentation("distribution").data() + ) + .def_property_readonly( + "multiplicity", + python::overload_cast<>(&Component::multiplicity), + Component::documentation("multiplicity").data() + ) + .def_property_readonly( + "output_channel", + python::overload_cast<>(&Component::outputChannel), + Component::documentation("output_channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Products.python.cpp b/python/src/v2.0/common/Products.python.cpp new file mode 100644 index 000000000..25d69fcc2 --- /dev/null +++ b/python/src/v2.0/common/Products.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Products.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Products wrapper +void wrapProducts(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Products; + + // create the component + python::class_ component( + module, + "Products", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("product") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "product", + python::overload_cast<>(&Component::product), + Component::documentation("product").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Q.python.cpp b/python/src/v2.0/common/Q.python.cpp new file mode 100644 index 000000000..7ef93a75e --- /dev/null +++ b/python/src/v2.0/common/Q.python.cpp @@ -0,0 +1,88 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Q.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Q wrapper +void wrapQ(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Q; + using _t = std::variant< + containers::XYs1d, + containers::Constant1d, + containers::Gridded1d, + containers::Polynomial1d, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "Q", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dconstant1dgridded1dpolynomial1dregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dconstant1dgridded1dpolynomial1dregions1d", + python::overload_cast<>(&Component::_XYs1dconstant1dgridded1dpolynomial1dregions1d), + Component::documentation("_xys1dconstant1dgridded1dpolynomial1dregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/common/Temperature.python.cpp b/python/src/v2.0/common/Temperature.python.cpp new file mode 100644 index 000000000..f139892a2 --- /dev/null +++ b/python/src/v2.0/common/Temperature.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/common/Temperature.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_common { + +// Temperature wrapper +void wrapTemperature(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = common::Temperature; + + // create the component + python::class_ component( + module, + "Temperature", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("unit") = std::nullopt, + python::arg("value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_common +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers.python.cpp b/python/src/v2.0/containers.python.cpp new file mode 100644 index 000000000..dd02d5077 --- /dev/null +++ b/python/src/v2.0/containers.python.cpp @@ -0,0 +1,89 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// containers declarations +namespace python_containers { + void wrapAxis(python::module &); + void wrapLink(python::module &); + void wrapValues(python::module &); + void wrapGrid(python::module &); + void wrapAxes(python::module &); + void wrapXYs1d(python::module &); + void wrapLegendre(python::module &); + void wrapConstant1d(python::module &); + void wrapArray(python::module &); + void wrapGridded1d(python::module &); + void wrapPolynomial1d(python::module &); + void wrapFunction1ds(python::module &); + void wrapRegions1d(python::module &); + void wrapDouble(python::module &); + void wrapXYs2d(python::module &); + void wrapGridded2d(python::module &); + void wrapFunction2ds(python::module &); + void wrapRegions2d(python::module &); + void wrapYs1d(python::module &); + void wrapXYs3d(python::module &); + void wrapGridded3d(python::module &); + void wrapString(python::module &); + void wrapColumn(python::module &); + void wrapColumnHeaders(python::module &); + void wrapData(python::module &); + void wrapFraction(python::module &); + void wrapFunction3ds(python::module &); + void wrapInteger(python::module &); + void wrapRegions3d(python::module &); + void wrapTable(python::module &); +} // namespace python_containers + +// containers wrapper +void wrapContainers(python::module &module) +{ + // create the containers submodule + python::module submodule = module.def_submodule( + "containers", + "GNDS v2.0 containers" + ); + + // wrap containers components + python_containers::wrapAxis(submodule); + python_containers::wrapLink(submodule); + python_containers::wrapValues(submodule); + python_containers::wrapGrid(submodule); + python_containers::wrapAxes(submodule); + python_containers::wrapXYs1d(submodule); + python_containers::wrapLegendre(submodule); + python_containers::wrapConstant1d(submodule); + python_containers::wrapArray(submodule); + python_containers::wrapGridded1d(submodule); + python_containers::wrapPolynomial1d(submodule); + python_containers::wrapFunction1ds(submodule); + python_containers::wrapRegions1d(submodule); + python_containers::wrapDouble(submodule); + python_containers::wrapXYs2d(submodule); + python_containers::wrapGridded2d(submodule); + python_containers::wrapFunction2ds(submodule); + python_containers::wrapRegions2d(submodule); + python_containers::wrapYs1d(submodule); + python_containers::wrapXYs3d(submodule); + python_containers::wrapGridded3d(submodule); + python_containers::wrapString(submodule); + python_containers::wrapColumn(submodule); + python_containers::wrapColumnHeaders(submodule); + python_containers::wrapData(submodule); + python_containers::wrapFraction(submodule); + python_containers::wrapFunction3ds(submodule); + python_containers::wrapInteger(submodule); + python_containers::wrapRegions3d(submodule); + python_containers::wrapTable(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Array.python.cpp b/python/src/v2.0/containers/Array.python.cpp new file mode 100644 index 000000000..88621ba67 --- /dev/null +++ b/python/src/v2.0/containers/Array.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Array.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Array wrapper +void wrapArray(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Array; + + // create the component + python::class_ component( + module, + "Array", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const IntegerTuple &, + const std::optional &, + const std::optional &, + const std::optional> &, + const std::optional> & + >(), + python::arg("compression") = std::nullopt, + python::arg("offset") = std::nullopt, + python::arg("permutation") = std::nullopt, + python::arg("shape"), + python::arg("storage_order") = std::nullopt, + python::arg("symmetry") = std::nullopt, + python::arg("array") = std::nullopt, + python::arg("values") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "compression", + [](const Component &self) { return self.compression().value(); }, + Component::documentation("compression").data() + ) + .def_property_readonly( + "offset", + &Component::offset, + Component::documentation("offset").data() + ) + .def_property_readonly( + "permutation", + [](const Component &self) { return self.permutation().value(); }, + Component::documentation("permutation").data() + ) + .def_property_readonly( + "shape", + &Component::shape, + Component::documentation("shape").data() + ) + .def_property_readonly( + "storage_order", + [](const Component &self) { return self.storageOrder().value(); }, + Component::documentation("storage_order").data() + ) + .def_property_readonly( + "symmetry", + [](const Component &self) { return self.symmetry().value(); }, + Component::documentation("symmetry").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Axes.python.cpp b/python/src/v2.0/containers/Axes.python.cpp new file mode 100644 index 000000000..bc2c6c773 --- /dev/null +++ b/python/src/v2.0/containers/Axes.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Axes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Axes wrapper +void wrapAxes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Axes; + + // create the component + python::class_ component( + module, + "Axes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional> &, + const std::optional> & + >(), + python::arg("href") = std::nullopt, + python::arg("axis") = std::nullopt, + python::arg("grid") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "axis", + python::overload_cast<>(&Component::axis), + Component::documentation("axis").data() + ) + .def_property_readonly( + "grid", + python::overload_cast<>(&Component::grid), + Component::documentation("grid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Axis.python.cpp b/python/src/v2.0/containers/Axis.python.cpp new file mode 100644 index 000000000..5d19b1fb9 --- /dev/null +++ b/python/src/v2.0/containers/Axis.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Axis.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Axis wrapper +void wrapAxis(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Axis; + + // create the component + python::class_ component( + module, + "Axis", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("index") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("unit") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Column.python.cpp b/python/src/v2.0/containers/Column.python.cpp new file mode 100644 index 000000000..3829a96cd --- /dev/null +++ b/python/src/v2.0/containers/Column.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Column.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Column wrapper +void wrapColumn(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Column; + + // create the component + python::class_ component( + module, + "Column", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("index"), + python::arg("name"), + python::arg("types") = std::nullopt, + python::arg("unit") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "types", + &Component::types, + Component::documentation("types").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/ColumnHeaders.python.cpp b/python/src/v2.0/containers/ColumnHeaders.python.cpp new file mode 100644 index 000000000..27ff66229 --- /dev/null +++ b/python/src/v2.0/containers/ColumnHeaders.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/ColumnHeaders.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// ColumnHeaders wrapper +void wrapColumnHeaders(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::ColumnHeaders; + + // create the component + python::class_ component( + module, + "ColumnHeaders", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("column"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "column", + python::overload_cast<>(&Component::column), + Component::documentation("column").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Constant1d.python.cpp b/python/src/v2.0/containers/Constant1d.python.cpp new file mode 100644 index 000000000..114a529e0 --- /dev/null +++ b/python/src/v2.0/containers/Constant1d.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Constant1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Constant1d wrapper +void wrapConstant1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Constant1d; + + // create the component + python::class_ component( + module, + "Constant1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Axes & + >(), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("value") = std::nullopt, + python::arg("axes"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Data.python.cpp b/python/src/v2.0/containers/Data.python.cpp new file mode 100644 index 000000000..25555de02 --- /dev/null +++ b/python/src/v2.0/containers/Data.python.cpp @@ -0,0 +1,92 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Data.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Data wrapper +void wrapData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Data; + + // create the component + python::class_ component( + module, + "Data", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("sep") = std::nullopt, + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("ints"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("doubles"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("strings"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "sep", + [](const Component &self) { return self.sep().value(); }, + Component::documentation("sep").data() + ) + .def_property_readonly( + "ints", + [] (const Component &self) { return self.ints(); }, + Component::documentation("ints").data() + ) + .def_property_readonly( + "doubles", + [] (const Component &self) { return self.doubles(); }, + Component::documentation("doubles").data() + ) + .def_property_readonly( + "strings", + [] (const Component &self) { return self.strings(); }, + Component::documentation("strings").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Double.python.cpp b/python/src/v2.0/containers/Double.python.cpp new file mode 100644 index 000000000..783c2029d --- /dev/null +++ b/python/src/v2.0/containers/Double.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Double.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Double wrapper +void wrapDouble(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Double; + + // create the component + python::class_ component( + module, + "Double", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const Float64 & + >(), + python::arg("label") = std::nullopt, + python::arg("unit") = std::nullopt, + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Fraction.python.cpp b/python/src/v2.0/containers/Fraction.python.cpp new file mode 100644 index 000000000..6c20d5221 --- /dev/null +++ b/python/src/v2.0/containers/Fraction.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Fraction.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Fraction wrapper +void wrapFraction(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Fraction; + + // create the component + python::class_ component( + module, + "Fraction", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const Fraction32 & + >(), + python::arg("label") = std::nullopt, + python::arg("unit") = std::nullopt, + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Function1ds.python.cpp b/python/src/v2.0/containers/Function1ds.python.cpp new file mode 100644 index 000000000..b60b9be90 --- /dev/null +++ b/python/src/v2.0/containers/Function1ds.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Function1ds.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Function1ds wrapper +void wrapFunction1ds(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Function1ds; + using _t = std::variant< + containers::Legendre, + containers::XYs1d, + containers::Constant1d, + containers::Gridded1d, + containers::Polynomial1d + >; + + // create the component + python::class_ component( + module, + "Function1ds", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector<_t> & + >(), + python::arg("_legendre_xys1dconstant1dgridded1dpolynomial1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "_legendre_xys1dconstant1dgridded1dpolynomial1d", + python::overload_cast<>(&Component::_LegendreXYs1dconstant1dgridded1dpolynomial1d), + Component::documentation("_legendre_xys1dconstant1dgridded1dpolynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Function2ds.python.cpp b/python/src/v2.0/containers/Function2ds.python.cpp new file mode 100644 index 000000000..f227d07f0 --- /dev/null +++ b/python/src/v2.0/containers/Function2ds.python.cpp @@ -0,0 +1,60 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Function2ds.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Function2ds wrapper +void wrapFunction2ds(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Function2ds; + using _t = std::variant< + containers::XYs2d, + containers::Gridded2d + >; + + // create the component + python::class_ component( + module, + "Function2ds", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector<_t> & + >(), + python::arg("_xys2dgridded2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "_xys2dgridded2d", + python::overload_cast<>(&Component::_XYs2dgridded2d), + Component::documentation("_xys2dgridded2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Function3ds.python.cpp b/python/src/v2.0/containers/Function3ds.python.cpp new file mode 100644 index 000000000..2350092aa --- /dev/null +++ b/python/src/v2.0/containers/Function3ds.python.cpp @@ -0,0 +1,60 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Function3ds.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Function3ds wrapper +void wrapFunction3ds(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Function3ds; + using _t = std::variant< + containers::XYs3d, + containers::Gridded3d + >; + + // create the component + python::class_ component( + module, + "Function3ds", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector<_t> & + >(), + python::arg("_xys3dgridded3d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "_xys3dgridded3d", + python::overload_cast<>(&Component::_XYs3dgridded3d), + Component::documentation("_xys3dgridded3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Grid.python.cpp b/python/src/v2.0/containers/Grid.python.cpp new file mode 100644 index 000000000..602ad3d60 --- /dev/null +++ b/python/src/v2.0/containers/Grid.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Grid.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Grid wrapper +void wrapGrid(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Grid; + using _t = std::variant< + containers::Link, + containers::Values + >; + + // create the component + python::class_ component( + module, + "Grid", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const _t & + >(), + python::arg("index") = std::nullopt, + python::arg("interpolation") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("style") = std::nullopt, + python::arg("unit") = std::nullopt, + python::arg("_linkvalues"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "interpolation", + [](const Component &self) { return self.interpolation().value(); }, + Component::documentation("interpolation").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "style", + &Component::style, + Component::documentation("style").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "link", + python::overload_cast<>(&Component::link), + Component::documentation("link").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + .def_property_readonly( + "_linkvalues", + python::overload_cast<>(&Component::_linkvalues), + Component::documentation("_linkvalues").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Gridded1d.python.cpp b/python/src/v2.0/containers/Gridded1d.python.cpp new file mode 100644 index 000000000..3ce9c5bd7 --- /dev/null +++ b/python/src/v2.0/containers/Gridded1d.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Gridded1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Gridded1d wrapper +void wrapGridded1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Gridded1d; + + // create the component + python::class_ component( + module, + "Gridded1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const containers::Array &, + const containers::Axes & + >(), + python::arg("label") = std::nullopt, + python::arg("array"), + python::arg("axes"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Gridded2d.python.cpp b/python/src/v2.0/containers/Gridded2d.python.cpp new file mode 100644 index 000000000..22a05b606 --- /dev/null +++ b/python/src/v2.0/containers/Gridded2d.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Gridded2d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Gridded2d wrapper +void wrapGridded2d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Gridded2d; + + // create the component + python::class_ component( + module, + "Gridded2d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const containers::Array &, + const containers::Axes & + >(), + python::arg("label") = std::nullopt, + python::arg("array"), + python::arg("axes"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Gridded3d.python.cpp b/python/src/v2.0/containers/Gridded3d.python.cpp new file mode 100644 index 000000000..2afb0c8a1 --- /dev/null +++ b/python/src/v2.0/containers/Gridded3d.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Gridded3d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Gridded3d wrapper +void wrapGridded3d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Gridded3d; + + // create the component + python::class_ component( + module, + "Gridded3d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const containers::Array &, + const containers::Axes & + >(), + python::arg("label") = std::nullopt, + python::arg("array"), + python::arg("axes"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Integer.python.cpp b/python/src/v2.0/containers/Integer.python.cpp new file mode 100644 index 000000000..35ac60981 --- /dev/null +++ b/python/src/v2.0/containers/Integer.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Integer.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Integer wrapper +void wrapInteger(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Integer; + + // create the component + python::class_ component( + module, + "Integer", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const Integer32 & + >(), + python::arg("label") = std::nullopt, + python::arg("unit") = std::nullopt, + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Legendre.python.cpp b/python/src/v2.0/containers/Legendre.python.cpp new file mode 100644 index 000000000..55d64b096 --- /dev/null +++ b/python/src/v2.0/containers/Legendre.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Legendre.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Legendre wrapper +void wrapLegendre(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Legendre; + + // create the component + python::class_ component( + module, + "Legendre", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Values & + >(), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("lower_index") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + [](const Component &self) { return self.domainMax().value(); }, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + [](const Component &self) { return self.domainMin().value(); }, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "lower_index", + [](const Component &self) { return self.lowerIndex().value(); }, + Component::documentation("lower_index").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Link.python.cpp b/python/src/v2.0/containers/Link.python.cpp new file mode 100644 index 000000000..d33ab3fe1 --- /dev/null +++ b/python/src/v2.0/containers/Link.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Link.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Link wrapper +void wrapLink(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Link; + + // create the component + python::class_ component( + module, + "Link", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Polynomial1d.python.cpp b/python/src/v2.0/containers/Polynomial1d.python.cpp new file mode 100644 index 000000000..bd2907a84 --- /dev/null +++ b/python/src/v2.0/containers/Polynomial1d.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Polynomial1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Polynomial1d wrapper +void wrapPolynomial1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Polynomial1d; + + // create the component + python::class_ component( + module, + "Polynomial1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Axes &, + const containers::Values & + >(), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("lower_index") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes"), + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "lower_index", + [](const Component &self) { return self.lowerIndex().value(); }, + Component::documentation("lower_index").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Regions1d.python.cpp b/python/src/v2.0/containers/Regions1d.python.cpp new file mode 100644 index 000000000..7a360511f --- /dev/null +++ b/python/src/v2.0/containers/Regions1d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Regions1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Regions1d wrapper +void wrapRegions1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Regions1d; + + // create the component + python::class_ component( + module, + "Regions1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Function1ds & + >(), + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("function1ds"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "function1ds", + python::overload_cast<>(&Component::function1ds), + Component::documentation("function1ds").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Regions2d.python.cpp b/python/src/v2.0/containers/Regions2d.python.cpp new file mode 100644 index 000000000..2e815efa1 --- /dev/null +++ b/python/src/v2.0/containers/Regions2d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Regions2d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Regions2d wrapper +void wrapRegions2d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Regions2d; + + // create the component + python::class_ component( + module, + "Regions2d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Function2ds & + >(), + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("function2ds"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "function2ds", + python::overload_cast<>(&Component::function2ds), + Component::documentation("function2ds").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Regions3d.python.cpp b/python/src/v2.0/containers/Regions3d.python.cpp new file mode 100644 index 000000000..2b8aff7a6 --- /dev/null +++ b/python/src/v2.0/containers/Regions3d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Regions3d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Regions3d wrapper +void wrapRegions3d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Regions3d; + + // create the component + python::class_ component( + module, + "Regions3d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Function3ds & + >(), + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("function3ds"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "function3ds", + python::overload_cast<>(&Component::function3ds), + Component::documentation("function3ds").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/String.python.cpp b/python/src/v2.0/containers/String.python.cpp new file mode 100644 index 000000000..c33b29969 --- /dev/null +++ b/python/src/v2.0/containers/String.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/String.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// String wrapper +void wrapString(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::String; + + // create the component + python::class_ component( + module, + "String", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const XMLName & + >(), + python::arg("label") = std::nullopt, + python::arg("unit") = std::nullopt, + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Table.python.cpp b/python/src/v2.0/containers/Table.python.cpp new file mode 100644 index 000000000..94239c1ba --- /dev/null +++ b/python/src/v2.0/containers/Table.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Table.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Table wrapper +void wrapTable(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Table; + + // create the component + python::class_ component( + module, + "Table", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const Integer32 &, + const std::optional &, + const containers::ColumnHeaders &, + const containers::Data & + >(), + python::arg("columns"), + python::arg("rows"), + python::arg("storage_order") = std::nullopt, + python::arg("column_headers"), + python::arg("data"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "columns", + &Component::columns, + Component::documentation("columns").data() + ) + .def_property_readonly( + "rows", + &Component::rows, + Component::documentation("rows").data() + ) + .def_property_readonly( + "storage_order", + [](const Component &self) { return self.storageOrder().value(); }, + Component::documentation("storage_order").data() + ) + .def_property_readonly( + "column_headers", + python::overload_cast<>(&Component::columnHeaders), + Component::documentation("column_headers").data() + ) + .def_property_readonly( + "data", + python::overload_cast<>(&Component::data), + Component::documentation("data").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Values.python.cpp b/python/src/v2.0/containers/Values.python.cpp new file mode 100644 index 000000000..b2358a8f6 --- /dev/null +++ b/python/src/v2.0/containers/Values.python.cpp @@ -0,0 +1,127 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Values.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Values wrapper +void wrapValues(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Values; + + // create the component + python::class_ component( + module, + "Values", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("count") = std::nullopt, + python::arg("href") = std::nullopt, + python::arg("length") = std::nullopt, + python::arg("start") = std::nullopt, + python::arg("start_index") = std::nullopt, + python::arg("value_type") = std::nullopt, + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("ints"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("doubles"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("strings"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "count", + &Component::count, + Component::documentation("count").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "length", + &Component::length, + Component::documentation("length").data() + ) + .def_property_readonly( + "start", + [](const Component &self) { return self.start().value(); }, + Component::documentation("start").data() + ) + .def_property_readonly( + "start_index", + &Component::startIndex, + Component::documentation("start_index").data() + ) + .def_property_readonly( + "value_type", + [](const Component &self) { return self.valueType().value(); }, + Component::documentation("value_type").data() + ) + .def_property_readonly( + "ints", + [] (const Component &self) { return self.ints(); }, + Component::documentation("ints").data() + ) + .def_property_readonly( + "doubles", + [] (const Component &self) { return self.doubles(); }, + Component::documentation("doubles").data() + ) + .def_property_readonly( + "strings", + [] (const Component &self) { return self.strings(); }, + Component::documentation("strings").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/XYs1d.python.cpp b/python/src/v2.0/containers/XYs1d.python.cpp new file mode 100644 index 000000000..44a5ea6cc --- /dev/null +++ b/python/src/v2.0/containers/XYs1d.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/XYs1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// XYs1d wrapper +void wrapXYs1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::XYs1d; + + // create the component + python::class_ component( + module, + "XYs1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Values & + >(), + python::arg("index") = std::nullopt, + python::arg("interpolation") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "interpolation", + [](const Component &self) { return self.interpolation().value(); }, + Component::documentation("interpolation").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/XYs2d.python.cpp b/python/src/v2.0/containers/XYs2d.python.cpp new file mode 100644 index 000000000..869f3b455 --- /dev/null +++ b/python/src/v2.0/containers/XYs2d.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/XYs2d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// XYs2d wrapper +void wrapXYs2d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::XYs2d; + + // create the component + python::class_ component( + module, + "XYs2d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Function1ds & + >(), + python::arg("index") = std::nullopt, + python::arg("interpolation") = std::nullopt, + python::arg("interpolation_qualifier") = std::nullopt, + python::arg("outer_domain_value") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("function1ds"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "interpolation", + [](const Component &self) { return self.interpolation().value(); }, + Component::documentation("interpolation").data() + ) + .def_property_readonly( + "interpolation_qualifier", + &Component::interpolationQualifier, + Component::documentation("interpolation_qualifier").data() + ) + .def_property_readonly( + "outer_domain_value", + &Component::outerDomainValue, + Component::documentation("outer_domain_value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "function1ds", + python::overload_cast<>(&Component::function1ds), + Component::documentation("function1ds").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/XYs3d.python.cpp b/python/src/v2.0/containers/XYs3d.python.cpp new file mode 100644 index 000000000..00e7e247a --- /dev/null +++ b/python/src/v2.0/containers/XYs3d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/XYs3d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// XYs3d wrapper +void wrapXYs3d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::XYs3d; + + // create the component + python::class_ component( + module, + "XYs3d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const containers::Function2ds & + >(), + python::arg("interpolation") = std::nullopt, + python::arg("interpolation_qualifier") = std::nullopt, + python::arg("axes") = std::nullopt, + python::arg("function2ds"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "interpolation", + [](const Component &self) { return self.interpolation().value(); }, + Component::documentation("interpolation").data() + ) + .def_property_readonly( + "interpolation_qualifier", + &Component::interpolationQualifier, + Component::documentation("interpolation_qualifier").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "function2ds", + python::overload_cast<>(&Component::function2ds), + Component::documentation("function2ds").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/containers/Ys1d.python.cpp b/python/src/v2.0/containers/Ys1d.python.cpp new file mode 100644 index 000000000..4c6ca9ecb --- /dev/null +++ b/python/src/v2.0/containers/Ys1d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/containers/Ys1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_containers { + +// Ys1d wrapper +void wrapYs1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = containers::Ys1d; + + // create the component + python::class_ component( + module, + "Ys1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const containers::Axes &, + const containers::Values & + >(), + python::arg("interpolation") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("axes"), + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "interpolation", + [](const Component &self) { return self.interpolation().value(); }, + Component::documentation("interpolation").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_containers +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance.python.cpp b/python/src/v2.0/covariance.python.cpp new file mode 100644 index 000000000..88456fdfe --- /dev/null +++ b/python/src/v2.0/covariance.python.cpp @@ -0,0 +1,73 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// covariance declarations +namespace python_covariance { + void wrapSlice(python::module &); + void wrapSlices(python::module &); + void wrapColumnData(python::module &); + void wrapRowData(python::module &); + void wrapColumnSensitivity(python::module &); + void wrapCovariance(python::module &); + void wrapRowSensitivity(python::module &); + void wrapSandwichProduct(python::module &); + void wrapCovarianceMatrix(python::module &); + void wrapAverageParameterCovariance(python::module &); + void wrapShortRangeSelfScalingVariance(python::module &); + void wrapSummand(python::module &); + void wrapSum(python::module &); + void wrapMixed(python::module &); + void wrapCovarianceSection(python::module &); + void wrapCovarianceSections(python::module &); + void wrapParameterCovariance(python::module &); + void wrapParameterCovariances(python::module &); + void wrapCovarianceSuite(python::module &); + void wrapParameterLink(python::module &); + void wrapParameters(python::module &); + void wrapParameterCovariancMatrix(python::module &); +} // namespace python_covariance + +// covariance wrapper +void wrapCovariance(python::module &module) +{ + // create the covariance submodule + python::module submodule = module.def_submodule( + "covariance", + "GNDS v2.0 covariance" + ); + + // wrap covariance components + python_covariance::wrapSlice(submodule); + python_covariance::wrapSlices(submodule); + python_covariance::wrapColumnData(submodule); + python_covariance::wrapRowData(submodule); + python_covariance::wrapColumnSensitivity(submodule); + python_covariance::wrapCovariance(submodule); + python_covariance::wrapRowSensitivity(submodule); + python_covariance::wrapSandwichProduct(submodule); + python_covariance::wrapCovarianceMatrix(submodule); + python_covariance::wrapAverageParameterCovariance(submodule); + python_covariance::wrapShortRangeSelfScalingVariance(submodule); + python_covariance::wrapSummand(submodule); + python_covariance::wrapSum(submodule); + python_covariance::wrapMixed(submodule); + python_covariance::wrapCovarianceSection(submodule); + python_covariance::wrapCovarianceSections(submodule); + python_covariance::wrapParameterCovariance(submodule); + python_covariance::wrapParameterCovariances(submodule); + python_covariance::wrapCovarianceSuite(submodule); + python_covariance::wrapParameterLink(submodule); + python_covariance::wrapParameters(submodule); + python_covariance::wrapParameterCovariancMatrix(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/AverageParameterCovariance.python.cpp b/python/src/v2.0/covariance/AverageParameterCovariance.python.cpp new file mode 100644 index 000000000..84cbc2b01 --- /dev/null +++ b/python/src/v2.0/covariance/AverageParameterCovariance.python.cpp @@ -0,0 +1,92 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/AverageParameterCovariance.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// AverageParameterCovariance wrapper +void wrapAverageParameterCovariance(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::AverageParameterCovariance; + using _t = std::variant< + covariance::CovarianceMatrix + >; + + // create the component + python::class_ component( + module, + "AverageParameterCovariance", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const _t & + >(), + python::arg("cross_term") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("column_data") = std::nullopt, + python::arg("row_data") = std::nullopt, + python::arg("_covariance_matrix"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "cross_term", + &Component::crossTerm, + Component::documentation("cross_term").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "column_data", + python::overload_cast<>(&Component::columnData), + Component::documentation("column_data").data() + ) + .def_property_readonly( + "row_data", + python::overload_cast<>(&Component::rowData), + Component::documentation("row_data").data() + ) + .def_property_readonly( + "covariance_matrix", + python::overload_cast<>(&Component::covarianceMatrix), + Component::documentation("covariance_matrix").data() + ) + .def_property_readonly( + "_covariance_matrix", + python::overload_cast<>(&Component::_covarianceMatrix), + Component::documentation("_covariance_matrix").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ColumnData.python.cpp b/python/src/v2.0/covariance/ColumnData.python.cpp new file mode 100644 index 000000000..fcc5b7044 --- /dev/null +++ b/python/src/v2.0/covariance/ColumnData.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ColumnData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ColumnData wrapper +void wrapColumnData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ColumnData; + + // create the component + python::class_ component( + module, + "ColumnData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("endf_mfmt") = std::nullopt, + python::arg("dimension") = std::nullopt, + python::arg("href") = std::nullopt, + python::arg("slices") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mfmt", + &Component::ENDF_MFMT, + Component::documentation("endf_mfmt").data() + ) + .def_property_readonly( + "dimension", + &Component::dimension, + Component::documentation("dimension").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "slices", + python::overload_cast<>(&Component::slices), + Component::documentation("slices").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ColumnSensitivity.python.cpp b/python/src/v2.0/covariance/ColumnSensitivity.python.cpp new file mode 100644 index 000000000..6abc20ce7 --- /dev/null +++ b/python/src/v2.0/covariance/ColumnSensitivity.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ColumnSensitivity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ColumnSensitivity wrapper +void wrapColumnSensitivity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ColumnSensitivity; + + // create the component + python::class_ component( + module, + "ColumnSensitivity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Array & + >(), + python::arg("array"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Covariance.python.cpp b/python/src/v2.0/covariance/Covariance.python.cpp new file mode 100644 index 000000000..e7dc38304 --- /dev/null +++ b/python/src/v2.0/covariance/Covariance.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Covariance.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Covariance wrapper +void wrapCovariance(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Covariance; + + // create the component + python::class_ component( + module, + "Covariance", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Array & + >(), + python::arg("array"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/CovarianceMatrix.python.cpp b/python/src/v2.0/covariance/CovarianceMatrix.python.cpp new file mode 100644 index 000000000..703aff5e3 --- /dev/null +++ b/python/src/v2.0/covariance/CovarianceMatrix.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/CovarianceMatrix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// CovarianceMatrix wrapper +void wrapCovarianceMatrix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::CovarianceMatrix; + using _t = std::variant< + containers::Gridded2d, + covariance::SandwichProduct + >; + + // create the component + python::class_ component( + module, + "CovarianceMatrix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const XMLName &, + const _t & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame") = std::nullopt, + python::arg("type"), + python::arg("_gridded2dsandwich_product"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + .def_property_readonly( + "gridded2d", + python::overload_cast<>(&Component::gridded2d), + Component::documentation("gridded2d").data() + ) + .def_property_readonly( + "sandwich_product", + python::overload_cast<>(&Component::sandwichProduct), + Component::documentation("sandwich_product").data() + ) + .def_property_readonly( + "_gridded2dsandwich_product", + python::overload_cast<>(&Component::_gridded2dsandwichProduct), + Component::documentation("_gridded2dsandwich_product").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/CovarianceSection.python.cpp b/python/src/v2.0/covariance/CovarianceSection.python.cpp new file mode 100644 index 000000000..683e94fc7 --- /dev/null +++ b/python/src/v2.0/covariance/CovarianceSection.python.cpp @@ -0,0 +1,104 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/CovarianceSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// CovarianceSection wrapper +void wrapCovarianceSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::CovarianceSection; + using _t = std::variant< + covariance::CovarianceMatrix, + covariance::Mixed, + covariance::Sum + >; + + // create the component + python::class_ component( + module, + "CovarianceSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const covariance::RowData &, + const _t & + >(), + python::arg("cross_term") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("column_data") = std::nullopt, + python::arg("row_data"), + python::arg("_covariance_matrixmixedsum"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "cross_term", + [](const Component &self) { return self.crossTerm().value(); }, + Component::documentation("cross_term").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "column_data", + python::overload_cast<>(&Component::columnData), + Component::documentation("column_data").data() + ) + .def_property_readonly( + "row_data", + python::overload_cast<>(&Component::rowData), + Component::documentation("row_data").data() + ) + .def_property_readonly( + "covariance_matrix", + python::overload_cast<>(&Component::covarianceMatrix), + Component::documentation("covariance_matrix").data() + ) + .def_property_readonly( + "mixed", + python::overload_cast<>(&Component::mixed), + Component::documentation("mixed").data() + ) + .def_property_readonly( + "sum", + python::overload_cast<>(&Component::sum), + Component::documentation("sum").data() + ) + .def_property_readonly( + "_covariance_matrixmixedsum", + python::overload_cast<>(&Component::_covarianceMatrixmixedsum), + Component::documentation("_covariance_matrixmixedsum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/CovarianceSections.python.cpp b/python/src/v2.0/covariance/CovarianceSections.python.cpp new file mode 100644 index 000000000..3adc2f904 --- /dev/null +++ b/python/src/v2.0/covariance/CovarianceSections.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/CovarianceSections.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// CovarianceSections wrapper +void wrapCovarianceSections(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::CovarianceSections; + + // create the component + python::class_ component( + module, + "CovarianceSections", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("covariance_section") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "covariance_section", + python::overload_cast<>(&Component::covarianceSection), + Component::documentation("covariance_section").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/CovarianceSuite.python.cpp b/python/src/v2.0/covariance/CovarianceSuite.python.cpp new file mode 100644 index 000000000..165492548 --- /dev/null +++ b/python/src/v2.0/covariance/CovarianceSuite.python.cpp @@ -0,0 +1,112 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/CovarianceSuite.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// CovarianceSuite wrapper +void wrapCovarianceSuite(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::CovarianceSuite; + + // create the component + python::class_ component( + module, + "CovarianceSuite", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const enums::Interaction &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("evaluation") = std::nullopt, + python::arg("version") = std::nullopt, + python::arg("interaction"), + python::arg("projectile") = std::nullopt, + python::arg("target") = std::nullopt, + python::arg("covariance_sections") = std::nullopt, + python::arg("external_files") = std::nullopt, + python::arg("parameter_covariances") = std::nullopt, + python::arg("styles") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "evaluation", + &Component::evaluation, + Component::documentation("evaluation").data() + ) + .def_property_readonly( + "version", + &Component::version, + Component::documentation("version").data() + ) + .def_property_readonly( + "interaction", + &Component::interaction, + Component::documentation("interaction").data() + ) + .def_property_readonly( + "projectile", + &Component::projectile, + Component::documentation("projectile").data() + ) + .def_property_readonly( + "target", + &Component::target, + Component::documentation("target").data() + ) + .def_property_readonly( + "covariance_sections", + python::overload_cast<>(&Component::covarianceSections), + Component::documentation("covariance_sections").data() + ) + .def_property_readonly( + "external_files", + python::overload_cast<>(&Component::externalFiles), + Component::documentation("external_files").data() + ) + .def_property_readonly( + "parameter_covariances", + python::overload_cast<>(&Component::parameterCovariances), + Component::documentation("parameter_covariances").data() + ) + .def_property_readonly( + "styles", + python::overload_cast<>(&Component::styles), + Component::documentation("styles").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Mixed.python.cpp b/python/src/v2.0/covariance/Mixed.python.cpp new file mode 100644 index 000000000..1d82d3864 --- /dev/null +++ b/python/src/v2.0/covariance/Mixed.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Mixed.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Mixed wrapper +void wrapMixed(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Mixed; + + // create the component + python::class_ component( + module, + "Mixed", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional> &, + const std::optional> &, + const std::optional> & + >(), + python::arg("label"), + python::arg("covariance_matrix") = std::nullopt, + python::arg("short_range_self_scaling_variance") = std::nullopt, + python::arg("sum") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "covariance_matrix", + python::overload_cast<>(&Component::covarianceMatrix), + Component::documentation("covariance_matrix").data() + ) + .def_property_readonly( + "short_range_self_scaling_variance", + python::overload_cast<>(&Component::shortRangeSelfScalingVariance), + Component::documentation("short_range_self_scaling_variance").data() + ) + .def_property_readonly( + "sum", + python::overload_cast<>(&Component::sum), + Component::documentation("sum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ParameterCovariancMatrix.python.cpp b/python/src/v2.0/covariance/ParameterCovariancMatrix.python.cpp new file mode 100644 index 000000000..63259079e --- /dev/null +++ b/python/src/v2.0/covariance/ParameterCovariancMatrix.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ParameterCovariancMatrix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ParameterCovariancMatrix wrapper +void wrapParameterCovariancMatrix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ParameterCovariancMatrix; + + // create the component + python::class_ component( + module, + "ParameterCovariancMatrix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const containers::Array &, + const covariance::Parameters & + >(), + python::arg("label"), + python::arg("type") = std::nullopt, + python::arg("array"), + python::arg("parameters"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + .def_property_readonly( + "parameters", + python::overload_cast<>(&Component::parameters), + Component::documentation("parameters").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ParameterCovariance.python.cpp b/python/src/v2.0/covariance/ParameterCovariance.python.cpp new file mode 100644 index 000000000..10a2fedb5 --- /dev/null +++ b/python/src/v2.0/covariance/ParameterCovariance.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ParameterCovariance.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ParameterCovariance wrapper +void wrapParameterCovariance(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ParameterCovariance; + + // create the component + python::class_ component( + module, + "ParameterCovariance", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::vector &, + const covariance::RowData & + >(), + python::arg("label") = std::nullopt, + python::arg("parameter_covariance_matrix"), + python::arg("row_data"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "parameter_covariance_matrix", + python::overload_cast<>(&Component::parameterCovarianceMatrix), + Component::documentation("parameter_covariance_matrix").data() + ) + .def_property_readonly( + "row_data", + python::overload_cast<>(&Component::rowData), + Component::documentation("row_data").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ParameterCovariances.python.cpp b/python/src/v2.0/covariance/ParameterCovariances.python.cpp new file mode 100644 index 000000000..cf937a7d0 --- /dev/null +++ b/python/src/v2.0/covariance/ParameterCovariances.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ParameterCovariances.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ParameterCovariances wrapper +void wrapParameterCovariances(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ParameterCovariances; + + // create the component + python::class_ component( + module, + "ParameterCovariances", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> &, + const std::optional> & + >(), + python::arg("average_parameter_covariance") = std::nullopt, + python::arg("parameter_covariance") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "average_parameter_covariance", + python::overload_cast<>(&Component::averageParameterCovariance), + Component::documentation("average_parameter_covariance").data() + ) + .def_property_readonly( + "parameter_covariance", + python::overload_cast<>(&Component::parameterCovariance), + Component::documentation("parameter_covariance").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ParameterLink.python.cpp b/python/src/v2.0/covariance/ParameterLink.python.cpp new file mode 100644 index 000000000..679c108f5 --- /dev/null +++ b/python/src/v2.0/covariance/ParameterLink.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ParameterLink.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ParameterLink wrapper +void wrapParameterLink(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ParameterLink; + + // create the component + python::class_ component( + module, + "ParameterLink", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("matrix_start_index") = std::nullopt, + python::arg("n_parameters") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "matrix_start_index", + [](const Component &self) { return self.matrixStartIndex().value(); }, + Component::documentation("matrix_start_index").data() + ) + .def_property_readonly( + "n_parameters", + [](const Component &self) { return self.nParameters().value(); }, + Component::documentation("n_parameters").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Parameters.python.cpp b/python/src/v2.0/covariance/Parameters.python.cpp new file mode 100644 index 000000000..578b63bca --- /dev/null +++ b/python/src/v2.0/covariance/Parameters.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Parameters.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Parameters wrapper +void wrapParameters(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Parameters; + + // create the component + python::class_ component( + module, + "Parameters", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("parameter_link") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "parameter_link", + python::overload_cast<>(&Component::parameterLink), + Component::documentation("parameter_link").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/RowData.python.cpp b/python/src/v2.0/covariance/RowData.python.cpp new file mode 100644 index 000000000..13b0d699c --- /dev/null +++ b/python/src/v2.0/covariance/RowData.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/RowData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// RowData wrapper +void wrapRowData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::RowData; + + // create the component + python::class_ component( + module, + "RowData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("endf_mfmt") = std::nullopt, + python::arg("dimension") = std::nullopt, + python::arg("href") = std::nullopt, + python::arg("slices") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mfmt", + &Component::ENDF_MFMT, + Component::documentation("endf_mfmt").data() + ) + .def_property_readonly( + "dimension", + &Component::dimension, + Component::documentation("dimension").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "slices", + python::overload_cast<>(&Component::slices), + Component::documentation("slices").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/RowSensitivity.python.cpp b/python/src/v2.0/covariance/RowSensitivity.python.cpp new file mode 100644 index 000000000..06ed2dd2f --- /dev/null +++ b/python/src/v2.0/covariance/RowSensitivity.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/RowSensitivity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// RowSensitivity wrapper +void wrapRowSensitivity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::RowSensitivity; + + // create the component + python::class_ component( + module, + "RowSensitivity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Array & + >(), + python::arg("array"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "array", + python::overload_cast<>(&Component::array), + Component::documentation("array").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/SandwichProduct.python.cpp b/python/src/v2.0/covariance/SandwichProduct.python.cpp new file mode 100644 index 000000000..9e0a11c62 --- /dev/null +++ b/python/src/v2.0/covariance/SandwichProduct.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/SandwichProduct.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// SandwichProduct wrapper +void wrapSandwichProduct(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::SandwichProduct; + + // create the component + python::class_ component( + module, + "SandwichProduct", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Axes &, + const std::optional &, + const covariance::Covariance &, + const covariance::RowSensitivity & + >(), + python::arg("axes"), + python::arg("column_sensitivity") = std::nullopt, + python::arg("covariance"), + python::arg("row_sensitivity"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + .def_property_readonly( + "column_sensitivity", + python::overload_cast<>(&Component::columnSensitivity), + Component::documentation("column_sensitivity").data() + ) + .def_property_readonly( + "covariance", + python::overload_cast<>(&Component::covariance), + Component::documentation("covariance").data() + ) + .def_property_readonly( + "row_sensitivity", + python::overload_cast<>(&Component::rowSensitivity), + Component::documentation("row_sensitivity").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/ShortRangeSelfScalingVariance.python.cpp b/python/src/v2.0/covariance/ShortRangeSelfScalingVariance.python.cpp new file mode 100644 index 000000000..e3cb40ee0 --- /dev/null +++ b/python/src/v2.0/covariance/ShortRangeSelfScalingVariance.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/ShortRangeSelfScalingVariance.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// ShortRangeSelfScalingVariance wrapper +void wrapShortRangeSelfScalingVariance(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::ShortRangeSelfScalingVariance; + + // create the component + python::class_ component( + module, + "ShortRangeSelfScalingVariance", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("dependence_on_processed_group_width") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("type") = std::nullopt, + python::arg("gridded2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "dependence_on_processed_group_width", + &Component::dependenceOnProcessedGroupWidth, + Component::documentation("dependence_on_processed_group_width").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + .def_property_readonly( + "gridded2d", + python::overload_cast<>(&Component::gridded2d), + Component::documentation("gridded2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Slice.python.cpp b/python/src/v2.0/covariance/Slice.python.cpp new file mode 100644 index 000000000..77eb6e2e2 --- /dev/null +++ b/python/src/v2.0/covariance/Slice.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Slice.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Slice wrapper +void wrapSlice(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Slice; + + // create the component + python::class_ component( + module, + "Slice", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("dimension"), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("domain_unit") = std::nullopt, + python::arg("domain_value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "dimension", + &Component::dimension, + Component::documentation("dimension").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "domain_unit", + &Component::domainUnit, + Component::documentation("domain_unit").data() + ) + .def_property_readonly( + "domain_value", + &Component::domainValue, + Component::documentation("domain_value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Slices.python.cpp b/python/src/v2.0/covariance/Slices.python.cpp new file mode 100644 index 000000000..6b749b173 --- /dev/null +++ b/python/src/v2.0/covariance/Slices.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Slices.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Slices wrapper +void wrapSlices(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Slices; + + // create the component + python::class_ component( + module, + "Slices", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("slice"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "slice", + python::overload_cast<>(&Component::slice), + Component::documentation("slice").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Sum.python.cpp b/python/src/v2.0/covariance/Sum.python.cpp new file mode 100644 index 000000000..bba0976c7 --- /dev/null +++ b/python/src/v2.0/covariance/Sum.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Sum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Sum wrapper +void wrapSum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Sum; + + // create the component + python::class_ component( + module, + "Sum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const Float64 &, + const XMLName &, + const std::optional &, + const std::optional> & + >(), + python::arg("domain_max"), + python::arg("domain_min"), + python::arg("domain_unit"), + python::arg("label") = std::nullopt, + python::arg("summand") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "domain_unit", + &Component::domainUnit, + Component::documentation("domain_unit").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "summand", + python::overload_cast<>(&Component::summand), + Component::documentation("summand").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/covariance/Summand.python.cpp b/python/src/v2.0/covariance/Summand.python.cpp new file mode 100644 index 000000000..268787c82 --- /dev/null +++ b/python/src/v2.0/covariance/Summand.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/covariance/Summand.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_covariance { + +// Summand wrapper +void wrapSummand(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = covariance::Summand; + + // create the component + python::class_ component( + module, + "Summand", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("endf_mfmt") = std::nullopt, + python::arg("coefficient") = std::nullopt, + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mfmt", + &Component::ENDF_MFMT, + Component::documentation("endf_mfmt").data() + ) + .def_property_readonly( + "coefficient", + &Component::coefficient, + Component::documentation("coefficient").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_covariance +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport.python.cpp b/python/src/v2.0/cpTransport.python.cpp new file mode 100644 index 000000000..c5513b630 --- /dev/null +++ b/python/src/v2.0/cpTransport.python.cpp @@ -0,0 +1,43 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// cpTransport declarations +namespace python_cpTransport { + void wrapRutherfordScattering(python::module &); + void wrapImaginaryInterferenceTerm(python::module &); + void wrapNuclearTerm(python::module &); + void wrapRealInterferenceTerm(python::module &); + void wrapNuclearAmplitudeExpansion(python::module &); + void wrapNuclearPlusInterference(python::module &); + void wrapCoulombPlusNuclearElastic(python::module &); +} // namespace python_cpTransport + +// cpTransport wrapper +void wrapCpTransport(python::module &module) +{ + // create the cpTransport submodule + python::module submodule = module.def_submodule( + "cpTransport", + "GNDS v2.0 cpTransport" + ); + + // wrap cpTransport components + python_cpTransport::wrapRutherfordScattering(submodule); + python_cpTransport::wrapImaginaryInterferenceTerm(submodule); + python_cpTransport::wrapNuclearTerm(submodule); + python_cpTransport::wrapRealInterferenceTerm(submodule); + python_cpTransport::wrapNuclearAmplitudeExpansion(submodule); + python_cpTransport::wrapNuclearPlusInterference(submodule); + python_cpTransport::wrapCoulombPlusNuclearElastic(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/CoulombPlusNuclearElastic.python.cpp b/python/src/v2.0/cpTransport/CoulombPlusNuclearElastic.python.cpp new file mode 100644 index 000000000..6cc40e4d2 --- /dev/null +++ b/python/src/v2.0/cpTransport/CoulombPlusNuclearElastic.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/CoulombPlusNuclearElastic.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// CoulombPlusNuclearElastic wrapper +void wrapCoulombPlusNuclearElastic(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::CoulombPlusNuclearElastic; + + // create the component + python::class_ component( + module, + "CoulombPlusNuclearElastic", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const XMLName &, + const XMLName &, + const enums::Frame &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("identical_particles") = std::nullopt, + python::arg("label"), + python::arg("pid"), + python::arg("product_frame"), + python::arg("rutherford_scattering") = std::nullopt, + python::arg("nuclear_amplitude_expansion") = std::nullopt, + python::arg("nuclear_plus_interference") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "identical_particles", + [](const Component &self) { return self.identicalParticles().value(); }, + Component::documentation("identical_particles").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "rutherford_scattering", + python::overload_cast<>(&Component::RutherfordScattering), + Component::documentation("rutherford_scattering").data() + ) + .def_property_readonly( + "nuclear_amplitude_expansion", + python::overload_cast<>(&Component::nuclearAmplitudeExpansion), + Component::documentation("nuclear_amplitude_expansion").data() + ) + .def_property_readonly( + "nuclear_plus_interference", + python::overload_cast<>(&Component::nuclearPlusInterference), + Component::documentation("nuclear_plus_interference").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/ImaginaryInterferenceTerm.python.cpp b/python/src/v2.0/cpTransport/ImaginaryInterferenceTerm.python.cpp new file mode 100644 index 000000000..f50a617ae --- /dev/null +++ b/python/src/v2.0/cpTransport/ImaginaryInterferenceTerm.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/ImaginaryInterferenceTerm.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// ImaginaryInterferenceTerm wrapper +void wrapImaginaryInterferenceTerm(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::ImaginaryInterferenceTerm; + + // create the component + python::class_ component( + module, + "ImaginaryInterferenceTerm", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys2d") = std::nullopt, + python::arg("regions2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/NuclearAmplitudeExpansion.python.cpp b/python/src/v2.0/cpTransport/NuclearAmplitudeExpansion.python.cpp new file mode 100644 index 000000000..bb2f70589 --- /dev/null +++ b/python/src/v2.0/cpTransport/NuclearAmplitudeExpansion.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/NuclearAmplitudeExpansion.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// NuclearAmplitudeExpansion wrapper +void wrapNuclearAmplitudeExpansion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::NuclearAmplitudeExpansion; + + // create the component + python::class_ component( + module, + "NuclearAmplitudeExpansion", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const cpTransport::ImaginaryInterferenceTerm &, + const cpTransport::NuclearTerm &, + const cpTransport::RealInterferenceTerm & + >(), + python::arg("imaginary_interference_term"), + python::arg("nuclear_term"), + python::arg("real_interference_term"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "imaginary_interference_term", + python::overload_cast<>(&Component::imaginaryInterferenceTerm), + Component::documentation("imaginary_interference_term").data() + ) + .def_property_readonly( + "nuclear_term", + python::overload_cast<>(&Component::nuclearTerm), + Component::documentation("nuclear_term").data() + ) + .def_property_readonly( + "real_interference_term", + python::overload_cast<>(&Component::realInterferenceTerm), + Component::documentation("real_interference_term").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/NuclearPlusInterference.python.cpp b/python/src/v2.0/cpTransport/NuclearPlusInterference.python.cpp new file mode 100644 index 000000000..fd1c96a29 --- /dev/null +++ b/python/src/v2.0/cpTransport/NuclearPlusInterference.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/NuclearPlusInterference.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// NuclearPlusInterference wrapper +void wrapNuclearPlusInterference(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::NuclearPlusInterference; + + // create the component + python::class_ component( + module, + "NuclearPlusInterference", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const transport::CrossSection &, + const transport::Distribution & + >(), + python::arg("mu_cutoff"), + python::arg("cross_section"), + python::arg("distribution"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "mu_cutoff", + &Component::muCutoff, + Component::documentation("mu_cutoff").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "distribution", + python::overload_cast<>(&Component::distribution), + Component::documentation("distribution").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/NuclearTerm.python.cpp b/python/src/v2.0/cpTransport/NuclearTerm.python.cpp new file mode 100644 index 000000000..25f0d280b --- /dev/null +++ b/python/src/v2.0/cpTransport/NuclearTerm.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/NuclearTerm.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// NuclearTerm wrapper +void wrapNuclearTerm(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::NuclearTerm; + + // create the component + python::class_ component( + module, + "NuclearTerm", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys2d") = std::nullopt, + python::arg("regions2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/RealInterferenceTerm.python.cpp b/python/src/v2.0/cpTransport/RealInterferenceTerm.python.cpp new file mode 100644 index 000000000..9e8e2aebd --- /dev/null +++ b/python/src/v2.0/cpTransport/RealInterferenceTerm.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/RealInterferenceTerm.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// RealInterferenceTerm wrapper +void wrapRealInterferenceTerm(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::RealInterferenceTerm; + + // create the component + python::class_ component( + module, + "RealInterferenceTerm", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys2d") = std::nullopt, + python::arg("regions2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/cpTransport/RutherfordScattering.python.cpp b/python/src/v2.0/cpTransport/RutherfordScattering.python.cpp new file mode 100644 index 000000000..e0c66a750 --- /dev/null +++ b/python/src/v2.0/cpTransport/RutherfordScattering.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/cpTransport/RutherfordScattering.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_cpTransport { + +// RutherfordScattering wrapper +void wrapRutherfordScattering(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = cpTransport::RutherfordScattering; + + // create the component + python::class_ component( + module, + "RutherfordScattering", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_cpTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation.python.cpp b/python/src/v2.0/documentation.python.cpp new file mode 100644 index 000000000..412446621 --- /dev/null +++ b/python/src/v2.0/documentation.python.cpp @@ -0,0 +1,89 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// documentation declarations +namespace python_documentation { + void wrapAcknowledgement(python::module &); + void wrapAcknowledgements(python::module &); + void wrapAffiliation(python::module &); + void wrapAffiliations(python::module &); + void wrapAuthor(python::module &); + void wrapAuthors(python::module &); + void wrapBibitem(python::module &); + void wrapBibliography(python::module &); + void wrapCollaboration(python::module &); + void wrapCollaborations(python::module &); + void wrapCodeRepo(python::module &); + void wrapInputDeck(python::module &); + void wrapInputDecks(python::module &); + void wrapOutputDeck(python::module &); + void wrapOutputDecks(python::module &); + void wrapComputerCode(python::module &); + void wrapComputerCodes(python::module &); + void wrapContributor(python::module &); + void wrapContributors(python::module &); + void wrapCopyright(python::module &); + void wrapDate(python::module &); + void wrapDates(python::module &); + void wrapExforDataSet(python::module &); + void wrapExforDataSets(python::module &); + void wrapExperimentalDataSets(python::module &); + void wrapKeyword(python::module &); + void wrapKeywords(python::module &); + void wrapRelatedItem(python::module &); + void wrapRelatedItems(python::module &); + void wrapDocumentation(python::module &); +} // namespace python_documentation + +// documentation wrapper +void wrapDocumentation(python::module &module) +{ + // create the documentation submodule + python::module submodule = module.def_submodule( + "documentation", + "GNDS v2.0 documentation" + ); + + // wrap documentation components + python_documentation::wrapAcknowledgement(submodule); + python_documentation::wrapAcknowledgements(submodule); + python_documentation::wrapAffiliation(submodule); + python_documentation::wrapAffiliations(submodule); + python_documentation::wrapAuthor(submodule); + python_documentation::wrapAuthors(submodule); + python_documentation::wrapBibitem(submodule); + python_documentation::wrapBibliography(submodule); + python_documentation::wrapCollaboration(submodule); + python_documentation::wrapCollaborations(submodule); + python_documentation::wrapCodeRepo(submodule); + python_documentation::wrapInputDeck(submodule); + python_documentation::wrapInputDecks(submodule); + python_documentation::wrapOutputDeck(submodule); + python_documentation::wrapOutputDecks(submodule); + python_documentation::wrapComputerCode(submodule); + python_documentation::wrapComputerCodes(submodule); + python_documentation::wrapContributor(submodule); + python_documentation::wrapContributors(submodule); + python_documentation::wrapCopyright(submodule); + python_documentation::wrapDate(submodule); + python_documentation::wrapDates(submodule); + python_documentation::wrapExforDataSet(submodule); + python_documentation::wrapExforDataSets(submodule); + python_documentation::wrapExperimentalDataSets(submodule); + python_documentation::wrapKeyword(submodule); + python_documentation::wrapKeywords(submodule); + python_documentation::wrapRelatedItem(submodule); + python_documentation::wrapRelatedItems(submodule); + python_documentation::wrapDocumentation(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Acknowledgement.python.cpp b/python/src/v2.0/documentation/Acknowledgement.python.cpp new file mode 100644 index 000000000..ad9aa4096 --- /dev/null +++ b/python/src/v2.0/documentation/Acknowledgement.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Acknowledgement.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Acknowledgement wrapper +void wrapAcknowledgement(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Acknowledgement; + + // create the component + python::class_ component( + module, + "Acknowledgement", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName & + >(), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Acknowledgements.python.cpp b/python/src/v2.0/documentation/Acknowledgements.python.cpp new file mode 100644 index 000000000..b4f45ea70 --- /dev/null +++ b/python/src/v2.0/documentation/Acknowledgements.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Acknowledgements.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Acknowledgements wrapper +void wrapAcknowledgements(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Acknowledgements; + + // create the component + python::class_ component( + module, + "Acknowledgements", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("acknowledgement"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "acknowledgement", + python::overload_cast<>(&Component::acknowledgement), + Component::documentation("acknowledgement").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Affiliation.python.cpp b/python/src/v2.0/documentation/Affiliation.python.cpp new file mode 100644 index 000000000..7855ab744 --- /dev/null +++ b/python/src/v2.0/documentation/Affiliation.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Affiliation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Affiliation wrapper +void wrapAffiliation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Affiliation; + + // create the component + python::class_ component( + module, + "Affiliation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const UTF8Text & + >(), + python::arg("href") = std::nullopt, + python::arg("name"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Affiliations.python.cpp b/python/src/v2.0/documentation/Affiliations.python.cpp new file mode 100644 index 000000000..c39742815 --- /dev/null +++ b/python/src/v2.0/documentation/Affiliations.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Affiliations.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Affiliations wrapper +void wrapAffiliations(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Affiliations; + + // create the component + python::class_ component( + module, + "Affiliations", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("affiliation"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "affiliation", + python::overload_cast<>(&Component::affiliation), + Component::documentation("affiliation").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Author.python.cpp b/python/src/v2.0/documentation/Author.python.cpp new file mode 100644 index 000000000..1b7e72afd --- /dev/null +++ b/python/src/v2.0/documentation/Author.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Author.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Author wrapper +void wrapAuthor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Author; + + // create the component + python::class_ component( + module, + "Author", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const UTF8Text &, + const std::optional &, + const std::optional & + >(), + python::arg("email") = std::nullopt, + python::arg("name"), + python::arg("orcid_id") = std::nullopt, + python::arg("affiliations") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "email", + &Component::email, + Component::documentation("email").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "orcid_id", + &Component::orcid_id, + Component::documentation("orcid_id").data() + ) + .def_property_readonly( + "affiliations", + python::overload_cast<>(&Component::affiliations), + Component::documentation("affiliations").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Authors.python.cpp b/python/src/v2.0/documentation/Authors.python.cpp new file mode 100644 index 000000000..2464c7a6c --- /dev/null +++ b/python/src/v2.0/documentation/Authors.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Authors.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Authors wrapper +void wrapAuthors(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Authors; + + // create the component + python::class_ component( + module, + "Authors", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("author"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "author", + python::overload_cast<>(&Component::author), + Component::documentation("author").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Bibitem.python.cpp b/python/src/v2.0/documentation/Bibitem.python.cpp new file mode 100644 index 000000000..597e83915 --- /dev/null +++ b/python/src/v2.0/documentation/Bibitem.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Bibitem.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Bibitem wrapper +void wrapBibitem(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Bibitem; + + // create the component + python::class_ component( + module, + "Bibitem", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName & + >(), + python::arg("xref"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xref", + &Component::xref, + Component::documentation("xref").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Bibliography.python.cpp b/python/src/v2.0/documentation/Bibliography.python.cpp new file mode 100644 index 000000000..92aea4702 --- /dev/null +++ b/python/src/v2.0/documentation/Bibliography.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Bibliography.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Bibliography wrapper +void wrapBibliography(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Bibliography; + + // create the component + python::class_ component( + module, + "Bibliography", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("bibitem"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "bibitem", + python::overload_cast<>(&Component::bibitem), + Component::documentation("bibitem").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Body.python.cpp b/python/src/v2.0/documentation/Body.python.cpp new file mode 100644 index 000000000..f3d692294 --- /dev/null +++ b/python/src/v2.0/documentation/Body.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Body.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Body wrapper +void wrapBody(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Body; + + // create the component + python::class_ component( + module, + "Body", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/CodeRepo.python.cpp b/python/src/v2.0/documentation/CodeRepo.python.cpp new file mode 100644 index 000000000..9bf199e41 --- /dev/null +++ b/python/src/v2.0/documentation/CodeRepo.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/CodeRepo.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// CodeRepo wrapper +void wrapCodeRepo(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::CodeRepo; + + // create the component + python::class_ component( + module, + "CodeRepo", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const XMLName & + >(), + python::arg("href"), + python::arg("revision_id"), + python::arg("revision_system"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "revision_id", + &Component::revisionID, + Component::documentation("revision_id").data() + ) + .def_property_readonly( + "revision_system", + &Component::revisionSystem, + Component::documentation("revision_system").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Collaboration.python.cpp b/python/src/v2.0/documentation/Collaboration.python.cpp new file mode 100644 index 000000000..f18576523 --- /dev/null +++ b/python/src/v2.0/documentation/Collaboration.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Collaboration.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Collaboration wrapper +void wrapCollaboration(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Collaboration; + + // create the component + python::class_ component( + module, + "Collaboration", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const UTF8Text & + >(), + python::arg("href") = std::nullopt, + python::arg("name"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Collaborations.python.cpp b/python/src/v2.0/documentation/Collaborations.python.cpp new file mode 100644 index 000000000..f53919497 --- /dev/null +++ b/python/src/v2.0/documentation/Collaborations.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Collaborations.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Collaborations wrapper +void wrapCollaborations(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Collaborations; + + // create the component + python::class_ component( + module, + "Collaborations", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("collaboration"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "collaboration", + python::overload_cast<>(&Component::collaboration), + Component::documentation("collaboration").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ComputerCode.python.cpp b/python/src/v2.0/documentation/ComputerCode.python.cpp new file mode 100644 index 000000000..983892e5b --- /dev/null +++ b/python/src/v2.0/documentation/ComputerCode.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ComputerCode.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ComputerCode wrapper +void wrapComputerCode(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ComputerCode; + + // create the component + python::class_ component( + module, + "ComputerCode", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const UTF8Text &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("name"), + python::arg("version"), + python::arg("code_repo") = std::nullopt, + python::arg("input_decks") = std::nullopt, + python::arg("output_decks") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "version", + &Component::version, + Component::documentation("version").data() + ) + .def_property_readonly( + "code_repo", + python::overload_cast<>(&Component::codeRepo), + Component::documentation("code_repo").data() + ) + .def_property_readonly( + "input_decks", + python::overload_cast<>(&Component::inputDecks), + Component::documentation("input_decks").data() + ) + .def_property_readonly( + "output_decks", + python::overload_cast<>(&Component::outputDecks), + Component::documentation("output_decks").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ComputerCodes.python.cpp b/python/src/v2.0/documentation/ComputerCodes.python.cpp new file mode 100644 index 000000000..7d879cd0c --- /dev/null +++ b/python/src/v2.0/documentation/ComputerCodes.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ComputerCodes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ComputerCodes wrapper +void wrapComputerCodes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ComputerCodes; + + // create the component + python::class_ component( + module, + "ComputerCodes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("computer_code"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "computer_code", + python::overload_cast<>(&Component::computerCode), + Component::documentation("computer_code").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Contributor.python.cpp b/python/src/v2.0/documentation/Contributor.python.cpp new file mode 100644 index 000000000..64c3a3c15 --- /dev/null +++ b/python/src/v2.0/documentation/Contributor.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Contributor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Contributor wrapper +void wrapContributor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Contributor; + + // create the component + python::class_ component( + module, + "Contributor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const enums::ContributorType &, + const std::optional &, + const UTF8Text &, + const std::optional &, + const std::optional & + >(), + python::arg("contributor_type"), + python::arg("email") = std::nullopt, + python::arg("name"), + python::arg("orcid_id") = std::nullopt, + python::arg("affiliations") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "contributor_type", + &Component::contributorType, + Component::documentation("contributor_type").data() + ) + .def_property_readonly( + "email", + &Component::email, + Component::documentation("email").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "orcid_id", + &Component::orcid_id, + Component::documentation("orcid_id").data() + ) + .def_property_readonly( + "affiliations", + python::overload_cast<>(&Component::affiliations), + Component::documentation("affiliations").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Contributors.python.cpp b/python/src/v2.0/documentation/Contributors.python.cpp new file mode 100644 index 000000000..c419eb923 --- /dev/null +++ b/python/src/v2.0/documentation/Contributors.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Contributors.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Contributors wrapper +void wrapContributors(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Contributors; + + // create the component + python::class_ component( + module, + "Contributors", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("contributor"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "contributor", + python::overload_cast<>(&Component::contributor), + Component::documentation("contributor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Copyright.python.cpp b/python/src/v2.0/documentation/Copyright.python.cpp new file mode 100644 index 000000000..9f0696bb2 --- /dev/null +++ b/python/src/v2.0/documentation/Copyright.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Copyright.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Copyright wrapper +void wrapCopyright(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Copyright; + + // create the component + python::class_ component( + module, + "Copyright", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/CorrectionScript.python.cpp b/python/src/v2.0/documentation/CorrectionScript.python.cpp new file mode 100644 index 000000000..5aba50f1f --- /dev/null +++ b/python/src/v2.0/documentation/CorrectionScript.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/CorrectionScript.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// CorrectionScript wrapper +void wrapCorrectionScript(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::CorrectionScript; + + // create the component + python::class_ component( + module, + "CorrectionScript", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/CovarianceScript.python.cpp b/python/src/v2.0/documentation/CovarianceScript.python.cpp new file mode 100644 index 000000000..609ec09d1 --- /dev/null +++ b/python/src/v2.0/documentation/CovarianceScript.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/CovarianceScript.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// CovarianceScript wrapper +void wrapCovarianceScript(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::CovarianceScript; + + // create the component + python::class_ component( + module, + "CovarianceScript", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Date.python.cpp b/python/src/v2.0/documentation/Date.python.cpp new file mode 100644 index 000000000..e36e73d16 --- /dev/null +++ b/python/src/v2.0/documentation/Date.python.cpp @@ -0,0 +1,92 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Date.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Date wrapper +void wrapDate(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Date; + + // create the component + python::class_ component( + module, + "Date", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const enums::DateType & + >(), + python::arg("date_type"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("ints"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("doubles"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("strings"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date_type", + &Component::dateType, + Component::documentation("date_type").data() + ) + .def_property_readonly( + "ints", + [] (const Component &self) { return self.ints(); }, + Component::documentation("ints").data() + ) + .def_property_readonly( + "doubles", + [] (const Component &self) { return self.doubles(); }, + Component::documentation("doubles").data() + ) + .def_property_readonly( + "strings", + [] (const Component &self) { return self.strings(); }, + Component::documentation("strings").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Dates.python.cpp b/python/src/v2.0/documentation/Dates.python.cpp new file mode 100644 index 000000000..aca6860bc --- /dev/null +++ b/python/src/v2.0/documentation/Dates.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Dates.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Dates wrapper +void wrapDates(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Dates; + + // create the component + python::class_ component( + module, + "Dates", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("date"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + python::overload_cast<>(&Component::date), + Component::documentation("date").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Documentation.python.cpp b/python/src/v2.0/documentation/Documentation.python.cpp new file mode 100644 index 000000000..cdedfe9b9 --- /dev/null +++ b/python/src/v2.0/documentation/Documentation.python.cpp @@ -0,0 +1,147 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Documentation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Documentation wrapper +void wrapDocumentation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Documentation; + + // create the component + python::class_ component( + module, + "Documentation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const documentation::Authors &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const documentation::Dates &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("doi") = std::nullopt, + python::arg("publication_date") = std::nullopt, + python::arg("version") = std::nullopt, + python::arg("acknowledgements") = std::nullopt, + python::arg("authors"), + python::arg("bibliography") = std::nullopt, + python::arg("collaborations") = std::nullopt, + python::arg("computer_codes") = std::nullopt, + python::arg("contributors") = std::nullopt, + python::arg("copyright") = std::nullopt, + python::arg("dates"), + python::arg("experimental_data_sets") = std::nullopt, + python::arg("keywords") = std::nullopt, + python::arg("related_items") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "doi", + &Component::doi, + Component::documentation("doi").data() + ) + .def_property_readonly( + "publication_date", + &Component::publicationDate, + Component::documentation("publication_date").data() + ) + .def_property_readonly( + "version", + &Component::version, + Component::documentation("version").data() + ) + .def_property_readonly( + "acknowledgements", + python::overload_cast<>(&Component::acknowledgements), + Component::documentation("acknowledgements").data() + ) + .def_property_readonly( + "authors", + python::overload_cast<>(&Component::authors), + Component::documentation("authors").data() + ) + .def_property_readonly( + "bibliography", + python::overload_cast<>(&Component::bibliography), + Component::documentation("bibliography").data() + ) + .def_property_readonly( + "collaborations", + python::overload_cast<>(&Component::collaborations), + Component::documentation("collaborations").data() + ) + .def_property_readonly( + "computer_codes", + python::overload_cast<>(&Component::computerCodes), + Component::documentation("computer_codes").data() + ) + .def_property_readonly( + "contributors", + python::overload_cast<>(&Component::contributors), + Component::documentation("contributors").data() + ) + .def_property_readonly( + "copyright", + python::overload_cast<>(&Component::copyright), + Component::documentation("copyright").data() + ) + .def_property_readonly( + "dates", + python::overload_cast<>(&Component::dates), + Component::documentation("dates").data() + ) + .def_property_readonly( + "experimental_data_sets", + python::overload_cast<>(&Component::experimentalDataSets), + Component::documentation("experimental_data_sets").data() + ) + .def_property_readonly( + "keywords", + python::overload_cast<>(&Component::keywords), + Component::documentation("keywords").data() + ) + .def_property_readonly( + "related_items", + python::overload_cast<>(&Component::relatedItems), + Component::documentation("related_items").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/EndfCompatible.python.cpp b/python/src/v2.0/documentation/EndfCompatible.python.cpp new file mode 100644 index 000000000..511ee9d89 --- /dev/null +++ b/python/src/v2.0/documentation/EndfCompatible.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/EndfCompatible.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// EndfCompatible wrapper +void wrapEndfCompatible(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::EndfCompatible; + + // create the component + python::class_ component( + module, + "EndfCompatible", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ExecutionArguments.python.cpp b/python/src/v2.0/documentation/ExecutionArguments.python.cpp new file mode 100644 index 000000000..7c95287c7 --- /dev/null +++ b/python/src/v2.0/documentation/ExecutionArguments.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ExecutionArguments.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ExecutionArguments wrapper +void wrapExecutionArguments(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ExecutionArguments; + + // create the component + python::class_ component( + module, + "ExecutionArguments", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ExforDataSet.python.cpp b/python/src/v2.0/documentation/ExforDataSet.python.cpp new file mode 100644 index 000000000..d2b649c26 --- /dev/null +++ b/python/src/v2.0/documentation/ExforDataSet.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ExforDataSet.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ExforDataSet wrapper +void wrapExforDataSet(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ExforDataSet; + + // create the component + python::class_ component( + module, + "ExforDataSet", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("retrieval_date"), + python::arg("subentry"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "retrieval_date", + &Component::retrievalDate, + Component::documentation("retrieval_date").data() + ) + .def_property_readonly( + "subentry", + &Component::subentry, + Component::documentation("subentry").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ExforDataSets.python.cpp b/python/src/v2.0/documentation/ExforDataSets.python.cpp new file mode 100644 index 000000000..4d6a7a9ca --- /dev/null +++ b/python/src/v2.0/documentation/ExforDataSets.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ExforDataSets.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ExforDataSets wrapper +void wrapExforDataSets(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ExforDataSets; + + // create the component + python::class_ component( + module, + "ExforDataSets", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("exfor_data_set"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "exfor_data_set", + python::overload_cast<>(&Component::exforDataSet), + Component::documentation("exfor_data_set").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/ExperimentalDataSets.python.cpp b/python/src/v2.0/documentation/ExperimentalDataSets.python.cpp new file mode 100644 index 000000000..7d45df8dd --- /dev/null +++ b/python/src/v2.0/documentation/ExperimentalDataSets.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/ExperimentalDataSets.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// ExperimentalDataSets wrapper +void wrapExperimentalDataSets(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::ExperimentalDataSets; + + // create the component + python::class_ component( + module, + "ExperimentalDataSets", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const documentation::ExforDataSets & + >(), + python::arg("exfor_data_sets"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "exfor_data_sets", + python::overload_cast<>(&Component::exforDataSets), + Component::documentation("exfor_data_sets").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/InputDeck.python.cpp b/python/src/v2.0/documentation/InputDeck.python.cpp new file mode 100644 index 000000000..cce675f10 --- /dev/null +++ b/python/src/v2.0/documentation/InputDeck.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/InputDeck.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// InputDeck wrapper +void wrapInputDeck(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::InputDeck; + + // create the component + python::class_ component( + module, + "InputDeck", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("filename") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "filename", + &Component::filename, + Component::documentation("filename").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/InputDecks.python.cpp b/python/src/v2.0/documentation/InputDecks.python.cpp new file mode 100644 index 000000000..87e030f00 --- /dev/null +++ b/python/src/v2.0/documentation/InputDecks.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/InputDecks.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// InputDecks wrapper +void wrapInputDecks(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::InputDecks; + + // create the component + python::class_ component( + module, + "InputDecks", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("input_deck"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "input_deck", + python::overload_cast<>(&Component::inputDeck), + Component::documentation("input_deck").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Keyword.python.cpp b/python/src/v2.0/documentation/Keyword.python.cpp new file mode 100644 index 000000000..85a7965e3 --- /dev/null +++ b/python/src/v2.0/documentation/Keyword.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Keyword.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Keyword wrapper +void wrapKeyword(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Keyword; + + // create the component + python::class_ component( + module, + "Keyword", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName & + >(), + python::arg("type"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Keywords.python.cpp b/python/src/v2.0/documentation/Keywords.python.cpp new file mode 100644 index 000000000..bf3bf30b5 --- /dev/null +++ b/python/src/v2.0/documentation/Keywords.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Keywords.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Keywords wrapper +void wrapKeywords(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Keywords; + + // create the component + python::class_ component( + module, + "Keywords", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("keyword"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "keyword", + python::overload_cast<>(&Component::keyword), + Component::documentation("keyword").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Note.python.cpp b/python/src/v2.0/documentation/Note.python.cpp new file mode 100644 index 000000000..9dcd6af22 --- /dev/null +++ b/python/src/v2.0/documentation/Note.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Note.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Note wrapper +void wrapNote(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Note; + + // create the component + python::class_ component( + module, + "Note", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/OutputDeck.python.cpp b/python/src/v2.0/documentation/OutputDeck.python.cpp new file mode 100644 index 000000000..ebbf13caf --- /dev/null +++ b/python/src/v2.0/documentation/OutputDeck.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/OutputDeck.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// OutputDeck wrapper +void wrapOutputDeck(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::OutputDeck; + + // create the component + python::class_ component( + module, + "OutputDeck", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("filename") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "filename", + &Component::filename, + Component::documentation("filename").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/OutputDecks.python.cpp b/python/src/v2.0/documentation/OutputDecks.python.cpp new file mode 100644 index 000000000..fd9aeda27 --- /dev/null +++ b/python/src/v2.0/documentation/OutputDecks.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/OutputDecks.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// OutputDecks wrapper +void wrapOutputDecks(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::OutputDecks; + + // create the component + python::class_ component( + module, + "OutputDecks", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("output_deck"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "output_deck", + python::overload_cast<>(&Component::outputDeck), + Component::documentation("output_deck").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/RelatedItem.python.cpp b/python/src/v2.0/documentation/RelatedItem.python.cpp new file mode 100644 index 000000000..946db207b --- /dev/null +++ b/python/src/v2.0/documentation/RelatedItem.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/RelatedItem.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// RelatedItem wrapper +void wrapRelatedItem(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::RelatedItem; + + // create the component + python::class_ component( + module, + "RelatedItem", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const UTF8Text &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("name"), + python::arg("relation_type") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "relation_type", + &Component::relationType, + Component::documentation("relation_type").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/RelatedItems.python.cpp b/python/src/v2.0/documentation/RelatedItems.python.cpp new file mode 100644 index 000000000..83755cd6d --- /dev/null +++ b/python/src/v2.0/documentation/RelatedItems.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/RelatedItems.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// RelatedItems wrapper +void wrapRelatedItems(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::RelatedItems; + + // create the component + python::class_ component( + module, + "RelatedItems", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("related_item"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "related_item", + python::overload_cast<>(&Component::relatedItem), + Component::documentation("related_item").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/documentation/Version.python.cpp b/python/src/v2.0/documentation/Version.python.cpp new file mode 100644 index 000000000..653c851db --- /dev/null +++ b/python/src/v2.0/documentation/Version.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/documentation/Version.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_documentation { + +// Version wrapper +void wrapVersion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = documentation::Version; + + // create the component + python::class_ component( + module, + "Version", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_documentation +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionFragmentData.python.cpp b/python/src/v2.0/fissionFragmentData.python.cpp new file mode 100644 index 000000000..f07e98b83 --- /dev/null +++ b/python/src/v2.0/fissionFragmentData.python.cpp @@ -0,0 +1,37 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// fissionFragmentData declarations +namespace python_fissionFragmentData { + void wrapRate(python::module &); + void wrapDelayedNeutron(python::module &); + void wrapDelayedNeutrons(python::module &); + void wrapFissionFragmentData(python::module &); +} // namespace python_fissionFragmentData + +// fissionFragmentData wrapper +void wrapFissionFragmentData(python::module &module) +{ + // create the fissionFragmentData submodule + python::module submodule = module.def_submodule( + "fissionFragmentData", + "GNDS v2.0 fissionFragmentData" + ); + + // wrap fissionFragmentData components + python_fissionFragmentData::wrapRate(submodule); + python_fissionFragmentData::wrapDelayedNeutron(submodule); + python_fissionFragmentData::wrapDelayedNeutrons(submodule); + python_fissionFragmentData::wrapFissionFragmentData(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionFragmentData/DelayedNeutron.python.cpp b/python/src/v2.0/fissionFragmentData/DelayedNeutron.python.cpp new file mode 100644 index 000000000..382706b79 --- /dev/null +++ b/python/src/v2.0/fissionFragmentData/DelayedNeutron.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionFragmentData/DelayedNeutron.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionFragmentData { + +// DelayedNeutron wrapper +void wrapDelayedNeutron(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionFragmentData::DelayedNeutron; + + // create the component + python::class_ component( + module, + "DelayedNeutron", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const pops::Product &, + const fissionFragmentData::Rate & + >(), + python::arg("label"), + python::arg("product"), + python::arg("rate"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product", + python::overload_cast<>(&Component::product), + Component::documentation("product").data() + ) + .def_property_readonly( + "rate", + python::overload_cast<>(&Component::rate), + Component::documentation("rate").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionFragmentData +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionFragmentData/DelayedNeutrons.python.cpp b/python/src/v2.0/fissionFragmentData/DelayedNeutrons.python.cpp new file mode 100644 index 000000000..bf0f6b0cc --- /dev/null +++ b/python/src/v2.0/fissionFragmentData/DelayedNeutrons.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionFragmentData/DelayedNeutrons.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionFragmentData { + +// DelayedNeutrons wrapper +void wrapDelayedNeutrons(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionFragmentData::DelayedNeutrons; + + // create the component + python::class_ component( + module, + "DelayedNeutrons", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("delayed_neutron"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "delayed_neutron", + python::overload_cast<>(&Component::delayedNeutron), + Component::documentation("delayed_neutron").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionFragmentData +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionFragmentData/FissionFragmentData.python.cpp b/python/src/v2.0/fissionFragmentData/FissionFragmentData.python.cpp new file mode 100644 index 000000000..ff341ce62 --- /dev/null +++ b/python/src/v2.0/fissionFragmentData/FissionFragmentData.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionFragmentData/FissionFragmentData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionFragmentData { + +// FissionFragmentData wrapper +void wrapFissionFragmentData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionFragmentData::FissionFragmentData; + + // create the component + python::class_ component( + module, + "FissionFragmentData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("delayed_neutrons") = std::nullopt, + python::arg("fission_energy_released") = std::nullopt, + python::arg("product_yields") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "delayed_neutrons", + python::overload_cast<>(&Component::delayedNeutrons), + Component::documentation("delayed_neutrons").data() + ) + .def_property_readonly( + "fission_energy_released", + python::overload_cast<>(&Component::fissionEnergyReleased), + Component::documentation("fission_energy_released").data() + ) + .def_property_readonly( + "product_yields", + python::overload_cast<>(&Component::productYields), + Component::documentation("product_yields").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionFragmentData +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionFragmentData/Rate.python.cpp b/python/src/v2.0/fissionFragmentData/Rate.python.cpp new file mode 100644 index 000000000..4f451f1d2 --- /dev/null +++ b/python/src/v2.0/fissionFragmentData/Rate.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionFragmentData/Rate.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionFragmentData { + +// Rate wrapper +void wrapRate(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionFragmentData::Rate; + + // create the component + python::class_ component( + module, + "Rate", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Double & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionFragmentData +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport.python.cpp b/python/src/v2.0/fissionTransport.python.cpp new file mode 100644 index 000000000..b1846e8ff --- /dev/null +++ b/python/src/v2.0/fissionTransport.python.cpp @@ -0,0 +1,67 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// fissionTransport declarations +namespace python_fissionTransport { + void wrapEFH(python::module &); + void wrapEFL(python::module &); + void wrapT_M(python::module &); + void wrapMadlandNix(python::module &); + void wrapB(python::module &); + void wrapWatt(python::module &); + void wrapSimpleMaxwellianFission(python::module &); + void wrapDelayedBetaEnergy(python::module &); + void wrapDelayedGammaEnergy(python::module &); + void wrapDelayedNeutronKE(python::module &); + void wrapNeutrinoEnergy(python::module &); + void wrapNonNeutrinoEnergy(python::module &); + void wrapPromptGammaEnergy(python::module &); + void wrapPromptNeutronKE(python::module &); + void wrapPromptProductKE(python::module &); + void wrapTotalEnergy(python::module &); + void wrapFissionEnergyReleased(python::module &); + void wrapFissionComponent(python::module &); + void wrapFissionComponents(python::module &); +} // namespace python_fissionTransport + +// fissionTransport wrapper +void wrapFissionTransport(python::module &module) +{ + // create the fissionTransport submodule + python::module submodule = module.def_submodule( + "fissionTransport", + "GNDS v2.0 fissionTransport" + ); + + // wrap fissionTransport components + python_fissionTransport::wrapEFH(submodule); + python_fissionTransport::wrapEFL(submodule); + python_fissionTransport::wrapT_M(submodule); + python_fissionTransport::wrapMadlandNix(submodule); + python_fissionTransport::wrapB(submodule); + python_fissionTransport::wrapWatt(submodule); + python_fissionTransport::wrapSimpleMaxwellianFission(submodule); + python_fissionTransport::wrapDelayedBetaEnergy(submodule); + python_fissionTransport::wrapDelayedGammaEnergy(submodule); + python_fissionTransport::wrapDelayedNeutronKE(submodule); + python_fissionTransport::wrapNeutrinoEnergy(submodule); + python_fissionTransport::wrapNonNeutrinoEnergy(submodule); + python_fissionTransport::wrapPromptGammaEnergy(submodule); + python_fissionTransport::wrapPromptNeutronKE(submodule); + python_fissionTransport::wrapPromptProductKE(submodule); + python_fissionTransport::wrapTotalEnergy(submodule); + python_fissionTransport::wrapFissionEnergyReleased(submodule); + python_fissionTransport::wrapFissionComponent(submodule); + python_fissionTransport::wrapFissionComponents(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/B.python.cpp b/python/src/v2.0/fissionTransport/B.python.cpp new file mode 100644 index 000000000..a6dc9e0dc --- /dev/null +++ b/python/src/v2.0/fissionTransport/B.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/B.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// B wrapper +void wrapB(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::B; + + // create the component + python::class_ component( + module, + "B", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/DelayedBetaEnergy.python.cpp b/python/src/v2.0/fissionTransport/DelayedBetaEnergy.python.cpp new file mode 100644 index 000000000..2adfc5aec --- /dev/null +++ b/python/src/v2.0/fissionTransport/DelayedBetaEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/DelayedBetaEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// DelayedBetaEnergy wrapper +void wrapDelayedBetaEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::DelayedBetaEnergy; + + // create the component + python::class_ component( + module, + "DelayedBetaEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/DelayedGammaEnergy.python.cpp b/python/src/v2.0/fissionTransport/DelayedGammaEnergy.python.cpp new file mode 100644 index 000000000..e815ed923 --- /dev/null +++ b/python/src/v2.0/fissionTransport/DelayedGammaEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/DelayedGammaEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// DelayedGammaEnergy wrapper +void wrapDelayedGammaEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::DelayedGammaEnergy; + + // create the component + python::class_ component( + module, + "DelayedGammaEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/DelayedNeutronKE.python.cpp b/python/src/v2.0/fissionTransport/DelayedNeutronKE.python.cpp new file mode 100644 index 000000000..e88c485cb --- /dev/null +++ b/python/src/v2.0/fissionTransport/DelayedNeutronKE.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/DelayedNeutronKE.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// DelayedNeutronKE wrapper +void wrapDelayedNeutronKE(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::DelayedNeutronKE; + + // create the component + python::class_ component( + module, + "DelayedNeutronKE", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/EFH.python.cpp b/python/src/v2.0/fissionTransport/EFH.python.cpp new file mode 100644 index 000000000..c3e619f97 --- /dev/null +++ b/python/src/v2.0/fissionTransport/EFH.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/EFH.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// EFH wrapper +void wrapEFH(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::EFH; + + // create the component + python::class_ component( + module, + "EFH", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/EFL.python.cpp b/python/src/v2.0/fissionTransport/EFL.python.cpp new file mode 100644 index 000000000..f2aa103d7 --- /dev/null +++ b/python/src/v2.0/fissionTransport/EFL.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/EFL.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// EFL wrapper +void wrapEFL(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::EFL; + + // create the component + python::class_ component( + module, + "EFL", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/FissionComponent.python.cpp b/python/src/v2.0/fissionTransport/FissionComponent.python.cpp new file mode 100644 index 000000000..27b3d23a8 --- /dev/null +++ b/python/src/v2.0/fissionTransport/FissionComponent.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/FissionComponent.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// FissionComponent wrapper +void wrapFissionComponent(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::FissionComponent; + + // create the component + python::class_ component( + module, + "FissionComponent", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("endf_mt") = std::nullopt, + python::arg("fission_genre"), + python::arg("label"), + python::arg("cross_section") = std::nullopt, + python::arg("output_channel") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "fission_genre", + &Component::fissionGenre, + Component::documentation("fission_genre").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "output_channel", + python::overload_cast<>(&Component::outputChannel), + Component::documentation("output_channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/FissionComponents.python.cpp b/python/src/v2.0/fissionTransport/FissionComponents.python.cpp new file mode 100644 index 000000000..edb038afb --- /dev/null +++ b/python/src/v2.0/fissionTransport/FissionComponents.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/FissionComponents.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// FissionComponents wrapper +void wrapFissionComponents(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::FissionComponents; + + // create the component + python::class_ component( + module, + "FissionComponents", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("fission_component") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "fission_component", + python::overload_cast<>(&Component::fissionComponent), + Component::documentation("fission_component").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/FissionEnergyReleased.python.cpp b/python/src/v2.0/fissionTransport/FissionEnergyReleased.python.cpp new file mode 100644 index 000000000..e5b217739 --- /dev/null +++ b/python/src/v2.0/fissionTransport/FissionEnergyReleased.python.cpp @@ -0,0 +1,119 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/FissionEnergyReleased.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// FissionEnergyReleased wrapper +void wrapFissionEnergyReleased(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::FissionEnergyReleased; + + // create the component + python::class_ component( + module, + "FissionEnergyReleased", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("label") = std::nullopt, + python::arg("delayed_beta_energy") = std::nullopt, + python::arg("delayed_gamma_energy") = std::nullopt, + python::arg("delayed_neutron_ke") = std::nullopt, + python::arg("neutrino_energy") = std::nullopt, + python::arg("non_neutrino_energy") = std::nullopt, + python::arg("prompt_gamma_energy") = std::nullopt, + python::arg("prompt_neutron_ke") = std::nullopt, + python::arg("prompt_product_ke") = std::nullopt, + python::arg("total_energy") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "delayed_beta_energy", + python::overload_cast<>(&Component::delayedBetaEnergy), + Component::documentation("delayed_beta_energy").data() + ) + .def_property_readonly( + "delayed_gamma_energy", + python::overload_cast<>(&Component::delayedGammaEnergy), + Component::documentation("delayed_gamma_energy").data() + ) + .def_property_readonly( + "delayed_neutron_ke", + python::overload_cast<>(&Component::delayedNeutronKE), + Component::documentation("delayed_neutron_ke").data() + ) + .def_property_readonly( + "neutrino_energy", + python::overload_cast<>(&Component::neutrinoEnergy), + Component::documentation("neutrino_energy").data() + ) + .def_property_readonly( + "non_neutrino_energy", + python::overload_cast<>(&Component::nonNeutrinoEnergy), + Component::documentation("non_neutrino_energy").data() + ) + .def_property_readonly( + "prompt_gamma_energy", + python::overload_cast<>(&Component::promptGammaEnergy), + Component::documentation("prompt_gamma_energy").data() + ) + .def_property_readonly( + "prompt_neutron_ke", + python::overload_cast<>(&Component::promptNeutronKE), + Component::documentation("prompt_neutron_ke").data() + ) + .def_property_readonly( + "prompt_product_ke", + python::overload_cast<>(&Component::promptProductKE), + Component::documentation("prompt_product_ke").data() + ) + .def_property_readonly( + "total_energy", + python::overload_cast<>(&Component::totalEnergy), + Component::documentation("total_energy").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/MadlandNix.python.cpp b/python/src/v2.0/fissionTransport/MadlandNix.python.cpp new file mode 100644 index 000000000..120c19301 --- /dev/null +++ b/python/src/v2.0/fissionTransport/MadlandNix.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/MadlandNix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// MadlandNix wrapper +void wrapMadlandNix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::MadlandNix; + + // create the component + python::class_ component( + module, + "MadlandNix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const fissionTransport::EFH &, + const fissionTransport::EFL &, + const fissionTransport::T_M & + >(), + python::arg("efh"), + python::arg("efl"), + python::arg("t_m"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "efh", + python::overload_cast<>(&Component::EFH), + Component::documentation("efh").data() + ) + .def_property_readonly( + "efl", + python::overload_cast<>(&Component::EFL), + Component::documentation("efl").data() + ) + .def_property_readonly( + "t_m", + python::overload_cast<>(&Component::T_M), + Component::documentation("t_m").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/NeutrinoEnergy.python.cpp b/python/src/v2.0/fissionTransport/NeutrinoEnergy.python.cpp new file mode 100644 index 000000000..05196fe8d --- /dev/null +++ b/python/src/v2.0/fissionTransport/NeutrinoEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/NeutrinoEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// NeutrinoEnergy wrapper +void wrapNeutrinoEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::NeutrinoEnergy; + + // create the component + python::class_ component( + module, + "NeutrinoEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/NonNeutrinoEnergy.python.cpp b/python/src/v2.0/fissionTransport/NonNeutrinoEnergy.python.cpp new file mode 100644 index 000000000..9528782dd --- /dev/null +++ b/python/src/v2.0/fissionTransport/NonNeutrinoEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/NonNeutrinoEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// NonNeutrinoEnergy wrapper +void wrapNonNeutrinoEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::NonNeutrinoEnergy; + + // create the component + python::class_ component( + module, + "NonNeutrinoEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/PromptGammaEnergy.python.cpp b/python/src/v2.0/fissionTransport/PromptGammaEnergy.python.cpp new file mode 100644 index 000000000..d9068e41d --- /dev/null +++ b/python/src/v2.0/fissionTransport/PromptGammaEnergy.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/PromptGammaEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// PromptGammaEnergy wrapper +void wrapPromptGammaEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::PromptGammaEnergy; + + // create the component + python::class_ component( + module, + "PromptGammaEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/PromptNeutronKE.python.cpp b/python/src/v2.0/fissionTransport/PromptNeutronKE.python.cpp new file mode 100644 index 000000000..2dc5eccde --- /dev/null +++ b/python/src/v2.0/fissionTransport/PromptNeutronKE.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/PromptNeutronKE.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// PromptNeutronKE wrapper +void wrapPromptNeutronKE(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::PromptNeutronKE; + + // create the component + python::class_ component( + module, + "PromptNeutronKE", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/PromptProductKE.python.cpp b/python/src/v2.0/fissionTransport/PromptProductKE.python.cpp new file mode 100644 index 000000000..cf9386a99 --- /dev/null +++ b/python/src/v2.0/fissionTransport/PromptProductKE.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/PromptProductKE.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// PromptProductKE wrapper +void wrapPromptProductKE(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::PromptProductKE; + + // create the component + python::class_ component( + module, + "PromptProductKE", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/SimpleMaxwellianFission.python.cpp b/python/src/v2.0/fissionTransport/SimpleMaxwellianFission.python.cpp new file mode 100644 index 000000000..8a0a954c7 --- /dev/null +++ b/python/src/v2.0/fissionTransport/SimpleMaxwellianFission.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/SimpleMaxwellianFission.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// SimpleMaxwellianFission wrapper +void wrapSimpleMaxwellianFission(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::SimpleMaxwellianFission; + + // create the component + python::class_ component( + module, + "SimpleMaxwellianFission", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("u") = std::nullopt, + python::arg("theta") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "u", + python::overload_cast<>(&Component::U), + Component::documentation("u").data() + ) + .def_property_readonly( + "theta", + python::overload_cast<>(&Component::theta), + Component::documentation("theta").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/T_M.python.cpp b/python/src/v2.0/fissionTransport/T_M.python.cpp new file mode 100644 index 000000000..7cca5fd4b --- /dev/null +++ b/python/src/v2.0/fissionTransport/T_M.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/T_M.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// T_M wrapper +void wrapT_M(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::T_M; + + // create the component + python::class_ component( + module, + "T_M", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/TotalEnergy.python.cpp b/python/src/v2.0/fissionTransport/TotalEnergy.python.cpp new file mode 100644 index 000000000..842417212 --- /dev/null +++ b/python/src/v2.0/fissionTransport/TotalEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/TotalEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// TotalEnergy wrapper +void wrapTotalEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::TotalEnergy; + + // create the component + python::class_ component( + module, + "TotalEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("polynomial1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fissionTransport/Watt.python.cpp b/python/src/v2.0/fissionTransport/Watt.python.cpp new file mode 100644 index 000000000..75cded907 --- /dev/null +++ b/python/src/v2.0/fissionTransport/Watt.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fissionTransport/Watt.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fissionTransport { + +// Watt wrapper +void wrapWatt(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fissionTransport::Watt; + + // create the component + python::class_ component( + module, + "Watt", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const transport::U &, + const transport::A &, + const fissionTransport::B & + >(), + python::arg("u"), + python::arg("a"), + python::arg("b"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "u", + python::overload_cast<>(&Component::U), + Component::documentation("u").data() + ) + .def_property_readonly( + "a", + python::overload_cast<>(&Component::a), + Component::documentation("a").data() + ) + .def_property_readonly( + "b", + python::overload_cast<>(&Component::b), + Component::documentation("b").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fissionTransport +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy.python.cpp b/python/src/v2.0/fpy.python.cpp new file mode 100644 index 000000000..df15af1ee --- /dev/null +++ b/python/src/v2.0/fpy.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// fpy declarations +namespace python_fpy { + void wrapTime(python::module &); + void wrapEnergy(python::module &); + void wrapNuclides(python::module &); + void wrapYields(python::module &); + void wrapIncidentEnergy(python::module &); + void wrapIncidentEnergies(python::module &); + void wrapElapsedTime(python::module &); + void wrapElapsedTimes(python::module &); + void wrapProductYield(python::module &); + void wrapProductYields(python::module &); +} // namespace python_fpy + +// fpy wrapper +void wrapFpy(python::module &module) +{ + // create the fpy submodule + python::module submodule = module.def_submodule( + "fpy", + "GNDS v2.0 fpy" + ); + + // wrap fpy components + python_fpy::wrapTime(submodule); + python_fpy::wrapEnergy(submodule); + python_fpy::wrapNuclides(submodule); + python_fpy::wrapYields(submodule); + python_fpy::wrapIncidentEnergy(submodule); + python_fpy::wrapIncidentEnergies(submodule); + python_fpy::wrapElapsedTime(submodule); + python_fpy::wrapElapsedTimes(submodule); + python_fpy::wrapProductYield(submodule); + python_fpy::wrapProductYields(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/ElapsedTime.python.cpp b/python/src/v2.0/fpy/ElapsedTime.python.cpp new file mode 100644 index 000000000..94dcdc678 --- /dev/null +++ b/python/src/v2.0/fpy/ElapsedTime.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/ElapsedTime.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// ElapsedTime wrapper +void wrapElapsedTime(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::ElapsedTime; + using _t = std::variant< + fpy::IncidentEnergies, + fpy::Yields + >; + + // create the component + python::class_ component( + module, + "ElapsedTime", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const fpy::Time &, + const _t & + >(), + python::arg("label") = std::nullopt, + python::arg("time"), + python::arg("_incident_energiesyields"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "time", + python::overload_cast<>(&Component::time), + Component::documentation("time").data() + ) + .def_property_readonly( + "incident_energies", + python::overload_cast<>(&Component::incidentEnergies), + Component::documentation("incident_energies").data() + ) + .def_property_readonly( + "yields", + python::overload_cast<>(&Component::yields), + Component::documentation("yields").data() + ) + .def_property_readonly( + "_incident_energiesyields", + python::overload_cast<>(&Component::_incidentEnergiesyields), + Component::documentation("_incident_energiesyields").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/ElapsedTimes.python.cpp b/python/src/v2.0/fpy/ElapsedTimes.python.cpp new file mode 100644 index 000000000..f22e9378f --- /dev/null +++ b/python/src/v2.0/fpy/ElapsedTimes.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/ElapsedTimes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// ElapsedTimes wrapper +void wrapElapsedTimes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::ElapsedTimes; + + // create the component + python::class_ component( + module, + "ElapsedTimes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("elapsed_time"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "elapsed_time", + python::overload_cast<>(&Component::elapsedTime), + Component::documentation("elapsed_time").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/Energy.python.cpp b/python/src/v2.0/fpy/Energy.python.cpp new file mode 100644 index 000000000..142ba67d4 --- /dev/null +++ b/python/src/v2.0/fpy/Energy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/Energy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// Energy wrapper +void wrapEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::Energy; + + // create the component + python::class_ component( + module, + "Energy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Double & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/IncidentEnergies.python.cpp b/python/src/v2.0/fpy/IncidentEnergies.python.cpp new file mode 100644 index 000000000..3b4138ae8 --- /dev/null +++ b/python/src/v2.0/fpy/IncidentEnergies.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/IncidentEnergies.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// IncidentEnergies wrapper +void wrapIncidentEnergies(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::IncidentEnergies; + + // create the component + python::class_ component( + module, + "IncidentEnergies", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("incident_energy"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "incident_energy", + python::overload_cast<>(&Component::incidentEnergy), + Component::documentation("incident_energy").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/IncidentEnergy.python.cpp b/python/src/v2.0/fpy/IncidentEnergy.python.cpp new file mode 100644 index 000000000..61fb000ac --- /dev/null +++ b/python/src/v2.0/fpy/IncidentEnergy.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/IncidentEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// IncidentEnergy wrapper +void wrapIncidentEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::IncidentEnergy; + + // create the component + python::class_ component( + module, + "IncidentEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const fpy::Energy &, + const fpy::Yields & + >(), + python::arg("label"), + python::arg("energy"), + python::arg("yields"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "energy", + python::overload_cast<>(&Component::energy), + Component::documentation("energy").data() + ) + .def_property_readonly( + "yields", + python::overload_cast<>(&Component::yields), + Component::documentation("yields").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/Nuclides.python.cpp b/python/src/v2.0/fpy/Nuclides.python.cpp new file mode 100644 index 000000000..c3829ef26 --- /dev/null +++ b/python/src/v2.0/fpy/Nuclides.python.cpp @@ -0,0 +1,92 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/Nuclides.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// Nuclides wrapper +void wrapNuclides(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::Nuclides; + + // create the component + python::class_ component( + module, + "Nuclides", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("ints"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("doubles"), + Component::documentation("constructor").data() + ) + .def( + python::init< + const std::vector & + >(), + python::arg("strings"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "ints", + [] (const Component &self) { return self.ints(); }, + Component::documentation("ints").data() + ) + .def_property_readonly( + "doubles", + [] (const Component &self) { return self.doubles(); }, + Component::documentation("doubles").data() + ) + .def_property_readonly( + "strings", + [] (const Component &self) { return self.strings(); }, + Component::documentation("strings").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/ProductYield.python.cpp b/python/src/v2.0/fpy/ProductYield.python.cpp new file mode 100644 index 000000000..1ea7dad70 --- /dev/null +++ b/python/src/v2.0/fpy/ProductYield.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/ProductYield.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// ProductYield wrapper +void wrapProductYield(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::ProductYield; + + // create the component + python::class_ component( + module, + "ProductYield", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const fpy::ElapsedTimes &, + const std::optional & + >(), + python::arg("label"), + python::arg("elapsed_times"), + python::arg("nuclides") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "elapsed_times", + python::overload_cast<>(&Component::elapsedTimes), + Component::documentation("elapsed_times").data() + ) + .def_property_readonly( + "nuclides", + python::overload_cast<>(&Component::nuclides), + Component::documentation("nuclides").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/ProductYields.python.cpp b/python/src/v2.0/fpy/ProductYields.python.cpp new file mode 100644 index 000000000..5b1d2e7ea --- /dev/null +++ b/python/src/v2.0/fpy/ProductYields.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/ProductYields.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// ProductYields wrapper +void wrapProductYields(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::ProductYields; + + // create the component + python::class_ component( + module, + "ProductYields", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("product_yield"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "product_yield", + python::overload_cast<>(&Component::productYield), + Component::documentation("product_yield").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/Time.python.cpp b/python/src/v2.0/fpy/Time.python.cpp new file mode 100644 index 000000000..9776283a0 --- /dev/null +++ b/python/src/v2.0/fpy/Time.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/Time.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// Time wrapper +void wrapTime(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::Time; + using _t = std::variant< + containers::Double, + containers::String + >; + + // create the component + python::class_ component( + module, + "Time", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_doublestring"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + .def_property_readonly( + "string", + python::overload_cast<>(&Component::string), + Component::documentation("string").data() + ) + .def_property_readonly( + "_doublestring", + python::overload_cast<>(&Component::_Doublestring), + Component::documentation("_doublestring").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/fpy/Yields.python.cpp b/python/src/v2.0/fpy/Yields.python.cpp new file mode 100644 index 000000000..fbc74c730 --- /dev/null +++ b/python/src/v2.0/fpy/Yields.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/fpy/Yields.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_fpy { + +// Yields wrapper +void wrapYields(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = fpy::Yields; + + // create the component + python::class_ component( + module, + "Yields", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const fpy::Nuclides &, + const containers::Values & + >(), + python::arg("nuclides"), + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "nuclides", + python::overload_cast<>(&Component::nuclides), + Component::documentation("nuclides").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_fpy +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops.python.cpp b/python/src/v2.0/pops.python.cpp new file mode 100644 index 000000000..0f178d45c --- /dev/null +++ b/python/src/v2.0/pops.python.cpp @@ -0,0 +1,129 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// pops declarations +namespace python_pops { + void wrapAlias(python::module &); + void wrapMetaStable(python::module &); + void wrapAliases(python::module &); + void wrapCharge(python::module &); + void wrapAverageEnergy(python::module &); + void wrapAverageEnergies(python::module &); + void wrapQ(python::module &); + void wrapProduct(python::module &); + void wrapProducts(python::module &); + void wrapDecay(python::module &); + void wrapDecayPath(python::module &); + void wrapShell(python::module &); + void wrapInternalConversionCoefficients(python::module &); + void wrapPhotonEmissionProbabilities(python::module &); + void wrapProbability(python::module &); + void wrapContinuum(python::module &); + void wrapEnergy(python::module &); + void wrapIntensity(python::module &); + void wrapInternalPairFormationCoefficient(python::module &); + void wrapDiscrete(python::module &); + void wrapSpectrum(python::module &); + void wrapSpectra(python::module &); + void wrapDecayMode(python::module &); + void wrapDecayModes(python::module &); + void wrapDecayData(python::module &); + void wrapHalflife(python::module &); + void wrapMass(python::module &); + void wrapParity(python::module &); + void wrapSpin(python::module &); + void wrapBaryon(python::module &); + void wrapBaryons(python::module &); + void wrapBindingEnergy(python::module &); + void wrapConfiguration(python::module &); + void wrapConfigurations(python::module &); + void wrapAtomic(python::module &); + void wrapEnergy(python::module &); + void wrapNucleus(python::module &); + void wrapNuclide(python::module &); + void wrapNuclides(python::module &); + void wrapIsotope(python::module &); + void wrapIsotopes(python::module &); + void wrapChemicalElement(python::module &); + void wrapChemicalElements(python::module &); + void wrapGaugeBoson(python::module &); + void wrapGaugeBosons(python::module &); + void wrapLepton(python::module &); + void wrapLeptons(python::module &); + void wrapUnorthodox(python::module &); + void wrapUnorthodoxes(python::module &); + void wrapPoPs(python::module &); +} // namespace python_pops + +// pops wrapper +void wrapPops(python::module &module) +{ + // create the pops submodule + python::module submodule = module.def_submodule( + "pops", + "GNDS v2.0 pops" + ); + + // wrap pops components + python_pops::wrapAlias(submodule); + python_pops::wrapMetaStable(submodule); + python_pops::wrapAliases(submodule); + python_pops::wrapCharge(submodule); + python_pops::wrapAverageEnergy(submodule); + python_pops::wrapAverageEnergies(submodule); + python_pops::wrapQ(submodule); + python_pops::wrapProduct(submodule); + python_pops::wrapProducts(submodule); + python_pops::wrapDecay(submodule); + python_pops::wrapDecayPath(submodule); + python_pops::wrapShell(submodule); + python_pops::wrapInternalConversionCoefficients(submodule); + python_pops::wrapPhotonEmissionProbabilities(submodule); + python_pops::wrapProbability(submodule); + python_pops::wrapContinuum(submodule); + python_pops::wrapEnergy(submodule); + python_pops::wrapIntensity(submodule); + python_pops::wrapInternalPairFormationCoefficient(submodule); + python_pops::wrapDiscrete(submodule); + python_pops::wrapSpectrum(submodule); + python_pops::wrapSpectra(submodule); + python_pops::wrapDecayMode(submodule); + python_pops::wrapDecayModes(submodule); + python_pops::wrapDecayData(submodule); + python_pops::wrapHalflife(submodule); + python_pops::wrapMass(submodule); + python_pops::wrapParity(submodule); + python_pops::wrapSpin(submodule); + python_pops::wrapBaryon(submodule); + python_pops::wrapBaryons(submodule); + python_pops::wrapBindingEnergy(submodule); + python_pops::wrapConfiguration(submodule); + python_pops::wrapConfigurations(submodule); + python_pops::wrapAtomic(submodule); + python_pops::wrapEnergy(submodule); + python_pops::wrapNucleus(submodule); + python_pops::wrapNuclide(submodule); + python_pops::wrapNuclides(submodule); + python_pops::wrapIsotope(submodule); + python_pops::wrapIsotopes(submodule); + python_pops::wrapChemicalElement(submodule); + python_pops::wrapChemicalElements(submodule); + python_pops::wrapGaugeBoson(submodule); + python_pops::wrapGaugeBosons(submodule); + python_pops::wrapLepton(submodule); + python_pops::wrapLeptons(submodule); + python_pops::wrapUnorthodox(submodule); + python_pops::wrapUnorthodoxes(submodule); + python_pops::wrapPoPs(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Alias.python.cpp b/python/src/v2.0/pops/Alias.python.cpp new file mode 100644 index 000000000..44c9f4e32 --- /dev/null +++ b/python/src/v2.0/pops/Alias.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Alias.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Alias wrapper +void wrapAlias(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Alias; + + // create the component + python::class_ component( + module, + "Alias", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("id"), + python::arg("pid"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Aliases.python.cpp b/python/src/v2.0/pops/Aliases.python.cpp new file mode 100644 index 000000000..7aa384847 --- /dev/null +++ b/python/src/v2.0/pops/Aliases.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Aliases.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Aliases wrapper +void wrapAliases(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Aliases; + + // create the component + python::class_ component( + module, + "Aliases", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> &, + const std::optional> & + >(), + python::arg("alias") = std::nullopt, + python::arg("meta_stable") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "alias", + python::overload_cast<>(&Component::alias), + Component::documentation("alias").data() + ) + .def_property_readonly( + "meta_stable", + python::overload_cast<>(&Component::metaStable), + Component::documentation("meta_stable").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Atomic.python.cpp b/python/src/v2.0/pops/Atomic.python.cpp new file mode 100644 index 000000000..3a2b35c71 --- /dev/null +++ b/python/src/v2.0/pops/Atomic.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Atomic.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Atomic wrapper +void wrapAtomic(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Atomic; + + // create the component + python::class_ component( + module, + "Atomic", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("configurations") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "configurations", + python::overload_cast<>(&Component::configurations), + Component::documentation("configurations").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/AverageEnergies.python.cpp b/python/src/v2.0/pops/AverageEnergies.python.cpp new file mode 100644 index 000000000..fddc39ac7 --- /dev/null +++ b/python/src/v2.0/pops/AverageEnergies.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/AverageEnergies.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// AverageEnergies wrapper +void wrapAverageEnergies(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::AverageEnergies; + + // create the component + python::class_ component( + module, + "AverageEnergies", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("average_energy"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "average_energy", + python::overload_cast<>(&Component::averageEnergy), + Component::documentation("average_energy").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/AverageEnergy.python.cpp b/python/src/v2.0/pops/AverageEnergy.python.cpp new file mode 100644 index 000000000..109763339 --- /dev/null +++ b/python/src/v2.0/pops/AverageEnergy.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/AverageEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// AverageEnergy wrapper +void wrapAverageEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::AverageEnergy; + + // create the component + python::class_ component( + module, + "AverageEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const Float64 & + >(), + python::arg("label"), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Baryon.python.cpp b/python/src/v2.0/pops/Baryon.python.cpp new file mode 100644 index 000000000..6475c9ead --- /dev/null +++ b/python/src/v2.0/pops/Baryon.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Baryon.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Baryon wrapper +void wrapBaryon(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Baryon; + + // create the component + python::class_ component( + module, + "Baryon", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("id"), + python::arg("charge") = std::nullopt, + python::arg("decay_data") = std::nullopt, + python::arg("halflife") = std::nullopt, + python::arg("mass") = std::nullopt, + python::arg("parity") = std::nullopt, + python::arg("spin") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + .def_property_readonly( + "halflife", + python::overload_cast<>(&Component::halflife), + Component::documentation("halflife").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + .def_property_readonly( + "parity", + python::overload_cast<>(&Component::parity), + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + python::overload_cast<>(&Component::spin), + Component::documentation("spin").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Baryons.python.cpp b/python/src/v2.0/pops/Baryons.python.cpp new file mode 100644 index 000000000..29dd9732d --- /dev/null +++ b/python/src/v2.0/pops/Baryons.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Baryons.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Baryons wrapper +void wrapBaryons(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Baryons; + + // create the component + python::class_ component( + module, + "Baryons", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("baryon") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "baryon", + python::overload_cast<>(&Component::baryon), + Component::documentation("baryon").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/BindingEnergy.python.cpp b/python/src/v2.0/pops/BindingEnergy.python.cpp new file mode 100644 index 000000000..17f2df4d8 --- /dev/null +++ b/python/src/v2.0/pops/BindingEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/BindingEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// BindingEnergy wrapper +void wrapBindingEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::BindingEnergy; + + // create the component + python::class_ component( + module, + "BindingEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("double") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Charge.python.cpp b/python/src/v2.0/pops/Charge.python.cpp new file mode 100644 index 000000000..ebb7e5889 --- /dev/null +++ b/python/src/v2.0/pops/Charge.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Charge.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Charge wrapper +void wrapCharge(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Charge; + using _t = std::variant< + containers::Fraction, + containers::Integer + >; + + // create the component + python::class_ component( + module, + "Charge", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_fractioninteger"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "fraction", + python::overload_cast<>(&Component::fraction), + Component::documentation("fraction").data() + ) + .def_property_readonly( + "integer", + python::overload_cast<>(&Component::integer), + Component::documentation("integer").data() + ) + .def_property_readonly( + "_fractioninteger", + python::overload_cast<>(&Component::_fractioninteger), + Component::documentation("_fractioninteger").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/ChemicalElement.python.cpp b/python/src/v2.0/pops/ChemicalElement.python.cpp new file mode 100644 index 000000000..4ab5f32a6 --- /dev/null +++ b/python/src/v2.0/pops/ChemicalElement.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/ChemicalElement.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// ChemicalElement wrapper +void wrapChemicalElement(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::ChemicalElement; + + // create the component + python::class_ component( + module, + "ChemicalElement", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("z"), + python::arg("name") = std::nullopt, + python::arg("symbol"), + python::arg("atomic") = std::nullopt, + python::arg("isotopes") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "z", + &Component::Z, + Component::documentation("z").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "symbol", + &Component::symbol, + Component::documentation("symbol").data() + ) + .def_property_readonly( + "atomic", + python::overload_cast<>(&Component::atomic), + Component::documentation("atomic").data() + ) + .def_property_readonly( + "isotopes", + python::overload_cast<>(&Component::isotopes), + Component::documentation("isotopes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/ChemicalElements.python.cpp b/python/src/v2.0/pops/ChemicalElements.python.cpp new file mode 100644 index 000000000..0f6112db2 --- /dev/null +++ b/python/src/v2.0/pops/ChemicalElements.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/ChemicalElements.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// ChemicalElements wrapper +void wrapChemicalElements(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::ChemicalElements; + + // create the component + python::class_ component( + module, + "ChemicalElements", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("chemical_element") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "chemical_element", + python::overload_cast<>(&Component::chemicalElement), + Component::documentation("chemical_element").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Configuration.python.cpp b/python/src/v2.0/pops/Configuration.python.cpp new file mode 100644 index 000000000..48c95dd4f --- /dev/null +++ b/python/src/v2.0/pops/Configuration.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Configuration.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Configuration wrapper +void wrapConfiguration(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Configuration; + + // create the component + python::class_ component( + module, + "Configuration", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const std::string &, + const pops::BindingEnergy &, + const std::optional & + >(), + python::arg("electron_number"), + python::arg("subshell"), + python::arg("binding_energy"), + python::arg("decay_data") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "electron_number", + &Component::electronNumber, + Component::documentation("electron_number").data() + ) + .def_property_readonly( + "subshell", + &Component::subshell, + Component::documentation("subshell").data() + ) + .def_property_readonly( + "binding_energy", + python::overload_cast<>(&Component::bindingEnergy), + Component::documentation("binding_energy").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Configurations.python.cpp b/python/src/v2.0/pops/Configurations.python.cpp new file mode 100644 index 000000000..9f7525447 --- /dev/null +++ b/python/src/v2.0/pops/Configurations.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Configurations.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Configurations wrapper +void wrapConfigurations(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Configurations; + + // create the component + python::class_ component( + module, + "Configurations", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("configuration"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "configuration", + python::overload_cast<>(&Component::configuration), + Component::documentation("configuration").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Continuum.python.cpp b/python/src/v2.0/pops/Continuum.python.cpp new file mode 100644 index 000000000..5730a879d --- /dev/null +++ b/python/src/v2.0/pops/Continuum.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Continuum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Continuum wrapper +void wrapContinuum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Continuum; + + // create the component + python::class_ component( + module, + "Continuum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Decay.python.cpp b/python/src/v2.0/pops/Decay.python.cpp new file mode 100644 index 000000000..f4174df78 --- /dev/null +++ b/python/src/v2.0/pops/Decay.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Decay.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Decay wrapper +void wrapDecay(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Decay; + + // create the component + python::class_ component( + module, + "Decay", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const Integer32 &, + const std::optional &, + const std::optional & + >(), + python::arg("complete") = std::nullopt, + python::arg("index"), + python::arg("mode") = std::nullopt, + python::arg("products") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "complete", + [](const Component &self) { return self.complete().value(); }, + Component::documentation("complete").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "mode", + &Component::mode, + Component::documentation("mode").data() + ) + .def_property_readonly( + "products", + python::overload_cast<>(&Component::products), + Component::documentation("products").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/DecayData.python.cpp b/python/src/v2.0/pops/DecayData.python.cpp new file mode 100644 index 000000000..d55ceace9 --- /dev/null +++ b/python/src/v2.0/pops/DecayData.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/DecayData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// DecayData wrapper +void wrapDecayData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::DecayData; + + // create the component + python::class_ component( + module, + "DecayData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("average_energies") = std::nullopt, + python::arg("decay_modes") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "average_energies", + python::overload_cast<>(&Component::averageEnergies), + Component::documentation("average_energies").data() + ) + .def_property_readonly( + "decay_modes", + python::overload_cast<>(&Component::decayModes), + Component::documentation("decay_modes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/DecayMode.python.cpp b/python/src/v2.0/pops/DecayMode.python.cpp new file mode 100644 index 000000000..630db23af --- /dev/null +++ b/python/src/v2.0/pops/DecayMode.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/DecayMode.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// DecayMode wrapper +void wrapDecayMode(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::DecayMode; + + // create the component + python::class_ component( + module, + "DecayMode", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const enums::DecayType &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const pops::Probability &, + const std::optional & + >(), + python::arg("label"), + python::arg("mode"), + python::arg("q") = std::nullopt, + python::arg("decay_path") = std::nullopt, + python::arg("internal_conversion_coefficients") = std::nullopt, + python::arg("photon_emission_probabilities") = std::nullopt, + python::arg("probability"), + python::arg("spectra") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "mode", + &Component::mode, + Component::documentation("mode").data() + ) + .def_property_readonly( + "q", + python::overload_cast<>(&Component::Q), + Component::documentation("q").data() + ) + .def_property_readonly( + "decay_path", + python::overload_cast<>(&Component::decayPath), + Component::documentation("decay_path").data() + ) + .def_property_readonly( + "internal_conversion_coefficients", + python::overload_cast<>(&Component::internalConversionCoefficients), + Component::documentation("internal_conversion_coefficients").data() + ) + .def_property_readonly( + "photon_emission_probabilities", + python::overload_cast<>(&Component::photonEmissionProbabilities), + Component::documentation("photon_emission_probabilities").data() + ) + .def_property_readonly( + "probability", + python::overload_cast<>(&Component::probability), + Component::documentation("probability").data() + ) + .def_property_readonly( + "spectra", + python::overload_cast<>(&Component::spectra), + Component::documentation("spectra").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/DecayModes.python.cpp b/python/src/v2.0/pops/DecayModes.python.cpp new file mode 100644 index 000000000..c13e0a8fa --- /dev/null +++ b/python/src/v2.0/pops/DecayModes.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/DecayModes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// DecayModes wrapper +void wrapDecayModes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::DecayModes; + + // create the component + python::class_ component( + module, + "DecayModes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("decay_mode"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "decay_mode", + python::overload_cast<>(&Component::decayMode), + Component::documentation("decay_mode").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/DecayPath.python.cpp b/python/src/v2.0/pops/DecayPath.python.cpp new file mode 100644 index 000000000..f6e2b0811 --- /dev/null +++ b/python/src/v2.0/pops/DecayPath.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/DecayPath.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// DecayPath wrapper +void wrapDecayPath(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::DecayPath; + + // create the component + python::class_ component( + module, + "DecayPath", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("decay"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "decay", + python::overload_cast<>(&Component::decay), + Component::documentation("decay").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Discrete.python.cpp b/python/src/v2.0/pops/Discrete.python.cpp new file mode 100644 index 000000000..b1cbe0a1e --- /dev/null +++ b/python/src/v2.0/pops/Discrete.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Discrete.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Discrete wrapper +void wrapDiscrete(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Discrete; + + // create the component + python::class_ component( + module, + "Discrete", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const pops::Energy &, + const pops::Intensity &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("type") = std::nullopt, + python::arg("energy"), + python::arg("intensity"), + python::arg("internal_conversion_coefficients") = std::nullopt, + python::arg("internal_pair_formation_coefficient") = std::nullopt, + python::arg("photon_emission_probabilities") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + .def_property_readonly( + "energy", + python::overload_cast<>(&Component::energy), + Component::documentation("energy").data() + ) + .def_property_readonly( + "intensity", + python::overload_cast<>(&Component::intensity), + Component::documentation("intensity").data() + ) + .def_property_readonly( + "internal_conversion_coefficients", + python::overload_cast<>(&Component::internalConversionCoefficients), + Component::documentation("internal_conversion_coefficients").data() + ) + .def_property_readonly( + "internal_pair_formation_coefficient", + python::overload_cast<>(&Component::internalPairFormationCoefficient), + Component::documentation("internal_pair_formation_coefficient").data() + ) + .def_property_readonly( + "photon_emission_probabilities", + python::overload_cast<>(&Component::photonEmissionProbabilities), + Component::documentation("photon_emission_probabilities").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Energy.python.cpp b/python/src/v2.0/pops/Energy.python.cpp new file mode 100644 index 000000000..ec2f9a194 --- /dev/null +++ b/python/src/v2.0/pops/Energy.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Energy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Energy wrapper +void wrapEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Energy; + + // create the component + python::class_ component( + module, + "Energy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 &, + const std::optional> & + >(), + python::arg("unit"), + python::arg("value"), + python::arg("double") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/GaugeBoson.python.cpp b/python/src/v2.0/pops/GaugeBoson.python.cpp new file mode 100644 index 000000000..83ea4000a --- /dev/null +++ b/python/src/v2.0/pops/GaugeBoson.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/GaugeBoson.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// GaugeBoson wrapper +void wrapGaugeBoson(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::GaugeBoson; + + // create the component + python::class_ component( + module, + "GaugeBoson", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("id"), + python::arg("charge") = std::nullopt, + python::arg("decay_data") = std::nullopt, + python::arg("halflife") = std::nullopt, + python::arg("mass") = std::nullopt, + python::arg("parity") = std::nullopt, + python::arg("spin") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + .def_property_readonly( + "halflife", + python::overload_cast<>(&Component::halflife), + Component::documentation("halflife").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + .def_property_readonly( + "parity", + python::overload_cast<>(&Component::parity), + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + python::overload_cast<>(&Component::spin), + Component::documentation("spin").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/GaugeBosons.python.cpp b/python/src/v2.0/pops/GaugeBosons.python.cpp new file mode 100644 index 000000000..f9a364045 --- /dev/null +++ b/python/src/v2.0/pops/GaugeBosons.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/GaugeBosons.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// GaugeBosons wrapper +void wrapGaugeBosons(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::GaugeBosons; + + // create the component + python::class_ component( + module, + "GaugeBosons", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("gauge_boson") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "gauge_boson", + python::overload_cast<>(&Component::gaugeBoson), + Component::documentation("gauge_boson").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Halflife.python.cpp b/python/src/v2.0/pops/Halflife.python.cpp new file mode 100644 index 000000000..a81ed4133 --- /dev/null +++ b/python/src/v2.0/pops/Halflife.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Halflife.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Halflife wrapper +void wrapHalflife(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Halflife; + using _t = std::variant< + containers::Double, + containers::String + >; + + // create the component + python::class_ component( + module, + "Halflife", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_doublestring"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + .def_property_readonly( + "string", + python::overload_cast<>(&Component::string), + Component::documentation("string").data() + ) + .def_property_readonly( + "_doublestring", + python::overload_cast<>(&Component::_Doublestring), + Component::documentation("_doublestring").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Intensity.python.cpp b/python/src/v2.0/pops/Intensity.python.cpp new file mode 100644 index 000000000..2032db005 --- /dev/null +++ b/python/src/v2.0/pops/Intensity.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Intensity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Intensity wrapper +void wrapIntensity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Intensity; + + // create the component + python::class_ component( + module, + "Intensity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/InternalConversionCoefficients.python.cpp b/python/src/v2.0/pops/InternalConversionCoefficients.python.cpp new file mode 100644 index 000000000..25dec44f6 --- /dev/null +++ b/python/src/v2.0/pops/InternalConversionCoefficients.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/InternalConversionCoefficients.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// InternalConversionCoefficients wrapper +void wrapInternalConversionCoefficients(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::InternalConversionCoefficients; + + // create the component + python::class_ component( + module, + "InternalConversionCoefficients", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("shell"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "shell", + python::overload_cast<>(&Component::shell), + Component::documentation("shell").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/InternalPairFormationCoefficient.python.cpp b/python/src/v2.0/pops/InternalPairFormationCoefficient.python.cpp new file mode 100644 index 000000000..358d9794d --- /dev/null +++ b/python/src/v2.0/pops/InternalPairFormationCoefficient.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/InternalPairFormationCoefficient.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// InternalPairFormationCoefficient wrapper +void wrapInternalPairFormationCoefficient(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::InternalPairFormationCoefficient; + + // create the component + python::class_ component( + module, + "InternalPairFormationCoefficient", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Isotope.python.cpp b/python/src/v2.0/pops/Isotope.python.cpp new file mode 100644 index 000000000..51832486b --- /dev/null +++ b/python/src/v2.0/pops/Isotope.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Isotope.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Isotope wrapper +void wrapIsotope(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Isotope; + + // create the component + python::class_ component( + module, + "Isotope", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const XMLName &, + const std::optional & + >(), + python::arg("a"), + python::arg("symbol"), + python::arg("nuclides") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "a", + &Component::A, + Component::documentation("a").data() + ) + .def_property_readonly( + "symbol", + &Component::symbol, + Component::documentation("symbol").data() + ) + .def_property_readonly( + "nuclides", + python::overload_cast<>(&Component::nuclides), + Component::documentation("nuclides").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Isotopes.python.cpp b/python/src/v2.0/pops/Isotopes.python.cpp new file mode 100644 index 000000000..2d4224237 --- /dev/null +++ b/python/src/v2.0/pops/Isotopes.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Isotopes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Isotopes wrapper +void wrapIsotopes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Isotopes; + + // create the component + python::class_ component( + module, + "Isotopes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("isotope"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "isotope", + python::overload_cast<>(&Component::isotope), + Component::documentation("isotope").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Lepton.python.cpp b/python/src/v2.0/pops/Lepton.python.cpp new file mode 100644 index 000000000..71543dc5a --- /dev/null +++ b/python/src/v2.0/pops/Lepton.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Lepton.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Lepton wrapper +void wrapLepton(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Lepton; + + // create the component + python::class_ component( + module, + "Lepton", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("generation") = std::nullopt, + python::arg("id"), + python::arg("charge") = std::nullopt, + python::arg("decay_data") = std::nullopt, + python::arg("halflife") = std::nullopt, + python::arg("mass") = std::nullopt, + python::arg("parity") = std::nullopt, + python::arg("spin") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "generation", + &Component::generation, + Component::documentation("generation").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + .def_property_readonly( + "halflife", + python::overload_cast<>(&Component::halflife), + Component::documentation("halflife").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + .def_property_readonly( + "parity", + python::overload_cast<>(&Component::parity), + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + python::overload_cast<>(&Component::spin), + Component::documentation("spin").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Leptons.python.cpp b/python/src/v2.0/pops/Leptons.python.cpp new file mode 100644 index 000000000..644ac0c94 --- /dev/null +++ b/python/src/v2.0/pops/Leptons.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Leptons.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Leptons wrapper +void wrapLeptons(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Leptons; + + // create the component + python::class_ component( + module, + "Leptons", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("lepton"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "lepton", + python::overload_cast<>(&Component::lepton), + Component::documentation("lepton").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Mass.python.cpp b/python/src/v2.0/pops/Mass.python.cpp new file mode 100644 index 000000000..9a3337ddf --- /dev/null +++ b/python/src/v2.0/pops/Mass.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Mass.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Mass wrapper +void wrapMass(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Mass; + + // create the component + python::class_ component( + module, + "Mass", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("double") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/MetaStable.python.cpp b/python/src/v2.0/pops/MetaStable.python.cpp new file mode 100644 index 000000000..13ad8fcd3 --- /dev/null +++ b/python/src/v2.0/pops/MetaStable.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/MetaStable.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// MetaStable wrapper +void wrapMetaStable(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::MetaStable; + + // create the component + python::class_ component( + module, + "MetaStable", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Integer32 &, + const XMLName & + >(), + python::arg("id"), + python::arg("meta_stable_index"), + python::arg("pid"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "meta_stable_index", + &Component::metaStableIndex, + Component::documentation("meta_stable_index").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Nucleus.python.cpp b/python/src/v2.0/pops/Nucleus.python.cpp new file mode 100644 index 000000000..d7cb79869 --- /dev/null +++ b/python/src/v2.0/pops/Nucleus.python.cpp @@ -0,0 +1,112 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Nucleus.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Nucleus wrapper +void wrapNucleus(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Nucleus; + + // create the component + python::class_ component( + module, + "Nucleus", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Integer32 &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("id"), + python::arg("index"), + python::arg("charge") = std::nullopt, + python::arg("decay_data") = std::nullopt, + python::arg("energy") = std::nullopt, + python::arg("fission_fragment_data") = std::nullopt, + python::arg("halflife") = std::nullopt, + python::arg("parity") = std::nullopt, + python::arg("spin") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + .def_property_readonly( + "energy", + python::overload_cast<>(&Component::energy), + Component::documentation("energy").data() + ) + .def_property_readonly( + "fission_fragment_data", + python::overload_cast<>(&Component::fissionFragmentData), + Component::documentation("fission_fragment_data").data() + ) + .def_property_readonly( + "halflife", + python::overload_cast<>(&Component::halflife), + Component::documentation("halflife").data() + ) + .def_property_readonly( + "parity", + python::overload_cast<>(&Component::parity), + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + python::overload_cast<>(&Component::spin), + Component::documentation("spin").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Nuclide.python.cpp b/python/src/v2.0/pops/Nuclide.python.cpp new file mode 100644 index 000000000..fe604313f --- /dev/null +++ b/python/src/v2.0/pops/Nuclide.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Nuclide.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Nuclide wrapper +void wrapNuclide(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Nuclide; + + // create the component + python::class_ component( + module, + "Nuclide", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("id"), + python::arg("charge") = std::nullopt, + python::arg("decay_data") = std::nullopt, + python::arg("fission_fragment_data") = std::nullopt, + python::arg("mass") = std::nullopt, + python::arg("nucleus") = std::nullopt, + python::arg("parity") = std::nullopt, + python::arg("spin") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "decay_data", + python::overload_cast<>(&Component::decayData), + Component::documentation("decay_data").data() + ) + .def_property_readonly( + "fission_fragment_data", + python::overload_cast<>(&Component::fissionFragmentData), + Component::documentation("fission_fragment_data").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + .def_property_readonly( + "nucleus", + python::overload_cast<>(&Component::nucleus), + Component::documentation("nucleus").data() + ) + .def_property_readonly( + "parity", + python::overload_cast<>(&Component::parity), + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + python::overload_cast<>(&Component::spin), + Component::documentation("spin").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Nuclides.python.cpp b/python/src/v2.0/pops/Nuclides.python.cpp new file mode 100644 index 000000000..d0efa5f8e --- /dev/null +++ b/python/src/v2.0/pops/Nuclides.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Nuclides.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Nuclides wrapper +void wrapNuclides(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Nuclides; + + // create the component + python::class_ component( + module, + "Nuclides", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("nuclide"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "nuclide", + python::overload_cast<>(&Component::nuclide), + Component::documentation("nuclide").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Parity.python.cpp b/python/src/v2.0/pops/Parity.python.cpp new file mode 100644 index 000000000..82adc4a0f --- /dev/null +++ b/python/src/v2.0/pops/Parity.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Parity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Parity wrapper +void wrapParity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Parity; + + // create the component + python::class_ component( + module, + "Parity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("integer") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "integer", + python::overload_cast<>(&Component::integer), + Component::documentation("integer").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/PhotonEmissionProbabilities.python.cpp b/python/src/v2.0/pops/PhotonEmissionProbabilities.python.cpp new file mode 100644 index 000000000..05fe46b31 --- /dev/null +++ b/python/src/v2.0/pops/PhotonEmissionProbabilities.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/PhotonEmissionProbabilities.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// PhotonEmissionProbabilities wrapper +void wrapPhotonEmissionProbabilities(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::PhotonEmissionProbabilities; + + // create the component + python::class_ component( + module, + "PhotonEmissionProbabilities", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("shell"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "shell", + python::overload_cast<>(&Component::shell), + Component::documentation("shell").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/PoPs.python.cpp b/python/src/v2.0/pops/PoPs.python.cpp new file mode 100644 index 000000000..398704e0f --- /dev/null +++ b/python/src/v2.0/pops/PoPs.python.cpp @@ -0,0 +1,126 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/PoPs.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// PoPs wrapper +void wrapPoPs(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::PoPs; + + // create the component + python::class_ component( + module, + "PoPs", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("format"), + python::arg("name"), + python::arg("version"), + python::arg("aliases") = std::nullopt, + python::arg("baryons") = std::nullopt, + python::arg("chemical_elements") = std::nullopt, + python::arg("documentation") = std::nullopt, + python::arg("gauge_bosons") = std::nullopt, + python::arg("leptons") = std::nullopt, + python::arg("styles") = std::nullopt, + python::arg("unorthodoxes") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "format", + &Component::format, + Component::documentation("format").data() + ) + .def_property_readonly( + "name", + &Component::name, + Component::documentation("name").data() + ) + .def_property_readonly( + "version", + &Component::version, + Component::documentation("version").data() + ) + .def_property_readonly( + "aliases", + python::overload_cast<>(&Component::aliases), + Component::documentation("aliases").data() + ) + .def_property_readonly( + "baryons", + python::overload_cast<>(&Component::baryons), + Component::documentation("baryons").data() + ) + .def_property_readonly( + "chemical_elements", + python::overload_cast<>(&Component::chemicalElements), + Component::documentation("chemical_elements").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::doc), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "gauge_bosons", + python::overload_cast<>(&Component::gaugeBosons), + Component::documentation("gauge_bosons").data() + ) + .def_property_readonly( + "leptons", + python::overload_cast<>(&Component::leptons), + Component::documentation("leptons").data() + ) + .def_property_readonly( + "styles", + python::overload_cast<>(&Component::styles), + Component::documentation("styles").data() + ) + .def_property_readonly( + "unorthodoxes", + python::overload_cast<>(&Component::unorthodoxes), + Component::documentation("unorthodoxes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Probability.python.cpp b/python/src/v2.0/pops/Probability.python.cpp new file mode 100644 index 000000000..fce7fb4b1 --- /dev/null +++ b/python/src/v2.0/pops/Probability.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Probability.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Probability wrapper +void wrapProbability(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Probability; + + // create the component + python::class_ component( + module, + "Probability", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Product.python.cpp b/python/src/v2.0/pops/Product.python.cpp new file mode 100644 index 000000000..ed673aad8 --- /dev/null +++ b/python/src/v2.0/pops/Product.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Product.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Product wrapper +void wrapProduct(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Product; + + // create the component + python::class_ component( + module, + "Product", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("label"), + python::arg("pid"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Products.python.cpp b/python/src/v2.0/pops/Products.python.cpp new file mode 100644 index 000000000..d7467e5c6 --- /dev/null +++ b/python/src/v2.0/pops/Products.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Products.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Products wrapper +void wrapProducts(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Products; + + // create the component + python::class_ component( + module, + "Products", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("product"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "product", + python::overload_cast<>(&Component::product), + Component::documentation("product").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Q.python.cpp b/python/src/v2.0/pops/Q.python.cpp new file mode 100644 index 000000000..7246cf770 --- /dev/null +++ b/python/src/v2.0/pops/Q.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Q.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Q wrapper +void wrapQ(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Q; + + // create the component + python::class_ component( + module, + "Q", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Shell.python.cpp b/python/src/v2.0/pops/Shell.python.cpp new file mode 100644 index 000000000..a1b97297a --- /dev/null +++ b/python/src/v2.0/pops/Shell.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Shell.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Shell wrapper +void wrapShell(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Shell; + + // create the component + python::class_ component( + module, + "Shell", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const Float64 & + >(), + python::arg("label"), + python::arg("unit") = std::nullopt, + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "unit", + [](const Component &self) { return self.unit().value(); }, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Spectra.python.cpp b/python/src/v2.0/pops/Spectra.python.cpp new file mode 100644 index 000000000..da31db827 --- /dev/null +++ b/python/src/v2.0/pops/Spectra.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Spectra.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Spectra wrapper +void wrapSpectra(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Spectra; + + // create the component + python::class_ component( + module, + "Spectra", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("spectrum"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "spectrum", + python::overload_cast<>(&Component::spectrum), + Component::documentation("spectrum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Spectrum.python.cpp b/python/src/v2.0/pops/Spectrum.python.cpp new file mode 100644 index 000000000..6773d1bc3 --- /dev/null +++ b/python/src/v2.0/pops/Spectrum.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Spectrum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Spectrum wrapper +void wrapSpectrum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Spectrum; + + // create the component + python::class_ component( + module, + "Spectrum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const std::optional &, + const std::optional> & + >(), + python::arg("label"), + python::arg("pid"), + python::arg("continuum") = std::nullopt, + python::arg("discrete") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "continuum", + python::overload_cast<>(&Component::continuum), + Component::documentation("continuum").data() + ) + .def_property_readonly( + "discrete", + python::overload_cast<>(&Component::discrete), + Component::documentation("discrete").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Spin.python.cpp b/python/src/v2.0/pops/Spin.python.cpp new file mode 100644 index 000000000..624d7005c --- /dev/null +++ b/python/src/v2.0/pops/Spin.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Spin.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Spin wrapper +void wrapSpin(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Spin; + + // create the component + python::class_ component( + module, + "Spin", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("fraction") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "fraction", + python::overload_cast<>(&Component::fraction), + Component::documentation("fraction").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Unorthodox.python.cpp b/python/src/v2.0/pops/Unorthodox.python.cpp new file mode 100644 index 000000000..eaa3214aa --- /dev/null +++ b/python/src/v2.0/pops/Unorthodox.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Unorthodox.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Unorthodox wrapper +void wrapUnorthodox(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Unorthodox; + + // create the component + python::class_ component( + module, + "Unorthodox", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("id"), + python::arg("charge") = std::nullopt, + python::arg("mass") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "id", + &Component::id, + Component::documentation("id").data() + ) + .def_property_readonly( + "charge", + python::overload_cast<>(&Component::charge), + Component::documentation("charge").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/pops/Unorthodoxes.python.cpp b/python/src/v2.0/pops/Unorthodoxes.python.cpp new file mode 100644 index 000000000..ca46f1c53 --- /dev/null +++ b/python/src/v2.0/pops/Unorthodoxes.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/pops/Unorthodoxes.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_pops { + +// Unorthodoxes wrapper +void wrapUnorthodoxes(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = pops::Unorthodoxes; + + // create the component + python::class_ component( + module, + "Unorthodoxes", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("unorthodox"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unorthodox", + python::overload_cast<>(&Component::unorthodox), + Component::documentation("unorthodox").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_pops +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed.python.cpp b/python/src/v2.0/processed.python.cpp new file mode 100644 index 000000000..f556b0ec4 --- /dev/null +++ b/python/src/v2.0/processed.python.cpp @@ -0,0 +1,43 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// processed declarations +namespace python_processed { + void wrapAngularEnergyMC(python::module &); + void wrapEnergyAngularMC(python::module &); + void wrapMultiGroup3d(python::module &); + void wrapAvailableEnergy(python::module &); + void wrapAvailableMomentum(python::module &); + void wrapAverageProductEnergy(python::module &); + void wrapAverageProductMomentum(python::module &); +} // namespace python_processed + +// processed wrapper +void wrapProcessed(python::module &module) +{ + // create the processed submodule + python::module submodule = module.def_submodule( + "processed", + "GNDS v2.0 processed" + ); + + // wrap processed components + python_processed::wrapAngularEnergyMC(submodule); + python_processed::wrapEnergyAngularMC(submodule); + python_processed::wrapMultiGroup3d(submodule); + python_processed::wrapAvailableEnergy(submodule); + python_processed::wrapAvailableMomentum(submodule); + python_processed::wrapAverageProductEnergy(submodule); + python_processed::wrapAverageProductMomentum(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/AngularEnergyMC.python.cpp b/python/src/v2.0/processed/AngularEnergyMC.python.cpp new file mode 100644 index 000000000..f352cc53a --- /dev/null +++ b/python/src/v2.0/processed/AngularEnergyMC.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/AngularEnergyMC.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// AngularEnergyMC wrapper +void wrapAngularEnergyMC(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::AngularEnergyMC; + + // create the component + python::class_ component( + module, + "AngularEnergyMC", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const transport::Angular &, + const transport::AngularEnergy & + >(), + python::arg("label"), + python::arg("product_frame"), + python::arg("angular"), + python::arg("angular_energy"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "angular", + python::overload_cast<>(&Component::angular), + Component::documentation("angular").data() + ) + .def_property_readonly( + "angular_energy", + python::overload_cast<>(&Component::angularEnergy), + Component::documentation("angular_energy").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/AvailableEnergy.python.cpp b/python/src/v2.0/processed/AvailableEnergy.python.cpp new file mode 100644 index 000000000..be1210306 --- /dev/null +++ b/python/src/v2.0/processed/AvailableEnergy.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/AvailableEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// AvailableEnergy wrapper +void wrapAvailableEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::AvailableEnergy; + + // create the component + python::class_ component( + module, + "AvailableEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("gridded1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/AvailableMomentum.python.cpp b/python/src/v2.0/processed/AvailableMomentum.python.cpp new file mode 100644 index 000000000..43cb3ee40 --- /dev/null +++ b/python/src/v2.0/processed/AvailableMomentum.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/AvailableMomentum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// AvailableMomentum wrapper +void wrapAvailableMomentum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::AvailableMomentum; + + // create the component + python::class_ component( + module, + "AvailableMomentum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("gridded1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/AverageProductEnergy.python.cpp b/python/src/v2.0/processed/AverageProductEnergy.python.cpp new file mode 100644 index 000000000..1b0578f8b --- /dev/null +++ b/python/src/v2.0/processed/AverageProductEnergy.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/AverageProductEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// AverageProductEnergy wrapper +void wrapAverageProductEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::AverageProductEnergy; + + // create the component + python::class_ component( + module, + "AverageProductEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d &, + const std::optional & + >(), + python::arg("xys1d"), + python::arg("gridded1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/AverageProductMomentum.python.cpp b/python/src/v2.0/processed/AverageProductMomentum.python.cpp new file mode 100644 index 000000000..391855bac --- /dev/null +++ b/python/src/v2.0/processed/AverageProductMomentum.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/AverageProductMomentum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// AverageProductMomentum wrapper +void wrapAverageProductMomentum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::AverageProductMomentum; + + // create the component + python::class_ component( + module, + "AverageProductMomentum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("gridded1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/EnergyAngularMC.python.cpp b/python/src/v2.0/processed/EnergyAngularMC.python.cpp new file mode 100644 index 000000000..c86df1ab3 --- /dev/null +++ b/python/src/v2.0/processed/EnergyAngularMC.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/EnergyAngularMC.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// EnergyAngularMC wrapper +void wrapEnergyAngularMC(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::EnergyAngularMC; + + // create the component + python::class_ component( + module, + "EnergyAngularMC", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const ambiguousNamespace::Energy &, + const transport::EnergyAngular & + >(), + python::arg("label"), + python::arg("product_frame"), + python::arg("energy"), + python::arg("energy_angular"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "energy", + python::overload_cast<>(&Component::energy), + Component::documentation("energy").data() + ) + .def_property_readonly( + "energy_angular", + python::overload_cast<>(&Component::energyAngular), + Component::documentation("energy_angular").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/processed/MultiGroup3d.python.cpp b/python/src/v2.0/processed/MultiGroup3d.python.cpp new file mode 100644 index 000000000..e0750d29b --- /dev/null +++ b/python/src/v2.0/processed/MultiGroup3d.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/processed/MultiGroup3d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_processed { + +// MultiGroup3d wrapper +void wrapMultiGroup3d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = processed::MultiGroup3d; + + // create the component + python::class_ component( + module, + "MultiGroup3d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const containers::Gridded3d & + >(), + python::arg("label"), + python::arg("product_frame"), + python::arg("gridded3d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "gridded3d", + python::overload_cast<>(&Component::gridded3d), + Component::documentation("gridded3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_processed +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances.python.cpp b/python/src/v2.0/resonances.python.cpp new file mode 100644 index 000000000..f8520240d --- /dev/null +++ b/python/src/v2.0/resonances.python.cpp @@ -0,0 +1,79 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// resonances declarations +namespace python_resonances { + void wrapHardSphereRadius(python::module &); + void wrapResonanceParameters(python::module &); + void wrapScatteringRadius(python::module &); + void wrapBreitWigner(python::module &); + void wrapLevelSpacing(python::module &); + void wrapWidth(python::module &); + void wrapWidths(python::module &); + void wrapJ(python::module &); + void wrapJs(python::module &); + void wrapL(python::module &); + void wrapLs(python::module &); + void wrapResonanceReaction(python::module &); + void wrapResonanceReactions(python::module &); + void wrapExternalRMatrix(python::module &); + void wrapChannel(python::module &); + void wrapChannels(python::module &); + void wrapSpinGroup(python::module &); + void wrapSpinGroups(python::module &); + void wrapRMatrix(python::module &); + void wrapEnergyInterval(python::module &); + void wrapEnergyIntervals(python::module &); + void wrapResolved(python::module &); + void wrapTabulatedWidths(python::module &); + void wrapUnresolved(python::module &); + void wrapResonances(python::module &); +} // namespace python_resonances + +// resonances wrapper +void wrapResonances(python::module &module) +{ + // create the resonances submodule + python::module submodule = module.def_submodule( + "resonances", + "GNDS v2.0 resonances" + ); + + // wrap resonances components + python_resonances::wrapHardSphereRadius(submodule); + python_resonances::wrapResonanceParameters(submodule); + python_resonances::wrapScatteringRadius(submodule); + python_resonances::wrapBreitWigner(submodule); + python_resonances::wrapLevelSpacing(submodule); + python_resonances::wrapWidth(submodule); + python_resonances::wrapWidths(submodule); + python_resonances::wrapJ(submodule); + python_resonances::wrapJs(submodule); + python_resonances::wrapL(submodule); + python_resonances::wrapLs(submodule); + python_resonances::wrapResonanceReaction(submodule); + python_resonances::wrapResonanceReactions(submodule); + python_resonances::wrapExternalRMatrix(submodule); + python_resonances::wrapChannel(submodule); + python_resonances::wrapChannels(submodule); + python_resonances::wrapSpinGroup(submodule); + python_resonances::wrapSpinGroups(submodule); + python_resonances::wrapRMatrix(submodule); + python_resonances::wrapEnergyInterval(submodule); + python_resonances::wrapEnergyIntervals(submodule); + python_resonances::wrapResolved(submodule); + python_resonances::wrapTabulatedWidths(submodule); + python_resonances::wrapUnresolved(submodule); + python_resonances::wrapResonances(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/BreitWigner.python.cpp b/python/src/v2.0/resonances/BreitWigner.python.cpp new file mode 100644 index 000000000..bac9108b2 --- /dev/null +++ b/python/src/v2.0/resonances/BreitWigner.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/BreitWigner.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// BreitWigner wrapper +void wrapBreitWigner(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::BreitWigner; + + // create the component + python::class_ component( + module, + "BreitWigner", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("approximation"), + python::arg("calculate_channel_radius") = std::nullopt, + python::arg("label"), + python::arg("use_for_self_shielding_only") = std::nullopt, + python::arg("po_ps") = std::nullopt, + python::arg("hard_sphere_radius") = std::nullopt, + python::arg("resonance_parameters") = std::nullopt, + python::arg("scattering_radius") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "approximation", + &Component::approximation, + Component::documentation("approximation").data() + ) + .def_property_readonly( + "calculate_channel_radius", + [](const Component &self) { return self.calculateChannelRadius().value(); }, + Component::documentation("calculate_channel_radius").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "use_for_self_shielding_only", + [](const Component &self) { return self.useForSelfShieldingOnly().value(); }, + Component::documentation("use_for_self_shielding_only").data() + ) + .def_property_readonly( + "po_ps", + python::overload_cast<>(&Component::PoPs), + Component::documentation("po_ps").data() + ) + .def_property_readonly( + "hard_sphere_radius", + python::overload_cast<>(&Component::hardSphereRadius), + Component::documentation("hard_sphere_radius").data() + ) + .def_property_readonly( + "resonance_parameters", + python::overload_cast<>(&Component::resonanceParameters), + Component::documentation("resonance_parameters").data() + ) + .def_property_readonly( + "scattering_radius", + python::overload_cast<>(&Component::scatteringRadius), + Component::documentation("scattering_radius").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Channel.python.cpp b/python/src/v2.0/resonances/Channel.python.cpp new file mode 100644 index 000000000..4cedf1b43 --- /dev/null +++ b/python/src/v2.0/resonances/Channel.python.cpp @@ -0,0 +1,112 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Channel.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Channel wrapper +void wrapChannel(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Channel; + + // create the component + python::class_ component( + module, + "Channel", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const std::optional &, + const Fraction32 &, + const Integer32 &, + const XMLName &, + const std::string &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("l"), + python::arg("boundary_condition_value") = std::nullopt, + python::arg("channel_spin"), + python::arg("column_index"), + python::arg("label"), + python::arg("resonance_reaction"), + python::arg("external_rmatrix") = std::nullopt, + python::arg("hard_sphere_radius") = std::nullopt, + python::arg("scattering_radius") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "l", + &Component::L, + Component::documentation("l").data() + ) + .def_property_readonly( + "boundary_condition_value", + &Component::boundaryConditionValue, + Component::documentation("boundary_condition_value").data() + ) + .def_property_readonly( + "channel_spin", + &Component::channelSpin, + Component::documentation("channel_spin").data() + ) + .def_property_readonly( + "column_index", + &Component::columnIndex, + Component::documentation("column_index").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "resonance_reaction", + &Component::resonanceReaction, + Component::documentation("resonance_reaction").data() + ) + .def_property_readonly( + "external_rmatrix", + python::overload_cast<>(&Component::externalRMatrix), + Component::documentation("external_rmatrix").data() + ) + .def_property_readonly( + "hard_sphere_radius", + python::overload_cast<>(&Component::hardSphereRadius), + Component::documentation("hard_sphere_radius").data() + ) + .def_property_readonly( + "scattering_radius", + python::overload_cast<>(&Component::scatteringRadius), + Component::documentation("scattering_radius").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Channels.python.cpp b/python/src/v2.0/resonances/Channels.python.cpp new file mode 100644 index 000000000..4f0bbacec --- /dev/null +++ b/python/src/v2.0/resonances/Channels.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Channels.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Channels wrapper +void wrapChannels(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Channels; + + // create the component + python::class_ component( + module, + "Channels", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("channel"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "channel", + python::overload_cast<>(&Component::channel), + Component::documentation("channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/EnergyInterval.python.cpp b/python/src/v2.0/resonances/EnergyInterval.python.cpp new file mode 100644 index 000000000..66165ece1 --- /dev/null +++ b/python/src/v2.0/resonances/EnergyInterval.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/EnergyInterval.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// EnergyInterval wrapper +void wrapEnergyInterval(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::EnergyInterval; + using _t = std::variant< + resonances::BreitWigner, + resonances::RMatrix + >; + + // create the component + python::class_ component( + module, + "EnergyInterval", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const Float64 &, + const XMLName &, + const Integer32 &, + const _t & + >(), + python::arg("domain_max"), + python::arg("domain_min"), + python::arg("domain_unit"), + python::arg("index"), + python::arg("_breit_wigner_rmatrix"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "domain_unit", + &Component::domainUnit, + Component::documentation("domain_unit").data() + ) + .def_property_readonly( + "index", + &Component::index, + Component::documentation("index").data() + ) + .def_property_readonly( + "breit_wigner", + python::overload_cast<>(&Component::BreitWigner), + Component::documentation("breit_wigner").data() + ) + .def_property_readonly( + "rmatrix", + python::overload_cast<>(&Component::RMatrix), + Component::documentation("rmatrix").data() + ) + .def_property_readonly( + "_breit_wigner_rmatrix", + python::overload_cast<>(&Component::_BreitWignerRMatrix), + Component::documentation("_breit_wigner_rmatrix").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/EnergyIntervals.python.cpp b/python/src/v2.0/resonances/EnergyIntervals.python.cpp new file mode 100644 index 000000000..d47f3e5cc --- /dev/null +++ b/python/src/v2.0/resonances/EnergyIntervals.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/EnergyIntervals.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// EnergyIntervals wrapper +void wrapEnergyIntervals(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::EnergyIntervals; + + // create the component + python::class_ component( + module, + "EnergyIntervals", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::vector & + >(), + python::arg("label"), + python::arg("energy_interval"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "energy_interval", + python::overload_cast<>(&Component::energyInterval), + Component::documentation("energy_interval").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/ExternalRMatrix.python.cpp b/python/src/v2.0/resonances/ExternalRMatrix.python.cpp new file mode 100644 index 000000000..4b155ab6a --- /dev/null +++ b/python/src/v2.0/resonances/ExternalRMatrix.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/ExternalRMatrix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// ExternalRMatrix wrapper +void wrapExternalRMatrix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::ExternalRMatrix; + + // create the component + python::class_ component( + module, + "ExternalRMatrix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::vector & + >(), + python::arg("type"), + python::arg("double"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "type", + &Component::type, + Component::documentation("type").data() + ) + .def_property_readonly( + "double", + python::overload_cast<>(&Component::Double), + Component::documentation("double").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/HardSphereRadius.python.cpp b/python/src/v2.0/resonances/HardSphereRadius.python.cpp new file mode 100644 index 000000000..143ca77b9 --- /dev/null +++ b/python/src/v2.0/resonances/HardSphereRadius.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/HardSphereRadius.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// HardSphereRadius wrapper +void wrapHardSphereRadius(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::HardSphereRadius; + + // create the component + python::class_ component( + module, + "HardSphereRadius", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Constant1d & + >(), + python::arg("constant1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/J.python.cpp b/python/src/v2.0/resonances/J.python.cpp new file mode 100644 index 000000000..b5b43169b --- /dev/null +++ b/python/src/v2.0/resonances/J.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/J.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// J wrapper +void wrapJ(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::J; + + // create the component + python::class_ component( + module, + "J", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Fraction32 &, + const resonances::LevelSpacing &, + const resonances::Widths & + >(), + python::arg("label"), + python::arg("value"), + python::arg("level_spacing"), + python::arg("widths"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "level_spacing", + python::overload_cast<>(&Component::levelSpacing), + Component::documentation("level_spacing").data() + ) + .def_property_readonly( + "widths", + python::overload_cast<>(&Component::widths), + Component::documentation("widths").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Js.python.cpp b/python/src/v2.0/resonances/Js.python.cpp new file mode 100644 index 000000000..e8878e5d3 --- /dev/null +++ b/python/src/v2.0/resonances/Js.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Js.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Js wrapper +void wrapJs(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Js; + + // create the component + python::class_ component( + module, + "Js", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("j"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "j", + python::overload_cast<>(&Component::J), + Component::documentation("j").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/L.python.cpp b/python/src/v2.0/resonances/L.python.cpp new file mode 100644 index 000000000..e7ffceeea --- /dev/null +++ b/python/src/v2.0/resonances/L.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/L.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// L wrapper +void wrapL(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::L; + + // create the component + python::class_ component( + module, + "L", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Integer32 &, + const resonances::Js & + >(), + python::arg("label"), + python::arg("value"), + python::arg("js"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "js", + python::overload_cast<>(&Component::Js), + Component::documentation("js").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/LevelSpacing.python.cpp b/python/src/v2.0/resonances/LevelSpacing.python.cpp new file mode 100644 index 000000000..0856fb696 --- /dev/null +++ b/python/src/v2.0/resonances/LevelSpacing.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/LevelSpacing.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// LevelSpacing wrapper +void wrapLevelSpacing(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::LevelSpacing; + + // create the component + python::class_ component( + module, + "LevelSpacing", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("constant1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Ls.python.cpp b/python/src/v2.0/resonances/Ls.python.cpp new file mode 100644 index 000000000..8922da2dc --- /dev/null +++ b/python/src/v2.0/resonances/Ls.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Ls.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Ls wrapper +void wrapLs(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Ls; + + // create the component + python::class_ component( + module, + "Ls", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("l"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "l", + python::overload_cast<>(&Component::L), + Component::documentation("l").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/RMatrix.python.cpp b/python/src/v2.0/resonances/RMatrix.python.cpp new file mode 100644 index 000000000..784487410 --- /dev/null +++ b/python/src/v2.0/resonances/RMatrix.python.cpp @@ -0,0 +1,126 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/RMatrix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// RMatrix wrapper +void wrapRMatrix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::RMatrix; + + // create the component + python::class_ component( + module, + "RMatrix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const resonances::ResonanceReactions &, + const resonances::SpinGroups & + >(), + python::arg("approximation"), + python::arg("boundary_condition") = std::nullopt, + python::arg("boundary_condition_value") = std::nullopt, + python::arg("calculate_channel_radius") = std::nullopt, + python::arg("calculate_penetrability") = std::nullopt, + python::arg("label"), + python::arg("supports_angular_reconstruction") = std::nullopt, + python::arg("use_for_self_shielding_only") = std::nullopt, + python::arg("po_ps") = std::nullopt, + python::arg("resonance_reactions"), + python::arg("spin_groups"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "approximation", + &Component::approximation, + Component::documentation("approximation").data() + ) + .def_property_readonly( + "boundary_condition", + [](const Component &self) { return self.boundaryCondition().value(); }, + Component::documentation("boundary_condition").data() + ) + .def_property_readonly( + "boundary_condition_value", + &Component::boundaryConditionValue, + Component::documentation("boundary_condition_value").data() + ) + .def_property_readonly( + "calculate_channel_radius", + [](const Component &self) { return self.calculateChannelRadius().value(); }, + Component::documentation("calculate_channel_radius").data() + ) + .def_property_readonly( + "calculate_penetrability", + [](const Component &self) { return self.calculatePenetrability().value(); }, + Component::documentation("calculate_penetrability").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "supports_angular_reconstruction", + [](const Component &self) { return self.supportsAngularReconstruction().value(); }, + Component::documentation("supports_angular_reconstruction").data() + ) + .def_property_readonly( + "use_for_self_shielding_only", + [](const Component &self) { return self.useForSelfShieldingOnly().value(); }, + Component::documentation("use_for_self_shielding_only").data() + ) + .def_property_readonly( + "po_ps", + python::overload_cast<>(&Component::PoPs), + Component::documentation("po_ps").data() + ) + .def_property_readonly( + "resonance_reactions", + python::overload_cast<>(&Component::resonanceReactions), + Component::documentation("resonance_reactions").data() + ) + .def_property_readonly( + "spin_groups", + python::overload_cast<>(&Component::spinGroups), + Component::documentation("spin_groups").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Resolved.python.cpp b/python/src/v2.0/resonances/Resolved.python.cpp new file mode 100644 index 000000000..f35d22c87 --- /dev/null +++ b/python/src/v2.0/resonances/Resolved.python.cpp @@ -0,0 +1,97 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Resolved.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Resolved wrapper +void wrapResolved(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Resolved; + using _t = std::variant< + resonances::BreitWigner, + resonances::RMatrix, + resonances::EnergyIntervals + >; + + // create the component + python::class_ component( + module, + "Resolved", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const Float64 &, + const XMLName &, + const _t & + >(), + python::arg("domain_max"), + python::arg("domain_min"), + python::arg("domain_unit"), + python::arg("_breit_wigner_rmatrixenergy_intervals"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "domain_unit", + &Component::domainUnit, + Component::documentation("domain_unit").data() + ) + .def_property_readonly( + "breit_wigner", + python::overload_cast<>(&Component::BreitWigner), + Component::documentation("breit_wigner").data() + ) + .def_property_readonly( + "rmatrix", + python::overload_cast<>(&Component::RMatrix), + Component::documentation("rmatrix").data() + ) + .def_property_readonly( + "energy_intervals", + python::overload_cast<>(&Component::energyIntervals), + Component::documentation("energy_intervals").data() + ) + .def_property_readonly( + "_breit_wigner_rmatrixenergy_intervals", + python::overload_cast<>(&Component::_BreitWignerRMatrixenergyIntervals), + Component::documentation("_breit_wigner_rmatrixenergy_intervals").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/ResonanceParameters.python.cpp b/python/src/v2.0/resonances/ResonanceParameters.python.cpp new file mode 100644 index 000000000..024aac8b0 --- /dev/null +++ b/python/src/v2.0/resonances/ResonanceParameters.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/ResonanceParameters.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// ResonanceParameters wrapper +void wrapResonanceParameters(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::ResonanceParameters; + + // create the component + python::class_ component( + module, + "ResonanceParameters", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Table & + >(), + python::arg("table"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "table", + python::overload_cast<>(&Component::table), + Component::documentation("table").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/ResonanceReaction.python.cpp b/python/src/v2.0/resonances/ResonanceReaction.python.cpp new file mode 100644 index 000000000..9cc2caf23 --- /dev/null +++ b/python/src/v2.0/resonances/ResonanceReaction.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/ResonanceReaction.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// ResonanceReaction wrapper +void wrapResonanceReaction(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::ResonanceReaction; + + // create the component + python::class_ component( + module, + "ResonanceReaction", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional &, + const containers::Link &, + const std::optional & + >(), + python::arg("boundary_condition_value") = std::nullopt, + python::arg("ejectile"), + python::arg("eliminated") = std::nullopt, + python::arg("label"), + python::arg("q") = std::nullopt, + python::arg("hard_sphere_radius") = std::nullopt, + python::arg("link"), + python::arg("scattering_radius") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "boundary_condition_value", + &Component::boundaryConditionValue, + Component::documentation("boundary_condition_value").data() + ) + .def_property_readonly( + "ejectile", + &Component::ejectile, + Component::documentation("ejectile").data() + ) + .def_property_readonly( + "eliminated", + [](const Component &self) { return self.eliminated().value(); }, + Component::documentation("eliminated").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "q", + python::overload_cast<>(&Component::Q), + Component::documentation("q").data() + ) + .def_property_readonly( + "hard_sphere_radius", + python::overload_cast<>(&Component::hardSphereRadius), + Component::documentation("hard_sphere_radius").data() + ) + .def_property_readonly( + "link", + python::overload_cast<>(&Component::link), + Component::documentation("link").data() + ) + .def_property_readonly( + "scattering_radius", + python::overload_cast<>(&Component::scatteringRadius), + Component::documentation("scattering_radius").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/ResonanceReactions.python.cpp b/python/src/v2.0/resonances/ResonanceReactions.python.cpp new file mode 100644 index 000000000..4ecd83df7 --- /dev/null +++ b/python/src/v2.0/resonances/ResonanceReactions.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/ResonanceReactions.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// ResonanceReactions wrapper +void wrapResonanceReactions(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::ResonanceReactions; + + // create the component + python::class_ component( + module, + "ResonanceReactions", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("resonance_reaction"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "resonance_reaction", + python::overload_cast<>(&Component::resonanceReaction), + Component::documentation("resonance_reaction").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Resonances.python.cpp b/python/src/v2.0/resonances/Resonances.python.cpp new file mode 100644 index 000000000..687301304 --- /dev/null +++ b/python/src/v2.0/resonances/Resonances.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Resonances.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Resonances wrapper +void wrapResonances(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Resonances; + + // create the component + python::class_ component( + module, + "Resonances", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional> &, + const resonances::ScatteringRadius &, + const std::optional> & + >(), + python::arg("href") = std::nullopt, + python::arg("hard_sphere_radius") = std::nullopt, + python::arg("resolved") = std::nullopt, + python::arg("scattering_radius"), + python::arg("unresolved") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "hard_sphere_radius", + python::overload_cast<>(&Component::hardSphereRadius), + Component::documentation("hard_sphere_radius").data() + ) + .def_property_readonly( + "resolved", + python::overload_cast<>(&Component::resolved), + Component::documentation("resolved").data() + ) + .def_property_readonly( + "scattering_radius", + python::overload_cast<>(&Component::scatteringRadius), + Component::documentation("scattering_radius").data() + ) + .def_property_readonly( + "unresolved", + python::overload_cast<>(&Component::unresolved), + Component::documentation("unresolved").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/ScatteringRadius.python.cpp b/python/src/v2.0/resonances/ScatteringRadius.python.cpp new file mode 100644 index 000000000..711114000 --- /dev/null +++ b/python/src/v2.0/resonances/ScatteringRadius.python.cpp @@ -0,0 +1,76 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/ScatteringRadius.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// ScatteringRadius wrapper +void wrapScatteringRadius(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::ScatteringRadius; + using _t = std::variant< + containers::XYs1d, + containers::Constant1d, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "ScatteringRadius", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dconstant1dregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dconstant1dregions1d", + python::overload_cast<>(&Component::_XYs1dconstant1dregions1d), + Component::documentation("_xys1dconstant1dregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/SpinGroup.python.cpp b/python/src/v2.0/resonances/SpinGroup.python.cpp new file mode 100644 index 000000000..87f6145f9 --- /dev/null +++ b/python/src/v2.0/resonances/SpinGroup.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/SpinGroup.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// SpinGroup wrapper +void wrapSpinGroup(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::SpinGroup; + + // create the component + python::class_ component( + module, + "SpinGroup", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Integer32 &, + const Fraction32 &, + const resonances::Channels &, + const resonances::ResonanceParameters & + >(), + python::arg("label"), + python::arg("parity"), + python::arg("spin"), + python::arg("channels"), + python::arg("resonance_parameters"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "parity", + &Component::parity, + Component::documentation("parity").data() + ) + .def_property_readonly( + "spin", + &Component::spin, + Component::documentation("spin").data() + ) + .def_property_readonly( + "channels", + python::overload_cast<>(&Component::channels), + Component::documentation("channels").data() + ) + .def_property_readonly( + "resonance_parameters", + python::overload_cast<>(&Component::resonanceParameters), + Component::documentation("resonance_parameters").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/SpinGroups.python.cpp b/python/src/v2.0/resonances/SpinGroups.python.cpp new file mode 100644 index 000000000..20ff833e6 --- /dev/null +++ b/python/src/v2.0/resonances/SpinGroups.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/SpinGroups.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// SpinGroups wrapper +void wrapSpinGroups(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::SpinGroups; + + // create the component + python::class_ component( + module, + "SpinGroups", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("spin_group"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "spin_group", + python::overload_cast<>(&Component::spinGroup), + Component::documentation("spin_group").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/TabulatedWidths.python.cpp b/python/src/v2.0/resonances/TabulatedWidths.python.cpp new file mode 100644 index 000000000..5b4c51036 --- /dev/null +++ b/python/src/v2.0/resonances/TabulatedWidths.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/TabulatedWidths.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// TabulatedWidths wrapper +void wrapTabulatedWidths(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::TabulatedWidths; + + // create the component + python::class_ component( + module, + "TabulatedWidths", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const std::optional &, + const resonances::Ls &, + const std::optional &, + const std::optional &, + const resonances::ResonanceReactions &, + const std::optional & + >(), + python::arg("approximation"), + python::arg("label"), + python::arg("use_for_self_shielding_only") = std::nullopt, + python::arg("ls"), + python::arg("po_ps") = std::nullopt, + python::arg("hard_sphere_radius") = std::nullopt, + python::arg("resonance_reactions"), + python::arg("scattering_radius") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "approximation", + &Component::approximation, + Component::documentation("approximation").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "use_for_self_shielding_only", + [](const Component &self) { return self.useForSelfShieldingOnly().value(); }, + Component::documentation("use_for_self_shielding_only").data() + ) + .def_property_readonly( + "ls", + python::overload_cast<>(&Component::Ls), + Component::documentation("ls").data() + ) + .def_property_readonly( + "po_ps", + python::overload_cast<>(&Component::PoPs), + Component::documentation("po_ps").data() + ) + .def_property_readonly( + "hard_sphere_radius", + python::overload_cast<>(&Component::hardSphereRadius), + Component::documentation("hard_sphere_radius").data() + ) + .def_property_readonly( + "resonance_reactions", + python::overload_cast<>(&Component::resonanceReactions), + Component::documentation("resonance_reactions").data() + ) + .def_property_readonly( + "scattering_radius", + python::overload_cast<>(&Component::scatteringRadius), + Component::documentation("scattering_radius").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Unresolved.python.cpp b/python/src/v2.0/resonances/Unresolved.python.cpp new file mode 100644 index 000000000..04c0afd0a --- /dev/null +++ b/python/src/v2.0/resonances/Unresolved.python.cpp @@ -0,0 +1,85 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Unresolved.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Unresolved wrapper +void wrapUnresolved(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Unresolved; + using _t = std::variant< + resonances::TabulatedWidths + >; + + // create the component + python::class_ component( + module, + "Unresolved", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const Float64 &, + const XMLName &, + const _t & + >(), + python::arg("domain_max"), + python::arg("domain_min"), + python::arg("domain_unit"), + python::arg("_tabulated_widths"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "domain_unit", + &Component::domainUnit, + Component::documentation("domain_unit").data() + ) + .def_property_readonly( + "tabulated_widths", + python::overload_cast<>(&Component::tabulatedWidths), + Component::documentation("tabulated_widths").data() + ) + .def_property_readonly( + "_tabulated_widths", + python::overload_cast<>(&Component::_tabulatedWidths), + Component::documentation("_tabulated_widths").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Width.python.cpp b/python/src/v2.0/resonances/Width.python.cpp new file mode 100644 index 000000000..e13ecc14b --- /dev/null +++ b/python/src/v2.0/resonances/Width.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Width.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Width wrapper +void wrapWidth(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Width; + + // create the component + python::class_ component( + module, + "Width", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const std::string &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("degrees_of_freedom"), + python::arg("resonance_reaction"), + python::arg("xys1d") = std::nullopt, + python::arg("constant1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "degrees_of_freedom", + &Component::degreesOfFreedom, + Component::documentation("degrees_of_freedom").data() + ) + .def_property_readonly( + "resonance_reaction", + &Component::resonanceReaction, + Component::documentation("resonance_reaction").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/resonances/Widths.python.cpp b/python/src/v2.0/resonances/Widths.python.cpp new file mode 100644 index 000000000..600eeb8c6 --- /dev/null +++ b/python/src/v2.0/resonances/Widths.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/resonances/Widths.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_resonances { + +// Widths wrapper +void wrapWidths(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = resonances::Widths; + + // create the component + python::class_ component( + module, + "Widths", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("width"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "width", + python::overload_cast<>(&Component::width), + Component::documentation("width").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_resonances +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles.python.cpp b/python/src/v2.0/styles.python.cpp new file mode 100644 index 000000000..f5c4c5579 --- /dev/null +++ b/python/src/v2.0/styles.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// styles declarations +namespace python_styles { + void wrapMonteCarlo_cdf(python::module &); + void wrapSnElasticUpScatter(python::module &); + void wrapURR_probabilityTables(python::module &); + void wrapTemperature(python::module &); + void wrapAngularDistributionReconstructed(python::module &); + void wrapAverageProductData(python::module &); + void wrapCrossSectionReconstructed(python::module &); + void wrapProjectileEnergyDomain(python::module &); + void wrapEvaluated(python::module &); + void wrapGriddedCrossSection(python::module &); + void wrapHeated(python::module &); + void wrapFlux(python::module &); + void wrapInverseSpeed(python::module &); + void wrapMultiGroup(python::module &); + void wrapTransportable(python::module &); + void wrapTransportables(python::module &); + void wrapHeatedMultiGroup(python::module &); + void wrapStyles(python::module &); + void wrapSigmaZeros(python::module &); + void wrapBondarenko(python::module &); + void wrapCoulombPlusNuclearElasticMuCutoff(python::module &); + void wrapEqualProbableBins(python::module &); + void wrapMultiBand(python::module &); + void wrapRealization(python::module &); +} // namespace python_styles + +// styles wrapper +void wrapStyles(python::module &module) +{ + // create the styles submodule + python::module submodule = module.def_submodule( + "styles", + "GNDS v2.0 styles" + ); + + // wrap styles components + python_styles::wrapMonteCarlo_cdf(submodule); + python_styles::wrapSnElasticUpScatter(submodule); + python_styles::wrapURR_probabilityTables(submodule); + python_styles::wrapTemperature(submodule); + python_styles::wrapAngularDistributionReconstructed(submodule); + python_styles::wrapAverageProductData(submodule); + python_styles::wrapCrossSectionReconstructed(submodule); + python_styles::wrapProjectileEnergyDomain(submodule); + python_styles::wrapEvaluated(submodule); + python_styles::wrapGriddedCrossSection(submodule); + python_styles::wrapHeated(submodule); + python_styles::wrapFlux(submodule); + python_styles::wrapInverseSpeed(submodule); + python_styles::wrapMultiGroup(submodule); + python_styles::wrapTransportable(submodule); + python_styles::wrapTransportables(submodule); + python_styles::wrapHeatedMultiGroup(submodule); + python_styles::wrapStyles(submodule); + python_styles::wrapSigmaZeros(submodule); + python_styles::wrapBondarenko(submodule); + python_styles::wrapCoulombPlusNuclearElasticMuCutoff(submodule); + python_styles::wrapEqualProbableBins(submodule); + python_styles::wrapMultiBand(submodule); + python_styles::wrapRealization(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/AngularDistributionReconstructed.python.cpp b/python/src/v2.0/styles/AngularDistributionReconstructed.python.cpp new file mode 100644 index 000000000..c9a3a2e8a --- /dev/null +++ b/python/src/v2.0/styles/AngularDistributionReconstructed.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/AngularDistributionReconstructed.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// AngularDistributionReconstructed wrapper +void wrapAngularDistributionReconstructed(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::AngularDistributionReconstructed; + + // create the component + python::class_ component( + module, + "AngularDistributionReconstructed", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("date"), + python::arg("derived_from") = std::nullopt, + python::arg("label"), + python::arg("documentation") = std::nullopt, + python::arg("temperature") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "temperature", + python::overload_cast<>(&Component::temperature), + Component::documentation("temperature").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/AverageProductData.python.cpp b/python/src/v2.0/styles/AverageProductData.python.cpp new file mode 100644 index 000000000..03d4b62a2 --- /dev/null +++ b/python/src/v2.0/styles/AverageProductData.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/AverageProductData.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// AverageProductData wrapper +void wrapAverageProductData(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::AverageProductData; + + // create the component + python::class_ component( + module, + "AverageProductData", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const std::optional &, + const XMLName &, + const std::optional &, + const styles::Temperature & + >(), + python::arg("date"), + python::arg("derived_from") = std::nullopt, + python::arg("label"), + python::arg("documentation") = std::nullopt, + python::arg("temperature"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "temperature", + python::overload_cast<>(&Component::temperature), + Component::documentation("temperature").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Bondarenko.python.cpp b/python/src/v2.0/styles/Bondarenko.python.cpp new file mode 100644 index 000000000..30a6fa1a8 --- /dev/null +++ b/python/src/v2.0/styles/Bondarenko.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Bondarenko.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Bondarenko wrapper +void wrapBondarenko(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Bondarenko; + + // create the component + python::class_ component( + module, + "Bondarenko", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const styles::SigmaZeros & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("sigma_zeros"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "sigma_zeros", + python::overload_cast<>(&Component::sigmaZeros), + Component::documentation("sigma_zeros").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/CoulombPlusNuclearElasticMuCutoff.python.cpp b/python/src/v2.0/styles/CoulombPlusNuclearElasticMuCutoff.python.cpp new file mode 100644 index 000000000..e4622931d --- /dev/null +++ b/python/src/v2.0/styles/CoulombPlusNuclearElasticMuCutoff.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/CoulombPlusNuclearElasticMuCutoff.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// CoulombPlusNuclearElasticMuCutoff wrapper +void wrapCoulombPlusNuclearElasticMuCutoff(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::CoulombPlusNuclearElasticMuCutoff; + + // create the component + python::class_ component( + module, + "CoulombPlusNuclearElasticMuCutoff", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const Float64 & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("mu_cutoff"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "mu_cutoff", + &Component::muCutoff, + Component::documentation("mu_cutoff").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/CrossSectionReconstructed.python.cpp b/python/src/v2.0/styles/CrossSectionReconstructed.python.cpp new file mode 100644 index 000000000..1db6c7ac6 --- /dev/null +++ b/python/src/v2.0/styles/CrossSectionReconstructed.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/CrossSectionReconstructed.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// CrossSectionReconstructed wrapper +void wrapCrossSectionReconstructed(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::CrossSectionReconstructed; + + // create the component + python::class_ component( + module, + "CrossSectionReconstructed", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional & + >(), + python::arg("date"), + python::arg("derived_from") = std::nullopt, + python::arg("label"), + python::arg("documentation") = std::nullopt, + python::arg("temperature") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "temperature", + python::overload_cast<>(&Component::temperature), + Component::documentation("temperature").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/EqualProbableBins.python.cpp b/python/src/v2.0/styles/EqualProbableBins.python.cpp new file mode 100644 index 000000000..df16e13e1 --- /dev/null +++ b/python/src/v2.0/styles/EqualProbableBins.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/EqualProbableBins.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// EqualProbableBins wrapper +void wrapEqualProbableBins(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::EqualProbableBins; + + // create the component + python::class_ component( + module, + "EqualProbableBins", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const Integer32 & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("number_of_bins"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "number_of_bins", + &Component::numberOfBins, + Component::documentation("number_of_bins").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Evaluated.python.cpp b/python/src/v2.0/styles/Evaluated.python.cpp new file mode 100644 index 000000000..5ab94ce77 --- /dev/null +++ b/python/src/v2.0/styles/Evaluated.python.cpp @@ -0,0 +1,105 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Evaluated.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Evaluated wrapper +void wrapEvaluated(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Evaluated; + + // create the component + python::class_ component( + module, + "Evaluated", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const std::optional &, + const XMLName &, + const XMLName &, + const XMLName &, + const documentation::Documentation &, + const styles::ProjectileEnergyDomain &, + const styles::Temperature & + >(), + python::arg("date"), + python::arg("derived_from") = std::nullopt, + python::arg("label"), + python::arg("library"), + python::arg("version"), + python::arg("documentation"), + python::arg("projectile_energy_domain"), + python::arg("temperature"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "library", + &Component::library, + Component::documentation("library").data() + ) + .def_property_readonly( + "version", + &Component::version, + Component::documentation("version").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "projectile_energy_domain", + python::overload_cast<>(&Component::projectileEnergyDomain), + Component::documentation("projectile_energy_domain").data() + ) + .def_property_readonly( + "temperature", + python::overload_cast<>(&Component::temperature), + Component::documentation("temperature").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Flux.python.cpp b/python/src/v2.0/styles/Flux.python.cpp new file mode 100644 index 000000000..b3ae3c56b --- /dev/null +++ b/python/src/v2.0/styles/Flux.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Flux.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Flux wrapper +void wrapFlux(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Flux; + + // create the component + python::class_ component( + module, + "Flux", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const containers::XYs2d & + >(), + python::arg("label"), + python::arg("xys2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/GriddedCrossSection.python.cpp b/python/src/v2.0/styles/GriddedCrossSection.python.cpp new file mode 100644 index 000000000..ef820b753 --- /dev/null +++ b/python/src/v2.0/styles/GriddedCrossSection.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/GriddedCrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// GriddedCrossSection wrapper +void wrapGriddedCrossSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::GriddedCrossSection; + + // create the component + python::class_ component( + module, + "GriddedCrossSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const std::optional &, + const containers::Grid & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("documentation") = std::nullopt, + python::arg("grid"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "grid", + python::overload_cast<>(&Component::grid), + Component::documentation("grid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Heated.python.cpp b/python/src/v2.0/styles/Heated.python.cpp new file mode 100644 index 000000000..441634058 --- /dev/null +++ b/python/src/v2.0/styles/Heated.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Heated.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Heated wrapper +void wrapHeated(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Heated; + + // create the component + python::class_ component( + module, + "Heated", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const std::optional &, + const styles::Temperature & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("documentation") = std::nullopt, + python::arg("temperature"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + .def_property_readonly( + "temperature", + python::overload_cast<>(&Component::temperature), + Component::documentation("temperature").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/HeatedMultiGroup.python.cpp b/python/src/v2.0/styles/HeatedMultiGroup.python.cpp new file mode 100644 index 000000000..697ac825d --- /dev/null +++ b/python/src/v2.0/styles/HeatedMultiGroup.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/HeatedMultiGroup.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// HeatedMultiGroup wrapper +void wrapHeatedMultiGroup(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::HeatedMultiGroup; + + // create the component + python::class_ component( + module, + "HeatedMultiGroup", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const styles::Flux &, + const styles::InverseSpeed &, + const styles::Transportables & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("flux"), + python::arg("inverse_speed"), + python::arg("transportables"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "flux", + python::overload_cast<>(&Component::flux), + Component::documentation("flux").data() + ) + .def_property_readonly( + "inverse_speed", + python::overload_cast<>(&Component::inverseSpeed), + Component::documentation("inverse_speed").data() + ) + .def_property_readonly( + "transportables", + python::overload_cast<>(&Component::transportables), + Component::documentation("transportables").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/InverseSpeed.python.cpp b/python/src/v2.0/styles/InverseSpeed.python.cpp new file mode 100644 index 000000000..7db133cf2 --- /dev/null +++ b/python/src/v2.0/styles/InverseSpeed.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/InverseSpeed.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// InverseSpeed wrapper +void wrapInverseSpeed(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::InverseSpeed; + + // create the component + python::class_ component( + module, + "InverseSpeed", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Gridded1d & + >(), + python::arg("gridded1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/MonteCarlo_cdf.python.cpp b/python/src/v2.0/styles/MonteCarlo_cdf.python.cpp new file mode 100644 index 000000000..f0703b286 --- /dev/null +++ b/python/src/v2.0/styles/MonteCarlo_cdf.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/MonteCarlo_cdf.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// MonteCarlo_cdf wrapper +void wrapMonteCarlo_cdf(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::MonteCarlo_cdf; + + // create the component + python::class_ component( + module, + "MonteCarlo_cdf", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const std::optional & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("documentation") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "documentation", + python::overload_cast<>(&Component::documentation), + Component::documentation("documentation").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/MultiBand.python.cpp b/python/src/v2.0/styles/MultiBand.python.cpp new file mode 100644 index 000000000..43d105fdc --- /dev/null +++ b/python/src/v2.0/styles/MultiBand.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/MultiBand.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// MultiBand wrapper +void wrapMultiBand(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::MultiBand; + + // create the component + python::class_ component( + module, + "MultiBand", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const Integer32 & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("number_of_bands"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "number_of_bands", + &Component::numberOfBands, + Component::documentation("number_of_bands").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/MultiGroup.python.cpp b/python/src/v2.0/styles/MultiGroup.python.cpp new file mode 100644 index 000000000..e3a092d98 --- /dev/null +++ b/python/src/v2.0/styles/MultiGroup.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/MultiGroup.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// MultiGroup wrapper +void wrapMultiGroup(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::MultiGroup; + + // create the component + python::class_ component( + module, + "MultiGroup", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const containers::Grid & + >(), + python::arg("label"), + python::arg("grid"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "grid", + python::overload_cast<>(&Component::grid), + Component::documentation("grid").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/ProjectileEnergyDomain.python.cpp b/python/src/v2.0/styles/ProjectileEnergyDomain.python.cpp new file mode 100644 index 000000000..c8adcba22 --- /dev/null +++ b/python/src/v2.0/styles/ProjectileEnergyDomain.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/ProjectileEnergyDomain.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// ProjectileEnergyDomain wrapper +void wrapProjectileEnergyDomain(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::ProjectileEnergyDomain; + + // create the component + python::class_ component( + module, + "ProjectileEnergyDomain", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Float64 &, + const Float64 &, + const XMLName & + >(), + python::arg("max"), + python::arg("min"), + python::arg("unit"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "max", + &Component::max, + Component::documentation("max").data() + ) + .def_property_readonly( + "min", + &Component::min, + Component::documentation("min").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Realization.python.cpp b/python/src/v2.0/styles/Realization.python.cpp new file mode 100644 index 000000000..10891198d --- /dev/null +++ b/python/src/v2.0/styles/Realization.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Realization.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Realization wrapper +void wrapRealization(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Realization; + + // create the component + python::class_ component( + module, + "Realization", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/SigmaZeros.python.cpp b/python/src/v2.0/styles/SigmaZeros.python.cpp new file mode 100644 index 000000000..6deba6699 --- /dev/null +++ b/python/src/v2.0/styles/SigmaZeros.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/SigmaZeros.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// SigmaZeros wrapper +void wrapSigmaZeros(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::SigmaZeros; + + // create the component + python::class_ component( + module, + "SigmaZeros", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Values & + >(), + python::arg("values"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "values", + python::overload_cast<>(&Component::values), + Component::documentation("values").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/SnElasticUpScatter.python.cpp b/python/src/v2.0/styles/SnElasticUpScatter.python.cpp new file mode 100644 index 000000000..a83a391d1 --- /dev/null +++ b/python/src/v2.0/styles/SnElasticUpScatter.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/SnElasticUpScatter.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// SnElasticUpScatter wrapper +void wrapSnElasticUpScatter(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::SnElasticUpScatter; + + // create the component + python::class_ component( + module, + "SnElasticUpScatter", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName &, + const std::optional & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + python::arg("upper_calculated_group") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "upper_calculated_group", + &Component::upperCalculatedGroup, + Component::documentation("upper_calculated_group").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Styles.python.cpp b/python/src/v2.0/styles/Styles.python.cpp new file mode 100644 index 000000000..5ff95939e --- /dev/null +++ b/python/src/v2.0/styles/Styles.python.cpp @@ -0,0 +1,119 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Styles.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Styles wrapper +void wrapStyles(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Styles; + + // create the component + python::class_ component( + module, + "Styles", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> &, + const std::optional> & + >(), + python::arg("monte_carlo_cdf") = std::nullopt, + python::arg("sn_elastic_up_scatter") = std::nullopt, + python::arg("urr_probability_tables") = std::nullopt, + python::arg("angular_distribution_reconstructed") = std::nullopt, + python::arg("average_product_data") = std::nullopt, + python::arg("cross_section_reconstructed") = std::nullopt, + python::arg("evaluated") = std::nullopt, + python::arg("gridded_cross_section") = std::nullopt, + python::arg("heated") = std::nullopt, + python::arg("heated_multi_group") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "monte_carlo_cdf", + python::overload_cast<>(&Component::MonteCarlo_cdf), + Component::documentation("monte_carlo_cdf").data() + ) + .def_property_readonly( + "sn_elastic_up_scatter", + python::overload_cast<>(&Component::SnElasticUpScatter), + Component::documentation("sn_elastic_up_scatter").data() + ) + .def_property_readonly( + "urr_probability_tables", + python::overload_cast<>(&Component::URR_probabilityTables), + Component::documentation("urr_probability_tables").data() + ) + .def_property_readonly( + "angular_distribution_reconstructed", + python::overload_cast<>(&Component::angularDistributionReconstructed), + Component::documentation("angular_distribution_reconstructed").data() + ) + .def_property_readonly( + "average_product_data", + python::overload_cast<>(&Component::averageProductData), + Component::documentation("average_product_data").data() + ) + .def_property_readonly( + "cross_section_reconstructed", + python::overload_cast<>(&Component::crossSectionReconstructed), + Component::documentation("cross_section_reconstructed").data() + ) + .def_property_readonly( + "evaluated", + python::overload_cast<>(&Component::evaluated), + Component::documentation("evaluated").data() + ) + .def_property_readonly( + "gridded_cross_section", + python::overload_cast<>(&Component::griddedCrossSection), + Component::documentation("gridded_cross_section").data() + ) + .def_property_readonly( + "heated", + python::overload_cast<>(&Component::heated), + Component::documentation("heated").data() + ) + .def_property_readonly( + "heated_multi_group", + python::overload_cast<>(&Component::heatedMultiGroup), + Component::documentation("heated_multi_group").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Temperature.python.cpp b/python/src/v2.0/styles/Temperature.python.cpp new file mode 100644 index 000000000..06a717973 --- /dev/null +++ b/python/src/v2.0/styles/Temperature.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Temperature.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Temperature wrapper +void wrapTemperature(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Temperature; + + // create the component + python::class_ component( + module, + "Temperature", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Transportable.python.cpp b/python/src/v2.0/styles/Transportable.python.cpp new file mode 100644 index 000000000..24207c559 --- /dev/null +++ b/python/src/v2.0/styles/Transportable.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Transportable.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Transportable wrapper +void wrapTransportable(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Transportable; + + // create the component + python::class_ component( + module, + "Transportable", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const styles::MultiGroup & + >(), + python::arg("conserve") = std::nullopt, + python::arg("label"), + python::arg("multi_group"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "conserve", + [](const Component &self) { return self.conserve().value(); }, + Component::documentation("conserve").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "multi_group", + python::overload_cast<>(&Component::multiGroup), + Component::documentation("multi_group").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/Transportables.python.cpp b/python/src/v2.0/styles/Transportables.python.cpp new file mode 100644 index 000000000..931542f2d --- /dev/null +++ b/python/src/v2.0/styles/Transportables.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/Transportables.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// Transportables wrapper +void wrapTransportables(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::Transportables; + + // create the component + python::class_ component( + module, + "Transportables", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("transportable"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "transportable", + python::overload_cast<>(&Component::transportable), + Component::documentation("transportable").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/styles/URR_probabilityTables.python.cpp b/python/src/v2.0/styles/URR_probabilityTables.python.cpp new file mode 100644 index 000000000..8a5dd6701 --- /dev/null +++ b/python/src/v2.0/styles/URR_probabilityTables.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/styles/URR_probabilityTables.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_styles { + +// URR_probabilityTables wrapper +void wrapURR_probabilityTables(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = styles::URR_probabilityTables; + + // create the component + python::class_ component( + module, + "URR_probabilityTables", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const XMLName &, + const XMLName & + >(), + python::arg("date"), + python::arg("derived_from"), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "date", + &Component::date, + Component::documentation("date").data() + ) + .def_property_readonly( + "derived_from", + &Component::derivedFrom, + Component::documentation("derived_from").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_styles +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport.python.cpp b/python/src/v2.0/transport.python.cpp new file mode 100644 index 000000000..53bade5a8 --- /dev/null +++ b/python/src/v2.0/transport.python.cpp @@ -0,0 +1,145 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// transport declarations +namespace python_transport { + void wrapURR_probabilityTables1d(python::module &); + void wrapReference(python::module &); + void wrapFastRegion(python::module &); + void wrapResolvedRegion(python::module &); + void wrapUnresolvedRegion(python::module &); + void wrapBackground(python::module &); + void wrapResonances(python::module &); + void wrapResonancesWithBackground(python::module &); + void wrapCrossSection(python::module &); + void wrapA(python::module &); + void wrapF(python::module &); + void wrapR(python::module &); + void wrapKalbachMann(python::module &); + void wrapAngularEnergy(python::module &); + void wrapForward(python::module &); + void wrapIsotropic2d(python::module &); + void wrapAngular(python::module &); + void wrapRecoil(python::module &); + void wrapAngularTwoBody(python::module &); + void wrapBranching3d(python::module &); + void wrapEnergyAngular(python::module &); + void wrapNBodyPhaseSpace(python::module &); + void wrapU(python::module &); + void wrapDiscreteGamma(python::module &); + void wrapTheta(python::module &); + void wrapEvaporation(python::module &); + void wrapG(python::module &); + void wrapGeneralEvaporation(python::module &); + void wrapPrimaryGamma(python::module &); + void wrapWeighted(python::module &); + void wrapWeightedFunctionals(python::module &); + void wrapEnergy(python::module &); + void wrapUncorrelated(python::module &); + void wrapUnspecified(python::module &); + void wrapDistribution(python::module &); + void wrapBranching1d(python::module &); + void wrapMultiplicity(python::module &); + void wrapOutputChannel(python::module &); + void wrapAdd(python::module &); + void wrapCoherentPhoton(python::module &); + void wrapSummands(python::module &); + void wrapCrossSectionSum(python::module &); + void wrapCrossSectionSums(python::module &); + void wrapDoubleDifferentialCrossSection(python::module &); + void wrapIncoherentPhoton(python::module &); + void wrapReaction(python::module &); + void wrapIncompleteReactions(python::module &); + void wrapScatteringMatrix(python::module &); + void wrapMultiplicitySum(python::module &); + void wrapMultiplicitySums(python::module &); + void wrapOrphanProduct(python::module &); + void wrapOrphanProducts(python::module &); + void wrapPhotonEmissionProbabilities(python::module &); + void wrapProduction(python::module &); + void wrapProductions(python::module &); + void wrapReactions(python::module &); + void wrapSums(python::module &); + void wrapReactionSuite(python::module &); +} // namespace python_transport + +// transport wrapper +void wrapTransport(python::module &module) +{ + // create the transport submodule + python::module submodule = module.def_submodule( + "transport", + "GNDS v2.0 transport" + ); + + // wrap transport components + python_transport::wrapURR_probabilityTables1d(submodule); + python_transport::wrapReference(submodule); + python_transport::wrapFastRegion(submodule); + python_transport::wrapResolvedRegion(submodule); + python_transport::wrapUnresolvedRegion(submodule); + python_transport::wrapBackground(submodule); + python_transport::wrapResonances(submodule); + python_transport::wrapResonancesWithBackground(submodule); + python_transport::wrapCrossSection(submodule); + python_transport::wrapA(submodule); + python_transport::wrapF(submodule); + python_transport::wrapR(submodule); + python_transport::wrapKalbachMann(submodule); + python_transport::wrapAngularEnergy(submodule); + python_transport::wrapForward(submodule); + python_transport::wrapIsotropic2d(submodule); + python_transport::wrapAngular(submodule); + python_transport::wrapRecoil(submodule); + python_transport::wrapAngularTwoBody(submodule); + python_transport::wrapBranching3d(submodule); + python_transport::wrapEnergyAngular(submodule); + python_transport::wrapNBodyPhaseSpace(submodule); + python_transport::wrapU(submodule); + python_transport::wrapDiscreteGamma(submodule); + python_transport::wrapTheta(submodule); + python_transport::wrapEvaporation(submodule); + python_transport::wrapG(submodule); + python_transport::wrapGeneralEvaporation(submodule); + python_transport::wrapPrimaryGamma(submodule); + python_transport::wrapWeighted(submodule); + python_transport::wrapWeightedFunctionals(submodule); + python_transport::wrapEnergy(submodule); + python_transport::wrapUncorrelated(submodule); + python_transport::wrapUnspecified(submodule); + python_transport::wrapDistribution(submodule); + python_transport::wrapBranching1d(submodule); + python_transport::wrapMultiplicity(submodule); + python_transport::wrapOutputChannel(submodule); + python_transport::wrapAdd(submodule); + python_transport::wrapCoherentPhoton(submodule); + python_transport::wrapSummands(submodule); + python_transport::wrapCrossSectionSum(submodule); + python_transport::wrapCrossSectionSums(submodule); + python_transport::wrapDoubleDifferentialCrossSection(submodule); + python_transport::wrapIncoherentPhoton(submodule); + python_transport::wrapReaction(submodule); + python_transport::wrapIncompleteReactions(submodule); + python_transport::wrapScatteringMatrix(submodule); + python_transport::wrapMultiplicitySum(submodule); + python_transport::wrapMultiplicitySums(submodule); + python_transport::wrapOrphanProduct(submodule); + python_transport::wrapOrphanProducts(submodule); + python_transport::wrapPhotonEmissionProbabilities(submodule); + python_transport::wrapProduction(submodule); + python_transport::wrapProductions(submodule); + python_transport::wrapReactions(submodule); + python_transport::wrapSums(submodule); + python_transport::wrapReactionSuite(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/A.python.cpp b/python/src/v2.0/transport/A.python.cpp new file mode 100644 index 000000000..60c61bd74 --- /dev/null +++ b/python/src/v2.0/transport/A.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/A.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// A wrapper +void wrapA(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::A; + using _t = std::variant< + containers::XYs2d, + containers::Regions2d + >; + + // create the component + python::class_ component( + module, + "A", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys2dregions2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + .def_property_readonly( + "_xys2dregions2d", + python::overload_cast<>(&Component::_XYs2dregions2d), + Component::documentation("_xys2dregions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Add.python.cpp b/python/src/v2.0/transport/Add.python.cpp new file mode 100644 index 000000000..1623dff81 --- /dev/null +++ b/python/src/v2.0/transport/Add.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Add.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Add wrapper +void wrapAdd(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Add; + + // create the component + python::class_ component( + module, + "Add", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("href") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Angular.python.cpp b/python/src/v2.0/transport/Angular.python.cpp new file mode 100644 index 000000000..07e7e8343 --- /dev/null +++ b/python/src/v2.0/transport/Angular.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Angular.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Angular wrapper +void wrapAngular(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Angular; + + // create the component + python::class_ component( + module, + "Angular", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("xys2d") = std::nullopt, + python::arg("forward") = std::nullopt, + python::arg("isotropic2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "forward", + python::overload_cast<>(&Component::forward), + Component::documentation("forward").data() + ) + .def_property_readonly( + "isotropic2d", + python::overload_cast<>(&Component::isotropic2d), + Component::documentation("isotropic2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/AngularEnergy.python.cpp b/python/src/v2.0/transport/AngularEnergy.python.cpp new file mode 100644 index 000000000..f1da46bc8 --- /dev/null +++ b/python/src/v2.0/transport/AngularEnergy.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/AngularEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// AngularEnergy wrapper +void wrapAngularEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::AngularEnergy; + + // create the component + python::class_ component( + module, + "AngularEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const containers::XYs3d & + >(), + python::arg("label"), + python::arg("product_frame"), + python::arg("xys3d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "xys3d", + python::overload_cast<>(&Component::XYs3d), + Component::documentation("xys3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/AngularTwoBody.python.cpp b/python/src/v2.0/transport/AngularTwoBody.python.cpp new file mode 100644 index 000000000..e09c8cb35 --- /dev/null +++ b/python/src/v2.0/transport/AngularTwoBody.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/AngularTwoBody.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// AngularTwoBody wrapper +void wrapAngularTwoBody(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::AngularTwoBody; + + // create the component + python::class_ component( + module, + "AngularTwoBody", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame"), + python::arg("xys2d") = std::nullopt, + python::arg("isotropic2d") = std::nullopt, + python::arg("recoil") = std::nullopt, + python::arg("regions2d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "isotropic2d", + python::overload_cast<>(&Component::isotropic2d), + Component::documentation("isotropic2d").data() + ) + .def_property_readonly( + "recoil", + python::overload_cast<>(&Component::recoil), + Component::documentation("recoil").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Background.python.cpp b/python/src/v2.0/transport/Background.python.cpp new file mode 100644 index 000000000..2ab924517 --- /dev/null +++ b/python/src/v2.0/transport/Background.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Background.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Background wrapper +void wrapBackground(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Background; + + // create the component + python::class_ component( + module, + "Background", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("fast_region") = std::nullopt, + python::arg("resolved_region") = std::nullopt, + python::arg("unresolved_region") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "fast_region", + python::overload_cast<>(&Component::fastRegion), + Component::documentation("fast_region").data() + ) + .def_property_readonly( + "resolved_region", + python::overload_cast<>(&Component::resolvedRegion), + Component::documentation("resolved_region").data() + ) + .def_property_readonly( + "unresolved_region", + python::overload_cast<>(&Component::unresolvedRegion), + Component::documentation("unresolved_region").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Branching1d.python.cpp b/python/src/v2.0/transport/Branching1d.python.cpp new file mode 100644 index 000000000..f3c25b174 --- /dev/null +++ b/python/src/v2.0/transport/Branching1d.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Branching1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Branching1d wrapper +void wrapBranching1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Branching1d; + + // create the component + python::class_ component( + module, + "Branching1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName & + >(), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Branching3d.python.cpp b/python/src/v2.0/transport/Branching3d.python.cpp new file mode 100644 index 000000000..eefec1d26 --- /dev/null +++ b/python/src/v2.0/transport/Branching3d.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Branching3d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Branching3d wrapper +void wrapBranching3d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Branching3d; + + // create the component + python::class_ component( + module, + "Branching3d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("label"), + python::arg("product_frame"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/CoherentPhoton.python.cpp b/python/src/v2.0/transport/CoherentPhoton.python.cpp new file mode 100644 index 000000000..85f4f8cd0 --- /dev/null +++ b/python/src/v2.0/transport/CoherentPhoton.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/CoherentPhoton.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// CoherentPhoton wrapper +void wrapCoherentPhoton(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::CoherentPhoton; + + // create the component + python::class_ component( + module, + "CoherentPhoton", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/CrossSection.python.cpp b/python/src/v2.0/transport/CrossSection.python.cpp new file mode 100644 index 000000000..5e615e550 --- /dev/null +++ b/python/src/v2.0/transport/CrossSection.python.cpp @@ -0,0 +1,112 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/CrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// CrossSection wrapper +void wrapCrossSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::CrossSection; + using _t = std::variant< + cpTransport::CoulombPlusNuclearElastic, + transport::URR_probabilityTables1d, + containers::XYs1d, + containers::Ys1d, + containers::Gridded1d, + transport::Reference, + containers::Regions1d, + transport::ResonancesWithBackground, + tsl::ThermalNeutronScatteringLaw1d + >; + + // create the component + python::class_ component( + module, + "CrossSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_coulomb_plus_nuclear_elastic_urr_probability_tables1d_xys1d_ys1dgridded1dreferenceregions1dresonances_with_backgroundthermal_neutron_scattering_law1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "coulomb_plus_nuclear_elastic", + python::overload_cast<>(&Component::CoulombPlusNuclearElastic), + Component::documentation("coulomb_plus_nuclear_elastic").data() + ) + .def_property_readonly( + "urr_probability_tables1d", + python::overload_cast<>(&Component::URR_probabilityTables1d), + Component::documentation("urr_probability_tables1d").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "ys1d", + python::overload_cast<>(&Component::Ys1d), + Component::documentation("ys1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + .def_property_readonly( + "reference", + python::overload_cast<>(&Component::reference), + Component::documentation("reference").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "resonances_with_background", + python::overload_cast<>(&Component::resonancesWithBackground), + Component::documentation("resonances_with_background").data() + ) + .def_property_readonly( + "thermal_neutron_scattering_law1d", + python::overload_cast<>(&Component::thermalNeutronScatteringLaw1d), + Component::documentation("thermal_neutron_scattering_law1d").data() + ) + .def_property_readonly( + "_coulomb_plus_nuclear_elastic_urr_probability_tables1d_xys1d_ys1dgridded1dreferenceregions1dresonances_with_backgroundthermal_neutron_scattering_law1d", + python::overload_cast<>(&Component::_CoulombPlusNuclearElasticURR_probabilityTables1dXYs1dYs1dgridded1dreferenceregions1dresonancesWithBackgroundthermalNeutronScatteringLaw1d), + Component::documentation("_coulomb_plus_nuclear_elastic_urr_probability_tables1d_xys1d_ys1dgridded1dreferenceregions1dresonances_with_backgroundthermal_neutron_scattering_law1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/CrossSectionSum.python.cpp b/python/src/v2.0/transport/CrossSectionSum.python.cpp new file mode 100644 index 000000000..9c854ce01 --- /dev/null +++ b/python/src/v2.0/transport/CrossSectionSum.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/CrossSectionSum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// CrossSectionSum wrapper +void wrapCrossSectionSum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::CrossSectionSum; + + // create the component + python::class_ component( + module, + "CrossSectionSum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const ambiguousNamespace::Q &, + const transport::CrossSection &, + const transport::Summands & + >(), + python::arg("endf_mt") = std::nullopt, + python::arg("label"), + python::arg("q"), + python::arg("cross_section"), + python::arg("summands"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "q", + python::overload_cast<>(&Component::Q), + Component::documentation("q").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "summands", + python::overload_cast<>(&Component::summands), + Component::documentation("summands").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/CrossSectionSums.python.cpp b/python/src/v2.0/transport/CrossSectionSums.python.cpp new file mode 100644 index 000000000..e531b6ed3 --- /dev/null +++ b/python/src/v2.0/transport/CrossSectionSums.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/CrossSectionSums.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// CrossSectionSums wrapper +void wrapCrossSectionSums(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::CrossSectionSums; + + // create the component + python::class_ component( + module, + "CrossSectionSums", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("cross_section_sum") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "cross_section_sum", + python::overload_cast<>(&Component::crossSectionSum), + Component::documentation("cross_section_sum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/DiscreteGamma.python.cpp b/python/src/v2.0/transport/DiscreteGamma.python.cpp new file mode 100644 index 000000000..145f3b5f1 --- /dev/null +++ b/python/src/v2.0/transport/DiscreteGamma.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/DiscreteGamma.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// DiscreteGamma wrapper +void wrapDiscreteGamma(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::DiscreteGamma; + + // create the component + python::class_ component( + module, + "DiscreteGamma", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("value") = std::nullopt, + python::arg("axes") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Distribution.python.cpp b/python/src/v2.0/transport/Distribution.python.cpp new file mode 100644 index 000000000..83219eb78 --- /dev/null +++ b/python/src/v2.0/transport/Distribution.python.cpp @@ -0,0 +1,148 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Distribution.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Distribution wrapper +void wrapDistribution(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Distribution; + using _t = std::variant< + cpTransport::CoulombPlusNuclearElastic, + transport::KalbachMann, + transport::AngularEnergy, + processed::AngularEnergyMC, + transport::AngularTwoBody, + transport::Branching3d, + atomic::CoherentPhotonScattering, + transport::EnergyAngular, + processed::EnergyAngularMC, + atomic::IncoherentPhotonScattering, + processed::MultiGroup3d, + transport::Reference, + tsl::ThermalNeutronScatteringLaw, + transport::Uncorrelated, + transport::Unspecified + >; + + // create the component + python::class_ component( + module, + "Distribution", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_coulomb_plus_nuclear_elastic_kalbach_mannangular_energyangular_energy_mcangular_two_bodybranching3dcoherent_photon_scatteringenergy_angularenergy_angular_mcincoherent_photon_scatteringmulti_group3dreferencethermal_neutron_scattering_lawuncorrelatedunspecified"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "coulomb_plus_nuclear_elastic", + python::overload_cast<>(&Component::CoulombPlusNuclearElastic), + Component::documentation("coulomb_plus_nuclear_elastic").data() + ) + .def_property_readonly( + "kalbach_mann", + python::overload_cast<>(&Component::KalbachMann), + Component::documentation("kalbach_mann").data() + ) + .def_property_readonly( + "angular_energy", + python::overload_cast<>(&Component::angularEnergy), + Component::documentation("angular_energy").data() + ) + .def_property_readonly( + "angular_energy_mc", + python::overload_cast<>(&Component::angularEnergyMC), + Component::documentation("angular_energy_mc").data() + ) + .def_property_readonly( + "angular_two_body", + python::overload_cast<>(&Component::angularTwoBody), + Component::documentation("angular_two_body").data() + ) + .def_property_readonly( + "branching3d", + python::overload_cast<>(&Component::branching3d), + Component::documentation("branching3d").data() + ) + .def_property_readonly( + "coherent_photon_scattering", + python::overload_cast<>(&Component::coherentPhotonScattering), + Component::documentation("coherent_photon_scattering").data() + ) + .def_property_readonly( + "energy_angular", + python::overload_cast<>(&Component::energyAngular), + Component::documentation("energy_angular").data() + ) + .def_property_readonly( + "energy_angular_mc", + python::overload_cast<>(&Component::energyAngularMC), + Component::documentation("energy_angular_mc").data() + ) + .def_property_readonly( + "incoherent_photon_scattering", + python::overload_cast<>(&Component::incoherentPhotonScattering), + Component::documentation("incoherent_photon_scattering").data() + ) + .def_property_readonly( + "multi_group3d", + python::overload_cast<>(&Component::multiGroup3d), + Component::documentation("multi_group3d").data() + ) + .def_property_readonly( + "reference", + python::overload_cast<>(&Component::reference), + Component::documentation("reference").data() + ) + .def_property_readonly( + "thermal_neutron_scattering_law", + python::overload_cast<>(&Component::thermalNeutronScatteringLaw), + Component::documentation("thermal_neutron_scattering_law").data() + ) + .def_property_readonly( + "uncorrelated", + python::overload_cast<>(&Component::uncorrelated), + Component::documentation("uncorrelated").data() + ) + .def_property_readonly( + "unspecified", + python::overload_cast<>(&Component::unspecified), + Component::documentation("unspecified").data() + ) + .def_property_readonly( + "_coulomb_plus_nuclear_elastic_kalbach_mannangular_energyangular_energy_mcangular_two_bodybranching3dcoherent_photon_scatteringenergy_angularenergy_angular_mcincoherent_photon_scatteringmulti_group3dreferencethermal_neutron_scattering_lawuncorrelatedunspecified", + python::overload_cast<>(&Component::_CoulombPlusNuclearElasticKalbachMannangularEnergyangularEnergyMCangularTwoBodybranching3dcoherentPhotonScatteringenergyAngularenergyAngularMCincoherentPhotonScatteringmultiGroup3dreferencethermalNeutronScatteringLawuncorrelatedunspecified), + Component::documentation("_coulomb_plus_nuclear_elastic_kalbach_mannangular_energyangular_energy_mcangular_two_bodybranching3dcoherent_photon_scatteringenergy_angularenergy_angular_mcincoherent_photon_scatteringmulti_group3dreferencethermal_neutron_scattering_lawuncorrelatedunspecified").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/DoubleDifferentialCrossSection.python.cpp b/python/src/v2.0/transport/DoubleDifferentialCrossSection.python.cpp new file mode 100644 index 000000000..8681a6a4b --- /dev/null +++ b/python/src/v2.0/transport/DoubleDifferentialCrossSection.python.cpp @@ -0,0 +1,112 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/DoubleDifferentialCrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// DoubleDifferentialCrossSection wrapper +void wrapDoubleDifferentialCrossSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::DoubleDifferentialCrossSection; + + // create the component + python::class_ component( + module, + "DoubleDifferentialCrossSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("coulomb_plus_nuclear_elastic") = std::nullopt, + python::arg("xys3d") = std::nullopt, + python::arg("coherent_photon_scattering") = std::nullopt, + python::arg("incoherent_photon_scattering") = std::nullopt, + python::arg("reference") = std::nullopt, + python::arg("regions3d") = std::nullopt, + python::arg("thermal_neutron_scattering_law_coherent_elastic") = std::nullopt, + python::arg("thermal_neutron_scattering_law_incoherent_elastic") = std::nullopt, + python::arg("thermal_neutron_scattering_law_incoherent_inelastic") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "coulomb_plus_nuclear_elastic", + python::overload_cast<>(&Component::CoulombPlusNuclearElastic), + Component::documentation("coulomb_plus_nuclear_elastic").data() + ) + .def_property_readonly( + "xys3d", + python::overload_cast<>(&Component::XYs3d), + Component::documentation("xys3d").data() + ) + .def_property_readonly( + "coherent_photon_scattering", + python::overload_cast<>(&Component::coherentPhotonScattering), + Component::documentation("coherent_photon_scattering").data() + ) + .def_property_readonly( + "incoherent_photon_scattering", + python::overload_cast<>(&Component::incoherentPhotonScattering), + Component::documentation("incoherent_photon_scattering").data() + ) + .def_property_readonly( + "reference", + python::overload_cast<>(&Component::reference), + Component::documentation("reference").data() + ) + .def_property_readonly( + "regions3d", + python::overload_cast<>(&Component::regions3d), + Component::documentation("regions3d").data() + ) + .def_property_readonly( + "thermal_neutron_scattering_law_coherent_elastic", + python::overload_cast<>(&Component::thermalNeutronScatteringLaw_coherentElastic), + Component::documentation("thermal_neutron_scattering_law_coherent_elastic").data() + ) + .def_property_readonly( + "thermal_neutron_scattering_law_incoherent_elastic", + python::overload_cast<>(&Component::thermalNeutronScatteringLaw_incoherentElastic), + Component::documentation("thermal_neutron_scattering_law_incoherent_elastic").data() + ) + .def_property_readonly( + "thermal_neutron_scattering_law_incoherent_inelastic", + python::overload_cast<>(&Component::thermalNeutronScatteringLaw_incoherentInelastic), + Component::documentation("thermal_neutron_scattering_law_incoherent_inelastic").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Energy.python.cpp b/python/src/v2.0/transport/Energy.python.cpp new file mode 100644 index 000000000..09b70c1fb --- /dev/null +++ b/python/src/v2.0/transport/Energy.python.cpp @@ -0,0 +1,126 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Energy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Energy wrapper +void wrapEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Energy; + + // create the component + python::class_ component( + module, + "Energy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("madland_nix") = std::nullopt, + python::arg("nbody_phase_space") = std::nullopt, + python::arg("watt") = std::nullopt, + python::arg("xys2d") = std::nullopt, + python::arg("discrete_gamma") = std::nullopt, + python::arg("evaporation") = std::nullopt, + python::arg("general_evaporation") = std::nullopt, + python::arg("primary_gamma") = std::nullopt, + python::arg("regions2d") = std::nullopt, + python::arg("simple_maxwellian_fission") = std::nullopt, + python::arg("weighted_functionals") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "madland_nix", + python::overload_cast<>(&Component::MadlandNix), + Component::documentation("madland_nix").data() + ) + .def_property_readonly( + "nbody_phase_space", + python::overload_cast<>(&Component::NBodyPhaseSpace), + Component::documentation("nbody_phase_space").data() + ) + .def_property_readonly( + "watt", + python::overload_cast<>(&Component::Watt), + Component::documentation("watt").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "discrete_gamma", + python::overload_cast<>(&Component::discreteGamma), + Component::documentation("discrete_gamma").data() + ) + .def_property_readonly( + "evaporation", + python::overload_cast<>(&Component::evaporation), + Component::documentation("evaporation").data() + ) + .def_property_readonly( + "general_evaporation", + python::overload_cast<>(&Component::generalEvaporation), + Component::documentation("general_evaporation").data() + ) + .def_property_readonly( + "primary_gamma", + python::overload_cast<>(&Component::primaryGamma), + Component::documentation("primary_gamma").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + .def_property_readonly( + "simple_maxwellian_fission", + python::overload_cast<>(&Component::simpleMaxwellianFission), + Component::documentation("simple_maxwellian_fission").data() + ) + .def_property_readonly( + "weighted_functionals", + python::overload_cast<>(&Component::weightedFunctionals), + Component::documentation("weighted_functionals").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/EnergyAngular.python.cpp b/python/src/v2.0/transport/EnergyAngular.python.cpp new file mode 100644 index 000000000..d2aa88a20 --- /dev/null +++ b/python/src/v2.0/transport/EnergyAngular.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/EnergyAngular.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// EnergyAngular wrapper +void wrapEnergyAngular(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::EnergyAngular; + + // create the component + python::class_ component( + module, + "EnergyAngular", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const containers::XYs3d & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame"), + python::arg("xys3d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "xys3d", + python::overload_cast<>(&Component::XYs3d), + Component::documentation("xys3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Evaporation.python.cpp b/python/src/v2.0/transport/Evaporation.python.cpp new file mode 100644 index 000000000..605387707 --- /dev/null +++ b/python/src/v2.0/transport/Evaporation.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Evaporation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Evaporation wrapper +void wrapEvaporation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Evaporation; + + // create the component + python::class_ component( + module, + "Evaporation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("u") = std::nullopt, + python::arg("theta") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "u", + python::overload_cast<>(&Component::U), + Component::documentation("u").data() + ) + .def_property_readonly( + "theta", + python::overload_cast<>(&Component::theta), + Component::documentation("theta").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/F.python.cpp b/python/src/v2.0/transport/F.python.cpp new file mode 100644 index 000000000..6307bdef5 --- /dev/null +++ b/python/src/v2.0/transport/F.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/F.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// F wrapper +void wrapF(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::F; + using _t = std::variant< + containers::XYs2d, + containers::Regions2d + >; + + // create the component + python::class_ component( + module, + "F", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys2dregions2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + .def_property_readonly( + "_xys2dregions2d", + python::overload_cast<>(&Component::_XYs2dregions2d), + Component::documentation("_xys2dregions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/FastRegion.python.cpp b/python/src/v2.0/transport/FastRegion.python.cpp new file mode 100644 index 000000000..52f50bfe5 --- /dev/null +++ b/python/src/v2.0/transport/FastRegion.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/FastRegion.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// FastRegion wrapper +void wrapFastRegion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::FastRegion; + using _t = std::variant< + containers::XYs1d, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "FastRegion", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dregions1d", + python::overload_cast<>(&Component::_XYs1dregions1d), + Component::documentation("_xys1dregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Forward.python.cpp b/python/src/v2.0/transport/Forward.python.cpp new file mode 100644 index 000000000..cba675358 --- /dev/null +++ b/python/src/v2.0/transport/Forward.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Forward.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Forward wrapper +void wrapForward(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Forward; + + // create the component + python::class_ component( + module, + "Forward", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/G.python.cpp b/python/src/v2.0/transport/G.python.cpp new file mode 100644 index 000000000..f01d26ee9 --- /dev/null +++ b/python/src/v2.0/transport/G.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/G.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// G wrapper +void wrapG(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::G; + + // create the component + python::class_ component( + module, + "G", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/GeneralEvaporation.python.cpp b/python/src/v2.0/transport/GeneralEvaporation.python.cpp new file mode 100644 index 000000000..001e45abe --- /dev/null +++ b/python/src/v2.0/transport/GeneralEvaporation.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/GeneralEvaporation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// GeneralEvaporation wrapper +void wrapGeneralEvaporation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::GeneralEvaporation; + + // create the component + python::class_ component( + module, + "GeneralEvaporation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("u") = std::nullopt, + python::arg("g") = std::nullopt, + python::arg("theta") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "u", + python::overload_cast<>(&Component::U), + Component::documentation("u").data() + ) + .def_property_readonly( + "g", + python::overload_cast<>(&Component::g), + Component::documentation("g").data() + ) + .def_property_readonly( + "theta", + python::overload_cast<>(&Component::theta), + Component::documentation("theta").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/IncoherentPhoton.python.cpp b/python/src/v2.0/transport/IncoherentPhoton.python.cpp new file mode 100644 index 000000000..3c34ab939 --- /dev/null +++ b/python/src/v2.0/transport/IncoherentPhoton.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/IncoherentPhoton.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// IncoherentPhoton wrapper +void wrapIncoherentPhoton(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::IncoherentPhoton; + + // create the component + python::class_ component( + module, + "IncoherentPhoton", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/IncompleteReactions.python.cpp b/python/src/v2.0/transport/IncompleteReactions.python.cpp new file mode 100644 index 000000000..e397cd3b5 --- /dev/null +++ b/python/src/v2.0/transport/IncompleteReactions.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/IncompleteReactions.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// IncompleteReactions wrapper +void wrapIncompleteReactions(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::IncompleteReactions; + + // create the component + python::class_ component( + module, + "IncompleteReactions", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("reaction") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "reaction", + python::overload_cast<>(&Component::reaction), + Component::documentation("reaction").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Isotropic2d.python.cpp b/python/src/v2.0/transport/Isotropic2d.python.cpp new file mode 100644 index 000000000..63326d8f1 --- /dev/null +++ b/python/src/v2.0/transport/Isotropic2d.python.cpp @@ -0,0 +1,49 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Isotropic2d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Isotropic2d wrapper +void wrapIsotropic2d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Isotropic2d; + + // create the component + python::class_ component( + module, + "Isotropic2d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + >(), + Component::documentation("constructor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/KalbachMann.python.cpp b/python/src/v2.0/transport/KalbachMann.python.cpp new file mode 100644 index 000000000..d141645b8 --- /dev/null +++ b/python/src/v2.0/transport/KalbachMann.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/KalbachMann.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// KalbachMann wrapper +void wrapKalbachMann(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::KalbachMann; + + // create the component + python::class_ component( + module, + "KalbachMann", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const std::optional &, + const transport::F &, + const transport::R & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame"), + python::arg("a") = std::nullopt, + python::arg("f"), + python::arg("r"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "a", + python::overload_cast<>(&Component::a), + Component::documentation("a").data() + ) + .def_property_readonly( + "f", + python::overload_cast<>(&Component::f), + Component::documentation("f").data() + ) + .def_property_readonly( + "r", + python::overload_cast<>(&Component::r), + Component::documentation("r").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Multiplicity.python.cpp b/python/src/v2.0/transport/Multiplicity.python.cpp new file mode 100644 index 000000000..53eb0807f --- /dev/null +++ b/python/src/v2.0/transport/Multiplicity.python.cpp @@ -0,0 +1,100 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Multiplicity.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Multiplicity wrapper +void wrapMultiplicity(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Multiplicity; + using _t = std::variant< + containers::XYs1d, + transport::Branching1d, + containers::Constant1d, + containers::Gridded1d, + containers::Polynomial1d, + transport::Reference, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "Multiplicity", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dbranching1dconstant1dgridded1dpolynomial1dreferenceregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "branching1d", + python::overload_cast<>(&Component::branching1d), + Component::documentation("branching1d").data() + ) + .def_property_readonly( + "constant1d", + python::overload_cast<>(&Component::constant1d), + Component::documentation("constant1d").data() + ) + .def_property_readonly( + "gridded1d", + python::overload_cast<>(&Component::gridded1d), + Component::documentation("gridded1d").data() + ) + .def_property_readonly( + "polynomial1d", + python::overload_cast<>(&Component::polynomial1d), + Component::documentation("polynomial1d").data() + ) + .def_property_readonly( + "reference", + python::overload_cast<>(&Component::reference), + Component::documentation("reference").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dbranching1dconstant1dgridded1dpolynomial1dreferenceregions1d", + python::overload_cast<>(&Component::_XYs1dbranching1dconstant1dgridded1dpolynomial1dreferenceregions1d), + Component::documentation("_xys1dbranching1dconstant1dgridded1dpolynomial1dreferenceregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/MultiplicitySum.python.cpp b/python/src/v2.0/transport/MultiplicitySum.python.cpp new file mode 100644 index 000000000..9e0b388b9 --- /dev/null +++ b/python/src/v2.0/transport/MultiplicitySum.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/MultiplicitySum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// MultiplicitySum wrapper +void wrapMultiplicitySum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::MultiplicitySum; + + // create the component + python::class_ component( + module, + "MultiplicitySum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const transport::Multiplicity &, + const transport::Summands & + >(), + python::arg("endf_mt") = std::nullopt, + python::arg("label"), + python::arg("multiplicity"), + python::arg("summands"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "multiplicity", + python::overload_cast<>(&Component::multiplicity), + Component::documentation("multiplicity").data() + ) + .def_property_readonly( + "summands", + python::overload_cast<>(&Component::summands), + Component::documentation("summands").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/MultiplicitySums.python.cpp b/python/src/v2.0/transport/MultiplicitySums.python.cpp new file mode 100644 index 000000000..8b069fddf --- /dev/null +++ b/python/src/v2.0/transport/MultiplicitySums.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/MultiplicitySums.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// MultiplicitySums wrapper +void wrapMultiplicitySums(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::MultiplicitySums; + + // create the component + python::class_ component( + module, + "MultiplicitySums", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("multiplicity_sum") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "multiplicity_sum", + python::overload_cast<>(&Component::multiplicitySum), + Component::documentation("multiplicity_sum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/NBodyPhaseSpace.python.cpp b/python/src/v2.0/transport/NBodyPhaseSpace.python.cpp new file mode 100644 index 000000000..e0e5c4c8b --- /dev/null +++ b/python/src/v2.0/transport/NBodyPhaseSpace.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/NBodyPhaseSpace.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// NBodyPhaseSpace wrapper +void wrapNBodyPhaseSpace(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::NBodyPhaseSpace; + + // create the component + python::class_ component( + module, + "NBodyPhaseSpace", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("number_of_products") = std::nullopt, + python::arg("mass") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "number_of_products", + &Component::numberOfProducts, + Component::documentation("number_of_products").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/OrphanProduct.python.cpp b/python/src/v2.0/transport/OrphanProduct.python.cpp new file mode 100644 index 000000000..3339c044a --- /dev/null +++ b/python/src/v2.0/transport/OrphanProduct.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/OrphanProduct.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// OrphanProduct wrapper +void wrapOrphanProduct(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::OrphanProduct; + + // create the component + python::class_ component( + module, + "OrphanProduct", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const XMLName &, + const transport::CrossSection &, + const transport::OutputChannel & + >(), + python::arg("endf_mt"), + python::arg("label"), + python::arg("cross_section"), + python::arg("output_channel"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "output_channel", + python::overload_cast<>(&Component::outputChannel), + Component::documentation("output_channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/OrphanProducts.python.cpp b/python/src/v2.0/transport/OrphanProducts.python.cpp new file mode 100644 index 000000000..04b5391cf --- /dev/null +++ b/python/src/v2.0/transport/OrphanProducts.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/OrphanProducts.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// OrphanProducts wrapper +void wrapOrphanProducts(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::OrphanProducts; + + // create the component + python::class_ component( + module, + "OrphanProducts", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("orphan_product"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "orphan_product", + python::overload_cast<>(&Component::orphanProduct), + Component::documentation("orphan_product").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/OutputChannel.python.cpp b/python/src/v2.0/transport/OutputChannel.python.cpp new file mode 100644 index 000000000..c3d8aa5e7 --- /dev/null +++ b/python/src/v2.0/transport/OutputChannel.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/OutputChannel.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// OutputChannel wrapper +void wrapOutputChannel(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::OutputChannel; + + // create the component + python::class_ component( + module, + "OutputChannel", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("genre") = std::nullopt, + python::arg("process") = std::nullopt, + python::arg("q") = std::nullopt, + python::arg("fission_fragment_data") = std::nullopt, + python::arg("products") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "genre", + &Component::genre, + Component::documentation("genre").data() + ) + .def_property_readonly( + "process", + &Component::process, + Component::documentation("process").data() + ) + .def_property_readonly( + "q", + python::overload_cast<>(&Component::Q), + Component::documentation("q").data() + ) + .def_property_readonly( + "fission_fragment_data", + python::overload_cast<>(&Component::fissionFragmentData), + Component::documentation("fission_fragment_data").data() + ) + .def_property_readonly( + "products", + python::overload_cast<>(&Component::products), + Component::documentation("products").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/PhotonEmissionProbabilities.python.cpp b/python/src/v2.0/transport/PhotonEmissionProbabilities.python.cpp new file mode 100644 index 000000000..cd51af174 --- /dev/null +++ b/python/src/v2.0/transport/PhotonEmissionProbabilities.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/PhotonEmissionProbabilities.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// PhotonEmissionProbabilities wrapper +void wrapPhotonEmissionProbabilities(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::PhotonEmissionProbabilities; + + // create the component + python::class_ component( + module, + "PhotonEmissionProbabilities", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("shell") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "shell", + python::overload_cast<>(&Component::shell), + Component::documentation("shell").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/PrimaryGamma.python.cpp b/python/src/v2.0/transport/PrimaryGamma.python.cpp new file mode 100644 index 000000000..de933e85e --- /dev/null +++ b/python/src/v2.0/transport/PrimaryGamma.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/PrimaryGamma.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// PrimaryGamma wrapper +void wrapPrimaryGamma(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::PrimaryGamma; + + // create the component + python::class_ component( + module, + "PrimaryGamma", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("domain_max") = std::nullopt, + python::arg("domain_min") = std::nullopt, + python::arg("final_state") = std::nullopt, + python::arg("value") = std::nullopt, + python::arg("axes") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "domain_max", + &Component::domainMax, + Component::documentation("domain_max").data() + ) + .def_property_readonly( + "domain_min", + &Component::domainMin, + Component::documentation("domain_min").data() + ) + .def_property_readonly( + "final_state", + &Component::finalState, + Component::documentation("final_state").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + .def_property_readonly( + "axes", + python::overload_cast<>(&Component::axes), + Component::documentation("axes").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Production.python.cpp b/python/src/v2.0/transport/Production.python.cpp new file mode 100644 index 000000000..e25a0c975 --- /dev/null +++ b/python/src/v2.0/transport/Production.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Production.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Production wrapper +void wrapProduction(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Production; + + // create the component + python::class_ component( + module, + "Production", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("endf_mt") = std::nullopt, + python::arg("label") = std::nullopt, + python::arg("cross_section") = std::nullopt, + python::arg("output_channel") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "output_channel", + python::overload_cast<>(&Component::outputChannel), + Component::documentation("output_channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Productions.python.cpp b/python/src/v2.0/transport/Productions.python.cpp new file mode 100644 index 000000000..d1a2fc935 --- /dev/null +++ b/python/src/v2.0/transport/Productions.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Productions.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Productions wrapper +void wrapProductions(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Productions; + + // create the component + python::class_ component( + module, + "Productions", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("production") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "production", + python::overload_cast<>(&Component::production), + Component::documentation("production").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/R.python.cpp b/python/src/v2.0/transport/R.python.cpp new file mode 100644 index 000000000..2e7dce263 --- /dev/null +++ b/python/src/v2.0/transport/R.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/R.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// R wrapper +void wrapR(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::R; + using _t = std::variant< + containers::XYs2d, + containers::Regions2d + >; + + // create the component + python::class_ component( + module, + "R", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys2dregions2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + .def_property_readonly( + "_xys2dregions2d", + python::overload_cast<>(&Component::_XYs2dregions2d), + Component::documentation("_xys2dregions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Reaction.python.cpp b/python/src/v2.0/transport/Reaction.python.cpp new file mode 100644 index 000000000..6414cc506 --- /dev/null +++ b/python/src/v2.0/transport/Reaction.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Reaction.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Reaction wrapper +void wrapReaction(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Reaction; + + // create the component + python::class_ component( + module, + "Reaction", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const std::optional &, + const XMLName &, + const transport::CrossSection &, + const std::optional &, + const transport::OutputChannel & + >(), + python::arg("endf_mt"), + python::arg("fission_genre") = std::nullopt, + python::arg("label"), + python::arg("cross_section"), + python::arg("double_differential_cross_section") = std::nullopt, + python::arg("output_channel"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "endf_mt", + &Component::ENDF_MT, + Component::documentation("endf_mt").data() + ) + .def_property_readonly( + "fission_genre", + &Component::fissionGenre, + Component::documentation("fission_genre").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "cross_section", + python::overload_cast<>(&Component::crossSection), + Component::documentation("cross_section").data() + ) + .def_property_readonly( + "double_differential_cross_section", + python::overload_cast<>(&Component::doubleDifferentialCrossSection), + Component::documentation("double_differential_cross_section").data() + ) + .def_property_readonly( + "output_channel", + python::overload_cast<>(&Component::outputChannel), + Component::documentation("output_channel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/ReactionSuite.python.cpp b/python/src/v2.0/transport/ReactionSuite.python.cpp new file mode 100644 index 000000000..12ea44914 --- /dev/null +++ b/python/src/v2.0/transport/ReactionSuite.python.cpp @@ -0,0 +1,168 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/ReactionSuite.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// ReactionSuite wrapper +void wrapReactionSuite(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::ReactionSuite; + + // create the component + python::class_ component( + module, + "ReactionSuite", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const enums::Interaction &, + const XMLName &, + const enums::Frame &, + const XMLName &, + const pops::PoPs &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional &, + const styles::Styles &, + const std::optional & + >(), + python::arg("evaluation"), + python::arg("format"), + python::arg("interaction"), + python::arg("projectile"), + python::arg("projectile_frame"), + python::arg("target"), + python::arg("po_ps"), + python::arg("application_data") = std::nullopt, + python::arg("external_files") = std::nullopt, + python::arg("fission_components") = std::nullopt, + python::arg("incomplete_reactions") = std::nullopt, + python::arg("orphan_products") = std::nullopt, + python::arg("productions") = std::nullopt, + python::arg("reactions") = std::nullopt, + python::arg("resonances") = std::nullopt, + python::arg("styles"), + python::arg("sums") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "evaluation", + &Component::evaluation, + Component::documentation("evaluation").data() + ) + .def_property_readonly( + "format", + &Component::format, + Component::documentation("format").data() + ) + .def_property_readonly( + "interaction", + &Component::interaction, + Component::documentation("interaction").data() + ) + .def_property_readonly( + "projectile", + &Component::projectile, + Component::documentation("projectile").data() + ) + .def_property_readonly( + "projectile_frame", + &Component::projectileFrame, + Component::documentation("projectile_frame").data() + ) + .def_property_readonly( + "target", + &Component::target, + Component::documentation("target").data() + ) + .def_property_readonly( + "po_ps", + python::overload_cast<>(&Component::PoPs), + Component::documentation("po_ps").data() + ) + .def_property_readonly( + "application_data", + python::overload_cast<>(&Component::applicationData), + Component::documentation("application_data").data() + ) + .def_property_readonly( + "external_files", + python::overload_cast<>(&Component::externalFiles), + Component::documentation("external_files").data() + ) + .def_property_readonly( + "fission_components", + python::overload_cast<>(&Component::fissionComponents), + Component::documentation("fission_components").data() + ) + .def_property_readonly( + "incomplete_reactions", + python::overload_cast<>(&Component::incompleteReactions), + Component::documentation("incomplete_reactions").data() + ) + .def_property_readonly( + "orphan_products", + python::overload_cast<>(&Component::orphanProducts), + Component::documentation("orphan_products").data() + ) + .def_property_readonly( + "productions", + python::overload_cast<>(&Component::productions), + Component::documentation("productions").data() + ) + .def_property_readonly( + "reactions", + python::overload_cast<>(&Component::reactions), + Component::documentation("reactions").data() + ) + .def_property_readonly( + "resonances", + python::overload_cast<>(&Component::resonances), + Component::documentation("resonances").data() + ) + .def_property_readonly( + "styles", + python::overload_cast<>(&Component::styles), + Component::documentation("styles").data() + ) + .def_property_readonly( + "sums", + python::overload_cast<>(&Component::sums), + Component::documentation("sums").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Reactions.python.cpp b/python/src/v2.0/transport/Reactions.python.cpp new file mode 100644 index 000000000..4dff38fd6 --- /dev/null +++ b/python/src/v2.0/transport/Reactions.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Reactions.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Reactions wrapper +void wrapReactions(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Reactions; + + // create the component + python::class_ component( + module, + "Reactions", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("reaction"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "reaction", + python::overload_cast<>(&Component::reaction), + Component::documentation("reaction").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Recoil.python.cpp b/python/src/v2.0/transport/Recoil.python.cpp new file mode 100644 index 000000000..fe73fd62e --- /dev/null +++ b/python/src/v2.0/transport/Recoil.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Recoil.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Recoil wrapper +void wrapRecoil(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Recoil; + + // create the component + python::class_ component( + module, + "Recoil", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string & + >(), + python::arg("href"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Reference.python.cpp b/python/src/v2.0/transport/Reference.python.cpp new file mode 100644 index 000000000..bd468c137 --- /dev/null +++ b/python/src/v2.0/transport/Reference.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Reference.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Reference wrapper +void wrapReference(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Reference; + + // create the component + python::class_ component( + module, + "Reference", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("href") = std::nullopt, + python::arg("label") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/ResolvedRegion.python.cpp b/python/src/v2.0/transport/ResolvedRegion.python.cpp new file mode 100644 index 000000000..f38517951 --- /dev/null +++ b/python/src/v2.0/transport/ResolvedRegion.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/ResolvedRegion.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// ResolvedRegion wrapper +void wrapResolvedRegion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::ResolvedRegion; + using _t = std::variant< + containers::XYs1d, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "ResolvedRegion", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dregions1d", + python::overload_cast<>(&Component::_XYs1dregions1d), + Component::documentation("_xys1dregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Resonances.python.cpp b/python/src/v2.0/transport/Resonances.python.cpp new file mode 100644 index 000000000..c1f2bca36 --- /dev/null +++ b/python/src/v2.0/transport/Resonances.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Resonances.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Resonances wrapper +void wrapResonances(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Resonances; + + // create the component + python::class_ component( + module, + "Resonances", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::string &, + const std::optional & + >(), + python::arg("href"), + python::arg("label") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/ResonancesWithBackground.python.cpp b/python/src/v2.0/transport/ResonancesWithBackground.python.cpp new file mode 100644 index 000000000..6c2e52104 --- /dev/null +++ b/python/src/v2.0/transport/ResonancesWithBackground.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/ResonancesWithBackground.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// ResonancesWithBackground wrapper +void wrapResonancesWithBackground(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::ResonancesWithBackground; + + // create the component + python::class_ component( + module, + "ResonancesWithBackground", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const transport::Background &, + const transport::Resonances &, + const std::optional & + >(), + python::arg("label"), + python::arg("background"), + python::arg("resonances"), + python::arg("uncertainty") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "background", + python::overload_cast<>(&Component::background), + Component::documentation("background").data() + ) + .def_property_readonly( + "resonances", + python::overload_cast<>(&Component::resonances), + Component::documentation("resonances").data() + ) + .def_property_readonly( + "uncertainty", + python::overload_cast<>(&Component::uncertainty), + Component::documentation("uncertainty").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/ScatteringMatrix.python.cpp b/python/src/v2.0/transport/ScatteringMatrix.python.cpp new file mode 100644 index 000000000..4c7139331 --- /dev/null +++ b/python/src/v2.0/transport/ScatteringMatrix.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/ScatteringMatrix.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// ScatteringMatrix wrapper +void wrapScatteringMatrix(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::ScatteringMatrix; + + // create the component + python::class_ component( + module, + "ScatteringMatrix", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const containers::Gridded3d & + >(), + python::arg("label"), + python::arg("product_frame"), + python::arg("gridded3d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "gridded3d", + python::overload_cast<>(&Component::gridded3d), + Component::documentation("gridded3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Summands.python.cpp b/python/src/v2.0/transport/Summands.python.cpp new file mode 100644 index 000000000..4367f562a --- /dev/null +++ b/python/src/v2.0/transport/Summands.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Summands.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Summands wrapper +void wrapSummands(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Summands; + + // create the component + python::class_ component( + module, + "Summands", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional> & + >(), + python::arg("add") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "add", + python::overload_cast<>(&Component::add), + Component::documentation("add").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Sums.python.cpp b/python/src/v2.0/transport/Sums.python.cpp new file mode 100644 index 000000000..257d47462 --- /dev/null +++ b/python/src/v2.0/transport/Sums.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Sums.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Sums wrapper +void wrapSums(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Sums; + + // create the component + python::class_ component( + module, + "Sums", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const transport::CrossSectionSums &, + const std::optional & + >(), + python::arg("cross_section_sums"), + python::arg("multiplicity_sums") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "cross_section_sums", + python::overload_cast<>(&Component::crossSectionSums), + Component::documentation("cross_section_sums").data() + ) + .def_property_readonly( + "multiplicity_sums", + python::overload_cast<>(&Component::multiplicitySums), + Component::documentation("multiplicity_sums").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Theta.python.cpp b/python/src/v2.0/transport/Theta.python.cpp new file mode 100644 index 000000000..274522a39 --- /dev/null +++ b/python/src/v2.0/transport/Theta.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Theta.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Theta wrapper +void wrapTheta(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Theta; + + // create the component + python::class_ component( + module, + "Theta", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("xys1d") = std::nullopt, + python::arg("regions1d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/U.python.cpp b/python/src/v2.0/transport/U.python.cpp new file mode 100644 index 000000000..57b21127c --- /dev/null +++ b/python/src/v2.0/transport/U.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/U.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// U wrapper +void wrapU(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::U; + + // create the component + python::class_ component( + module, + "U", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("unit") = std::nullopt, + python::arg("value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/URR_probabilityTables1d.python.cpp b/python/src/v2.0/transport/URR_probabilityTables1d.python.cpp new file mode 100644 index 000000000..bd4bc6305 --- /dev/null +++ b/python/src/v2.0/transport/URR_probabilityTables1d.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/URR_probabilityTables1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// URR_probabilityTables1d wrapper +void wrapURR_probabilityTables1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::URR_probabilityTables1d; + using _t = std::variant< + containers::XYs2d, + containers::Regions2d + >; + + // create the component + python::class_ component( + module, + "URR_probabilityTables1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const _t & + >(), + python::arg("label"), + python::arg("_xys2dregions2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "regions2d", + python::overload_cast<>(&Component::regions2d), + Component::documentation("regions2d").data() + ) + .def_property_readonly( + "_xys2dregions2d", + python::overload_cast<>(&Component::_XYs2dregions2d), + Component::documentation("_xys2dregions2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Uncorrelated.python.cpp b/python/src/v2.0/transport/Uncorrelated.python.cpp new file mode 100644 index 000000000..776665628 --- /dev/null +++ b/python/src/v2.0/transport/Uncorrelated.python.cpp @@ -0,0 +1,77 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Uncorrelated.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Uncorrelated wrapper +void wrapUncorrelated(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Uncorrelated; + + // create the component + python::class_ component( + module, + "Uncorrelated", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const transport::Angular &, + const transport::Energy & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame"), + python::arg("angular"), + python::arg("energy"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "angular", + python::overload_cast<>(&Component::angular), + Component::documentation("angular").data() + ) + .def_property_readonly( + "energy", + python::overload_cast<>(&Component::energy), + Component::documentation("energy").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/UnresolvedRegion.python.cpp b/python/src/v2.0/transport/UnresolvedRegion.python.cpp new file mode 100644 index 000000000..a8cf9ff51 --- /dev/null +++ b/python/src/v2.0/transport/UnresolvedRegion.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/UnresolvedRegion.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// UnresolvedRegion wrapper +void wrapUnresolvedRegion(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::UnresolvedRegion; + using _t = std::variant< + containers::XYs1d, + containers::Regions1d + >; + + // create the component + python::class_ component( + module, + "UnresolvedRegion", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const _t & + >(), + python::arg("_xys1dregions1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "regions1d", + python::overload_cast<>(&Component::regions1d), + Component::documentation("regions1d").data() + ) + .def_property_readonly( + "_xys1dregions1d", + python::overload_cast<>(&Component::_XYs1dregions1d), + Component::documentation("_xys1dregions1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Unspecified.python.cpp b/python/src/v2.0/transport/Unspecified.python.cpp new file mode 100644 index 000000000..cbfad1442 --- /dev/null +++ b/python/src/v2.0/transport/Unspecified.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Unspecified.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Unspecified wrapper +void wrapUnspecified(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Unspecified; + + // create the component + python::class_ component( + module, + "Unspecified", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName & + >(), + python::arg("label") = std::nullopt, + python::arg("product_frame"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/Weighted.python.cpp b/python/src/v2.0/transport/Weighted.python.cpp new file mode 100644 index 000000000..342809cc7 --- /dev/null +++ b/python/src/v2.0/transport/Weighted.python.cpp @@ -0,0 +1,98 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/Weighted.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// Weighted wrapper +void wrapWeighted(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::Weighted; + + // create the component + python::class_ component( + module, + "Weighted", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const containers::XYs1d &, + const std::optional &, + const std::optional &, + const std::optional &, + const std::optional & + >(), + python::arg("madland_nix") = std::nullopt, + python::arg("watt") = std::nullopt, + python::arg("xys1d"), + python::arg("xys2d") = std::nullopt, + python::arg("evaporation") = std::nullopt, + python::arg("general_evaporation") = std::nullopt, + python::arg("simple_maxwellian_fission") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "madland_nix", + python::overload_cast<>(&Component::MadlandNix), + Component::documentation("madland_nix").data() + ) + .def_property_readonly( + "watt", + python::overload_cast<>(&Component::Watt), + Component::documentation("watt").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + .def_property_readonly( + "xys2d", + python::overload_cast<>(&Component::XYs2d), + Component::documentation("xys2d").data() + ) + .def_property_readonly( + "evaporation", + python::overload_cast<>(&Component::evaporation), + Component::documentation("evaporation").data() + ) + .def_property_readonly( + "general_evaporation", + python::overload_cast<>(&Component::generalEvaporation), + Component::documentation("general_evaporation").data() + ) + .def_property_readonly( + "simple_maxwellian_fission", + python::overload_cast<>(&Component::simpleMaxwellianFission), + Component::documentation("simple_maxwellian_fission").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/transport/WeightedFunctionals.python.cpp b/python/src/v2.0/transport/WeightedFunctionals.python.cpp new file mode 100644 index 000000000..37993ba20 --- /dev/null +++ b/python/src/v2.0/transport/WeightedFunctionals.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/transport/WeightedFunctionals.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_transport { + +// WeightedFunctionals wrapper +void wrapWeightedFunctionals(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = transport::WeightedFunctionals; + + // create the component + python::class_ component( + module, + "WeightedFunctionals", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const transport::Weighted & + >(), + python::arg("weighted"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "weighted", + python::overload_cast<>(&Component::weighted), + Component::documentation("weighted").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_transport +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl.python.cpp b/python/src/v2.0/tsl.python.cpp new file mode 100644 index 000000000..01ca73493 --- /dev/null +++ b/python/src/v2.0/tsl.python.cpp @@ -0,0 +1,75 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#include +#include + +namespace python = pybind11; + +// v2.0 interface +namespace python_v2_0 { + +// tsl declarations +namespace python_tsl { + void wrapThermalNeutronScatteringLaw1d(python::module &); + void wrapThermalNeutronScatteringLaw(python::module &); + void wrapBraggEnergy(python::module &); + void wrapStructureFactor(python::module &); + void wrapBraggEdge(python::module &); + void wrapBraggEdges(python::module &); + void wrapS_table(python::module &); + void wrapThermalNeutronScatteringLaw_coherentElastic(python::module &); + void wrapDebyeWallerIntegral(python::module &); + void wrapBoundAtomCrossSection(python::module &); + void wrapThermalNeutronScatteringLaw_incoherentElastic(python::module &); + void wrapCoherentAtomCrossSection(python::module &); + void wrapDistinctScatteringKernel(python::module &); + void wrapE_critical(python::module &); + void wrapE_max(python::module &); + void wrapT_effective(python::module &); + void wrapSelfScatteringKernelSCTApproximation(python::module &); + void wrapPhononSpectrum(python::module &); + void wrapSelfScatteringKernelGaussianApproximation(python::module &); + void wrapSelfScatteringKernel(python::module &); + void wrapScatteringAtom(python::module &); + void wrapScatteringAtoms(python::module &); + void wrapThermalNeutronScatteringLaw_incoherentInelastic(python::module &); +} // namespace python_tsl + +// tsl wrapper +void wrapTsl(python::module &module) +{ + // create the tsl submodule + python::module submodule = module.def_submodule( + "tsl", + "GNDS v2.0 tsl" + ); + + // wrap tsl components + python_tsl::wrapThermalNeutronScatteringLaw1d(submodule); + python_tsl::wrapThermalNeutronScatteringLaw(submodule); + python_tsl::wrapBraggEnergy(submodule); + python_tsl::wrapStructureFactor(submodule); + python_tsl::wrapBraggEdge(submodule); + python_tsl::wrapBraggEdges(submodule); + python_tsl::wrapS_table(submodule); + python_tsl::wrapThermalNeutronScatteringLaw_coherentElastic(submodule); + python_tsl::wrapDebyeWallerIntegral(submodule); + python_tsl::wrapBoundAtomCrossSection(submodule); + python_tsl::wrapThermalNeutronScatteringLaw_incoherentElastic(submodule); + python_tsl::wrapCoherentAtomCrossSection(submodule); + python_tsl::wrapDistinctScatteringKernel(submodule); + python_tsl::wrapE_critical(submodule); + python_tsl::wrapE_max(submodule); + python_tsl::wrapT_effective(submodule); + python_tsl::wrapSelfScatteringKernelSCTApproximation(submodule); + python_tsl::wrapPhononSpectrum(submodule); + python_tsl::wrapSelfScatteringKernelGaussianApproximation(submodule); + python_tsl::wrapSelfScatteringKernel(submodule); + python_tsl::wrapScatteringAtom(submodule); + python_tsl::wrapScatteringAtoms(submodule); + python_tsl::wrapThermalNeutronScatteringLaw_incoherentInelastic(submodule); +}; + +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/BoundAtomCrossSection.python.cpp b/python/src/v2.0/tsl/BoundAtomCrossSection.python.cpp new file mode 100644 index 000000000..d97759f20 --- /dev/null +++ b/python/src/v2.0/tsl/BoundAtomCrossSection.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/BoundAtomCrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// BoundAtomCrossSection wrapper +void wrapBoundAtomCrossSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::BoundAtomCrossSection; + + // create the component + python::class_ component( + module, + "BoundAtomCrossSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/BraggEdge.python.cpp b/python/src/v2.0/tsl/BraggEdge.python.cpp new file mode 100644 index 000000000..47d7fcf04 --- /dev/null +++ b/python/src/v2.0/tsl/BraggEdge.python.cpp @@ -0,0 +1,70 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/BraggEdge.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// BraggEdge wrapper +void wrapBraggEdge(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::BraggEdge; + + // create the component + python::class_ component( + module, + "BraggEdge", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const tsl::BraggEnergy &, + const tsl::StructureFactor & + >(), + python::arg("label"), + python::arg("bragg_energy"), + python::arg("structure_factor"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "bragg_energy", + python::overload_cast<>(&Component::BraggEnergy), + Component::documentation("bragg_energy").data() + ) + .def_property_readonly( + "structure_factor", + python::overload_cast<>(&Component::structureFactor), + Component::documentation("structure_factor").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/BraggEdges.python.cpp b/python/src/v2.0/tsl/BraggEdges.python.cpp new file mode 100644 index 000000000..4b77ce9b9 --- /dev/null +++ b/python/src/v2.0/tsl/BraggEdges.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/BraggEdges.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// BraggEdges wrapper +void wrapBraggEdges(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::BraggEdges; + + // create the component + python::class_ component( + module, + "BraggEdges", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("bragg_edge"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "bragg_edge", + python::overload_cast<>(&Component::BraggEdge), + Component::documentation("bragg_edge").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/BraggEnergy.python.cpp b/python/src/v2.0/tsl/BraggEnergy.python.cpp new file mode 100644 index 000000000..4c7ec4669 --- /dev/null +++ b/python/src/v2.0/tsl/BraggEnergy.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/BraggEnergy.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// BraggEnergy wrapper +void wrapBraggEnergy(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::BraggEnergy; + + // create the component + python::class_ component( + module, + "BraggEnergy", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/CoherentAtomCrossSection.python.cpp b/python/src/v2.0/tsl/CoherentAtomCrossSection.python.cpp new file mode 100644 index 000000000..6b28d2e10 --- /dev/null +++ b/python/src/v2.0/tsl/CoherentAtomCrossSection.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/CoherentAtomCrossSection.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// CoherentAtomCrossSection wrapper +void wrapCoherentAtomCrossSection(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::CoherentAtomCrossSection; + + // create the component + python::class_ component( + module, + "CoherentAtomCrossSection", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const Float64 & + >(), + python::arg("unit"), + python::arg("value"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/DebyeWallerIntegral.python.cpp b/python/src/v2.0/tsl/DebyeWallerIntegral.python.cpp new file mode 100644 index 000000000..d3a243c7e --- /dev/null +++ b/python/src/v2.0/tsl/DebyeWallerIntegral.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/DebyeWallerIntegral.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// DebyeWallerIntegral wrapper +void wrapDebyeWallerIntegral(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::DebyeWallerIntegral; + + // create the component + python::class_ component( + module, + "DebyeWallerIntegral", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/DistinctScatteringKernel.python.cpp b/python/src/v2.0/tsl/DistinctScatteringKernel.python.cpp new file mode 100644 index 000000000..9b6f5fb69 --- /dev/null +++ b/python/src/v2.0/tsl/DistinctScatteringKernel.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/DistinctScatteringKernel.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// DistinctScatteringKernel wrapper +void wrapDistinctScatteringKernel(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::DistinctScatteringKernel; + + // create the component + python::class_ component( + module, + "DistinctScatteringKernel", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("gridded3d") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "gridded3d", + python::overload_cast<>(&Component::gridded3d), + Component::documentation("gridded3d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/E_critical.python.cpp b/python/src/v2.0/tsl/E_critical.python.cpp new file mode 100644 index 000000000..7fbfee12e --- /dev/null +++ b/python/src/v2.0/tsl/E_critical.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/E_critical.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// E_critical wrapper +void wrapE_critical(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::E_critical; + + // create the component + python::class_ component( + module, + "E_critical", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("unit") = std::nullopt, + python::arg("value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/E_max.python.cpp b/python/src/v2.0/tsl/E_max.python.cpp new file mode 100644 index 000000000..06d1cf6c8 --- /dev/null +++ b/python/src/v2.0/tsl/E_max.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/E_max.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// E_max wrapper +void wrapE_max(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::E_max; + + // create the component + python::class_ component( + module, + "E_max", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional & + >(), + python::arg("unit") = std::nullopt, + python::arg("value") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "unit", + &Component::unit, + Component::documentation("unit").data() + ) + .def_property_readonly( + "value", + &Component::value, + Component::documentation("value").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/PhononSpectrum.python.cpp b/python/src/v2.0/tsl/PhononSpectrum.python.cpp new file mode 100644 index 000000000..d9c14c30c --- /dev/null +++ b/python/src/v2.0/tsl/PhononSpectrum.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/PhononSpectrum.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// PhononSpectrum wrapper +void wrapPhononSpectrum(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::PhononSpectrum; + + // create the component + python::class_ component( + module, + "PhononSpectrum", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/S_table.python.cpp b/python/src/v2.0/tsl/S_table.python.cpp new file mode 100644 index 000000000..45954234e --- /dev/null +++ b/python/src/v2.0/tsl/S_table.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/S_table.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// S_table wrapper +void wrapS_table(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::S_table; + + // create the component + python::class_ component( + module, + "S_table", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::Gridded2d & + >(), + python::arg("gridded2d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "gridded2d", + python::overload_cast<>(&Component::gridded2d), + Component::documentation("gridded2d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ScatteringAtom.python.cpp b/python/src/v2.0/tsl/ScatteringAtom.python.cpp new file mode 100644 index 000000000..f8781527e --- /dev/null +++ b/python/src/v2.0/tsl/ScatteringAtom.python.cpp @@ -0,0 +1,119 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ScatteringAtom.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ScatteringAtom wrapper +void wrapScatteringAtom(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ScatteringAtom; + + // create the component + python::class_ component( + module, + "ScatteringAtom", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const Integer32 &, + const XMLName &, + const bool &, + const tsl::BoundAtomCrossSection &, + const std::optional &, + const std::optional &, + const std::optional &, + const tsl::E_max &, + const ambiguousNamespace::Mass &, + const tsl::SelfScatteringKernel & + >(), + python::arg("number_per_molecule"), + python::arg("pid"), + python::arg("primary_scatterer"), + python::arg("bound_atom_cross_section"), + python::arg("coherent_atom_cross_section") = std::nullopt, + python::arg("distinct_scattering_kernel") = std::nullopt, + python::arg("e_critical") = std::nullopt, + python::arg("e_max"), + python::arg("mass"), + python::arg("self_scattering_kernel"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "number_per_molecule", + &Component::numberPerMolecule, + Component::documentation("number_per_molecule").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "primary_scatterer", + &Component::primaryScatterer, + Component::documentation("primary_scatterer").data() + ) + .def_property_readonly( + "bound_atom_cross_section", + python::overload_cast<>(&Component::boundAtomCrossSection), + Component::documentation("bound_atom_cross_section").data() + ) + .def_property_readonly( + "coherent_atom_cross_section", + python::overload_cast<>(&Component::coherentAtomCrossSection), + Component::documentation("coherent_atom_cross_section").data() + ) + .def_property_readonly( + "distinct_scattering_kernel", + python::overload_cast<>(&Component::distinctScatteringKernel), + Component::documentation("distinct_scattering_kernel").data() + ) + .def_property_readonly( + "e_critical", + python::overload_cast<>(&Component::e_critical), + Component::documentation("e_critical").data() + ) + .def_property_readonly( + "e_max", + python::overload_cast<>(&Component::e_max), + Component::documentation("e_max").data() + ) + .def_property_readonly( + "mass", + python::overload_cast<>(&Component::mass), + Component::documentation("mass").data() + ) + .def_property_readonly( + "self_scattering_kernel", + python::overload_cast<>(&Component::selfScatteringKernel), + Component::documentation("self_scattering_kernel").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ScatteringAtoms.python.cpp b/python/src/v2.0/tsl/ScatteringAtoms.python.cpp new file mode 100644 index 000000000..af3eeefd7 --- /dev/null +++ b/python/src/v2.0/tsl/ScatteringAtoms.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ScatteringAtoms.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ScatteringAtoms wrapper +void wrapScatteringAtoms(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ScatteringAtoms; + + // create the component + python::class_ component( + module, + "ScatteringAtoms", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::vector & + >(), + python::arg("scattering_atom"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "scattering_atom", + python::overload_cast<>(&Component::scatteringAtom), + Component::documentation("scattering_atom").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/SelfScatteringKernel.python.cpp b/python/src/v2.0/tsl/SelfScatteringKernel.python.cpp new file mode 100644 index 000000000..10c15ff62 --- /dev/null +++ b/python/src/v2.0/tsl/SelfScatteringKernel.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/SelfScatteringKernel.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// SelfScatteringKernel wrapper +void wrapSelfScatteringKernel(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::SelfScatteringKernel; + using _t = std::variant< + containers::Gridded3d, + tsl::SelfScatteringKernelGaussianApproximation + >; + + // create the component + python::class_ component( + module, + "SelfScatteringKernel", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const std::optional &, + const _t & + >(), + python::arg("symmetric") = std::nullopt, + python::arg("self_scattering_kernel_sctapproximation") = std::nullopt, + python::arg("_gridded3dself_scattering_kernel_gaussian_approximation"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "symmetric", + &Component::symmetric, + Component::documentation("symmetric").data() + ) + .def_property_readonly( + "self_scattering_kernel_sctapproximation", + python::overload_cast<>(&Component::selfScatteringKernelSCTApproximation), + Component::documentation("self_scattering_kernel_sctapproximation").data() + ) + .def_property_readonly( + "gridded3d", + python::overload_cast<>(&Component::gridded3d), + Component::documentation("gridded3d").data() + ) + .def_property_readonly( + "self_scattering_kernel_gaussian_approximation", + python::overload_cast<>(&Component::selfScatteringKernelGaussianApproximation), + Component::documentation("self_scattering_kernel_gaussian_approximation").data() + ) + .def_property_readonly( + "_gridded3dself_scattering_kernel_gaussian_approximation", + python::overload_cast<>(&Component::_gridded3dselfScatteringKernelGaussianApproximation), + Component::documentation("_gridded3dself_scattering_kernel_gaussian_approximation").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/SelfScatteringKernelGaussianApproximation.python.cpp b/python/src/v2.0/tsl/SelfScatteringKernelGaussianApproximation.python.cpp new file mode 100644 index 000000000..f6aead58a --- /dev/null +++ b/python/src/v2.0/tsl/SelfScatteringKernelGaussianApproximation.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/SelfScatteringKernelGaussianApproximation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// SelfScatteringKernelGaussianApproximation wrapper +void wrapSelfScatteringKernelGaussianApproximation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::SelfScatteringKernelGaussianApproximation; + + // create the component + python::class_ component( + module, + "SelfScatteringKernelGaussianApproximation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("phonon_spectrum") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "phonon_spectrum", + python::overload_cast<>(&Component::phononSpectrum), + Component::documentation("phonon_spectrum").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/SelfScatteringKernelSCTApproximation.python.cpp b/python/src/v2.0/tsl/SelfScatteringKernelSCTApproximation.python.cpp new file mode 100644 index 000000000..a12063e2d --- /dev/null +++ b/python/src/v2.0/tsl/SelfScatteringKernelSCTApproximation.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/SelfScatteringKernelSCTApproximation.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// SelfScatteringKernelSCTApproximation wrapper +void wrapSelfScatteringKernelSCTApproximation(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::SelfScatteringKernelSCTApproximation; + + // create the component + python::class_ component( + module, + "SelfScatteringKernelSCTApproximation", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional & + >(), + python::arg("t_effective") = std::nullopt, + Component::documentation("constructor").data() + ) + .def_property_readonly( + "t_effective", + python::overload_cast<>(&Component::T_effective), + Component::documentation("t_effective").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/StructureFactor.python.cpp b/python/src/v2.0/tsl/StructureFactor.python.cpp new file mode 100644 index 000000000..df7c26894 --- /dev/null +++ b/python/src/v2.0/tsl/StructureFactor.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/StructureFactor.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// StructureFactor wrapper +void wrapStructureFactor(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::StructureFactor; + + // create the component + python::class_ component( + module, + "StructureFactor", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/T_effective.python.cpp b/python/src/v2.0/tsl/T_effective.python.cpp new file mode 100644 index 000000000..a39fdc9fd --- /dev/null +++ b/python/src/v2.0/tsl/T_effective.python.cpp @@ -0,0 +1,56 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/T_effective.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// T_effective wrapper +void wrapT_effective(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::T_effective; + + // create the component + python::class_ component( + module, + "T_effective", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const containers::XYs1d & + >(), + python::arg("xys1d"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "xys1d", + python::overload_cast<>(&Component::XYs1d), + Component::documentation("xys1d").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ThermalNeutronScatteringLaw.python.cpp b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw.python.cpp new file mode 100644 index 000000000..6ad6cf54b --- /dev/null +++ b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ThermalNeutronScatteringLaw wrapper +void wrapThermalNeutronScatteringLaw(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ThermalNeutronScatteringLaw; + + // create the component + python::class_ component( + module, + "ThermalNeutronScatteringLaw", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("href"), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ThermalNeutronScatteringLaw1d.python.cpp b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw1d.python.cpp new file mode 100644 index 000000000..551de2d7d --- /dev/null +++ b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw1d.python.cpp @@ -0,0 +1,63 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw1d.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ThermalNeutronScatteringLaw1d wrapper +void wrapThermalNeutronScatteringLaw1d(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ThermalNeutronScatteringLaw1d; + + // create the component + python::class_ component( + module, + "ThermalNeutronScatteringLaw1d", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName & + >(), + python::arg("href"), + python::arg("label"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "href", + &Component::href, + Component::documentation("href").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_coherentElastic.python.cpp b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_coherentElastic.python.cpp new file mode 100644 index 000000000..7589dd4f1 --- /dev/null +++ b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_coherentElastic.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_coherentElastic.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ThermalNeutronScatteringLaw_coherentElastic wrapper +void wrapThermalNeutronScatteringLaw_coherentElastic(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ThermalNeutronScatteringLaw_coherentElastic; + using _t = std::variant< + tsl::BraggEdges, + tsl::S_table + >; + + // create the component + python::class_ component( + module, + "ThermalNeutronScatteringLaw_coherentElastic", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const enums::Frame &, + const _t & + >(), + python::arg("label"), + python::arg("pid"), + python::arg("product_frame"), + python::arg("_bragg_edges_s_table"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "bragg_edges", + python::overload_cast<>(&Component::BraggEdges), + Component::documentation("bragg_edges").data() + ) + .def_property_readonly( + "s_table", + python::overload_cast<>(&Component::S_table), + Component::documentation("s_table").data() + ) + .def_property_readonly( + "_bragg_edges_s_table", + python::overload_cast<>(&Component::_BraggEdgesS_table), + Component::documentation("_bragg_edges_s_table").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentElastic.python.cpp b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentElastic.python.cpp new file mode 100644 index 000000000..54b3b5af3 --- /dev/null +++ b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentElastic.python.cpp @@ -0,0 +1,84 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentElastic.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ThermalNeutronScatteringLaw_incoherentElastic wrapper +void wrapThermalNeutronScatteringLaw_incoherentElastic(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ThermalNeutronScatteringLaw_incoherentElastic; + + // create the component + python::class_ component( + module, + "ThermalNeutronScatteringLaw_incoherentElastic", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const XMLName &, + const XMLName &, + const enums::Frame &, + const tsl::DebyeWallerIntegral &, + const tsl::BoundAtomCrossSection & + >(), + python::arg("label"), + python::arg("pid"), + python::arg("product_frame"), + python::arg("debye_waller_integral"), + python::arg("bound_atom_cross_section"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "debye_waller_integral", + python::overload_cast<>(&Component::DebyeWallerIntegral), + Component::documentation("debye_waller_integral").data() + ) + .def_property_readonly( + "bound_atom_cross_section", + python::overload_cast<>(&Component::boundAtomCrossSection), + Component::documentation("bound_atom_cross_section").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentInelastic.python.cpp b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentInelastic.python.cpp new file mode 100644 index 000000000..01fe70507 --- /dev/null +++ b/python/src/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentInelastic.python.cpp @@ -0,0 +1,91 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +// system includes +#include +#include + +// local includes +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentInelastic.hpp" +#include "definitions.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace python_v2_0 { +namespace python_tsl { + +// ThermalNeutronScatteringLaw_incoherentInelastic wrapper +void wrapThermalNeutronScatteringLaw_incoherentInelastic(python::module &module) +{ + using namespace njoy::GNDStk; + using namespace njoy::GNDStk::v2_0; + + // type aliases + using Component = tsl::ThermalNeutronScatteringLaw_incoherentInelastic; + + // create the component + python::class_ component( + module, + "ThermalNeutronScatteringLaw_incoherentInelastic", + Component::documentation().data() + ); + + // wrap the component + component + .def( + python::init< + const std::optional &, + const XMLName &, + const XMLName &, + const XMLName &, + const enums::Frame &, + const tsl::ScatteringAtoms & + >(), + python::arg("incoherent_approximation") = std::nullopt, + python::arg("label"), + python::arg("pid"), + python::arg("primary_scatterer"), + python::arg("product_frame"), + python::arg("scattering_atoms"), + Component::documentation("constructor").data() + ) + .def_property_readonly( + "incoherent_approximation", + [](const Component &self) { return self.incoherentApproximation().value(); }, + Component::documentation("incoherent_approximation").data() + ) + .def_property_readonly( + "label", + &Component::label, + Component::documentation("label").data() + ) + .def_property_readonly( + "pid", + &Component::pid, + Component::documentation("pid").data() + ) + .def_property_readonly( + "primary_scatterer", + &Component::primaryScatterer, + Component::documentation("primary_scatterer").data() + ) + .def_property_readonly( + "product_frame", + &Component::productFrame, + Component::documentation("product_frame").data() + ) + .def_property_readonly( + "scattering_atoms", + python::overload_cast<>(&Component::scatteringAtoms), + Component::documentation("scattering_atoms").data() + ) + ; + + // add standard component definitions + addStandardComponentDefinitions< Component >( component ); +} + +} // namespace python_tsl +} // namespace python_v2_0 diff --git a/python/test/Test_GNDStk_BoundaryCondition.py b/python/test/Test_GNDStk_BoundaryCondition.py new file mode 100644 index 000000000..7e9467ba0 --- /dev/null +++ b/python/test/Test_GNDStk_BoundaryCondition.py @@ -0,0 +1,64 @@ +# standard imports +import unittest + +# third party imports + +# local imports +from GNDStk import BoundaryCondition + +class Test_GNDStk_BoundaryCondition( unittest.TestCase ) : + """Unit test for the BoundaryCondition enumerator.""" + + def test_component( self ) : + + value = BoundaryCondition.EliminateShiftFunction + + self.assertTrue( value == BoundaryCondition.EliminateShiftFunction ) + self.assertFalse( value == BoundaryCondition.NegativeOrbitalMomentum ) + self.assertFalse( value == BoundaryCondition.Brune ) + self.assertFalse( value == BoundaryCondition.Given ) + + self.assertFalse( value != BoundaryCondition.EliminateShiftFunction ) + self.assertTrue( value != BoundaryCondition.NegativeOrbitalMomentum ) + self.assertTrue( value != BoundaryCondition.Brune ) + self.assertTrue( value != BoundaryCondition.Given ) + + value = BoundaryCondition.NegativeOrbitalMomentum + + self.assertFalse( value == BoundaryCondition.EliminateShiftFunction ) + self.assertTrue( value == BoundaryCondition.NegativeOrbitalMomentum ) + self.assertFalse( value == BoundaryCondition.Brune ) + self.assertFalse( value == BoundaryCondition.Given ) + + self.assertTrue( value != BoundaryCondition.EliminateShiftFunction ) + self.assertFalse( value != BoundaryCondition.NegativeOrbitalMomentum ) + self.assertTrue( value != BoundaryCondition.Brune ) + self.assertTrue( value != BoundaryCondition.Given ) + + value = BoundaryCondition.Brune + + self.assertFalse( value == BoundaryCondition.EliminateShiftFunction ) + self.assertFalse( value == BoundaryCondition.NegativeOrbitalMomentum ) + self.assertTrue( value == BoundaryCondition.Brune ) + self.assertFalse( value == BoundaryCondition.Given ) + + self.assertTrue( value != BoundaryCondition.EliminateShiftFunction ) + self.assertTrue( value != BoundaryCondition.NegativeOrbitalMomentum ) + self.assertFalse( value != BoundaryCondition.Brune ) + self.assertTrue( value != BoundaryCondition.Given ) + + value = BoundaryCondition.Given + + self.assertFalse( value == BoundaryCondition.EliminateShiftFunction ) + self.assertFalse( value == BoundaryCondition.NegativeOrbitalMomentum ) + self.assertFalse( value == BoundaryCondition.Brune ) + self.assertTrue( value == BoundaryCondition.Given ) + + self.assertTrue( value != BoundaryCondition.EliminateShiftFunction ) + self.assertTrue( value != BoundaryCondition.NegativeOrbitalMomentum ) + self.assertTrue( value != BoundaryCondition.Brune ) + self.assertFalse( value != BoundaryCondition.Given ) + +if __name__ == '__main__' : + + unittest.main() diff --git a/python/test/Test_GNDStk_Interpolation.pyc b/python/test/Test_GNDStk_Interpolation.pyc new file mode 100644 index 000000000..feefb9231 Binary files /dev/null and b/python/test/Test_GNDStk_Interpolation.pyc differ diff --git a/python/test/__init__.pyc b/python/test/__init__.pyc new file mode 100644 index 000000000..b65ba59b5 Binary files /dev/null and b/python/test/__init__.pyc differ diff --git a/python/test/core/Test_GNDStk_core_Node.pyc b/python/test/core/Test_GNDStk_core_Node.pyc new file mode 100644 index 000000000..e48dd2c5e Binary files /dev/null and b/python/test/core/Test_GNDStk_core_Node.pyc differ diff --git a/python/test/core/__init__.pyc b/python/test/core/__init__.pyc new file mode 100644 index 000000000..f09dbaae2 Binary files /dev/null and b/python/test/core/__init__.pyc differ diff --git a/src/GNDStk.hpp b/src/GNDStk.hpp index c665be5ae..98b374590 100644 --- a/src/GNDStk.hpp +++ b/src/GNDStk.hpp @@ -1,14 +1,26 @@ -#pragma once +#ifndef NJOY_GNDSTK +#define NJOY_GNDSTK // ------------------------ // External libraries // ------------------------ +// To circumvent errors in other libraries +#include +#undef CHAR_WIDTH + #include "pugixml.hpp" #include "nlohmann/json.hpp" #include "Log.hpp" +#include +#include + +// OpenMP +#ifdef _OPENMP +#include +#endif // ------------------------ @@ -26,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -55,90 +69,54 @@ namespace njoy { namespace GNDStk { -// basic +// Basic #include "GNDStk/utility.hpp" #include "GNDStk/precision.hpp" #include "GNDStk/enums.hpp" -// external-library wrappers +// External-library wrappers #include "GNDStk/XML.hpp" #include "GNDStk/JSON.hpp" +#include "GNDStk/HDF5.hpp" -// string/Node to/from type +// std::string/Node to/from type #include "GNDStk/string2type.hpp" #include "GNDStk/type2string.hpp" // Meta, Child, and related -#include "GNDStk/convert_t.hpp" #include "GNDStk/Meta.hpp" #include "GNDStk/Child.hpp" -#include "GNDStk/keyword.hpp" #include "GNDStk/or.hpp" -// optional, with default -#include "GNDStk/Defaulted.hpp" +// Our alternative to std::optional +#include "GNDStk/Optional.hpp" -// sets of Meta/Child -#include "GNDStk/basic.hpp" -#include "GNDStk/misc.hpp" +// Like std::optional, but with a default +#include "GNDStk/Defaulted.hpp" -// Tree: primary constructs +// Main classes #include "GNDStk/Node.hpp" #include "GNDStk/Tree.hpp" -// fixme This really belongs with basic.hpp and misc.hpp above, but I had to -// move it here due to some ordering issues that arose when I de-templated -// Node and Tree. We'll deal with this later; it's an internal issue, not -// something that will affect users in any manner. -#include "GNDStk/common.hpp" - // Node to/from type #include "GNDStk/node2type.hpp" #include "GNDStk/type2node.hpp" -// xml/json/tree conversions +// Node/XML/JSON/HDF5 conversions #include "GNDStk/convert.hpp" -// fixme See above fixme -namespace basic { using namespace common; } -namespace misc { using namespace common; } - // Miscellaneous support constructs for Standard Interface classes #include "GNDStk/Support.hpp" +#include "GNDStk/Lookup.hpp" // Base classes for primary Standard Interface data classes -#include "GNDStk/BodyText.hpp" +#include "GNDStk/BlockData.hpp" #include "GNDStk/Component.hpp" - -// ------------------------ -// GNDStk "core interface" -// ------------------------ - -/* -In a user code, writing this: - - using namespace njoy::GNDStk::core; - -gives the same effect as writing this: - - using namespace njoy::GNDStk; - using namespace njoy::GNDStk::basic; - -Meaning: We consider our "core interface" to consist of everything in GNDStk:: -proper, plus our basic:: set of Meta and Child objects. Those are the ones with - type, so that they return metadata and nodes in their original tree form. -Note that basic:: itself brings in Meta and Child objects from its own nested -meta:: and child:: namespaces. Those are separate because there's a small amount -of overlap between allowable GNDS metadatum names and node names. With this -scheme, if a name you wish to use isn't one of the overlapping names, just use -it. If it is, then prefix with meta:: or child:: as necessary. -*/ - -namespace core { - using namespace GNDStk; - using namespace basic; -} +// Helper constructs for C language interfaces +#include "GNDStk/CInterface.hpp" } // namespace GNDStk } // namespace njoy + +#endif diff --git a/src/GNDStk/BlockData.hpp b/src/GNDStk/BlockData.hpp new file mode 100644 index 000000000..e7fc497f4 --- /dev/null +++ b/src/GNDStk/BlockData.hpp @@ -0,0 +1,166 @@ + +// Printing style +enum class PrintMode { + cpp, + python +}; +inline PrintMode printMode = PrintMode::cpp; + +// Printing-related colors. +// todo Eventually, this probably belongs in a more context-agnostic +// location, such as GNDStk's utility.hpp file or something like it. +#include "GNDStk/BlockData/src/colors.hpp" + +// Miscellaneous helper constructs. +#include "GNDStk/BlockData/src/detail.hpp" + + +// ----------------------------------------------------------------------------- +// BlockData +// The case is specialized and has the fun stuff. This one +// needs just a bit of content, to allow for uniform treatment of BlockData. +// ----------------------------------------------------------------------------- + +template +class BlockData { +public: + using VariantOfVectors = std::variant; + using VariantOfScalars = std::variant; + static inline constexpr bool runtime = false; + template + static inline constexpr bool supported = false; +}; + + +// ----------------------------------------------------------------------------- +// BlockData +// +// Designed to be flexible, smart, and safe. Does lots of checks, and, for the +// DATATYPE == void case, can essentially re-form itself depending on what type +// of data someone tries to extract. +// +// For efficiency in the DATATYPE == void case, an application may want to copy +// to its own vector (e.g. auto myvec = myblockdata.get>()) +// in order to do work on (or with) the vector there, before copying it back. +// ----------------------------------------------------------------------------- + +template +class BlockData { +public: + + #include "GNDStk/BlockData/src/types.hpp" + + // For convenience in various SFINAE and if-constexpr constructs + static inline constexpr bool runtime = detail::isVoid; + template + struct is_supported { + static inline constexpr bool value = + ( runtime && detail::isAlternative) || + (!runtime && ( + std::is_constructible_v || + std::is_convertible_v + )); + }; + template + static inline constexpr bool supported = is_supported::value; + + enum class Active { string, vector }; + +private: + + // For internal use + mutable Active act = Active::string; + + // Raw string, directly from "plain character data" in a GNDS file. + // We'll allow callers to set this by using a setter. + std::string rawstring; + + // Vector of . + // *** This will be used if, and only if, DATATYPE == void. + // Mutable, so that we can defer processing of the raw string into + // a vector until, and unless, a caller *asks* for the vector. + mutable VariantOfVectors variant; + + // Vector of + // *** This will be used if, and only if, DATATYPE != void. + // data_t is used in a few places where, without it, we'd create compilation + // errors by using "void" in invalid ways. The "int" below is arbitrary - + // basically a placeholder - because the following is used only if !runtime. + using data_t = std::conditional_t; + mutable std::vector vector; + +public: + + // Parameters that affect interpretation of the raw string: + // struct vars { length, start, valueType } + // Includes public getters and setters for those. + // We won't use valueType if DATATYPE != void. + #include "GNDStk/BlockData/src/params.hpp" + + // trim + // Flag: should the conversion of BlockData data back into textual data, + // in a Node, trim zeros from the start and end of the output? + mutable bool trim = true; + + // Getters and setters for the raw string: + #include "GNDStk/BlockData/src/string.hpp" + + // active() + Active active() const { return act; } + + // clear() + // Clears the vector, or the active vector alternative in the variant. + BlockData &clear() + { + if constexpr (runtime) + std::visit([](auto &&alt) { alt.clear(); }, variant); + else + vector.clear(); + + act = Active::vector; + return *this; + } + + // size() + // Returns the size of the vector, or of the active vector alternative in + // the variant. Depending on what someone may or may not have done with the + // current BlockData object, size() might or might not reflect the values of + // length and/or start, or reflect the current contents of the raw string. + std::size_t size() const + { + if constexpr (runtime) + return std::visit([](auto &&alt) { return alt.size(); }, variant); + else + return vector.size(); + } + + // Various vector get() functions, and the type-specific doubles() etc. + #include "GNDStk/BlockData/src/get.hpp" + + // Read/write data, from/to a Node + #include "GNDStk/BlockData/src/fromNode.hpp" + #include "GNDStk/BlockData/src/toNode.hpp" + + // Print to ostream + #include "GNDStk/BlockData/src/print.hpp" + + // Pull/push length/start/valueType from/to derived-class object + #include "GNDStk/BlockData/src/sync.hpp" + + // Assignment + // From string or vector; the former == calling our raw string setter + #include "GNDStk/BlockData/src/assign.hpp" + + // Conversion to vector + // *** Available if, and only if, DATATYPE != void. + template< + class T = DATATYPE, + class = std::enable_if_t> + > + operator std::vector() const + { + // get(), not vector; get() handles properly if the string is active + return get(); + } + +}; // class BlockData diff --git a/src/GNDStk/BlockData/src/assign.hpp b/src/GNDStk/BlockData/src/assign.hpp new file mode 100644 index 000000000..c809b3a80 --- /dev/null +++ b/src/GNDStk/BlockData/src/assign.hpp @@ -0,0 +1,75 @@ + +// ----------------------------------------------------------------------------- +// Assignment from string +// Same effect as the string(new string) setter +// ----------------------------------------------------------------------------- + +BlockData &operator=(const std::string &str) +{ + return string(str); +} + + +// ----------------------------------------------------------------------------- +// Assignment from vector +// ----------------------------------------------------------------------------- + +/* +DISCUSSION + +Elsewhere, a BlockData object can be made from a GNDS node. From GNDS, we get +a text string (copied to the rawstring field), from which a vector of values +can be created on an as-needed basis. A GNDS node might also give us any of +length, start, and valueType, which, when pulling data from the Node, we'll +use if they're there, or otherwise assume to be our defaults. + +Here, we're allowing for an assignment BlockData = vector. For this assignment, +the caller should send the full, complete vector of values that's appropriate +for the GNDS Node whose data this BlockData object is intended to represent. + +Specifically: the vector should contain whatever leading and/or trailing 0s +the full data vector is supposed to have. The length and start values are +completely ignored by this function; they're neither used nor set. Future +vector accesses though our various get() functions simply access the vector +exactly as-is. Length and start won't come into play until - and unless - a +caller uses the string setter (or assignment to string) and subsequently +triggers a remake of the vector. (Which would then be a newly-created vector, +based on the value of the raw string - not the vector from which we're +assigning here.) + +As for valueType, this function attempts to guess it from the vector's element +type, and sets it to "", the empty string, if we don't recognize that type. + +If a vector that's assigned from, here, is still in play when this BlockData's +data are written to a Node (see the toNode() function), then toNode() will +recompute length and start automatically, based on the vector's beginning and +ending content, if the "trim" flag is set. See toNode() for more information. +*/ + +template +std::enable_if_t, BlockData &> +operator=(const std::vector &vec) +{ + // set the raw string to "", because it's no longer considered meaningful + rawstring = ""; + + // length, start, valueType + length(vec.size()); + start(0); + valueType(detail::Type2Names::value[0]); + + // assign vector + if constexpr (runtime) + variant = vec; + else if constexpr (std::is_same_v) + vector = vec; + else { + vector.clear(); + vector.reserve(vec.size()); + for (const T &element : vec) + vector.push_back(DATATYPE(element)); + } + + act = Active::vector; + return *this; +} diff --git a/src/GNDStk/BlockData/src/colors.hpp b/src/GNDStk/BlockData/src/colors.hpp new file mode 100644 index 000000000..60ad07c7c --- /dev/null +++ b/src/GNDStk/BlockData/src/colors.hpp @@ -0,0 +1,702 @@ + +inline bool shades = true; + +namespace color { + +// makeColor +// Here, not in detail::, because it may be of interest to users. +inline std::string makeColor(const int r, const int g, const int b) +{ + return "\033[38;2;" + + std::to_string(r < 0 ? 0 : r > 255 ? 255 : r) + ";" + + std::to_string(g < 0 ? 0 : g > 255 ? 255 : g) + ";" + + std::to_string(b < 0 ? 0 : b > 255 ? 255 : b) + "m"; +} + + +// ----------------------------------------------------------------------------- +// Simple ANSI colors +// ----------------------------------------------------------------------------- + +// Specific colors: +// color::plain::* +// color::bold::* +// Reset/clear: +// color::reset +// These are ANSI color escape sequences. They'll work on many terminals, +// perhaps most, but working isn't guaranteed. The GNDStk::colors flag +// can be set to false (so that colors aren't used) if the escapes don't +// work, or if someone simply doesn't want colors. + +// color::plain:: +namespace plain { + inline const std::string + black = "\033[30;1m", + red = "\033[31;1m", + green = "\033[32;1m", + blue = "\033[34;1m", + cyan = "\033[36;1m", + magenta = "\033[35;1m", + yellow = "\033[33;1m", + white = "\033[37;1m"; +} + +// color::bold:: +namespace bold { + inline const std::string + black = "\033[30;21m", + red = "\033[31;21m", + green = "\033[32;21m", + blue = "\033[34;21m", + cyan = "\033[36;21m", + magenta = "\033[35;21m", + yellow = "\033[33;21m", + white = "\033[37;21m"; +} + +// color::reset +inline const std::string reset = "\033[0m"; + + +// ----------------------------------------------------------------------------- +// blue2red +// ----------------------------------------------------------------------------- + +template>> +std::string blue2red(T min, T value, T max) +{ + static const int ncolors = 511; + static const int rgb[ncolors][3] = { + { 0, 0, 255 }, // blue... + { 0, 1, 254 }, // decrease, while increasing green... + { 0, 2, 253 }, + { 0, 3, 252 }, + { 0, 4, 251 }, + { 0, 5, 250 }, + { 0, 6, 249 }, + { 0, 7, 248 }, + { 0, 8, 247 }, + { 0, 9, 246 }, + { 0, 10, 245 }, + { 0, 11, 244 }, + { 0, 12, 243 }, + { 0, 13, 242 }, + { 0, 14, 241 }, + { 0, 15, 240 }, + { 0, 16, 239 }, + { 0, 17, 238 }, + { 0, 18, 237 }, + { 0, 19, 236 }, + { 0, 20, 235 }, + { 0, 21, 234 }, + { 0, 22, 233 }, + { 0, 23, 232 }, + { 0, 24, 231 }, + { 0, 25, 230 }, + { 0, 26, 229 }, + { 0, 27, 228 }, + { 0, 28, 227 }, + { 0, 29, 226 }, + { 0, 30, 225 }, + { 0, 31, 224 }, + { 0, 32, 223 }, + { 0, 33, 222 }, + { 0, 34, 221 }, + { 0, 35, 220 }, + { 0, 36, 219 }, + { 0, 37, 218 }, + { 0, 38, 217 }, + { 0, 39, 216 }, + { 0, 40, 215 }, + { 0, 41, 214 }, + { 0, 42, 213 }, + { 0, 43, 212 }, + { 0, 44, 211 }, + { 0, 45, 210 }, + { 0, 46, 209 }, + { 0, 47, 208 }, + { 0, 48, 207 }, + { 0, 49, 206 }, + { 0, 50, 205 }, + { 0, 51, 204 }, + { 0, 52, 203 }, + { 0, 53, 202 }, + { 0, 54, 201 }, + { 0, 55, 200 }, + { 0, 56, 199 }, + { 0, 57, 198 }, + { 0, 58, 197 }, + { 0, 59, 196 }, + { 0, 60, 195 }, + { 0, 61, 194 }, + { 0, 62, 193 }, + { 0, 63, 192 }, + { 0, 64, 191 }, + { 0, 65, 190 }, + { 0, 66, 189 }, + { 0, 67, 188 }, + { 0, 68, 187 }, + { 0, 69, 186 }, + { 0, 70, 185 }, + { 0, 71, 184 }, + { 0, 72, 183 }, + { 0, 73, 182 }, + { 0, 74, 181 }, + { 0, 75, 180 }, + { 0, 76, 179 }, + { 0, 77, 178 }, + { 0, 78, 177 }, + { 0, 79, 176 }, + { 0, 80, 175 }, + { 0, 81, 174 }, + { 0, 82, 173 }, + { 0, 83, 172 }, + { 0, 84, 171 }, + { 0, 85, 170 }, + { 0, 86, 169 }, + { 0, 87, 168 }, + { 0, 88, 167 }, + { 0, 89, 166 }, + { 0, 90, 165 }, + { 0, 91, 164 }, + { 0, 92, 163 }, + { 0, 93, 162 }, + { 0, 94, 161 }, + { 0, 95, 160 }, + { 0, 96, 159 }, + { 0, 97, 158 }, + { 0, 98, 157 }, + { 0, 99, 156 }, + { 0, 100, 155 }, + { 0, 101, 154 }, + { 0, 102, 153 }, + { 0, 103, 152 }, + { 0, 104, 151 }, + { 0, 105, 150 }, + { 0, 106, 149 }, + { 0, 107, 148 }, + { 0, 108, 147 }, + { 0, 109, 146 }, + { 0, 110, 145 }, + { 0, 111, 144 }, + { 0, 112, 143 }, + { 0, 113, 142 }, + { 0, 114, 141 }, + { 0, 115, 140 }, + { 0, 116, 139 }, + { 0, 117, 138 }, + { 0, 118, 137 }, + { 0, 119, 136 }, + { 0, 120, 135 }, + { 0, 121, 134 }, + { 0, 122, 133 }, + { 0, 123, 132 }, + { 0, 124, 131 }, + { 0, 125, 130 }, + { 0, 126, 129 }, + { 0, 127, 128 }, + { 0, 128, 127 }, + { 0, 129, 126 }, + { 0, 130, 125 }, + { 0, 131, 124 }, + { 0, 132, 123 }, + { 0, 133, 122 }, + { 0, 134, 121 }, + { 0, 135, 120 }, + { 0, 136, 119 }, + { 0, 137, 118 }, + { 0, 138, 117 }, + { 0, 139, 116 }, + { 0, 140, 115 }, + { 0, 141, 114 }, + { 0, 142, 113 }, + { 0, 143, 112 }, + { 0, 144, 111 }, + { 0, 145, 110 }, + { 0, 146, 109 }, + { 0, 147, 108 }, + { 0, 148, 107 }, + { 0, 149, 106 }, + { 0, 150, 105 }, + { 0, 151, 104 }, + { 0, 152, 103 }, + { 0, 153, 102 }, + { 0, 154, 101 }, + { 0, 155, 100 }, + { 0, 156, 99 }, + { 0, 157, 98 }, + { 0, 158, 97 }, + { 0, 159, 96 }, + { 0, 160, 95 }, + { 0, 161, 94 }, + { 0, 162, 93 }, + { 0, 163, 92 }, + { 0, 164, 91 }, + { 0, 165, 90 }, + { 0, 166, 89 }, + { 0, 167, 88 }, + { 0, 168, 87 }, + { 0, 169, 86 }, + { 0, 170, 85 }, + { 0, 171, 84 }, + { 0, 172, 83 }, + { 0, 173, 82 }, + { 0, 174, 81 }, + { 0, 175, 80 }, + { 0, 176, 79 }, + { 0, 177, 78 }, + { 0, 178, 77 }, + { 0, 179, 76 }, + { 0, 180, 75 }, + { 0, 181, 74 }, + { 0, 182, 73 }, + { 0, 183, 72 }, + { 0, 184, 71 }, + { 0, 185, 70 }, + { 0, 186, 69 }, + { 0, 187, 68 }, + { 0, 188, 67 }, + { 0, 189, 66 }, + { 0, 190, 65 }, + { 0, 191, 64 }, + { 0, 192, 63 }, + { 0, 193, 62 }, + { 0, 194, 61 }, + { 0, 195, 60 }, + { 0, 196, 59 }, + { 0, 197, 58 }, + { 0, 198, 57 }, + { 0, 199, 56 }, + { 0, 200, 55 }, + { 0, 201, 54 }, + { 0, 202, 53 }, + { 0, 203, 52 }, + { 0, 204, 51 }, + { 0, 205, 50 }, + { 0, 206, 49 }, + { 0, 207, 48 }, + { 0, 208, 47 }, + { 0, 209, 46 }, + { 0, 210, 45 }, + { 0, 211, 44 }, + { 0, 212, 43 }, + { 0, 213, 42 }, + { 0, 214, 41 }, + { 0, 215, 40 }, + { 0, 216, 39 }, + { 0, 217, 38 }, + { 0, 218, 37 }, + { 0, 219, 36 }, + { 0, 220, 35 }, + { 0, 221, 34 }, + { 0, 222, 33 }, + { 0, 223, 32 }, + { 0, 224, 31 }, + { 0, 225, 30 }, + { 0, 226, 29 }, + { 0, 227, 28 }, + { 0, 228, 27 }, + { 0, 229, 26 }, + { 0, 230, 25 }, + { 0, 231, 24 }, + { 0, 232, 23 }, + { 0, 233, 22 }, + { 0, 234, 21 }, + { 0, 235, 20 }, + { 0, 236, 19 }, + { 0, 237, 18 }, + { 0, 238, 17 }, + { 0, 239, 16 }, + { 0, 240, 15 }, + { 0, 241, 14 }, + { 0, 242, 13 }, + { 0, 243, 12 }, + { 0, 244, 11 }, + { 0, 245, 10 }, + { 0, 246, 9 }, + { 0, 247, 8 }, + { 0, 248, 7 }, + { 0, 249, 6 }, + { 0, 250, 5 }, + { 0, 251, 4 }, + { 0, 252, 3 }, + { 0, 253, 2 }, + { 0, 254, 1 }, + { 0, 255, 0 }, // green... + { 1, 254, 0 }, // decrease, while increasing red... + { 2, 253, 0 }, + { 3, 252, 0 }, + { 4, 251, 0 }, + { 5, 250, 0 }, + { 6, 249, 0 }, + { 7, 248, 0 }, + { 8, 247, 0 }, + { 9, 246, 0 }, + { 10, 245, 0 }, + { 11, 244, 0 }, + { 12, 243, 0 }, + { 13, 242, 0 }, + { 14, 241, 0 }, + { 15, 240, 0 }, + { 16, 239, 0 }, + { 17, 238, 0 }, + { 18, 237, 0 }, + { 19, 236, 0 }, + { 20, 235, 0 }, + { 21, 234, 0 }, + { 22, 233, 0 }, + { 23, 232, 0 }, + { 24, 231, 0 }, + { 25, 230, 0 }, + { 26, 229, 0 }, + { 27, 228, 0 }, + { 28, 227, 0 }, + { 29, 226, 0 }, + { 30, 225, 0 }, + { 31, 224, 0 }, + { 32, 223, 0 }, + { 33, 222, 0 }, + { 34, 221, 0 }, + { 35, 220, 0 }, + { 36, 219, 0 }, + { 37, 218, 0 }, + { 38, 217, 0 }, + { 39, 216, 0 }, + { 40, 215, 0 }, + { 41, 214, 0 }, + { 42, 213, 0 }, + { 43, 212, 0 }, + { 44, 211, 0 }, + { 45, 210, 0 }, + { 46, 209, 0 }, + { 47, 208, 0 }, + { 48, 207, 0 }, + { 49, 206, 0 }, + { 50, 205, 0 }, + { 51, 204, 0 }, + { 52, 203, 0 }, + { 53, 202, 0 }, + { 54, 201, 0 }, + { 55, 200, 0 }, + { 56, 199, 0 }, + { 57, 198, 0 }, + { 58, 197, 0 }, + { 59, 196, 0 }, + { 60, 195, 0 }, + { 61, 194, 0 }, + { 62, 193, 0 }, + { 63, 192, 0 }, + { 64, 191, 0 }, + { 65, 190, 0 }, + { 66, 189, 0 }, + { 67, 188, 0 }, + { 68, 187, 0 }, + { 69, 186, 0 }, + { 70, 185, 0 }, + { 71, 184, 0 }, + { 72, 183, 0 }, + { 73, 182, 0 }, + { 74, 181, 0 }, + { 75, 180, 0 }, + { 76, 179, 0 }, + { 77, 178, 0 }, + { 78, 177, 0 }, + { 79, 176, 0 }, + { 80, 175, 0 }, + { 81, 174, 0 }, + { 82, 173, 0 }, + { 83, 172, 0 }, + { 84, 171, 0 }, + { 85, 170, 0 }, + { 86, 169, 0 }, + { 87, 168, 0 }, + { 88, 167, 0 }, + { 89, 166, 0 }, + { 90, 165, 0 }, + { 91, 164, 0 }, + { 92, 163, 0 }, + { 93, 162, 0 }, + { 94, 161, 0 }, + { 95, 160, 0 }, + { 96, 159, 0 }, + { 97, 158, 0 }, + { 98, 157, 0 }, + { 99, 156, 0 }, + { 100, 155, 0 }, + { 101, 154, 0 }, + { 102, 153, 0 }, + { 103, 152, 0 }, + { 104, 151, 0 }, + { 105, 150, 0 }, + { 106, 149, 0 }, + { 107, 148, 0 }, + { 108, 147, 0 }, + { 109, 146, 0 }, + { 110, 145, 0 }, + { 111, 144, 0 }, + { 112, 143, 0 }, + { 113, 142, 0 }, + { 114, 141, 0 }, + { 115, 140, 0 }, + { 116, 139, 0 }, + { 117, 138, 0 }, + { 118, 137, 0 }, + { 119, 136, 0 }, + { 120, 135, 0 }, + { 121, 134, 0 }, + { 122, 133, 0 }, + { 123, 132, 0 }, + { 124, 131, 0 }, + { 125, 130, 0 }, + { 126, 129, 0 }, + { 127, 128, 0 }, + { 128, 127, 0 }, + { 129, 126, 0 }, + { 130, 125, 0 }, + { 131, 124, 0 }, + { 132, 123, 0 }, + { 133, 122, 0 }, + { 134, 121, 0 }, + { 135, 120, 0 }, + { 136, 119, 0 }, + { 137, 118, 0 }, + { 138, 117, 0 }, + { 139, 116, 0 }, + { 140, 115, 0 }, + { 141, 114, 0 }, + { 142, 113, 0 }, + { 143, 112, 0 }, + { 144, 111, 0 }, + { 145, 110, 0 }, + { 146, 109, 0 }, + { 147, 108, 0 }, + { 148, 107, 0 }, + { 149, 106, 0 }, + { 150, 105, 0 }, + { 151, 104, 0 }, + { 152, 103, 0 }, + { 153, 102, 0 }, + { 154, 101, 0 }, + { 155, 100, 0 }, + { 156, 99, 0 }, + { 157, 98, 0 }, + { 158, 97, 0 }, + { 159, 96, 0 }, + { 160, 95, 0 }, + { 161, 94, 0 }, + { 162, 93, 0 }, + { 163, 92, 0 }, + { 164, 91, 0 }, + { 165, 90, 0 }, + { 166, 89, 0 }, + { 167, 88, 0 }, + { 168, 87, 0 }, + { 169, 86, 0 }, + { 170, 85, 0 }, + { 171, 84, 0 }, + { 172, 83, 0 }, + { 173, 82, 0 }, + { 174, 81, 0 }, + { 175, 80, 0 }, + { 176, 79, 0 }, + { 177, 78, 0 }, + { 178, 77, 0 }, + { 179, 76, 0 }, + { 180, 75, 0 }, + { 181, 74, 0 }, + { 182, 73, 0 }, + { 183, 72, 0 }, + { 184, 71, 0 }, + { 185, 70, 0 }, + { 186, 69, 0 }, + { 187, 68, 0 }, + { 188, 67, 0 }, + { 189, 66, 0 }, + { 190, 65, 0 }, + { 191, 64, 0 }, + { 192, 63, 0 }, + { 193, 62, 0 }, + { 194, 61, 0 }, + { 195, 60, 0 }, + { 196, 59, 0 }, + { 197, 58, 0 }, + { 198, 57, 0 }, + { 199, 56, 0 }, + { 200, 55, 0 }, + { 201, 54, 0 }, + { 202, 53, 0 }, + { 203, 52, 0 }, + { 204, 51, 0 }, + { 205, 50, 0 }, + { 206, 49, 0 }, + { 207, 48, 0 }, + { 208, 47, 0 }, + { 209, 46, 0 }, + { 210, 45, 0 }, + { 211, 44, 0 }, + { 212, 43, 0 }, + { 213, 42, 0 }, + { 214, 41, 0 }, + { 215, 40, 0 }, + { 216, 39, 0 }, + { 217, 38, 0 }, + { 218, 37, 0 }, + { 219, 36, 0 }, + { 220, 35, 0 }, + { 221, 34, 0 }, + { 222, 33, 0 }, + { 223, 32, 0 }, + { 224, 31, 0 }, + { 225, 30, 0 }, + { 226, 29, 0 }, + { 227, 28, 0 }, + { 228, 27, 0 }, + { 229, 26, 0 }, + { 230, 25, 0 }, + { 231, 24, 0 }, + { 232, 23, 0 }, + { 233, 22, 0 }, + { 234, 21, 0 }, + { 235, 20, 0 }, + { 236, 19, 0 }, + { 237, 18, 0 }, + { 238, 17, 0 }, + { 239, 16, 0 }, + { 240, 15, 0 }, + { 241, 14, 0 }, + { 242, 13, 0 }, + { 243, 12, 0 }, + { 244, 11, 0 }, + { 245, 10, 0 }, + { 246, 9, 0 }, + { 247, 8, 0 }, + { 248, 7, 0 }, + { 249, 6, 0 }, + { 250, 5, 0 }, + { 251, 4, 0 }, + { 252, 3, 0 }, + { 253, 2, 0 }, + { 254, 1, 0 }, + { 255, 0, 0 } // red + }; + + if (max == min) + return makeColor(rgb[0][0], rgb[0][1], rgb[0][2]); + if (max < min) + std::swap(min,max); + value = value < min ? min : value > max ? max : value; + + int n = ncolors*(value-min)/(max-min); + n = n < 0 ? 0 : n > ncolors-1 ? ncolors-1 : n; + + return makeColor(rgb[n][0], rgb[n][1], rgb[n][2]); +} // blue2red + + +// ----------------------------------------------------------------------------- +// Some custom colors +// ----------------------------------------------------------------------------- + +// color::custom:: +namespace custom { + inline const std::string + red = makeColor( 200, 40, 80 ), + yellow = makeColor( 220, 220, 40 ), + green = makeColor( 20, 200, 120 ), + blue = makeColor( 40, 160, 250 ), + purple = makeColor( 142, 110, 202 ); + + // color::custom::faded:: + namespace faded { + inline const std::string + red = makeColor( (200+128)/2, ( 40+128)/2, ( 80+128)/2 ), + yellow = makeColor( (220+128)/2, (220+128)/2, ( 40+128)/2 ), + green = makeColor( ( 20+128)/2, (200+128)/2, (120+128)/2 ), + blue = makeColor( ( 40+128)/2, (160+128)/2, (250+128)/2 ), + purple = makeColor( (142+128)/2, (110+128)/2, (202+128)/2 ); + } + + inline const std::string + black = makeColor( 0, 0, 0 ), + gray = makeColor( 128, 128, 128 ), + white = makeColor( 255, 255, 255 ); +} + + +// ----------------------------------------------------------------------------- +// For Component prettyprinting +// Non-const, so you can change them if they don't work well with your window's +// color scheme, or if you just prefer something else. All of the following are +// in color::. The empty string, "", means no special color treatment, so that +// you'll get the text color your terminal already uses. +// ----------------------------------------------------------------------------- + +// Component labels +inline std::string component = custom::blue; + +// Vector labels +inline std::string vector = custom::green; + +// General labels +inline std::string label = custom::red; + +// General values +inline std::string value = custom::purple; + +// Re: data nodes +namespace data { + // Comments that appear in a Component.comment vector. + inline std::string comment = custom::yellow; + // Strings and vectors in data nodes. Emphasis: only strings and vectors + // specifically in DATA NODES, not those appearing in other ways. + inline std::string string = custom::white; + inline std::string vector = custom::white; +} + +// If an object is optional or GNDStk::Defaulted, the color for its label, +// or for its value, can be modified by using the following. +namespace optional { + inline std::string component = custom::faded::blue; + inline std::string vector = custom::faded::green; + inline std::string label = custom::faded::red; + inline std::string value = custom::faded::purple; +} + + +// ----------------------------------------------------------------------------- +// simple +// Set the color strings to use simple ANSI colors. +// These may work on your terminal if full RGB terminal-text colors don't. +// ----------------------------------------------------------------------------- + +inline void simple() +{ + // Shading isn't compatible with *simple* coloring. + shades = false; + + // Note: the given values seemed to work reasonably well on terminal + // applications we tried. One such app, in particular, was "terminator" + // on a Linux platform. We like terminator - it allows a single terminal + // window to be split, recursively, horizontally or vertically, allowing + // someone to run multiple logically-related codes on different command + // prompts, within the same overall window on their screen.) We noticed, + // however, that terminator prints all of the basic ANSI "bold" colors + // not just colored, but *underlined* as well. So, we avoided using bold + // colors, as we found underlines to be more distracting than helpful. + + component = plain::blue; + vector = plain::green; + label = plain::red; + value = plain::magenta; + + data::comment = plain::yellow; + data::string = plain::white; + data::vector = plain::white; + + optional::component = component; + optional::vector = vector; + optional::label = label; + optional::value = value; +} + +} // namespace color diff --git a/src/GNDStk/BlockData/src/detail.hpp b/src/GNDStk/BlockData/src/detail.hpp new file mode 100644 index 000000000..bd79224e2 --- /dev/null +++ b/src/GNDStk/BlockData/src/detail.hpp @@ -0,0 +1,164 @@ + +namespace detail { + +// ----------------------------------------------------------------------------- +// Miscellaneous +// ----------------------------------------------------------------------------- + +// scalarize +template +auto scalarize(const std::variant) +{ + return std::variant{}; +} + +// getBounds +template +auto getBounds(const std::vector &vec) +{ + T zero; + if constexpr (std::is_same_v) + zero = ""; + else + zero = T(0); + std::pair bnd(0,vec.size()); + while (bnd.first < bnd.second && vec[bnd.first ] == zero) ++bnd.first; + while (bnd.first < bnd.second && vec[bnd.second-1] == zero) --bnd.second; + return bnd; +} + + +// ----------------------------------------------------------------------------- +// SFINAE constructs for detecting whether or not a class has certain members. +// Adapted from an answer here: https://stackoverflow.com/questions/1005476 +// ----------------------------------------------------------------------------- + +// ------------------------ +// has_index +// ------------------------ + +template +struct has_index + : std::false_type { }; + +template +struct has_index< + T, + decltype( + (void) + // Just using T{}.index() on the next line, like we do with other has_* + // classes above, can lead to an ambiguity between this specialization + // and the std::variant specialization below, arising from the fact that + // std::variant has an index() function. Hence the std::conditional_t. + std::conditional_t,void,T>{}.index(), + 0 + ) +> + : std::true_type { }; + +// for variant +template +struct has_index> { + // does any alternative have index? + static constexpr bool value = (has_index::value || ...); +}; + +// ------------------------ +// has_label +// ------------------------ + +template +struct has_label + : std::false_type { }; + +template +struct has_label< + T, + // std::variant doesn't have a label(), like it has an index(), but we'll + // do the same thing here, for has_label, as we do above for has_index. + // It's harmless, and if std::variant is ever given a label() function... + decltype((void)std::conditional_t,void,T>{}.label(),0) +> + : std::true_type { }; + +// for variant +template +struct has_label> { + // for variant: does any alternative have label? + static constexpr bool value = (has_label::value || ...); +}; + +// ------------------------ +// Prefer these. +// They apply std::decay, +// and don't need ::value +// ------------------------ + +template +inline constexpr bool hasIndex = has_index>::value; + +template +inline constexpr bool hasLabel = has_label>::value; + + +// ----------------------------------------------------------------------------- +// element2element +// ----------------------------------------------------------------------------- + +// Remark: PrecisionContext::data, not PrecisionContext::metadata, is the right +// precision context (in terms of our functionality for handling floating-point +// precision) in the code for which element2element() is called. We could bypass +// element2element() entirely, using convert_t{}(...) instead, except that then +// PrecisionContext::metadata would ultimately get used for floating-point T. +// So, below, we recognize floating-point T directly, and handle it correctly. + +// string ==> arithmetic +template>> +void element2element(const std::string &str, T &value) +{ + if constexpr (std::is_floating_point_v) + value = Precision{}.read(str); + else + convert_t{}(str,value); +} + +// arithmetic ==> arithmetic +template +void element2element(const FROM &from, TO &to) +{ + convert_t{}(from,to); +} + +// arithmetic ==> string +template>> +void element2element(const T &value, std::string &str) +{ + if constexpr (std::is_floating_point_v) + str = Precision{}.write(value); + else + convert_t{}(value,str); +} + + +// ----------------------------------------------------------------------------- +// colorize +// colorize_comment +// ----------------------------------------------------------------------------- + +inline std::string colorize( + const std::string &text, + const std::string &color +) { + return GNDStk::colors && color != "" + ? color + text + GNDStk::color::reset + : text; +} + +inline std::string colorize_comment( + const std::string &text, + const std::string &color = "" +) { + return colorize((printMode == PrintMode::cpp ? "// " : "# ") + text, color); +} + +} // namespace detail diff --git a/src/GNDStk/BlockData/src/fromNode.hpp b/src/GNDStk/BlockData/src/fromNode.hpp new file mode 100644 index 000000000..e96c12ccd --- /dev/null +++ b/src/GNDStk/BlockData/src/fromNode.hpp @@ -0,0 +1,39 @@ + +// ----------------------------------------------------------------------------- +// BlockData::fromNode(Node) +// ----------------------------------------------------------------------------- + +void fromNode(const Node &node) +{ + // length, start, and valueType might be present in the Node, but we won't + // fetch any of them here. Elsewhere, the current BlockData object should + // have had its length, start, and valueType pulled from those respective + // values in an object of a class derived from Component, which in turn + // derived from BlockData. That object's content will have been pulled from + // the same Node. Here, we just get the Node's values: plain character data, + // in XML terminology. + + bool found = false; + rawstring = node.data(found); + + if (!found) { + rawstring = ""; + + // Warning, re: why are we in BlockData if there's no block + // data? Perhaps the Node has a non-default length and/or start, so that + // the values are all supposed to be...zero. Until and unless we discover + // otherwise, however, we doubt that that would be the case, and will + // consider a Node's lack of plain character data, in the present context, + // to be something that merits a warning. + log::warning( + "Component marked as having block data, " + "but no such content was found in the GNDS node." + ); + log::member("BlockData::fromNode(Node, with name \"{}\")", node.name); + } + + // Above, we set the raw string. The following reflects this, so that the + // vector, or a vector in the variant, will be rebuilt from the raw string + // if and when a caller asks for it. + act = Active::string; +} diff --git a/src/GNDStk/BlockData/src/get.hpp b/src/GNDStk/BlockData/src/get.hpp new file mode 100644 index 000000000..4e62f00f0 --- /dev/null +++ b/src/GNDStk/BlockData/src/get.hpp @@ -0,0 +1,573 @@ + +// ----------------------------------------------------------------------------- +// Cases +// ----------------------------------------------------------------------------- + +/* +------------------------ +When DATATYPE == void +------------------------ + +Case 1 +Return reference to [const] vector: + get> const + get> +T must be such that vector is in our variant. + +Case 2 +Return reference to [const] T: + get(n) const + get(n) +T must be such that vector is in our variant. + +Case 3 +Return reference to [const] variants>: + get() const + get() + +Case 4 +Return (by value) a variant: + get(n) const + operator[](n) const +A reference return isn't possible with the above two, because there's +no variant to reference; it's computed on-the-fly. The value +return means, further, that non-const version aren't necessary. + +Case 5 +Type-specific getters with specific names: + const std::vector &name() const + std::vector &name() + const T &name(n) const + T &name(n) +For example, name == doubles when T == double. + +------------------------ +When DATATYPE != void +------------------------ + +Case 1 +Return reference to [const] vector: + get> const + get> +T must == DATATYPE. + +Case 2 +Return reference to [const] T: + get(n) const + get(n) +T must == DATATYPE. + +Case 3 +Return reference to [const] vector + get() const + get() + +Case 4 +Return reference to [const] DATATYPE: + get(n) const + operator[](n) const + get(n) + operator[](n) + +Case 5 +Type-specific getters with a specific name: + const std::vector &name() const + std::vector &name() + const DATATYPE &name(n) const + DATATYPE &name(n) +For example, name == doubles if DATATYPE == double. Unlike in the DATATYPE == +void case, we won't have this set of functions for each of name == doubles, +name == ints, name == strings, etc., but only for the name that's appropriate +for type DATATYPE. +*/ + + + +// ----------------------------------------------------------------------------- +// 1. get>() +// ----------------------------------------------------------------------------- + +/* +------------------------ +DESCRIPTION +------------------------ + +If active == string: + + Warn if T appears to conflict with valueType. + Warn if length appears to be wrong. + + Make the vector in the variant contain data from the raw string. + INCLUDE any leading and trailing zeros, per start and length. + Note that length == 0 is interpreted as no particular length prescribed. + + Briefly: create vector = [0 ... 0 values_from_raw_string 0 ... 0]. + For the T == string case, 0 really means "" (empty string). + +If active == vector: + + If the variant already contains a vector: + Return it; we're done. + *** Under the correct and normal use of BlockData, *** + *** this simple action will probably be the most common. *** + + Else: + Convert the variant's vector into a vector. + Print a note to the effect that this might be unintentional. + The note can be suppressed if the call *is* intentional. + +In the active == vector case, length, start, and valueType aren't considered +to be relevant, and play no role. We consider those values to be meaningful +ONLY in relation to BlockData's raw string, and we deal with them here only +if and when we make the vector from the raw string. + +That way, callers can access, manipulate, and even completely change the +vector's contents or its type - basically, can work in peace with a vector, +as someone working with data would surely often want to do - without length, +start, or valueType interfering with the process. Those values are considered +to be relevant ONLY when we absolutely must deal with the raw string. This +generally happens only during creation of the current object from a Node, +or creation of a Node from the current object. (And if we create a Node from +a vector in the current object, then we'll compute length, etc. for ourselves. +See the toNode() function for more information about that.) + +Therefore, if you want length, start, and valueType to be used, then proceed +as follows. Set the raw string to what you wish, using the string() setter. +Set length, start, or valueType as you wish, either before or after possibly +setting the string. Finally, after doing all that, do a get>(). +Then the vector in the variant will be remade, per the new string and/or the +length etc. parameters, as described earlier in this remark, if and when a +get> function is next called. + +The return value of the const version is a const reference to a (possibly +newly converted-to from the raw string, possibly existing, or possibly remade) +vector in the variant. Note that because the variant was declared to be +mutable, we were indeed able to rebuild the vector if doing so was necessary. +But we'll still return a *const* reference in that case, because the present +object is conceptually const, and a caller shouldn't therefore be allowed to +modify the vector outside of BlockData's machinery. + +Of course we also have a non-const version, for a non-const *this. +*/ + + +// const +template +std::enable_if_t< + ( runtime && detail::isAlternative) || + (!runtime && std::is_same_v>), + const VECTOR & +> get() const +{ + // Element type requested + using T = typename VECTOR::value_type; + + + // ------------------------ + // if active == string + // ------------------------ + + if (active() == Active::string) { + static const std::string context_rebuilding = + "BlockData::get>(), remade from raw string"; + + // Completely rebuild the vector from the raw string, making use of + // length, start, and valueType. + + // For this get(), the caller has stipulated a particular vector type. + // We'll print a warning if that vector type appears to conflict with + // valueType. Regardless, we'll return what the caller requested. Note + // that valueType == "" is acceptable with any element type. + if (valueType() != "" && !detail::Type2Names::find(valueType())) { + log::warning( + "Vector element type may be inconsistent with valueType \"{}\";\n" + "we'll create the requested std::vector<> anyway", + valueType() + ); + log::member(context_rebuilding); + } + + // Initialize + VECTOR *to; + if constexpr (runtime) { + variant = VECTOR{}; + to = &std::get(variant); // std::get, not this get :-) + } else { + vector.clear(); + to = &vector; + } + + T zero; + if constexpr (std::is_same_v) + zero = ""; + else + zero = T(0); + + // [*****----------]: leading 0s + for (std::size_t i = 0; i < start(); ++i) + to->push_back(zero); + + // [-----*****-----]: values from the raw string + if constexpr (std::is_floating_point_v) { + // Below, the "false" means "don't clear the vector." We need that + // here, because leading 0s from the earlier loop might be present. + detail::Precision{}. + read(rawstring,*to,false); + } else { + // The above read would ultimately do the following for non-floating- + // point T, but only after extra logic that we might as well avoid. + std::istringstream iss(rawstring); + T element; + while (iss >> element) + to->push_back(element); + } + + // Print a warning if length appears to be impossible because we already + // have more than that number of values. (But length == 0 is ignored.) + if (0 < length() && length() < to->size()) { + log::warning( + "The value of length == {} appears to be wrong, because we\n" + "already have {} values from start == {}, plus {} values read\n" + "from the raw string, for a total of {} values.", + length(), + start(), + start(), + to->size() - start(), + to->size() + ); + log::member(context_rebuilding); + } + + // [----------*****]: trailing 0s + for (std::size_t i = to->size(); i < length(); ++i) + to->push_back(zero); + + act = Active::vector; // was string; now is vector + return *to; + } // if (active == Active::string) + + + // ------------------------ + // if active == vector + // ------------------------ + + if constexpr (runtime) { + // VARIANT CASE... + // Do we already have a vector of the requested type? + if (std::holds_alternative(variant)) + return std::get(variant); + + // If we reach this point, it means two things. (1) We're NOT remaking + // a vector from the raw string (that case was handled first). (2) The + // caller wants a vector of a different type than the type the variant + // currently holds (or we'd have returned immediately above). + // + // So, for example, perhaps the variant currently has a vector, + // and a call get>() was made, meaning that the caller + // wants a vector. + // + // BlockData is intended to store just one vector - one that represents + // values in a GNDS node that has block data. We don't, and shouldn't, + // try to juggle multiple vectors of different types. Therefore, we'll + // attempt to convert the existing vector to one of the requested type, + // then place the new vector into the variant (replacing the old one.) + // + // This is arguably an odd situation, but one that might - might - have + // some utility. (We're not sure yet.) So, we'll print an informational + // note (not even a warning), then proceed. + + log::info( + "Re-forming vector of one type into vector of another type;\n" + "was this intentional?"); + log::member("BlockData::get>()"); + + // Initialize a new vector that will soon replace the old one + VECTOR newVector; + newVector.reserve(size()); + + // Convert elements from the old vector to the new vector + std::visit( + [&newVector](auto &&oldVector) + { + for (const auto &from : oldVector) { + newVector.push_back(T()); + detail::element2element(from,newVector.back()); + } + }, + variant + ); + + // Replace the existing vector with the new vector + variant = newVector; + return std::get(variant); + + } else { + // VECTOR CASE... + // The vector is (via SFINAE) already of the requested type + return vector; + } +} + + +// non-const +template +std::enable_if_t< + ( runtime && detail::isAlternative) || + (!runtime && std::is_same_v>), + VECTOR & +> get() +{ + return const_cast(std::as_const(*this).template get()); +} + + + +// ----------------------------------------------------------------------------- +// 2. get(n) +// ----------------------------------------------------------------------------- + +// For DATATYPE == void (so that we have a variants>): +// These trigger a complete rebuild of the vector, if it isn't already of type +// vector for the given T. This is intentional, in order to provide maximum +// flexibility. However, be aware of it, for the sake of efficiency! In general, +// when using a BlockData object, we recommend sticking with one underlying +// type, not dynamically changing from one type to another. + +// For DATATYPE != void (so that we have a vector): +// T == DATATYPE is required, so that returning an element of the +// vector will return a reference to T. (A constructibility/ +// convertibility requirement that we have in other BlockData-related code thus +// needs to be more stringent here. We can't just be able to make a T from a +// DATATYPE. They must in fact be the same type, because we return a reference.) + +// For both of the above cases: +// If the string (not the variant or the vector) is active, then a rebuild from +// the string is necessary, and will happen in the get>() call. + +// const +template +std::enable_if_t< + supported && (runtime || std::is_same_v), + const T & +> +get(const std::size_t n) const +{ + try { + return get>()[n]; + } catch (...) { + log::member("BlockData::get({})", n); + throw; + } +} + +// non-const +template +std::enable_if_t< + supported && (runtime || std::is_same_v), + T & +> +get(const std::size_t n) +{ + return const_cast(std::as_const(*this).template get(n)); +} + + + +// ----------------------------------------------------------------------------- +// 3. get() +// If DATATYPE == void, returns a variants>. +// If DATATYPE != void, returns a vector<>. +// ----------------------------------------------------------------------------- + +// const +std::conditional_t< + runtime, + const VariantOfVectors &, + const std::vector & +> get() const +{ + if constexpr (runtime) { + detail::Names2Type( + valueType(), + [this](auto &&t) + { + // clang seems to need this-> explicitly to *not* emit a warning + this->get>>(); + } + ); + // We can't return the specific variant alternative that was just put + // in place; it depended on a runtime check. So, we return the entire + // variant, for whatever use that might have to a caller. + return variant; + } else { + // Simpler, but we do still need a get (in case the *string* is active). + get>(); + return vector; + } +} + +// non-const +std::conditional_t< + runtime, + VariantOfVectors &, + std::vector & +> get() +{ + return const_cast< + std::conditional_t< + runtime, + VariantOfVectors &, + std::vector & + > + >(std::as_const(*this).get()); +} + + + +// ----------------------------------------------------------------------------- +// 4. get(n) +// +// If DATATYPE == void, returns a variant (by value, because the +// returned object must be made on-the-fly from our variants>). +// +// If DATATYPE != void, returns a scalar of type [const] DATATYPE (by reference, +// because it's available directly in our vector). +// ----------------------------------------------------------------------------- + +// ------------------------ +// const +// ------------------------ + +// get(n) +std::conditional_t< + runtime, + VariantOfScalars, + const data_t & +> get(const std::size_t n) const +{ + try { + get(); + if constexpr (runtime) { + return std::visit( + [n](auto &&alt) { return VariantOfScalars(alt[n]); }, + variant + ); + } else { + return vector[n]; + } + } catch (...) { + log::member("BlockData::get({})", n); + throw; + } +} + +// operator[](n): useful alternative form +std::conditional_t< + runtime, + VariantOfScalars, + const data_t & +> operator[](const std::size_t n) const +{ + return get(n); +} + + +// ------------------------ +// non-const +// ------------------------ + +// If DATATYPE == void: +// Not needed, because the const versions return by value. +// +// If DATATYPE != void: +// Meaningful, because returns are by reference in this (DATATYPE != void) case. +// So, we'll enable non-const versions for this case only. + +// In case anyone wonders, D (not just DATATYPE) is needed below because SFINAE +// applies when template argument *deduction* is taking place. DATATYPE is +// already fixed, by context - we're in BlockData - and thus it +// isn't being deduced here. Templating these (otherwise non-template) functions +// with an argument that defaults to DATATYPE, then using that argument in the +// SFINAE, is a simple trick that makes the SFINAE work as intended. As for +// VOID, it's necessary in order for the following to be unambiguous with the +// template versions of get(n) that are defined elsewhere in this file. + +// get(n) +template +std::enable_if_t && !detail::isVoid, data_t &> +get(const std::size_t n) +{ + try { + get(); + return vector[n]; + } catch (...) { + log::member("BlockData::get({})", n); + throw; + } +} + +// operator[](n) +template +std::enable_if_t, data_t &> +operator[](const std::size_t n) +{ + return get(n); +} + + + +// ----------------------------------------------------------------------------- +// 5. Type-specific "get()" functions. +// Function names reflect the types: strings(), ints(), doubles(), etc. +// These provide convenient, shorthand access to specific gets. +// ----------------------------------------------------------------------------- + +// Cases: +// vector, const +// vector, non-const +// element, const +// element, non-const + +#define GNDSTK_MAKE_GETTER(name,TYPE) \ + \ + template \ + std::enable_if_t< \ + detail::isVoid || std::is_same_v, \ + const std::vector & \ + > name() const { return get>(); } \ + \ + template \ + std::enable_if_t< \ + detail::isVoid || std::is_same_v, \ + std::vector & \ + > name() { return get>(); } \ + \ + template \ + std::enable_if_t< \ + detail::isVoid || std::is_same_v, \ + const TYPE & \ + > name(const std::size_t n) const { return get(n); } \ + \ + template \ + std::enable_if_t< \ + detail::isVoid || std::is_same_v, \ + TYPE & \ + > name(const std::size_t n) { return get(n); } + +GNDSTK_MAKE_GETTER(strings, std::string) +GNDSTK_MAKE_GETTER(chars, char) +GNDSTK_MAKE_GETTER(schars, signed char) +GNDSTK_MAKE_GETTER(shorts, short) +GNDSTK_MAKE_GETTER(ints, int) +GNDSTK_MAKE_GETTER(longs, long) +GNDSTK_MAKE_GETTER(longlongs, long long) +GNDSTK_MAKE_GETTER(uchars, unsigned char) +GNDSTK_MAKE_GETTER(ushorts, unsigned short) +GNDSTK_MAKE_GETTER(uints, unsigned) +GNDSTK_MAKE_GETTER(ulongs, unsigned long) +GNDSTK_MAKE_GETTER(ulonglongs, unsigned long long) +GNDSTK_MAKE_GETTER(floats, float) +GNDSTK_MAKE_GETTER(doubles, double) +GNDSTK_MAKE_GETTER(longdoubles, long double) + +#undef GNDSTK_MAKE_GETTER diff --git a/src/GNDStk/BlockData/src/params.hpp b/src/GNDStk/BlockData/src/params.hpp new file mode 100644 index 000000000..fdbce039b --- /dev/null +++ b/src/GNDStk/BlockData/src/params.hpp @@ -0,0 +1,126 @@ + +// ----------------------------------------------------------------------------- +// length, start, valueType +// We place these into a struct so our setters can have the names themselves. +// ----------------------------------------------------------------------------- + +/* +Quoted [slightly edited] from the official JSON specification files for GNDS: + + length + The total number of data values including leading and trailing zero + values that are not stored. This attribute should only be used when + the sum of start and the number of listed values do not add to the + total number of data values. This should only happen when there are + trailing zeros not listed in the block data. + + start + Default: 0 + For start = N, the first N values are zero and are not stored. + + valueType + Specifies the type of data in the body (e.g., "Integer32", "Float64"). + Only one type of data can be stored in each instance of a values node. + +In some places, e.g. the JSON-format GNDS spec files, these are listed in +a different order: valueType, start, length. Ordering doesn't really matter. +We just chose to use alphabetical) ordering here. +*/ + +private: + +// toNode() works with a conceptually const object, but may update these to be +// consistent with vector data; so, mutable. +struct { + // Any of these might or might not have appeared in a particular node that + // had block data. For uniformity, we have them all here, and with defaults. + mutable std::size_t length = 0; + mutable std::size_t start = 0; + mutable std::string valueType = ""; +} vars; + + +// ----------------------------------------------------------------------------- +// Getters +// Note: we intentionally return by (non-const!) reference, because the values +// in question are mutable. +// ----------------------------------------------------------------------------- + +public: + +// length +std::size_t &length() const +{ + return vars.length; +} + +// start +std::size_t &start() const +{ + return vars.start; +} + +// valueType +std::string &valueType() const +{ + return vars.valueType; +} + + +// ----------------------------------------------------------------------------- +// Setters +// Builder pattern for all: return *this. +// Arguments of optional type allow for more flexibility in derived classes. +// ----------------------------------------------------------------------------- + +// todo Consider using a macro to shorten the similar code below. + +// ------------------------ +// For std::optional +// ------------------------ + +BlockData &length(const std::optional &opt) +{ + if (opt.has_value()) + vars.length = opt.value(); + return *this; +} + +BlockData &start(const std::optional &opt) +{ + if (opt.has_value()) + vars.start = opt.value(); + return *this; +} + +BlockData &valueType(const std::optional &opt) +{ + if (opt.has_value()) + vars.valueType = opt.value(); + return *this; +} + +// ------------------------ +// For GNDStk::Optional +// ------------------------ + +BlockData &length(const GNDStk::Optional &opt) +{ + if (opt.has_value()) + vars.length = opt.value(); + return *this; +} + +BlockData &start(const GNDStk::Optional &opt) +{ + if (opt.has_value()) + vars.start = opt.value(); + return *this; +} + +BlockData &valueType(const GNDStk::Optional &opt) +{ + if (opt.has_value()) + vars.valueType = opt.value(); + return *this; +} diff --git a/src/GNDStk/BlockData/src/print.hpp b/src/GNDStk/BlockData/src/print.hpp new file mode 100644 index 000000000..e7d614b63 --- /dev/null +++ b/src/GNDStk/BlockData/src/print.hpp @@ -0,0 +1,92 @@ + +// ----------------------------------------------------------------------------- +// print +// Used by Component's prettyprinting. +// ----------------------------------------------------------------------------- + +std::ostream &print(std::ostream &os, const int level) const +{ + try { + + // If empty, don't even print a newline + if ((active() == Active::string && rawstring == "") || + (active() == Active::vector && size() == 0)) + return os; + + // ------------------------ + // If string is active + // ------------------------ + + if (active() == Active::string) { + // Print the string exactly as-is, without column formatting + // or any indentation; then also print a newline + return GNDStk::colors && color::data::string != "" + ? os << color::data::string << rawstring << color::reset + << std::endl + : os << rawstring << std::endl; + } + + // ------------------------ + // If vector is active + // ------------------------ + + // Coloring? + const bool coloring = GNDStk::colors && color::data::vector != ""; + + // Indentation (string, with some number of spaces) + const std::string indent(GNDStk::indent*level,' '); + + const auto printLambda = + [&os,&indent,coloring](auto &&alt) + { + using T = std::decay_t; + const std::size_t size = alt.size(); + const std::size_t end = (GNDStk::elements < 0) + ? size + : std::min(size,std::size_t(GNDStk::elements)); + + // Print, using column formatting + for (std::size_t i = 0; i < end; ++i) { + const T &element = alt[i]; + + // value's whitespace prefix + i == 0 + ? os << indent // at the very beginning, or... + : GNDStk::columns <= 0 || + i % std::size_t(GNDStk::columns) != 0 + ? os << ' ' // still on the current line, or... + : os << '\n' << indent; // starting the next line + + // value + using namespace detail; + if (coloring) os << color::data::vector; + if constexpr (std::is_floating_point_v) + os << Precision{}.write(element); + else + os << element; + if (coloring) os << color::reset; + }; + + // If applicable, print a message saying the data were truncated + if (end < size) { + if (end > 0) + os << '\n'; + os << indent << detail::colorize_comment( + "truncated; actual #elements == " + std::to_string(size), + color::data::vector + ); + } + }; + + if constexpr (runtime) + std::visit(printLambda,variant); + else + printLambda(vector); + + return os << std::endl; + + } catch (...) { + log::member("BlockData.print()"); + throw; + } +} diff --git a/src/GNDStk/BlockData/src/string.hpp b/src/GNDStk/BlockData/src/string.hpp new file mode 100644 index 000000000..7b40d34e3 --- /dev/null +++ b/src/GNDStk/BlockData/src/string.hpp @@ -0,0 +1,25 @@ + +// ----------------------------------------------------------------------------- +// Getters and setters for the raw string +// ----------------------------------------------------------------------------- + +// getter +// string() +// Not to be confused with strings() (plural), which returns vector. +// Returns const &; the raw string can be *changed* only through the setter. +const std::string &string() const +{ + return rawstring; +} + +// setter +// string(new string) +// Builder pattern: return *this, so callers can use this function smoothly +// in conjunction with the setters for length, start, and valueType. +BlockData &string(const std::string &str) +{ + clear(); // <== the vector, because it's no longer considered meaningful + rawstring = str; + act = Active::string; + return *this; +} diff --git a/src/GNDStk/BlockData/src/sync.hpp b/src/GNDStk/BlockData/src/sync.hpp new file mode 100644 index 000000000..f73166935 --- /dev/null +++ b/src/GNDStk/BlockData/src/sync.hpp @@ -0,0 +1,22 @@ + +// pullFromDerived(derived) +// Make this BlockData's length, start, and valueType be consistent with any or +// all such parameters that exist in the given object. Remember that this class, +// BlockData, is a base of Component, which is a base of some other class. +template +void pullFromDerived(const DERIVED &derived) +{ + length (derived.length ()); + start (derived.start ()); + valueType(derived.valueType()); +} + +// pushToDerived(derived) +// The reverse of the above. +template +void pushToDerived(DERIVED &derived) const +{ + derived.length () = length (); + derived.start () = start (); + derived.valueType() = valueType(); +} diff --git a/src/GNDStk/BlockData/src/toNode.hpp b/src/GNDStk/BlockData/src/toNode.hpp new file mode 100644 index 000000000..e571dc2ba --- /dev/null +++ b/src/GNDStk/BlockData/src/toNode.hpp @@ -0,0 +1,91 @@ + +// ----------------------------------------------------------------------------- +// BlockData::toNode +// This is called by Component's conversion-to-Node (not toNode()) function. +// It's "toNode()" here, not a conversion, because we're simply writing text +// that Component's full conversion-to-Node will place into the Node itself. +// ----------------------------------------------------------------------------- + +// Use either (1) the original raw string, or (2) either the variant of vectors +// or the vector (depending on DATATYPE ==/!= void), based on whether or not the +// raw string is active. If a vector (not the raw string) is active, then we'll +// also compute length, start, and valueType. +void toNode(std::string &text) const +{ + // Use the raw string? + if (active() == Active::string) { + text = rawstring; + return; + } + + // Use the vector... + const bool isStringVector = + ( runtime && std::holds_alternative>(variant)) || + (!runtime && std::is_same_v); + + if constexpr ( + runtime || + (!runtime && std::is_same_v) + ) { + // the runtime if's get() calls below won't + // necessarily make sense without the above if-constexpr + if (isStringVector && !trim && + // only bother with the warning if trim would make a difference... + size() > 0 && + (get(0) == "" || get(size()-1) == "") + ) { + log::warning( + "BlockData.toNode() called with BlockData " + "trim flag == false, but active\n" + "data are in a vector. Printing " + "leading/trailing empty strings\n" + "won't preserve them, so we'll treat as if trim == true." + ); + } + } + + // Re: leading/trailing 0s + const auto bounds = + trim || isStringVector + ? runtime + ? std::visit([](auto &&vec) { return detail::getBounds(vec); }, variant) + : detail::getBounds(vector) + : std::make_pair(std::size_t(0),size()); + + // Compute length, start, and valueType + vars.length = size(); // independent of trim + vars.start = bounds.first; // dependent on trim, per the bounds computation + if constexpr (runtime) + vars.valueType = detail::visitType2Names(variant); + else + vars.valueType = detail::Type2Names::value[0]; + + // Values + std::ostringstream oss; + + const auto toNodeLambda = + [bounds,&oss](auto &&vec) + { + using T = std::decay_t; + std::size_t count = 0; + + for (auto i = bounds.first; i < bounds.second; ++i) { + oss << (count++ ? " " : ""); + if constexpr (std::is_floating_point_v) { + oss << detail::Precision< + detail::PrecisionContext::data, + T + >{}.write(vec[i]); + } else { + oss << vec[i]; + } + } + }; + + if constexpr (runtime) + std::visit(toNodeLambda,variant); + else + toNodeLambda(vector); + + text = oss.str(); +} diff --git a/src/GNDStk/BodyText/src/types.hpp b/src/GNDStk/BlockData/src/types.hpp similarity index 96% rename from src/GNDStk/BodyText/src/types.hpp rename to src/GNDStk/BlockData/src/types.hpp index 3eca8c0e1..46f7c3502 100644 --- a/src/GNDStk/BodyText/src/types.hpp +++ b/src/GNDStk/BlockData/src/types.hpp @@ -21,7 +21,7 @@ using VariantOfVectors = std::variant< // unsigned integrals std::vector, std::vector, - std::vector, + std::vector, std::vector, std::vector, diff --git a/src/GNDStk/BlockData/test/BlockData.test.cpp b/src/GNDStk/BlockData/test/BlockData.test.cpp new file mode 100644 index 000000000..ab5c35d60 --- /dev/null +++ b/src/GNDStk/BlockData/test/BlockData.test.cpp @@ -0,0 +1,192 @@ + +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + +// ----------------------------------------------------------------------------- +// Scenario for DATATYPE == void +// ----------------------------------------------------------------------------- + +SCENARIO("Testing GNDStk BlockData with DATATYPE == void") { + // Most BlockData functionality is tested in the individual test files. + // There are just a few things we'll do here. + + // Ensure that we can make const and non-const and BlockData + // objects. Note that BlockData has only a default constructor. + + GIVEN("A const BlockData cbtextt") { + const BlockData cbtextt; + THEN("It constructed correctly, and its data are as expected") { + CHECK(cbtextt.length () == 0); + CHECK(cbtextt.size () == 0); + CHECK(cbtextt.valueType() == ""); + CHECK(cbtextt.string () == ""); + } + } + + GIVEN("A const BlockData cbtextf") { + const BlockData cbtextf; + THEN("It constructed correctly") { + // no data for + } + } + + GIVEN("A non-const BlockData nbtextt") { + BlockData nbtextt; + THEN("It constructed correctly, and its data are as expected") { + CHECK(nbtextt.length () == 0); + CHECK(nbtextt.size () == 0); + CHECK(nbtextt.valueType() == ""); + CHECK(nbtextt.string () == ""); + } + } + + GIVEN("A non-const BlockData nbtextf") { + BlockData nbtextf; + THEN("It constructed correctly") { + // no data for + } + } + + // clear() and size() are defined (at the time of this writing) in the + // BlockData.hpp file itself, so we'll test them here. size() actually + // was used in various tests, and thus was indirectly tested elsewhere. + + GIVEN("A BlockData") { + // clear + WHEN("We test clear()") { + BlockData b; + + // try int + THEN("size() works correctly for vector") { + b = std::vector{1,2,3,4,5}; + CHECK(b.size() == 5); + b.clear(); + CHECK(b.size() == 0); + } + + // try double + THEN("size() works correctly for vector") { + b = std::vector{1.1, 2.2, 3.3, 4.4, 5.5}; + CHECK(b.size() == 5); + b.clear(); + CHECK(b.size() == 0); + } + + // try string + THEN("size() works correctly for vector") { + b = std::vector{"one","two","three","four","five"}; + CHECK(b.size() == 5); + b.clear(); + CHECK(b.size() == 0); + } + } + + // size + WHEN("We test size()") { + BlockData b; + + // try int + THEN("size() works correctly for vector") { + b = std::vector{1,2,3,4,5}; + CHECK(b.size() == 5); + b = std::vector{1}; + CHECK(b.size() == 1); + b = std::vector{}; + CHECK(b.size() == 0); + } + + // try double + THEN("size() works correctly for vector") { + b = std::vector{1.1, 2.2, 3.3, 4.4, 5.5}; + CHECK(b.size() == 5); + b = std::vector{1.1}; + CHECK(b.size() == 1); + b = std::vector{}; + CHECK(b.size() == 0); + } + + // try string + THEN("size() works correctly for vector") { + b = std::vector{"one","two","three","four","five"}; + CHECK(b.size() == 5); + b = std::vector{"one"}; + CHECK(b.size() == 1); + b = std::vector{}; + CHECK(b.size() == 0); + } + } + } +} // SCENARIO + + +// ----------------------------------------------------------------------------- +// Scenario for DATATYPE != void +// ----------------------------------------------------------------------------- + +SCENARIO("Testing GNDStk BlockData with DATATYPE != void") { + + GIVEN("A const BlockData cbtextt") { + const BlockData cbtextt; + THEN("It constructed correctly, and its data are as expected") { + CHECK(cbtextt.length () == 0); + CHECK(cbtextt.size () == 0); + CHECK(cbtextt.valueType() == ""); + CHECK(cbtextt.string () == ""); + } + } + + GIVEN("A const BlockData cbtextf") { + const BlockData cbtextf; + THEN("It constructed correctly") { + // no data for + } + } + + GIVEN("A non-const BlockData nbtextt") { + BlockData nbtextt; + THEN("It constructed correctly, and its data are as expected") { + CHECK(nbtextt.length () == 0); + CHECK(nbtextt.size () == 0); + CHECK(nbtextt.valueType() == ""); + CHECK(nbtextt.string () == ""); + } + } + + GIVEN("A non-const BlockData nbtextf") { + BlockData nbtextf; + THEN("It constructed correctly") { + // no data for + } + } + + GIVEN("A BlockData") { + // clear + WHEN("We test clear()") { + BlockData b; + THEN("size() works correctly") { + b = std::vector{1,2,3,4,5}; + CHECK(b.size() == 5); + b.clear(); + CHECK(b.size() == 0); + } + } + + // size + WHEN("We test size()") { + BlockData b; + THEN("size() works correctly") { + b = std::vector{"one","two","three","four","five"}; + CHECK(b.size() == 5); + b = std::vector{"one"}; + CHECK(b.size() == 1); + b = std::vector{}; + CHECK(b.size() == 0); + } + } + } +} // SCENARIO diff --git a/src/GNDStk/BlockData/test/CMakeLists.txt b/src/GNDStk/BlockData/test/CMakeLists.txt new file mode 100644 index 000000000..a240f071b --- /dev/null +++ b/src/GNDStk/BlockData/test/CMakeLists.txt @@ -0,0 +1,26 @@ + +add_executable( GNDStk.BlockData.test + BlockData.test.cpp + assign.test.cpp + convert.test.cpp + detail.test.cpp + fromNode.test.cpp + get.test.cpp + params.test.cpp + string.test.cpp + sync.test.cpp + toNode.test.cpp + types.test.cpp + print.test.cpp ) +target_compile_options( GNDStk.BlockData.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.BlockData.test PUBLIC GNDStk ) +add_test( NAME GNDStk.BlockData COMMAND GNDStk.BlockData.test ) diff --git a/src/GNDStk/BodyText/test/assign.test.cpp b/src/GNDStk/BlockData/test/assign.test.cpp similarity index 88% rename from src/GNDStk/BodyText/test/assign.test.cpp rename to src/GNDStk/BlockData/test/assign.test.cpp index 7326ae81d..8da3e023f 100644 --- a/src/GNDStk/BodyText/test/assign.test.cpp +++ b/src/GNDStk/BlockData/test/assign.test.cpp @@ -2,20 +2,20 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- -// Scenario for DATA == void +// Scenario for DATATYPE == void // ----------------------------------------------------------------------------- -SCENARIO("BodyText assignment operators") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData assignment operators") { + GIVEN("A default-constructed BlockData object") { // Default value of raw string is as expected WHEN("We examine the raw string") { THEN("It is as expected") { - BodyText b; + BlockData b; CHECK(b.string() == ""); } } @@ -23,7 +23,7 @@ SCENARIO("BodyText assignment operators") { // Assignment from string works WHEN("We assign from a string") { THEN("The raw string has the correct value, and vector size() == 0") { - BodyText b; + BlockData b; // to ensure it clears the vector below... b = std::vector(10); @@ -40,7 +40,7 @@ SCENARIO("BodyText assignment operators") { // Assignment from vector works WHEN("We assign from a vector") { THEN("The variant has the correct value, and raw string == \"\"") { - BodyText b; + BlockData b; // to ensure it clears the raw string etc. below... b = "foo bar"; @@ -70,7 +70,7 @@ SCENARIO("BodyText assignment operators") { // Assign from vector; should set valueType WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); @@ -83,7 +83,7 @@ SCENARIO("BodyText assignment operators") { // Assign from vector; should set valueType WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); @@ -96,7 +96,7 @@ SCENARIO("BodyText assignment operators") { // For now, non-{int,double} sets valueType == "" WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); @@ -111,16 +111,16 @@ SCENARIO("BodyText assignment operators") { // ----------------------------------------------------------------------------- -// Scenario for DATA != void +// Scenario for DATATYPE != void // ----------------------------------------------------------------------------- -SCENARIO("BodyText assignment operators") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData assignment operators") { + GIVEN("A default-constructed BlockData object") { // Default value of raw string is as expected WHEN("We examine the raw string") { THEN("It is as expected") { - BodyText b; + BlockData b; CHECK(b.string() == ""); } } @@ -128,7 +128,7 @@ SCENARIO("BodyText assignment operators") { // Assignment from string works WHEN("We assign from a string") { THEN("The raw string has the correct value, and vector size() == 0") { - BodyText b; + BlockData b; // to ensure it clears the vector below... b = std::vector(10); @@ -145,7 +145,7 @@ SCENARIO("BodyText assignment operators") { // Assignment from vector works WHEN("We assign from a vector") { THEN("The vector has the correct value, and raw string == \"\"") { - BodyText b; + BlockData b; // to ensure it clears the raw string etc. below... b = "foo bar"; @@ -175,7 +175,7 @@ SCENARIO("BodyText assignment operators") { // Assign from vector; should set valueType WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); @@ -188,7 +188,7 @@ SCENARIO("BodyText assignment operators") { // Assign from vector; should set valueType WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); @@ -201,7 +201,7 @@ SCENARIO("BodyText assignment operators") { // For now, non-{int,double} sets valueType == "" WHEN("We assign from a vector") { THEN("valueType is set correctly") { - BodyText b; + BlockData b; b.string("foo").valueType("unknown"); CHECK(b.valueType() == "unknown"); diff --git a/src/GNDStk/BlockData/test/convert.test.cpp b/src/GNDStk/BlockData/test/convert.test.cpp new file mode 100644 index 000000000..b41c3848c --- /dev/null +++ b/src/GNDStk/BlockData/test/convert.test.cpp @@ -0,0 +1,53 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + +SCENARIO("BlockData conversion to vector") { + GIVEN("A BlockData object") { + + { + using T = int; + BlockData b; + b.start(2).length(6).string("-12 34 -56"); + std::vector myVector = b; + CHECK(myVector.size() == 6); + CHECK(myVector[0] == 0); + CHECK(myVector[1] == 0); + CHECK(myVector[2] == -12); + CHECK(myVector[3] == 34); + CHECK(myVector[4] == -56); + CHECK(myVector[5] == 0); + } + + { + using T = double; + BlockData b; + b.start(2).length(6).string("1.2 3.4 5.6"); + std::vector myVector = b; + CHECK(myVector.size() == 6); + CHECK(myVector[0] == 0); + CHECK(myVector[1] == 0); + CHECK(myVector[2] == 1.2); + CHECK(myVector[3] == 3.4); + CHECK(myVector[4] == 5.6); + CHECK(myVector[5] == 0); + } + + { + using T = std::string; + BlockData b; + b.start(2).length(6).string("ab cd ef"); + std::vector myVector = b; + CHECK(myVector.size() == 6); + CHECK(myVector[0] == ""); + CHECK(myVector[1] == ""); + CHECK(myVector[2] == "ab"); + CHECK(myVector[3] == "cd"); + CHECK(myVector[4] == "ef"); + CHECK(myVector[5] == ""); + } + + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/BlockData/test/detail.test.cpp b/src/GNDStk/BlockData/test/detail.test.cpp new file mode 100644 index 000000000..c1df565b6 --- /dev/null +++ b/src/GNDStk/BlockData/test/detail.test.cpp @@ -0,0 +1,286 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; +inline std::string bar = "bar"; + +// ----------------------------------------------------------------------------- +// Scenario +// ----------------------------------------------------------------------------- + +SCENARIO("Testing various BlockData-related detail:: constructs") { + + // ------------------------ + // scalarize + // ------------------------ + + GIVEN("Some variants of vectors") { + using vc = std::variant< + std::vector + >; + using vci = std::variant< + std::vector, + std::vector + >; + using vcid = std::variant< + std::vector, + std::vector, + std::vector + >; + + // Double parenthesis are needed for the CHECK macro, + // because of the commas... + THEN("detail::scalarize() works correctly") { + CHECK(( + std::is_same_v< + decltype(detail::scalarize(vc{})), + std::variant + > + )); + CHECK(( + std::is_same_v< + decltype(detail::scalarize(vci{})), + std::variant + > + )); + CHECK(( + std::is_same_v< + decltype(detail::scalarize(vcid{})), + std::variant + > + )); + } + } // GIVEN + + + // ------------------------ + // element2element + // ------------------------ + + GIVEN("Testing detail::element2element") { + WHEN("We use element2element(from int, to string)") { + const int from = 123; + std::string to; + detail::element2element(from,to); + CHECK(to == "123"); + } + + WHEN("We use element2element(from double, to string)") { + const double from = 4.56; + std::string to; + detail::element2element(from,to); + CHECK(to == "4.56"); + } + + WHEN("We use element2element(from string, to int)") { + const std::string from = "987"; + int to; + detail::element2element(from,to); + CHECK(to == 987); + } + + WHEN("We use element2element(from string, to double)") { + const std::string from = "6.54"; + double to; + detail::element2element(from,to); + CHECK(Approx(to) == 6.54); + } + + WHEN("We use element2element(from int, to double)") { + const int from = 345; + double to; + detail::element2element(from,to); + CHECK(to == double(345)); + } + + WHEN("We use element2element(from double, to int)") { + const double from = 6.78; + int to; + detail::element2element(from,to); + CHECK(to == 6); + } + } + + + // ------------------------ + // getBounds + // ------------------------ + + GIVEN("Testing detail::getBounds") { + + // ------------------------ + // Various vectors + // ------------------------ + + WHEN("We try vectors of varying sizes") { + + THEN("Bounds are correct when size == 0") { + std::vector v = {}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 0); + } + + THEN("Bounds are correct when size == 1, with a 0") { + std::vector v = {0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 1); + CHECK(bounds.second == 1); + } + + THEN("Bounds are correct when size == 2, all 0") { + std::vector v = {0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 2); + } + + THEN("Bounds are correct when size == 3, all non-0") { + std::vector v = {2, 3, 5}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 3); + } + + THEN("Bounds are correct when there are trailing 0s") { + std::vector v = {2, 3, 5, 0, 0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 3); + } + + THEN("Bounds are correct when there are leading 0s") { + std::vector v = {0, 0, 2, 3, 5}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 5); + } + + THEN("Bounds are correct when there are leading and trailing 0s") { + std::vector v = {0, 0, 2, 3, 5, 0, 0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 5); + } + + } // WHEN + + + // ------------------------ + // Various vectors + // ------------------------ + + WHEN("We try vectors of varying sizes") { + + THEN("Bounds are correct when size == 0") { + std::vector v = {}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 0); + } + + THEN("Bounds are correct when size == 1, with a 0") { + std::vector v = {0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 1); + CHECK(bounds.second == 1); + } + + THEN("Bounds are correct when size == 3, all 0") { + std::vector v = {0, 0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 3); + CHECK(bounds.second == 3); + } + + THEN("Bounds are correct when size == 3, all non-0") { + std::vector v = {1.2, 3.4, 5.6}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 3); + } + + THEN("Bounds are correct when there are trailing 0s") { + std::vector v = {1.2, 3.4, 5.6, 0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 3); + } + + THEN("Bounds are correct when there are leading 0s") { + std::vector v = {0, 0, 0, 1.2, 3.4, 5.6}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 3); + CHECK(bounds.second == 6); + } + + THEN("Bounds are correct when there are leading and trailing 0s") { + std::vector v = {0, 0, 0, 1.2, 3.4, 5.6, 0, 0}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 3); + CHECK(bounds.second == 6); + } + + } + + + // ------------------------ + // Various vectors + // ------------------------ + + WHEN("We try vectors of varying sizes") { + + THEN("Bounds are correct when size == 0") { + std::vector v = {}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 0); + } + + THEN("Bounds are correct when size == 1, with a \"\"") { + std::vector v = {""}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 1); + CHECK(bounds.second == 1); + } + + THEN("Bounds are correct when size == 2, all \"\"") { + std::vector v = {"", ""}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 2); + } + + THEN("Bounds are correct when size == 2, all non-\"\"") { + std::vector v = {"abc", "def"}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 2); + } + + THEN("Bounds are correct when there are trailing \"\"s") { + std::vector v = {"abc", "def", "", "", ""}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 0); + CHECK(bounds.second == 2); + } + + THEN("Bounds are correct when there are leading \"\"s") { + std::vector v = {"", "", "abc", "def"}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 4); + } + + THEN("Bounds are correct when there are leading and trailing \"\"s") { + std::vector v = {"", "", "abc", "def", "", "", ""}; + const auto bounds = detail::getBounds(v); + CHECK(bounds.first == 2); + CHECK(bounds.second == 4); + } + + } // WHEN + } // GIVEN + +} // SCENARIO diff --git a/src/GNDStk/BlockData/test/fromNode.test.cpp b/src/GNDStk/BlockData/test/fromNode.test.cpp new file mode 100644 index 000000000..695fdc378 --- /dev/null +++ b/src/GNDStk/BlockData/test/fromNode.test.cpp @@ -0,0 +1,115 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + +// ----------------------------------------------------------------------------- +// Scenario for DATATYPE == void +// ----------------------------------------------------------------------------- + +SCENARIO("BlockData fromNode()") { + + GIVEN("A Node with no \"block data\"") { + WHEN("BlockData.fromNode(the node) is called") { + THEN("The BlockData's raw string is \"\", as expected") { + BlockData b; + b.string("This string should be replaced"); + CHECK(b.string() != ""); + + Node node; + node << ""; + b.fromNode(node); + CHECK(b.string() == ""); + } + } + } + + GIVEN("A Node with some \"block data\"") { + WHEN("BlockData.fromNode(the node) is called") { + THEN("The BlockData's raw string equals the text from the Node") { + BlockData b; + b.string("This string should be replaced"); + CHECK(b.string() != ""); + + Node node; + + node << "some plain character data"; + b.fromNode(node); + CHECK(b.string() == "some plain character data"); + + // it shouldn't matter, but leading spaces are preserved + node << " data with leading spaces"; + b.fromNode(node); + CHECK(b.string() == " data with leading spaces"); + + // ditto for trailing spaces + node << "data with trailing spaces "; + b.fromNode(node); + CHECK(b.string() == "data with trailing spaces "); + + // ditto for both together + node << " data "; + b.fromNode(node); + CHECK(b.string() == " data "); + } + } + } + +} // SCENARIO + + +// ----------------------------------------------------------------------------- +// Scenario for DATATYPE != void +// ----------------------------------------------------------------------------- + +SCENARIO("BlockData fromNode()") { + + GIVEN("A Node with no \"block data\"") { + WHEN("BlockData.fromNode(the node) is called") { + THEN("The BlockData's raw string is \"\", as expected") { + BlockData b; + b.string("This string should be replaced"); + CHECK(b.string() != ""); + + Node node; + node << ""; + b.fromNode(node); + CHECK(b.string() == ""); + } + } + } + + GIVEN("A Node with some \"block data\"") { + WHEN("BlockData.fromNode(the node) is called") { + THEN("The BlockData's raw string equals the text from the Node") { + BlockData b; + b.string("This string should be replaced"); + CHECK(b.string() != ""); + + Node node; + + node << "some plain character data"; + b.fromNode(node); + CHECK(b.string() == "some plain character data"); + + // it shouldn't matter, but leading spaces are preserved + node << " data with leading spaces"; + b.fromNode(node); + CHECK(b.string() == " data with leading spaces"); + + // ditto for trailing spaces + node << "data with trailing spaces "; + b.fromNode(node); + CHECK(b.string() == "data with trailing spaces "); + + // ditto for both together + node << " data "; + b.fromNode(node); + CHECK(b.string() == " data "); + } + } + } + +} // SCENARIO diff --git a/src/GNDStk/BlockData/test/get.test.cpp b/src/GNDStk/BlockData/test/get.test.cpp new file mode 100644 index 000000000..375a4d0f3 --- /dev/null +++ b/src/GNDStk/BlockData/test/get.test.cpp @@ -0,0 +1,695 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + + +// ----------------------------------------------------------------------------- +// 1. Scenario: get() +// ----------------------------------------------------------------------------- + +// Helper +template +void scenario_get_vector() +{ + // We'll deal with these vector types for the test. They should cover + // sufficient cases (int, double, string, and none of the above) + // that we get good coverage, without this test being excessively long. + using ivec = std::vector; + using fvec = std::vector; + using svec = std::vector; + using uvec = std::vector; + + // We'll leave valueType at its default of "", which is compatible with + // every possible get type T. This simply means we won't get spammed + // with warnings about the asked-for T possibly being incompatible with + // valueType. Either way - with or without a "" for valueType - get + // gives us back a vector. + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); + CHECK((b.template get() == ivec{})); } + { BlockData b; b.start(0).length(4).string(""); + CHECK((b.template get() == ivec{{0,0,0,0}})); } + { BlockData b; b.start(1).length(5).string(""); + CHECK((b.template get() == ivec{{0,0,0,0,0}})); } + { BlockData b; b.start(2).length(6).string(""); + CHECK((b.template get() == ivec{{0,0,0,0,0,0}})); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("-12"); + CHECK((b.template get() == ivec(1,-12))); } + { BlockData b; b.start(0).length(4).string("-12"); + CHECK((b.template get() == ivec{{-12,0,0,0}})); } + { BlockData b; b.start(1).length(5).string("-12"); + CHECK((b.template get() == ivec{{0,-12,0,0,0}})); } + { BlockData b; b.start(2).length(6).string("-12"); + CHECK((b.template get() == ivec{{0,0,-12,0,0,0}})); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("-12 34 -56"); + CHECK((b.template get() == ivec{{-12,34,-56}})); } + { BlockData b; b.start(0).length(4).string("-12 34 -56"); + CHECK((b.template get() == ivec{{-12,34,-56,0}})); } + { BlockData b; b.start(1).length(5).string("-12 34 -56"); + CHECK((b.template get() == ivec{{0,-12,34,-56,0}})); } + { BlockData b; b.start(2).length(6).string("-12 34 -56"); + CHECK((b.template get() == ivec{{0,0,-12,34,-56,0}})); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); + CHECK((b.template get() == fvec{})); } + { BlockData b; b.start(0).length(4).string(""); + CHECK((b.template get() == fvec{{0,0,0,0}})); } + { BlockData b; b.start(1).length(5).string(""); + CHECK((b.template get() == fvec{{0,0,0,0,0}})); } + { BlockData b; b.start(2).length(6).string(""); + CHECK((b.template get() == fvec{{0,0,0,0,0,0}})); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("1.2"); + CHECK((b.template get() == fvec(1,1.2))); } + { BlockData b; b.start(0).length(4).string("1.2"); + CHECK((b.template get() == fvec{{1.2,0,0,0}})); } + { BlockData b; b.start(1).length(5).string("1.2"); + CHECK((b.template get() == fvec{{0,1.2,0,0,0}})); } + { BlockData b; b.start(2).length(6).string("1.2"); + CHECK((b.template get() == fvec{{0,0,1.2,0,0,0}})); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("1.2 3.4 5.6"); + CHECK((b.template get() == fvec{{1.2,3.4,5.6}})); } + { BlockData b; b.start(0).length(4).string("1.2 3.4 5.6"); + CHECK((b.template get() == fvec{{1.2,3.4,5.6,0}})); } + { BlockData b; b.start(1).length(5).string("1.2 3.4 5.6"); + CHECK((b.template get() == fvec{{0,1.2,3.4,5.6,0}})); } + { BlockData b; b.start(2).length(6).string("1.2 3.4 5.6"); + CHECK((b.template get() == fvec{{0,0,1.2,3.4,5.6,0}})); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); + CHECK((b.template get() == svec{})); } + { BlockData b; b.start(0).length(4).string(""); + CHECK((b.template get() == svec{{"","","",""}})); } + { BlockData b; b.start(1).length(5).string(""); + CHECK((b.template get() == svec{{"","","","",""}})); } + { BlockData b; b.start(2).length(6).string(""); + CHECK((b.template get() == svec{{"","","","","",""}})); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("ab"); + CHECK((b.template get() == svec(1,"ab"))); } + { BlockData b; b.start(0).length(4).string("ab"); + CHECK((b.template get() == svec{{"ab","","",""}})); } + { BlockData b; b.start(1).length(5).string("ab"); + CHECK((b.template get() == svec{{"","ab","","",""}})); } + { BlockData b; b.start(2).length(6).string("ab"); + CHECK((b.template get() == svec{{"","","ab","","",""}})); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("ab cd ef"); + CHECK((b.template get() == svec{{"ab","cd","ef"}})); } + { BlockData b; b.start(0).length(4).string("ab cd ef"); + CHECK((b.template get() == svec{{"ab","cd","ef",""}})); } + { BlockData b; b.start(1).length(5).string("ab cd ef"); + CHECK((b.template get() == svec{{"","ab","cd","ef",""}})); } + { BlockData b; b.start(2).length(6).string("ab cd ef"); + CHECK((b.template get() == svec{{"","","ab","cd","ef",""}})); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); + CHECK((b.template get() == uvec{})); } + { BlockData b; b.start(0).length(4).string(""); + CHECK((b.template get() == uvec{{0,0,0,0}})); } + { BlockData b; b.start(1).length(5).string(""); + CHECK((b.template get() == uvec{{0,0,0,0,0}})); } + { BlockData b; b.start(2).length(6).string(""); + CHECK((b.template get() == uvec{{0,0,0,0,0,0}})); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("12"); + CHECK((b.template get() == uvec(1,12))); } + { BlockData b; b.start(0).length(4).string("12"); + CHECK((b.template get() == uvec{{12,0,0,0}})); } + { BlockData b; b.start(1).length(5).string("12"); + CHECK((b.template get() == uvec{{0,12,0,0,0}})); } + { BlockData b; b.start(2).length(6).string("12"); + CHECK((b.template get() == uvec{{0,0,12,0,0,0}})); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("12 34 56"); + CHECK((b.template get() == uvec{{12,34,56}})); } + { BlockData b; b.start(0).length(4).string("12 34 56"); + CHECK((b.template get() == uvec{{12,34,56,0}})); } + { BlockData b; b.start(1).length(5).string("12 34 56"); + CHECK((b.template get() == uvec{{0,12,34,56,0}})); } + { BlockData b; b.start(2).length(6).string("12 34 56"); + CHECK((b.template get() == uvec{{0,0,12,34,56,0}})); } +} + +// For BlockData +SCENARIO("BlockData get()") { + GIVEN("A BlockData object") { + scenario_get_vector(); + } +} + +// For BlockData +SCENARIO("BlockData get()") { + GIVEN("A BlockData object") { + scenario_get_vector(); + } +} + + + +// ----------------------------------------------------------------------------- +// 2. Scenario: get(n) +// ----------------------------------------------------------------------------- + +// Helper +template +void scenario_get_template_n() +{ + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); } + { BlockData b; b.start(0).length(4).string(""); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string(""); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string(""); + CHECK(b.template get(3) == 0); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("-12"); + CHECK(b.template get(0) == -12); } + { BlockData b; b.start(0).length(4).string("-12"); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string("-12"); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string("-12"); + CHECK(b.template get(3) == 0); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("-12 34 -56"); + CHECK(b.template get(0) == -12); } + { BlockData b; b.start(0).length(4).string("-12 34 -56"); + CHECK(b.template get(1) == 34); } + { BlockData b; b.start(1).length(5).string("-12 34 -56"); + CHECK(b.template get(2) == 34); } + { BlockData b; b.start(2).length(6).string("-12 34 -56"); + CHECK(b.template get(3) == 34); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); } + { BlockData b; b.start(0).length(4).string(""); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string(""); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string(""); + CHECK(b.template get(3) == 0); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("1.2"); + CHECK(b.template get(0) == 1.2); } + { BlockData b; b.start(0).length(4).string("1.2"); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string("1.2"); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string("1.2"); + CHECK(b.template get(3) == 0); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("1.2 3.4 5.6"); + CHECK(b.template get(0) == 1.2); } + { BlockData b; b.start(0).length(4).string("1.2 3.4 5.6"); + CHECK(b.template get(1) == 3.4); } + { BlockData b; b.start(1).length(5).string("1.2 3.4 5.6"); + CHECK(b.template get(2) == 3.4); } + { BlockData b; b.start(2).length(6).string("1.2 3.4 5.6"); + CHECK(b.template get(3) == 3.4); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); } + { BlockData b; b.start(0).length(4).string(""); + CHECK(b.template get(1) == ""); } + { BlockData b; b.start(1).length(5).string(""); + CHECK(b.template get(2) == ""); } + { BlockData b; b.start(2).length(6).string(""); + CHECK(b.template get(3) == ""); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("ab"); + CHECK(b.template get(0) == "ab"); } + { BlockData b; b.start(0).length(4).string("ab"); + CHECK(b.template get(1) == ""); } + { BlockData b; b.start(1).length(5).string("ab"); + CHECK(b.template get(2) == ""); } + { BlockData b; b.start(2).length(6).string("ab"); + CHECK(b.template get(3) == ""); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("ab cd ef"); + CHECK(b.template get(0) == "ab"); } + { BlockData b; b.start(0).length(4).string("ab cd ef"); + CHECK(b.template get(1) == "cd"); } + { BlockData b; b.start(1).length(5).string("ab cd ef"); + CHECK(b.template get(2) == "cd"); } + { BlockData b; b.start(2).length(6).string("ab cd ef"); + CHECK(b.template get(3) == "cd"); } + + // ------------------------ + // vector + // ------------------------ + + // 0 elements in string + { BlockData b; b.start(0).length(0).string(""); } + { BlockData b; b.start(0).length(4).string(""); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string(""); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string(""); + CHECK(b.template get(3) == 0); } + + // 1 element in string + { BlockData b; b.start(0).length(0).string("12"); + CHECK(b.template get(0) == 12); } + { BlockData b; b.start(0).length(4).string("12"); + CHECK(b.template get(1) == 0); } + { BlockData b; b.start(1).length(5).string("12"); + CHECK(b.template get(2) == 0); } + { BlockData b; b.start(2).length(6).string("12"); + CHECK(b.template get(3) == 0); } + + // 3 elements in string + { BlockData b; b.start(0).length(0).string("12 34 56"); + CHECK(b.template get(0) == 12); } + { BlockData b; b.start(0).length(4).string("12 34 56"); + CHECK(b.template get(1) == 34); } + { BlockData b; b.start(1).length(5).string("12 34 56"); + CHECK(b.template get(2) == 34); } + { BlockData b; b.start(2).length(6).string("12 34 56"); + CHECK(b.template get(3) == 34); } +} + +// For BlockData +SCENARIO("BlockData get(n)") { + GIVEN("A BlockData object") { + scenario_get_template_n(); + } +} + +// For BlockData +SCENARIO("BlockData get(n)") { + GIVEN("A BlockData object") { + scenario_get_template_n(); + } +} + + + +// ----------------------------------------------------------------------------- +// 3. Scenario: get() +// ----------------------------------------------------------------------------- + +// For BlockData +SCENARIO("BlockData get()") { + GIVEN("A BlockData object") { + + using ivec = std::vector; + using fvec = std::vector; + using svec = std::vector; + + BlockData b; + + b.start(2).length(6).string("-12 34 -56"); + b.valueType("Integer32"); + CHECK(( std::holds_alternative(b.get()))); + CHECK((!std::holds_alternative(b.get()))); + CHECK((!std::holds_alternative(b.get()))); + CHECK((std::get(b.get()) == ivec{{0,0,-12,34,-56,0}})); + + b.start(2).length(6).string("1.2 3.4 5.6"); + b.valueType("Float64"); + CHECK((!std::holds_alternative(b.get()))); + CHECK(( std::holds_alternative(b.get()))); + CHECK((!std::holds_alternative(b.get()))); + CHECK((std::get(b.get()) == fvec{{0,0,1.2,3.4,5.6,0}})); + + b.start(2).length(6).string("ab cd ef"); + b.valueType(""); + CHECK((!std::holds_alternative(b.get()))); + CHECK((!std::holds_alternative(b.get()))); + CHECK(( std::holds_alternative(b.get()))); + CHECK((std::get(b.get()) == svec{{"","","ab","cd","ef",""}})); + + } // GIVEN +} // SCENARIO + + +// For BlockData +SCENARIO("BlockData get()") { + GIVEN("A BlockData object") { + + using ivec = std::vector; + using fvec = std::vector; + using svec = std::vector; + + { + BlockData b; + b.start(2).length(6).string("-12 34 -56"); + CHECK((b.get() == ivec{{0,0,-12,34,-56,0}})); + } + + { + BlockData b; + b.start(2).length(6).string("1.2 3.4 5.6"); + CHECK((b.get() == fvec{{0,0,1.2,3.4,5.6,0}})); + } + + { + BlockData b; + b.start(2).length(6).string("ab cd ef"); + CHECK((b.get() == svec{{"","","ab","cd","ef",""}})); + } + + } // GIVEN +} // SCENARIO + + + +// ----------------------------------------------------------------------------- +// 4. Scenario: get(n) +// ----------------------------------------------------------------------------- + +// For BlockData +SCENARIO("BlockData get(n)") { + GIVEN("A BlockData object") { + + BlockData b; + + // ------------------------ + // get(n) form + // ------------------------ + + b.start(2).length(6).string("-12 34 -56"); + b.valueType("Integer32"); + CHECK(( std::holds_alternative(b.get(0)))); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK(( std::get( b.get(0) ) == 0 )); + CHECK(( std::get( b.get(1) ) == 0 )); + CHECK(( std::get( b.get(2) ) == -12 )); + CHECK(( std::get( b.get(3) ) == 34 )); + CHECK(( std::get( b.get(4) ) == -56 )); + CHECK(( std::get( b.get(5) ) == 0 )); + // test type changes (inefficient, but they work)... + CHECK(b.get(2) == -12); + CHECK(b.get(3) == double(34)); + CHECK(b.get(4) == "-56"); + + b.start(2).length(6).string("1.2 3.4 5.6"); + b.valueType("Float64"); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK(( std::holds_alternative(b.get(0)))); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK(( std::get( b.get(0) ) == 0 )); + CHECK(( std::get( b.get(1) ) == 0 )); + CHECK(( std::get( b.get(2) ) == 1.2 )); + CHECK(( std::get( b.get(3) ) == 3.4 )); + CHECK(( std::get( b.get(4) ) == 5.6 )); + CHECK(( std::get( b.get(5) ) == 0 )); + // test type changes... + CHECK(b.get(2) == 1); // truncated from 1.2 + // having converted to vector, the .#s aren't there any longer... + CHECK(b.get(2) == "1"); + CHECK(b.get(3) == 3); + CHECK(b.get(4) == "5"); + + b.start(2).length(8).string("ab cd ef 123 4.5"); + b.valueType(""); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK((!std::holds_alternative(b.get(0)))); + CHECK(( std::holds_alternative(b.get(0)))); + CHECK(( std::get( b.get(0) ) == "" )); + CHECK(( std::get( b.get(1) ) == "" )); + CHECK(( std::get( b.get(2) ) == "ab" )); + CHECK(( std::get( b.get(3) ) == "cd" )); + CHECK(( std::get( b.get(4) ) == "ef" )); + CHECK(( std::get( b.get(5) ) == "123")); + CHECK(( std::get( b.get(6) ) == "4.5")); + CHECK(( std::get( b.get(7) ) == "" )); + + // ------------------------ + // operator[] form + // ------------------------ + + b.start(2).length(6).string("-12 34 -56"); + b.valueType("Integer32"); + CHECK(( std::holds_alternative(b[0]))); + CHECK((!std::holds_alternative(b[0]))); + CHECK((!std::holds_alternative(b[0]))); + CHECK(( std::get( b[0] ) == 0 )); + CHECK(( std::get( b[1] ) == 0 )); + CHECK(( std::get( b[2] ) == -12 )); + CHECK(( std::get( b[3] ) == 34 )); + CHECK(( std::get( b[4] ) == -56 )); + CHECK(( std::get( b[5] ) == 0 )); + + b.start(2).length(6).string("1.2 3.4 5.6"); + b.valueType("Float64"); + CHECK((!std::holds_alternative(b[0]))); + CHECK(( std::holds_alternative(b[0]))); + CHECK((!std::holds_alternative(b[0]))); + CHECK(( std::get( b[0] ) == 0 )); + CHECK(( std::get( b[1] ) == 0 )); + CHECK(( std::get( b[2] ) == 1.2 )); + CHECK(( std::get( b[3] ) == 3.4 )); + CHECK(( std::get( b[4] ) == 5.6 )); + CHECK(( std::get( b[5] ) == 0 )); + + b.start(2).length(6).string("ab cd ef"); + b.valueType(""); + CHECK((!std::holds_alternative(b[0]))); + CHECK((!std::holds_alternative(b[0]))); + CHECK(( std::holds_alternative(b[0]))); + CHECK(( std::get( b[0] ) == "" )); + CHECK(( std::get( b[1] ) == "" )); + CHECK(( std::get( b[2] ) == "ab" )); + CHECK(( std::get( b[3] ) == "cd" )); + CHECK(( std::get( b[4] ) == "ef" )); + CHECK(( std::get( b[5] ) == "" )); + + } // GIVEN +} // SCENARIO + + +// For BlockData +SCENARIO("BlockData get(n)") { + GIVEN("A BlockData object") { + + // ------------------------ + // get(n) form + // ------------------------ + + { + BlockData b; + b.start(2).length(6).string("-12 34 -56"); + CHECK(( b.get(0) == 0 )); + CHECK(( b.get(1) == 0 )); + CHECK(( b.get(2) == -12 )); + CHECK(( b.get(3) == 34 )); + CHECK(( b.get(4) == -56 )); + CHECK(( b.get(5) == 0 )); + } + + { + BlockData b; + b.start(2).length(6).string("1.2 3.4 5.6"); + CHECK(( b.get(0) == 0 )); + CHECK(( b.get(1) == 0 )); + CHECK(( b.get(2) == 1.2 )); + CHECK(( b.get(3) == 3.4 )); + CHECK(( b.get(4) == 5.6 )); + CHECK(( b.get(5) == 0 )); + } + + { + BlockData b; + b.start(2).length(8).string("ab cd ef 123 4.5"); + CHECK(( b.get(0) == "" )); + CHECK(( b.get(1) == "" )); + CHECK(( b.get(2) == "ab" )); + CHECK(( b.get(3) == "cd" )); + CHECK(( b.get(4) == "ef" )); + CHECK(( b.get(5) == "123")); + CHECK(( b.get(6) == "4.5")); + CHECK(( b.get(7) == "" )); + } + + // ------------------------ + // operator[] form + // ------------------------ + + { + BlockData b; + b.start(2).length(6).string("-12 34 -56"); + CHECK(( b[0] == 0 )); + CHECK(( b[1] == 0 )); + CHECK(( b[2] == -12 )); + CHECK(( b[3] == 34 )); + CHECK(( b[4] == -56 )); + CHECK(( b[5] == 0 )); + } + + { + BlockData b; + b.start(2).length(6).string("1.2 3.4 5.6"); + CHECK(( b[0] == 0 )); + CHECK(( b[1] == 0 )); + CHECK(( b[2] == 1.2 )); + CHECK(( b[3] == 3.4 )); + CHECK(( b[4] == 5.6 )); + CHECK(( b[5] == 0 )); + } + + { + BlockData b; + b.start(2).length(6).string("ab cd ef"); + CHECK(( b[0] == "" )); + CHECK(( b[1] == "" )); + CHECK(( b[2] == "ab" )); + CHECK(( b[3] == "cd" )); + CHECK(( b[4] == "ef" )); + CHECK(( b[5] == "" )); + } + + } // GIVEN +} // SCENARIO + + + +// ----------------------------------------------------------------------------- +// 5. Scenario: doubles() etc. +// ----------------------------------------------------------------------------- + +// Helper +template +void scenario_get_named() +{ + { + BlockData b; + + b.start(2).length(6).string("-12 34 -56"); + auto result = b.ints(); + CHECK((std::is_same_v>)); + + CHECK(result[0] == 0 ); + CHECK(result[1] == 0 ); + CHECK(result[2] == -12 ); + CHECK(result[3] == 34 ); + CHECK(result[4] == -56 ); + CHECK(result[5] == 0 ); + + CHECK(result[0] == b.ints(0) ); + CHECK(result[1] == b.ints(1) ); + CHECK(result[2] == b.ints(2) ); + CHECK(result[3] == b.ints(3) ); + CHECK(result[4] == b.ints(4) ); + CHECK(result[5] == b.ints(5) ); + } + + { + BlockData b; + + b.start(2).length(6).string("1.2 3.4 5.6"); + const BlockData &bconst = b; // ensure it works with const + const auto result = bconst.doubles(); + CHECK((std::is_same_v>)); + + CHECK(result[0] == 0 ); + CHECK(result[1] == 0 ); + CHECK(result[2] == 1.2 ); + CHECK(result[3] == 3.4 ); + CHECK(result[4] == 5.6 ); + CHECK(result[5] == 0 ); + + CHECK(result[0] == bconst.doubles(0) ); + CHECK(result[1] == bconst.doubles(1) ); + CHECK(result[2] == bconst.doubles(2) ); + CHECK(result[3] == bconst.doubles(3) ); + CHECK(result[4] == bconst.doubles(4) ); + CHECK(result[5] == bconst.doubles(5) ); + } + + { + BlockData b; + + b.start(2).length(6).string("ab cd ef"); + const auto &result = b.strings(); + CHECK((std::is_same_v &>)); + + CHECK(result[0] == "" ); + CHECK(result[1] == "" ); + CHECK(result[2] == "ab" ); + CHECK(result[3] == "cd" ); + CHECK(result[4] == "ef" ); + CHECK(result[5] == "" ); + + CHECK(result[0] == b.strings(0) ); + CHECK(result[1] == b.strings(1) ); + CHECK(result[2] == b.strings(2) ); + CHECK(result[3] == b.strings(3) ); + CHECK(result[4] == b.strings(4) ); + CHECK(result[5] == b.strings(5) ); + } +} + +// For BlockData +SCENARIO("BlockData type-specific get functions: " + "doubles() etc.") { + GIVEN("A BlockData object") { + scenario_get_named(); + } +} + +// For BlockData +SCENARIO("BlockData type-specific get functions: " + "doubles() etc.") { + GIVEN("A BlockData object") { + scenario_get_named(); + } +} diff --git a/src/GNDStk/BodyText/test/params.test.cpp b/src/GNDStk/BlockData/test/params.test.cpp similarity index 81% rename from src/GNDStk/BodyText/test/params.test.cpp rename to src/GNDStk/BlockData/test/params.test.cpp index 7e43e3e32..7f6df6682 100644 --- a/src/GNDStk/BodyText/test/params.test.cpp +++ b/src/GNDStk/BlockData/test/params.test.cpp @@ -2,20 +2,20 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- // Helper // ----------------------------------------------------------------------------- -template +template void scenario_params() { // Default values of parameters are as expected WHEN("We examine the default length, start, and valueType") { THEN("They are as expected") { - BodyText b; + BlockData b; CHECK(b.length() == 0); CHECK(b.start() == 0); CHECK(b.valueType() == ""); @@ -25,17 +25,17 @@ void scenario_params() // length setter/getter works WHEN("We set length, then get and verify") { THEN("It works for a plain value") { - BodyText b; + BlockData b; b.length(12); CHECK(b.length() == 12); } THEN("It works for optional-with-value") { - BodyText b; + BlockData b; b.length(std::optional(34)); CHECK(b.length() == 34); } THEN("It works for optional-without-value (remains unchanged)") { - BodyText b; + BlockData b; b.length(56); b.length(std::optional(std::nullopt)); CHECK(b.length() == 56); @@ -45,17 +45,17 @@ void scenario_params() // start setter/getter works WHEN("We set start, then get and verify") { THEN("It works for a plain value") { - BodyText b; + BlockData b; b.start(11); CHECK(b.start() == 11); } THEN("It works for optional-with-value") { - BodyText b; + BlockData b; b.start(std::optional(13)); CHECK(b.start() == 13); } THEN("It works for optional-without-value (remains unchanged)") { - BodyText b; + BlockData b; b.start(17); b.start(std::optional(std::nullopt)); CHECK(b.start() == 17); @@ -65,17 +65,17 @@ void scenario_params() // valueType setter/getter works WHEN("We set valueType, then get and verify") { THEN("It works for a plain value") { - BodyText b; + BlockData b; b.valueType("unknown"); CHECK(b.valueType() == "unknown"); } THEN("It works for optional-with-value") { - BodyText b; + BlockData b; b.valueType(std::optional("Integer32")); CHECK(b.valueType() == "Integer32"); } THEN("It works for optional-without-value (remains unchanged)") { - BodyText b; + BlockData b; b.valueType("Float64"); b.valueType(std::optional(std::nullopt)); CHECK(b.valueType() == "Float64"); @@ -85,7 +85,7 @@ void scenario_params() // Combo of the above, using builder-pattern nature of the setters WHEN("We set length/start/valueType together, then get and verify") { THEN("It works for a plain value") { - BodyText b; + BlockData b; b.length(1) .start(2) .valueType("a"); @@ -94,7 +94,7 @@ void scenario_params() CHECK(b.valueType() == "a"); } THEN("It works for optional-with-value") { - BodyText b; + BlockData b; b.length(std::optional(3)) .start(std::optional(4)) .valueType(std::optional("b")); @@ -103,7 +103,7 @@ void scenario_params() CHECK(b.valueType() == "b"); } THEN("It works for optional-without-value (remains unchanged)") { - BodyText b; + BlockData b; b.length(100).start(200).valueType("c"); b.length(std::optional(std::nullopt)) .start(std::optional(std::nullopt)) @@ -120,14 +120,14 @@ void scenario_params() // Scenarios // ----------------------------------------------------------------------------- -SCENARIO("BodyText length/start/valueType") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData length/start/valueType") { + GIVEN("A default-constructed BlockData object") { scenario_params(); } } -SCENARIO("BodyText length/start/valueType") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData length/start/valueType") { + GIVEN("A default-constructed BlockData object") { scenario_params(); } } diff --git a/src/GNDStk/BlockData/test/print.test.cpp b/src/GNDStk/BlockData/test/print.test.cpp new file mode 100644 index 000000000..c82f84359 --- /dev/null +++ b/src/GNDStk/BlockData/test/print.test.cpp @@ -0,0 +1,440 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + +// ----------------------------------------------------------------------------- +// Scenario: raw string is active +// ----------------------------------------------------------------------------- + +// Helper: scenario_print_string_active +template +void scenario_print_string_active() +{ + // string is active, but empty + GIVEN("A BlockData with an empty raw string") { + WHEN("BlockData.print() is called") { + THEN("Nothing is printed") { + BlockData b; + b.string(""); + + // with no indentation + std::ostringstream oss; + b.print(oss,0); + CHECK(oss.str() == ""); + + // the same (nothing is printed) even if indentation is nonzero + oss.str(""); + b.print(oss,2); + CHECK(oss.str() == ""); + } + } + } + + // string is active, and contains values + GIVEN("A BlockData with a non-empty raw string") { + WHEN("BlockData.print() is called") { + THEN("The raw string and a newline are printed") { + BlockData b; + b.string("foo bar baz"); + + njoy::GNDStk::colors = false; + njoy::GNDStk::shades = false; + + // with no indentation + std::ostringstream oss; + b.print(oss,0); + CHECK(oss.str() == "foo bar baz\n"); + + // the same, even if indentation is nonzero; indentation isn't + // applied when the raw string (as opposed to the ) is active + oss.str(""); + b.print(oss,2); + CHECK(oss.str() == "foo bar baz\n"); + } + } + } +} + +// For DATATYPE == void +SCENARIO("BlockData print(), when the raw string is active") +{ + scenario_print_string_active(); +} + +// For DATATYPE == double +SCENARIO("BlockData print(), when the raw string is active") +{ + scenario_print_string_active(); +} + + +// ----------------------------------------------------------------------------- +// Scenario: vector is active +// ----------------------------------------------------------------------------- + +SCENARIO("BlockData print(), when a vector is active") +{ + // vector is active, but empty + GIVEN("A BlockData with an empty vector") { + WHEN("BlockData.print() is called") { + THEN("Nothing is printed") { + BlockData b; + b = std::vector{}; + + // with no indentation + std::ostringstream oss; + b.print(oss,0); + CHECK(oss.str() == ""); + + // the same (nothing is printed) even if indentation is nonzero + oss.str(""); + b.print(oss,2); + CHECK(oss.str() == ""); + } + } + } + + // vector is active, and contains values + GIVEN("A BlockData with a non-empty vector") { + WHEN("BlockData.print() is called") { + THEN("The vector and a newline are printed") { + BlockData b; + b = std::vector{{2, 3, 5, 7, 11, 13, 17, 19, 21, 23}}; + std::ostringstream oss; + + // Cases: + // indent: 0, 3 (number of spaces per indentation level) + // columns: 0, 1, 2, 5, 10, 11 (note that 10 == vector size) + // level: 0, 1, 2 (indentation level) + // Note: columns <= 0 means unlimited: so, all values on one line. + // Lots of cases, but we want to check that our prettyprinting + // functionality works perfectly, and doesn't do anything that's + // unexpected around "boundaries" like columns==10 with 10 values. + + oss.str(""); indent = 0; columns = 0; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 0; b.print(oss,1); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 0; b.print(oss,2); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 1; b.print(oss,0); + CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); + + oss.str(""); indent = 0; columns = 1; b.print(oss,1); + CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); + + oss.str(""); indent = 0; columns = 1; b.print(oss,2); + CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); + + oss.str(""); indent = 0; columns = 2; b.print(oss,0); + CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); + + oss.str(""); indent = 0; columns = 2; b.print(oss,1); + CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); + + oss.str(""); indent = 0; columns = 2; b.print(oss,2); + CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); + + oss.str(""); indent = 0; columns = 5; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 5; b.print(oss,1); + CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 5; b.print(oss,2); + CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 10; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 10; b.print(oss,1); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 10; b.print(oss,2); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 11; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 11; b.print(oss,1); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 0; columns = 11; b.print(oss,2); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 0; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 0; b.print(oss,1); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 0; b.print(oss,2); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 1; b.print(oss,0); + CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); + + oss.str(""); indent = 3; columns = 1; b.print(oss,1); + CHECK(oss.str() == + " 2\n 3\n 5\n 7\n 11\n" + " 13\n 17\n 19\n 21\n 23\n"); + + oss.str(""); indent = 3; columns = 1; b.print(oss,2); + CHECK(oss.str() == + " 2\n 3\n 5\n 7\n 11\n" + " 13\n 17\n 19\n 21\n 23\n"); + + oss.str(""); indent = 3; columns = 2; b.print(oss,0); + CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); + + oss.str(""); indent = 3; columns = 2; b.print(oss,1); + CHECK( + oss.str() == + " 2 3\n 5 7\n 11 13\n 17 19\n 21 23\n" + ); + + oss.str(""); indent = 3; columns = 2; b.print(oss,2); + CHECK( + oss.str() == + " 2 3\n 5 7\n 11 13\n 17 19\n 21 23\n" + ); + + oss.str(""); indent = 3; columns = 5; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 5; b.print(oss,1); + CHECK(oss.str() == " 2 3 5 7 11\n 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 5; b.print(oss,2); + CHECK(oss.str() == " 2 3 5 7 11\n 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 10; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 10; b.print(oss,1); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 10; b.print(oss,2); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 11; b.print(oss,0); + CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 11; b.print(oss,1); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + + oss.str(""); indent = 3; columns = 11; b.print(oss,2); + CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); + } + } + } +} + + + +// ----------------------------------------------------------------------------- +// Scenario: vector is active; test GNDStk::elements +// ----------------------------------------------------------------------------- + +// Helper: test_elements +template +void test_elements( + const BlockData &b, + const int indent, + const std::size_t columns, + const int level, + const long elements, + const std::string &want +) { + njoy::GNDStk::indent = indent; + njoy::GNDStk::columns = columns; + njoy::GNDStk::elements = elements; + + std::ostringstream oss; + b.print(oss,level); + + std::cout << "test_elements:" << std::endl; + std::cout << oss.str() << std::endl; + + CHECK(oss.str() == want); +} + +SCENARIO("BlockData print(), vector, trying GNDStk::elements") +{ + // vector is active, but empty + GIVEN("A BlockData with an empty vector") { + WHEN("BlockData.print() is called") { + THEN("Nothing is printed") { + BlockData b; + b = std::vector{}; + + using njoy::GNDStk::elements; + for (elements = -10; elements <= 10; ++elements) { + // with no indentation + std::ostringstream oss; + b.print(oss,0); + CHECK(oss.str() == ""); + + // the same (nothing is printed) even if indentation is nonzero + oss.str(""); + b.print(oss,2); + CHECK(oss.str() == ""); + } + } + } + } + + // vector is active, and contains values + GIVEN("A BlockData with a non-empty vector") { + WHEN("BlockData.print() is called") { + THEN("The vector and a newline are printed") { + BlockData b; + b = std::vector{{2.3, 5.7, 11.13, 17.19, 21.23}}; + + // Cases: + // indent: 3 (number of spaces per indentation level) + // columns: 0, 2, 3 (0 means unlimited) + // level: 0, 1, 2 (indentation level) + // elements: -1, 0, 1, 2, 3 (-1 means none; so, print all values) + // Lots of cases; we want prettyprinting to be perfect. + + // Integral parameters below are: indent, columns, level, elements + test_elements(b, 3, 0, 0, -1, + "2.3 5.7 11.13 17.19 21.23\n"); + test_elements(b, 3, 0, 0, +0, + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 0, +1, + "2.3\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 0, +2, + "2.3 5.7\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 0, +3, + "2.3 5.7 11.13\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 1, -1, + " 2.3 5.7 11.13 17.19 21.23\n"); + test_elements(b, 3, 0, 1, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 1, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 1, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 1, +3, + " 2.3 5.7 11.13\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 2, -1, + " 2.3 5.7 11.13 17.19 21.23\n"); + test_elements(b, 3, 0, 2, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 2, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 2, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 0, 2, +3, + " 2.3 5.7 11.13\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 0, -1, + "2.3 5.7\n" + "11.13 17.19\n" + "21.23\n"); + test_elements(b, 3, 2, 0, +0, + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 0, +1, + "2.3\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 0, +2, + "2.3 5.7\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 0, +3, + "2.3 5.7\n" + "11.13\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 1, -1, + " 2.3 5.7\n" + " 11.13 17.19\n" + " 21.23\n"); + test_elements(b, 3, 2, 1, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 1, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 1, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 1, +3, + " 2.3 5.7\n" + " 11.13\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 2, -1, + " 2.3 5.7\n" + " 11.13 17.19\n" + " 21.23\n"); + test_elements(b, 3, 2, 2, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 2, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 2, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 2, 2, +3, + " 2.3 5.7\n" + " 11.13\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 0, -1, + "2.3 5.7 11.13\n" + "17.19 21.23\n"); + test_elements(b, 3, 3, 0, +0, + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 0, +1, + "2.3\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 0, +2, + "2.3 5.7\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 0, +3, + "2.3 5.7 11.13\n" + "// truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 1, -1, + " 2.3 5.7 11.13\n" + " 17.19 21.23\n"); + test_elements(b, 3, 3, 1, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 1, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 1, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 1, +3, + " 2.3 5.7 11.13\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 2, -1, + " 2.3 5.7 11.13\n" + " 17.19 21.23\n"); + test_elements(b, 3, 3, 2, +0, + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 2, +1, + " 2.3\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 2, +2, + " 2.3 5.7\n" + " // truncated; actual #elements == 5\n"); + test_elements(b, 3, 3, 2, +3, + " 2.3 5.7 11.13\n" + " // truncated; actual #elements == 5\n"); + } + } + } +} diff --git a/src/GNDStk/BodyText/test/string.test.cpp b/src/GNDStk/BlockData/test/string.test.cpp similarity index 79% rename from src/GNDStk/BodyText/test/string.test.cpp rename to src/GNDStk/BlockData/test/string.test.cpp index 549b38041..fb8e8ed39 100644 --- a/src/GNDStk/BodyText/test/string.test.cpp +++ b/src/GNDStk/BlockData/test/string.test.cpp @@ -2,20 +2,20 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- // Helper // ----------------------------------------------------------------------------- -template +template void scenario_string() { // Default value of raw string is as expected WHEN("We examine the raw string") { THEN("It is as expected") { - BodyText b; + BlockData b; CHECK(b.string() == ""); } } @@ -23,7 +23,7 @@ void scenario_string() // Raw string setter/getter works WHEN("We set the raw string") { THEN("It has the correct value, and vector size() == 0 too") { - BodyText b; + BlockData b; // to ensure it clears below... b = std::vector(10); @@ -40,7 +40,7 @@ void scenario_string() // Test in conjunction with length, start, and valueType WHEN("We set string, length, start, and valueType together") { THEN("All values check out") { - BodyText b; + BlockData b; b.string("3 4 5 6").length(10).start(2).valueType("Integer32"); CHECK(b.length() == 10); @@ -56,14 +56,14 @@ void scenario_string() // Scenarios // ----------------------------------------------------------------------------- -SCENARIO("BodyText string()") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData string()") { + GIVEN("A default-constructed BlockData object") { scenario_string(); } } -SCENARIO("BodyText string()") { - GIVEN("A default-constructed BodyText object") { +SCENARIO("BlockData string()") { + GIVEN("A default-constructed BlockData object") { scenario_string(); } } diff --git a/src/GNDStk/BlockData/test/sync.test.cpp b/src/GNDStk/BlockData/test/sync.test.cpp new file mode 100644 index 000000000..9a088d851 --- /dev/null +++ b/src/GNDStk/BlockData/test/sync.test.cpp @@ -0,0 +1,345 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + +// ----------------------------------------------------------------------------- +// Scenario: pull +// Content == any of {length,start,valueType} +// ----------------------------------------------------------------------------- + +// Helper +template +void scenario_pull() +{ + WHEN("pullFromDerived() is called") { + // none of length, start, valueType + THEN("Push to Content{} works") { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + b.length(100).start(200).valueType("300"); + b.pullFromDerived(derived); // should do nothing here + CHECK(b.length() == 100); + CHECK(b.start() == 200); + CHECK(b.valueType() == "300"); + } + + // length only + THEN("Push to Content{length} works") { + struct : public BlockData { + struct { + int length = 10; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + } derived; + BlockData &b = derived; + b.length(11).start(12).valueType("13"); + b.pullFromDerived(derived); + CHECK(b.length() == 10); + CHECK(b.start() == 12); + CHECK(b.valueType() == "13"); + } + + // start only + THEN("Push to Content{start} works") { + struct : public BlockData { + struct { + int start = 14; + } Content; + const int &start() const { return Content.start; } + int &start() { return Content.start; } + } derived; + BlockData &b = derived; + b.length(15).start(16).valueType("17"); + b.pullFromDerived(derived); + CHECK(b.length() == 15); + CHECK(b.start() == 14); + CHECK(b.valueType() == "17"); + } + + // valueType only + THEN("Push to Content{valueType} works") { + struct : public BlockData { + struct { + std::string valueType = "18"; + } Content; + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(19).start(20).valueType("21"); + b.pullFromDerived(derived); + CHECK(b.length() == 19); + CHECK(b.start() == 20); + CHECK(b.valueType() == "18"); + } + + // all but length + THEN("Push to Content{start,valueType} works") { + struct : public BlockData { + struct { + int start = 22; + std::string valueType = "23"; + } Content; + const int &start() const { return Content.start; } + int &start() { return Content.start; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(24).start(25).valueType("26"); + b.pullFromDerived(derived); + CHECK(b.length() == 24); + CHECK(b.start() == 22); + CHECK(b.valueType() == "23"); + } + + // all but start + THEN("Push to Content{length,valueType} works") { + struct : public BlockData { + struct { + int length = 27; + std::string valueType = "28"; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(29).start(30).valueType("31"); + b.pullFromDerived(derived); + CHECK(b.length() == 27); + CHECK(b.start() == 30); + CHECK(b.valueType() == "28"); + } + + // all but valueType + THEN("Push to Content{length,start} works") { + struct : public BlockData { + struct { + int length = 32; + int start = 33; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const int &start() const { return Content.start; } + int &start() { return Content.start; } + } derived; + BlockData &b = derived; + b.length(34).start(35).valueType("36"); + b.pullFromDerived(derived); + CHECK(b.length() == 32); + CHECK(b.start() == 33); + CHECK(b.valueType() == "36"); + } + + // all three + THEN("Push to Content{length,start,valueType} works") { + struct : public BlockData { + struct { + int length = 37; + int start = 38; + std::string valueType = "39"; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const int &start() const { return Content.start; } + int &start() { return Content.start; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(40).start(41).valueType("42"); + b.pullFromDerived(derived); + CHECK(b.length() == 37); + CHECK(b.start() == 38); + CHECK(b.valueType() == "39"); + } + } +} + + +SCENARIO("BlockData pull from Content") { + GIVEN("A BlockData object") { + scenario_pull(); + } +} + +SCENARIO("BlockData pull from Content") { + GIVEN("A BlockData object") { + scenario_pull(); + } +} + + +// ----------------------------------------------------------------------------- +// Scenario: push +// Content == any of {length,start,valueType} +// ----------------------------------------------------------------------------- + +// Helper +template +void scenario_push() +{ + WHEN("pushToDerived() is called") { + // none of length, start, valueType + THEN("Push to Content{} works") { + struct : public BlockData { + struct { + int ignored = 123456; // not length, start, or valueType + } Content; + const int &ignored() const { return Content.ignored; } + int &ignored() { return Content.ignored; } + } derived; + BlockData &b = derived; + b.length(0).start(0).valueType("0"); + b.pushToDerived(derived); // should do nothing here + CHECK(derived.ignored() == 123456); + } + + // length only + THEN("Push to Content{length} works") { + struct : public BlockData { + struct { + int length = 10; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + } derived; + BlockData &b = derived; + b.length(11).start(12).valueType("13"); + b.pushToDerived(derived); + CHECK(derived.length() == 11); + } + + // start only + THEN("Push to Content{start} works") { + struct : public BlockData { + struct { + int start = 14; + } Content; + const int &start() const { return Content.start; } + int &start() { return Content.start; } + } derived; + BlockData &b = derived; + b.length(15).start(16).valueType("17"); + b.pushToDerived(derived); + CHECK(derived.start() == 16); + } + + // valueType only + THEN("Push to Content{valueType} works") { + struct : public BlockData { + struct { + std::string valueType = "18"; + } Content; + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(19).start(20).valueType("21"); + b.pushToDerived(derived); + CHECK(derived.valueType() == "21"); + } + + // all but length + THEN("Push to Content{start,valueType} works") { + struct : public BlockData { + struct { + int start = 22; + std::string valueType = "23"; + } Content; + const int &start() const { return Content.start; } + int &start() { return Content.start; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(24).start(25).valueType("26"); + b.pushToDerived(derived); + CHECK(derived.start() == 25); + CHECK(derived.valueType() == "26"); + } + + // all but start + THEN("Push to Content{length,valueType} works") { + struct : public BlockData { + struct { + int length = 27; + std::string valueType = "28"; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(29).start(30).valueType("31"); + b.pushToDerived(derived); + CHECK(derived.length() == 29); + CHECK(derived.valueType() == "31"); + } + + // all but valueType + THEN("Push to Content{length,start} works") { + struct : public BlockData { + struct { + int length = 32; + int start = 33; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const int &start() const { return Content.start; } + int &start() { return Content.start; } + } derived; + BlockData &b = derived; + b.length(34).start(35).valueType("36"); + b.pushToDerived(derived); + CHECK(derived.length() == 34); + CHECK(derived.start() == 35); + } + + // all three + THEN("Push to Content{length,start,valueType} works") { + struct : public BlockData { + struct { + int length = 37; + int start = 38; + std::string valueType = "39"; + } Content; + const int &length() const { return Content.length; } + int &length() { return Content.length; } + const int &start() const { return Content.start; } + int &start() { return Content.start; } + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + } derived; + BlockData &b = derived; + b.length(40).start(41).valueType("42"); + b.pushToDerived(derived); + CHECK(derived.length() == 40); + CHECK(derived.start() == 41); + CHECK(derived.valueType() == "42"); + } + } +} + + +SCENARIO("BlockData push to Content") { + GIVEN("A BlockData object") { + scenario_push(); + } +} + +SCENARIO("BlockData push to Content") { + GIVEN("A BlockData object") { + scenario_push(); + } +} diff --git a/src/GNDStk/BlockData/test/toNode.test.cpp b/src/GNDStk/BlockData/test/toNode.test.cpp new file mode 100644 index 000000000..6bd63314a --- /dev/null +++ b/src/GNDStk/BlockData/test/toNode.test.cpp @@ -0,0 +1,248 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + + +// ----------------------------------------------------------------------------- +// Helper +// ----------------------------------------------------------------------------- + +// Tests use either void for each template parameter, or int, double, +// std::string, and char, in that order. In the former case, we're testing +// toNode() for the generic BlockData<...,void>. In the latter case, we're +// testing toNode() for non-generic BlockData. +template +void scenario_toNode() +{ + // Default-constructed BlockData + GIVEN("A default-constructed BlockData") { + WHEN("toNode() is called") { + THEN("The computed text string is empty") { + std::string text = "abc"; + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + // w/trim == true (shouldn't matter here; applies to vector) + b.trim = true; + b.toNode(text); + CHECK(text == ""); + + // w/trim == false (shouldn't matter here; applies to vector) + b.trim = false; + b.toNode(text); + CHECK(text == ""); + } + } + } + + // BlockData, after being given a particular raw string and parameters + GIVEN("A BlockData, with given raw string and parameters") { + WHEN("toNode() is called") { + THEN("The computed text string is as expected, " + "and the parameters remain as given" + ) { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + b.string("0 12 34 56 0 0") + .start(100).length(200).valueType("hello"); + + // Someone who sets the raw string directly (as opposed to using + // a vector) is stating that they want *exactly* that raw string, + // including any 0s or anything else. To have BlockData's trim flag + // be relevant, use a vector. + + // w/trim == true (shouldn't matter here; applies to vector) + std::string text = "abc"; + b.trim = true; + b.toNode(text); + CHECK(text == "0 12 34 56 0 0"); + CHECK(b.start() == 100); + CHECK(b.length() == 200); + CHECK(b.valueType() == "hello"); + + // w/trim == false (shouldn't matter here; applies to vector) + text = "abc"; + b.trim = false; + b.toNode(text); + CHECK(text == "0 12 34 56 0 0"); + CHECK(b.start() == 100); + CHECK(b.length() == 200); + CHECK(b.valueType() == "hello"); + } + } + } + + // BlockData, after being given a particular vector + GIVEN("A BlockData, assigned from a particular vector") { + WHEN("toNode() is called") { + THEN("The computed text string is as expected, " + "and the parameters were computed properly" + ) { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + // what's set here should be replaced upon assignment from vector + b.string("a b c").start(10).length(20).valueType("foobar"); + + // assign from vector + b = std::vector{{0, 0, 12, 34, 56, 78, 0, 0, 0, 0, 0}}; + + // w/trim == true + std::string text = "this should be replaced"; + b.trim = true; + b.toNode(text); + CHECK(text == "12 34 56 78"); + CHECK(b.start() == 2); + CHECK(b.length() == 11); + CHECK(b.valueType() == "Integer32"); + + // w/trim == false + text = "this should be replaced"; + b.trim = false; + b.toNode(text); + CHECK(text == "0 0 12 34 56 78 0 0 0 0 0"); + CHECK(b.start() == 0); + CHECK(b.length() == 11); + CHECK(b.valueType() == "Integer32"); + } + } + } + + // BlockData, after being given a particular vector + GIVEN("A BlockData, assigned from a particular vector") { + WHEN("toNode() is called") { + THEN("The computed text string is as expected, " + "and the parameters were computed properly" + ) { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + // what's set here should be replaced upon assignment from vector + b.string("d e f").start(100).length(200).valueType("foobar"); + + // assign from vector + b = std::vector{{0, 0, 0, 1.234, 5.678, 0, 0 }}; + + // w/trim == true + std::string text = "this should be replaced"; + b.trim = true; + b.toNode(text); + CHECK(text == "1.234 5.678"); + CHECK(b.start() == 3); + CHECK(b.length() == 7); + CHECK(b.valueType() == "Float64"); + + // w/trim == false + text = "this should be replaced"; + b.trim = false; + b.toNode(text); + CHECK(text == "0 0 0 1.234 5.678 0 0"); + CHECK(b.start() == 0); + CHECK(b.length() == 7); + CHECK(b.valueType() == "Float64"); + } + } + } + + // BlockData, after being given a particular vector + // A key point here is to ensure that ""s (string "zeros") are properly + // trimmed at the beginning and end. + GIVEN("A BlockData, assigned from a particular vector") { + WHEN("toNode() is called") { + THEN("The computed text string is as expected, " + "and the parameters were computed properly" + ) { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + // what's set here should be replaced upon assignment from vector + b.string("d e f").start(100).length(200).valueType("foobar"); + + // assign from vector + b = std::vector{{"","","","foo","bar","baz","",""}}; + + // w/trim == true + std::string text = "this should be replaced"; + b.trim = true; + b.toNode(text); + CHECK(text == "foo bar baz"); + CHECK(b.start() == 3); + CHECK(b.length() == 8); + CHECK(b.valueType() == "UTF8Text"); + + // w/trim == false + // toNode() should treat this (the std::string) case as if trim + // were true. If it didn't, we'd end up with, well, leading and + // trailing *empty* strings, which, well, amount to leading and + // trailing nothing. + text = "this should be replaced"; + b.trim = false; + b.toNode(text); + CHECK(text == "foo bar baz"); + CHECK(b.start() == 3); + CHECK(b.length() == 8); + CHECK(b.valueType() == "UTF8Text"); + } + } + } + + // BlockData, after being given a particular vector + // For T something other than int, double, and std::string + GIVEN("A BlockData, assigned from a particular vector") { + WHEN("toNode() is called") { + THEN("The computed text string is as expected, " + "and the parameters were computed properly" + ) { + struct : public BlockData { + struct { + } Content; + } derived; + BlockData &b = derived; + + // what's set here should be replaced upon assignment from vector + b.string("x y z").start(100).length(200).valueType("foobar"); + + // assign from vector + b = std::vector{{0,0,0,0,0,'a','b','c','d',0}}; + + std::string text = "this should be replaced"; + b.toNode(text); + CHECK(text == "a b c d"); + CHECK(b.start() == 5); + CHECK(b.length() == 10); + CHECK(b.valueType() == "char"); + } + } + } +} + + +// ----------------------------------------------------------------------------- +// Scenario +// ----------------------------------------------------------------------------- + +SCENARIO("BlockData toNode()") { + scenario_toNode(); +} + +SCENARIO("BlockData toNode()") { + scenario_toNode(); +} diff --git a/src/GNDStk/BlockData/test/types.test.cpp b/src/GNDStk/BlockData/test/types.test.cpp new file mode 100644 index 000000000..ffbee513b --- /dev/null +++ b/src/GNDStk/BlockData/test/types.test.cpp @@ -0,0 +1,121 @@ + +#include "catch.hpp" +#include "GNDStk.hpp" + +using namespace njoy::GNDStk; + +// ----------------------------------------------------------------------------- +// Scenario +// ----------------------------------------------------------------------------- + +SCENARIO("BlockData data types") { + GIVEN("std::vector for certain specific Ts") { + + WHEN("Via BlockData, we make variants of vectors and of scalars") { + // vector type + using vv = BlockData::VariantOfVectors; + THEN("The variant-of-vector size should be correct") { + CHECK(std::variant_size_v == 15); + } + vv vectors; + + // scalar type + using vs = BlockData::VariantOfScalars; + THEN("The variant-of-scalar size should be correct") { + CHECK(std::variant_size_v == 15); + } + vs scalars; + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,"a"); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == "a"); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,'b'); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 'b'); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-100); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -100); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-200); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -200); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-300); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -300); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-400); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -400); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-500); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -500); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,100); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 100); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,200); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 200); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,300); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 300); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,400); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 400); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,500); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 500); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-1.2f); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -1.2f); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,3.4); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == 3.4); + } + + THEN("Transforming to vector, and access, work") { + vectors = std::vector(10,-5.6); + scalars = std::get>(vectors)[0]; + CHECK(std::get(scalars) == -5.6); + } + } // WHEN + + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/BodyText.hpp b/src/GNDStk/BodyText.hpp deleted file mode 100644 index 7b963fd0c..000000000 --- a/src/GNDStk/BodyText.hpp +++ /dev/null @@ -1,148 +0,0 @@ - -// Printing-related colors. -// todo Eventually, this probably belongs in a more context-agnostic -// location, such as GNDStk's utility.hpp file or something like it. -#include "GNDStk/BodyText/src/colors.hpp" - -// Miscellaneous helper constructs. -#include "GNDStk/BodyText/src/detail.hpp" - - -// ----------------------------------------------------------------------------- -// BodyText -// The case is specialized and has the fun stuff. This one needs -// just a bit of content, in order to facilitate uniform treatment of BodyText. -// ----------------------------------------------------------------------------- - -template -class BodyText { -public: - using VariantOfVectors = std::variant; - using VariantOfScalars = std::variant; - static inline constexpr bool runtime = false; - template - static inline constexpr bool supported = false; -}; - - -// ----------------------------------------------------------------------------- -// BodyText -// -// Designed to be flexible, smart, and safe. Does lots of checks, and, for the -// DATA == void case, can essentially re-form itself depending on what type of -// data someone tries to extract. -// -// For efficiency in the DATA == void case, an application might want to copy -// to its own vector (e.g. auto myvec = mybodytext.get>()) -// in order to do work on (or with) the vector there, before copying it back. -// ----------------------------------------------------------------------------- - -template -class BodyText { -public: - - #include "GNDStk/BodyText/src/types.hpp" - - // For convenience in various SFINAE and if-constexpr constructs - static inline constexpr bool runtime = detail::isVoid; - template - struct is_supported { - static inline constexpr bool value = - ( runtime && detail::isAlternative) || - (!runtime && ( - std::is_constructible_v || - std::is_convertible_v - )); - }; - template - static inline constexpr bool supported = is_supported::value; - - enum class Active { string, vector }; - -private: - - // For internal use - mutable Active act = Active::string; - - // Raw string, directly from "plain character data" in a GNDS file. - // We'll allow callers to set this by using a setter. - std::string rawstring; - - // Vector of . - // Mutable, so that we can defer processing of the raw string into - // a vector until, and unless, a caller *asks* for the vector. - // This will be used if, and only if, DATA == void. - mutable VariantOfVectors variant; - - // Vector of - // This will be used if, and only if, DATA != void. - // data_t is used in a few places where, without it, we'd create compilation - // errors by using "void" in invalid ways. The "int" below is arbitrary - - // essentially a placeholder; the following is only used when !runtime. - using data_t = std::conditional_t; - mutable std::vector vector; - -public: - - // Parameters that affect interpretation of the raw string: - // struct vars { length, start, valueType } - // Includes public getters and setters for those. - // We won't use valueType if DATA != void. - #include "GNDStk/BodyText/src/params.hpp" - - // trim - // Flag: should the conversion of BodyText data back into textual data, - // in a Node, trim zeros from the start and end of the output? - mutable bool trim = true; - - // Getters and setters for the raw string: - #include "GNDStk/BodyText/src/string.hpp" - - // active() - Active active() const { return act; } - - // clear() - // Clears the vector, or the active vector alternative in the variant. - BodyText &clear() - { - if constexpr (runtime) - std::visit([](auto &&alt) { alt.clear(); }, variant); - else - vector.clear(); - - act = Active::vector; - return *this; - } - - // size() - // Returns the size of the vector, or of the active vector alternative in - // the variant. Depending on what someone may or may not have done with the - // current BodyText object, size() might or might not reflect the values of - // length and/or start, or reflect the current contents of the raw string. - std::size_t size() const - { - if constexpr (runtime) - return std::visit([](auto &&alt) { return alt.size(); }, variant); - else - return vector.size(); - } - - // Various vector get() functions, and the type-specific doubles() etc. - #include "GNDStk/BodyText/src/get.hpp" - - // Read/write data, from/to a Node - #include "GNDStk/BodyText/src/fromNode.hpp" - #include "GNDStk/BodyText/src/toNode.hpp" - - // Write to ostream - // Not to be confused with the process of writing data to a Node - #include "GNDStk/BodyText/src/write.hpp" - - // Pull/push length/start/valueType from/to derived-class struct content - #include "GNDStk/BodyText/src/sync.hpp" - - // Assignment - // From string or vector; the former == calling our raw string setter - #include "GNDStk/BodyText/src/assign.hpp" - -}; // class BodyText diff --git a/src/GNDStk/BodyText/src/assign.hpp b/src/GNDStk/BodyText/src/assign.hpp deleted file mode 100644 index b1b975822..000000000 --- a/src/GNDStk/BodyText/src/assign.hpp +++ /dev/null @@ -1,75 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Assignment from string -// Same effect as the string(new string) setter -// ----------------------------------------------------------------------------- - -BodyText &operator=(const std::string &str) -{ - return string(str); -} - - -// ----------------------------------------------------------------------------- -// Assignment from vector -// ----------------------------------------------------------------------------- - -/* -DISCUSSION - -Elsewhere, a BodyText object can be made from a GNDS node. From GNDS, we get -a text string (copied to the rawstring field), from which a vector of values -can be created on an as-needed basis. A GNDS node might also give us any of -length, start, and valueType, which, when pulling data from the Node, we'll -use if they're there, or otherwise assume to be our defaults. - -Here, we're allowing for an assignment BodyText = vector. For this assignment, -the caller should send the full, complete vector of values that's appropriate -for the GNDS Node whose data this BodyText object is intended to represent. - -Specifically: the vector should contain whatever leading and/or trailing 0s -the full data vector is supposed to have. The length and start values are -completely ignored by this function; they're neither used nor set. Future -vector accesses though our various get() functions simply access the vector -exactly as-is. Length and start won't come into play until - and unless - a -caller uses the string setter (or assignment to string) and subsequently -triggers a remake of the vector. (Which would then be a newly-created vector, -based on the value of the raw string - not the vector from which we're -assigning here.) - -As for valueType, this function attempts to guess it from the vector's element -type, and sets it to "", the empty string, if we don't recognize that type. - -If a vector that's assigned from, here, is still in play when this BodyText's -data are written to a Node (see the toNode() function), then toNode() will -recompute length and start automatically, based on the vector's beginning and -ending content, if the "trim" flag is set. See toNode() for more information. -*/ - -template -std::enable_if_t, BodyText &> -operator=(const std::vector &vec) -{ - // set the raw string to "", because it's no longer considered meaningful - rawstring = ""; - - // length, start, valueType - length(vec.size()); - start(0); - valueType(detail::MapTypeString::value[0]); - - // assign vector - if constexpr (runtime) - variant = vec; - else if constexpr (std::is_same_v) - vector = vec; - else { - vector.clear(); - vector.reserve(vec.size()); - for (const T &element : vec) - vector.push_back(DATA(element)); - } - - act = Active::vector; - return *this; -} diff --git a/src/GNDStk/BodyText/src/colors.hpp b/src/GNDStk/BodyText/src/colors.hpp deleted file mode 100644 index f8850fde7..000000000 --- a/src/GNDStk/BodyText/src/colors.hpp +++ /dev/null @@ -1,89 +0,0 @@ - -namespace colors { - -// ----------------------------------------------------------------------------- -// Colors themselves -// ----------------------------------------------------------------------------- - -// Specific colors: -// colors::plain::* -// colors::vivid::* -// Reset/clear: -// colors::reset -// Note that all of these are ANSI color escape sequences. They'll work on many -// terminals, perhaps most, but working isn't guaranteed. GNDStk::color is false -// by default, so colors aren't actually used unless someone sets it to true. - -namespace plain { - -inline const std::string - black = "\033[30;1m", - red = "\033[31;1m", - green = "\033[32;1m", - blue = "\033[34;1m", - cyan = "\033[36;1m", - magenta = "\033[35;1m", - purple = magenta, - violet = magenta, - yellow = "\033[33;1m", - white = "\033[37;1m"; - -} // namespace plain - -namespace vivid { - -inline const std::string - black = "\033[30;21m", - red = "\033[31;21m", - green = "\033[32;21m", - blue = "\033[34;21m", - cyan = "\033[36;21m", - magenta = "\033[35;21m", - purple = magenta, - violet = magenta, - yellow = "\033[33;21m", - white = "\033[37;21m"; - -} // namespace vivid - -inline const std::string reset = "\033[0m"; - - - -// ----------------------------------------------------------------------------- -// For Component printing -// Non-const, so that you can change them if they don't work well with your -// window's color scheme, or if you just prefer something else. -// ----------------------------------------------------------------------------- - -// Use: -// colors::part -// Where part is a particular portion of the relevant printed output. -// Available parts appear below. "" means no special color treatment, -// so that users get whatever text color their terminal already uses. - -// General labels, and colon separator between label and value -inline std::string label = ""; -inline std::string colon = ""; - -// Component labels + begin/end curly braces -inline std::string component = plain::magenta; -inline std::string brace = plain::magenta; - -// Vector labels + begin/end square brackets -inline std::string vector = plain::yellow; -inline std::string bracket = plain::yellow; - -// If optional/defaulted, label (but not curly braces or square brackets, -// where applicable) are modified to these. Both are blue-ish, reflecting -// the general similarities between std::optional and GNDStk::Defaulted. -inline std::string optional = plain::cyan; -inline std::string defaulted = plain::blue; - -// Values in nodes with "body text" -inline std::string value = plain::white; - -// Comments -inline std::string comment = plain::red; - -} // namespace colors diff --git a/src/GNDStk/BodyText/src/detail.hpp b/src/GNDStk/BodyText/src/detail.hpp deleted file mode 100644 index dd5053e9e..000000000 --- a/src/GNDStk/BodyText/src/detail.hpp +++ /dev/null @@ -1,170 +0,0 @@ - -namespace detail { - -// ----------------------------------------------------------------------------- -// Miscellaneous -// ----------------------------------------------------------------------------- - -// scalarize -template -auto scalarize(const std::variant) -{ - return std::variant{}; -} - -// decays, decays_t -// Like std::decay and std::decay_t, but for tuple -template -struct decays { }; -template -struct decays> { - using type = std::tuple ...>; -}; - -template -using decays_t = typename decays::type; - - - -// ----------------------------------------------------------------------------- -// SFINAE constructs for detecting whether or not a class has certain members. -// Adapted from an answer here: https://stackoverflow.com/questions/1005476 -// ----------------------------------------------------------------------------- - -// ------------------------ -// Helpers -// ------------------------ - -// has_length -template -struct has_length - : std::false_type { }; - -template -struct has_length - : std::true_type { }; - -// has_start -template -struct has_start - : std::false_type { }; - -template -struct has_start - : std::true_type { }; - -// has_valueType -template -struct has_valueType - : std::false_type { }; - -template -struct has_valueType - : std::true_type { }; - -// has_index -template -struct has_index - : std::false_type { }; - -template -struct has_index - : std::true_type { }; - -template -struct has_index> { - // for variant: does any alternative have index? - static constexpr bool value = (has_index::value || ...); -}; - -// has_label -template -struct has_label - : std::false_type { }; - -template -struct has_label - : std::true_type { }; - -template -struct has_label> { - // for variant: does any alternative have label? - static constexpr bool value = (has_label::value || ...); -}; - - -// ------------------------ -// Prefer these. -// They apply std::decay, -// and don't need ::value -// ------------------------ - -template -inline constexpr bool hasLength = has_length >::value; -template -inline constexpr bool hasStart = has_start >::value; -template -inline constexpr bool hasValueType = has_valueType>::value; -template -inline constexpr bool hasIndex = has_index >::value; -template -inline constexpr bool hasLabel = has_label >::value; - - - -// ----------------------------------------------------------------------------- -// element2element -// ----------------------------------------------------------------------------- - -// Remark: PrecisionContext::data, not PrecisionContext::metadata, is the right -// precision context (in terms of our functionality for handling floating-point -// precision) in the code for which element2element() is called. We could bypass -// element2element() entirely, using convert_t{}(...) instead, except that then -// PrecisionContext::metadata would ultimately get used for floating-point T. -// So, below, we recognize floating-point T directly, and handle it correctly. - -// string ==> arithmetic -template>> -void element2element(const std::string &str, T &value) -{ - if constexpr (std::is_floating_point_v) - value = Precision{}.read(str); - else - convert_t{}(str,value); -} - -// arithmetic ==> arithmetic -template -void element2element(const FROM &from, TO &to) -{ - convert_t{}(from,to); -} - -// arithmetic ==> string -template>> -void element2element(const T &value, std::string &str) -{ - if constexpr (std::is_floating_point_v) - str = Precision{}.write(value); - else - convert_t{}(value,str); -} - - - -// ----------------------------------------------------------------------------- -// getBounds -// ----------------------------------------------------------------------------- - -template -auto getBounds(const std::vector &vec) -{ - T zero; - if constexpr (std::is_same_v) zero = ""; else zero = T(0); - std::pair bnd(0,vec.size()); - while (bnd.first < bnd.second && vec[bnd.first ] == zero) ++bnd.first; - while (bnd.first < bnd.second && vec[bnd.second-1] == zero) --bnd.second; - return bnd; -} - -} // namespace detail diff --git a/src/GNDStk/BodyText/src/fromNode.hpp b/src/GNDStk/BodyText/src/fromNode.hpp deleted file mode 100644 index c54b50027..000000000 --- a/src/GNDStk/BodyText/src/fromNode.hpp +++ /dev/null @@ -1,39 +0,0 @@ - -// ----------------------------------------------------------------------------- -// BodyText::fromNode(Node) -// ----------------------------------------------------------------------------- - -void fromNode(const Node &node) -{ - // length, start, and valueType might be present in the Node, but we won't - // fetch any of them here. Elsewhere, the current BodyText object should have - // its length, start, and valueType pulled from those respective values in - // an object of a class derived from Component (which in turn derives from - // BodyText). That object's content will have been pulled from the same Node. - // Here, we just get the Node's values: "plain character data" in XML terms. - - bool found = false; - rawstring = node.pcdata(found); - - if (!found) { - rawstring = ""; - - // Warning, re: why are we in BodyText if there's no body text? - // Perhaps it's possible that the Node has a non-default length and/or - // start, so that the values are all supposed to be...zero. Until and - // unless we discover otherwise, however, we doubt that that would be - // the case, and will consider a Node's lack of plain character data, - // in the present context, to be something that merits a warning. - log::warning( - "Component marked as having \"body text\", a.k.a. XML \"pcdata\" " - "(plain\ncharacter data), " - "but no such content was found in the GNDS node." - ); - log::member("BodyText::fromNode(Node, with name \"{}\")", node.name); - } - - // Above, we set the raw string. The following reflects this, so that the - // vector, or a vector in the variant, will be rebuilt from the raw string - // if and when a caller asks for it. - act = Active::string; -} diff --git a/src/GNDStk/BodyText/src/get.hpp b/src/GNDStk/BodyText/src/get.hpp deleted file mode 100644 index c2ff03d81..000000000 --- a/src/GNDStk/BodyText/src/get.hpp +++ /dev/null @@ -1,563 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Cases -// ----------------------------------------------------------------------------- - -/* ------------------------- -When DATA == void ------------------------- - -Case 1 -Return reference to [const] vector: - get> const - get> -T must be such that vector is in our variant. - -Case 2 -Return reference to [const] T: - get(n) const - get(n) -T must be such that vector is in our variant. - -Case 3 -Return reference to [const] variants>: - get() const - get() - -Case 4 -Return (by value) a variant: - get(n) const - operator[](n) const -A reference return isn't possible with the above two, because there's -no variant to reference; it's computed on-the-fly. The value -return means, further, that non-const version aren't necessary. - -Case 5 -Type-specific getters with specific names: - const std::vector &name() const - std::vector &name() - const T &name(n) const - T &name(n) -For example, name == doubles when T == double. - ------------------------- -When DATA != void ------------------------- - -Case 1 -Return reference to [const] vector: - get> const - get> -T must == DATA. - -Case 2 -Return reference to [const] T: - get(n) const - get(n) -T must == DATA. - -Case 3 -Return reference to [const] vector - get() const - get() - -Case 4 -Return reference to [const] DATA: - get(n) const - operator[](n) const - get(n) - operator[](n) - -Case 5 -Type-specific getters with a specific name: - const std::vector &name() const - std::vector &name() - const DATA &name(n) const - DATA &name(n) -For example, name == doubles if DATA == double. Unlike in the DATA == void case, -we won't have this set of functions for each of name == doubles, name == ints, -name == strings, etc., but only for the name that's appropriate for type DATA. -*/ - - - -// ----------------------------------------------------------------------------- -// 1. get>() -// ----------------------------------------------------------------------------- - -/* ------------------------- -DESCRIPTION ------------------------- - -If active == string: - - Warn if T appears to conflict with valueType. - Warn if length appears to be wrong. - - Make the vector in the variant contain data from the raw string. - INCLUDE any leading and trailing zeros, per start and length. - Note that length == 0 is interpreted as no particular length prescribed. - - Briefly: create vector = [0 ... 0 values_from_raw_string 0 ... 0]. - For the T == string case, 0 really means "" (empty string). - -If active == vector: - - If the variant already contains a vector: - Return it; we're done. - *** Under the correct and normal use of BodyText, *** - *** this simple action will probably be the most common. *** - - Else: - Convert the variant's vector into a vector. - Print a note to the effect that this might be unintentional. - The note can be suppressed if the call *is* intentional. - -In the active == vector case, length, start, and valueType aren't considered -to be relevant, and play no role. We consider those values to be meaningful -ONLY in relation to BodyText's raw string, and we deal with them here only -if and when we make the vector from the raw string. - -That way, callers can access, manipulate, and even completely change the -vector's contents or its type - basically, can work in peace with a vector, -as someone working with data would surely often want to do - without length, -start, or valueType interfering with the process. Those values are considered -to be relevant ONLY when we absolutely must deal with the raw string. This -generally happens only during creation of the current object from a Node, -or creation of a Node from the current object. (And if we create a Node from -a vector in the current object, then we'll compute length, etc. for ourselves. -See the toNode() function for more information about that.) - -Therefore, if you want length, start, and valueType to be used, then proceed -as follows. Set the raw string to what you wish, using the string() setter. -Set length, start, or valueType as you wish, either before or after possibly -setting the string. Finally, after doing all that, do a get>(). -Then the vector in the variant will be remade, per the new string and/or the -length etc. parameters, as described earlier in this descriptive comment, if -and when a get> function is next called. - -The return value of the const version is a const reference to a (possibly -newly converted-to from the raw string, possibly existing, or possibly remade) -vector in the variant. Note that because the variant was declared to be -mutable, we were indeed able to rebuild the vector if doing so was necessary. -But we'll still return a *const* reference in that case, because the present -object is conceptually const, and a caller shouldn't therefore be allowed to -modify the vector outside of BodyText's machinery. - -Of course we also have a non-const version, for a non-const *this. -*/ - - -// const -template -std::enable_if_t< - ( runtime && detail::isAlternative) || - (!runtime && std::is_same_v>), - const VECTOR & -> get() const -{ - // Element type requested - using T = typename VECTOR::value_type; - - - // ------------------------ - // if active == string - // ------------------------ - - if (active() == Active::string) { - static const std::string context_rebuilding = - "BodyText::get>(), remade from raw string"; - - // Completely rebuild the vector from the raw string, making use of - // length, start, and valueType. - - // For this get(), the caller has stipulated a particular vector type. - // We'll print a warning if that vector type appears to conflict with - // valueType. Regardless, we'll return what the caller requested. Note - // that valueType == "" is acceptable with any element type. - if (valueType() != "" && !detail::MapTypeString::find(valueType())) { - log::warning( - "Vector element type may be inconsistent with valueType \"{}\";\n" - "we'll create the requested std::vector<> anyway", - valueType() - ); - log::member(context_rebuilding); - } - - // Initialize - VECTOR *to; - if constexpr (runtime) { - variant = VECTOR{}; - to = &std::get(variant); // std::get, not this get :-) - } else { - vector.clear(); - to = &vector; - } - - T zero; - if constexpr (std::is_same_v) zero = ""; else zero = T(0); - - // [*****----------]: leading 0s - for (std::size_t i = 0; i < start(); ++i) - to->push_back(zero); - - // [-----*****-----]: values from the raw string - std::istringstream iss(rawstring); - if constexpr (std::is_floating_point_v) { - std::string str; - while (iss >> str) - to->push_back( - detail::Precision{}.read(str) - ); - } else { - T element; - while (iss >> element) - to->push_back(element); - } - - // Print a warning if length appears to be impossible because we already - // have more than that number of values. (But length == 0 is ignored.) - if (0 < length() && length() < to->size()) { - log::warning( - "The value of length == {} appears to be wrong, because we\n" - "already have {} values from start == {}, plus {} values read\n" - "from the raw string, for a total of {} values.", - length(), - start(), - start(), - to->size() - start(), - to->size() - ); - log::member(context_rebuilding); - } - - // [----------*****]: trailing 0s - for (std::size_t i = to->size(); i < length(); ++i) - to->push_back(zero); - - act = Active::vector; // was string; now is vector - return *to; - } // if (active == Active::string) - - - // ------------------------ - // if active == vector - // ------------------------ - - if constexpr (runtime) { - // VARIANT CASE... - // Do we already have a vector of the requested type? - if (std::holds_alternative(variant)) - return std::get(variant); - - // If we reach this point, it means two things. (1) We're NOT remaking - // a vector from the raw string (that case was handled first). (2) The - // caller wants a vector of a different type than the type the variant - // currently holds (or we'd have returned immediately above). - // - // So, for example, perhaps the variant currently has a vector, - // and a call get>() was made, meaning that the caller - // wants a vector. - // - // BodyText is intended to store just one vector - one that represents - // values in a GNDS node that has "body text." We don't, and shouldn't, - // try to juggle multiple vectors of different types. Therefore, we'll - // attempt to convert the existing vector to one of the requested type, - // then place the new vector into the variant (replacing the old one.) - // - // This is arguably an odd situation, but one that might - might - have - // some utility. (We're not sure yet.) So, we'll print an informational - // note (not even a warning), then proceed. - - log::info( - "Re-forming vector of one type into vector of another type;\n" - "was this intentional?"); - log::member("BodyText::get>()"); - - // Initialize a new vector that will soon replace the old one - VECTOR newVector; - newVector.reserve(size()); - - // Convert elements from the old vector to the new vector - std::visit( - [&newVector](auto &&oldVector) - { - for (const auto &from : oldVector) { - newVector.push_back(T()); - detail::element2element(from,newVector.back()); - } - }, - variant - ); - - // Replace the existing vector with the new vector - variant = newVector; - return std::get(variant); - - } else { - // VECTOR CASE... - // The vector is (via SFINAE) already of the requested type - return vector; - } -} - - -// non-const -template -std::enable_if_t< - ( runtime && detail::isAlternative) || - (!runtime && std::is_same_v>), - VECTOR & -> get() -{ - return const_cast(std::as_const(*this).template get()); -} - - - -// ----------------------------------------------------------------------------- -// 2. get(n) -// ----------------------------------------------------------------------------- - -// For DATA == void (so that we have a variants>): -// These trigger a complete rebuild of the vector, if it isn't already of type -// vector for the given T. This is intentional, in order to provide maximum -// flexibility. However, be aware of it, for the sake of efficiency! In general, -// when using a BodyText object, we recommend sticking with one underlying type. - -// For DATA != void (so that we have a vector): -// T == DATA is required, so that returning an element of the vector will -// return a reference to T. (A constructibility/convertibility requirement that -// we have in other BodyText-related code thus needs to be more stringent here. -// We can't just be able to make a T from a DATA. Those must in fact be the same -// type, because we return a reference.) - -// For both of the above cases: -// If the string (not the variant or the vector) is active, then a rebuild from -// the string is necessary, and will happen in the get>() call. - -// const -template -std::enable_if_t< - supported && (runtime || std::is_same_v), - const T & -> -get(const std::size_t n) const -{ - try { - return get>()[n]; - } catch (...) { - log::member("BodyText::get({})", n); - throw; - } -} - -// non-const -template -std::enable_if_t< - supported && (runtime || std::is_same_v), - T & -> -get(const std::size_t n) -{ - return const_cast(std::as_const(*this).template get(n)); -} - - - -// ----------------------------------------------------------------------------- -// 3. get() -// If DATA == void, returns a variants>. -// If DATA != void, returns a vector<>. -// ----------------------------------------------------------------------------- - -// const -std::conditional_t< - runtime, - const VariantOfVectors &, - const std::vector & -> get() const -{ - if constexpr (runtime) { - detail::MapStringType( - valueType(), - [this](auto &&t) { get>>(); } - ); - // We can't return the specific variant alternative that was just put - // in place; it depended on a run-time check. So, we return the whole - // variant, for whatever use that might have to a caller. - return variant; - } else { - // Simpler, but we do still need a get (in case the *string* is active). - get>(); - return vector; - } -} - -// non-const -std::conditional_t< - runtime, - VariantOfVectors &, - std::vector & -> get() -{ - return const_cast< - std::conditional_t< - runtime, - VariantOfVectors &, - std::vector & - > - >(std::as_const(*this).get()); -} - - - -// ----------------------------------------------------------------------------- -// 4. get(n) -// -// If DATA == void, returns a variant (by value, because the returned -// object must be made on-the-fly from our variants>). -// -// If DATA != void, returns a scalar of type [const] DATA (by reference, because -// it's available directly in our vector). -// ----------------------------------------------------------------------------- - -// ------------------------ -// const -// ------------------------ - -// get(n) -std::conditional_t< - runtime, - VariantOfScalars, - const data_t & -> get(const std::size_t n) const -{ - try { - get(); - if constexpr (runtime) { - return std::visit( - [n](auto &&alt) { return VariantOfScalars(alt[n]); }, - variant - ); - } else { - return vector[n]; - } - } catch (...) { - log::member("BodyText::get({})", n); - throw; - } -} - -// operator[](n): useful alternative form -std::conditional_t< - runtime, - VariantOfScalars, - const data_t & -> operator[](const std::size_t n) const -{ - return get(n); -} - - -// ------------------------ -// non-const -// ------------------------ - -// If DATA == void: -// Not needed, because the const versions return by value. -// -// If DATA != void: -// Meaningful, because returns are by reference in this (DATA != void) case. -// So, we'll enable non-const versions for this case only. - -// In case anyone wonders, D (not just DATA) is needed below because SFINAE -// applies when template argument *deduction* is taking place. DATA is already -// fixed, by context - we're in BodyText - and thus it isn't being -// deduced here. Templating these (otherwise non-template) functions with an -// argument that defaults to DATA, then using that argument in the SFINAE, is -// a simple trick that makes the SFINAE work as intended. As for VOID, it's -// necessary in order for the following to be unambiguous with the template -// versions of get(n) that are defined elsewhere in this file. - -// get(n) -template -std::enable_if_t && !detail::isVoid, data_t &> -get(const std::size_t n) -{ - try { - get(); - return vector[n]; - } catch (...) { - log::member("BodyText::get({})", n); - throw; - } -} - -// operator[](n) -template -std::enable_if_t, data_t &> -operator[](const std::size_t n) -{ - return get(n); -} - - - -// ----------------------------------------------------------------------------- -// 5. Type-specific "get()" functions. -// Function names reflect the types: strings(), ints(), doubles(), etc. -// These provide convenient, shorthand access to specific gets. -// ----------------------------------------------------------------------------- - -// Cases: -// vector, const -// vector, non-const -// element, const -// element, non-const - -#define GNDSTK_MAKE_GETTER(name,TYPE) \ - \ - template \ - std::enable_if_t< \ - detail::isVoid || \ - std::is_same_v, const std::vector & \ - > name() const { return get>(); } \ - \ - template \ - std::enable_if_t< \ - detail::isVoid || \ - std::is_same_v, std::vector & \ - > name() { return get>(); } \ - \ - template \ - std::enable_if_t< \ - detail::isVoid || \ - std::is_same_v, const TYPE & \ - > name(const std::size_t n) const { return get(n); } \ - \ - template \ - std::enable_if_t< \ - detail::isVoid || \ - std::is_same_v, TYPE & \ - > name(const std::size_t n) { return get(n); } - -GNDSTK_MAKE_GETTER(strings, std::string) -GNDSTK_MAKE_GETTER(chars, char) -GNDSTK_MAKE_GETTER(schars, signed char) -GNDSTK_MAKE_GETTER(shorts, short) -GNDSTK_MAKE_GETTER(ints, int) -GNDSTK_MAKE_GETTER(longs, long) -GNDSTK_MAKE_GETTER(longlongs, long long) -GNDSTK_MAKE_GETTER(uchars, unsigned char) -GNDSTK_MAKE_GETTER(ushorts, unsigned short) -GNDSTK_MAKE_GETTER(uints, unsigned int) -GNDSTK_MAKE_GETTER(ulongs, unsigned long) -GNDSTK_MAKE_GETTER(ulonglongs, unsigned long long) -GNDSTK_MAKE_GETTER(floats, float) -GNDSTK_MAKE_GETTER(doubles, double) -GNDSTK_MAKE_GETTER(longdoubles, long double) - -#undef GNDSTK_MAKE_GETTER diff --git a/src/GNDStk/BodyText/src/params.hpp b/src/GNDStk/BodyText/src/params.hpp deleted file mode 100644 index c545310f1..000000000 --- a/src/GNDStk/BodyText/src/params.hpp +++ /dev/null @@ -1,98 +0,0 @@ - -// ----------------------------------------------------------------------------- -// length, start, valueType -// We place these into a struct so our setters can use the names themselves. -// ----------------------------------------------------------------------------- - -/* -Quoted [slightly edited] from the official JSON specification files for GNDS: - - length - The total number of data values including leading and trailing zero - values that are not stored. This attribute should only be used when - the sum of start and the number of listed values do not add to the - total number of data values. This should only happen when there are - trailing zeros not listed in the body text. - - start - Default: 0 - For start = N, the first N values are zero and are not stored. - - valueType - Specifies the type of data in the body (e.g., "Integer32", "Float64"). - Only one type of data can be stored in each instance of a values node. - -In some places, e.g. the JSON-format GNDS spec files, these are listed in -a different order: valueType, start, length. Ordering doesn't really matter. -We'll just note, here, that throughout our code, we'll use the length, start, -valueType ordering, to be consistent with the (alphabetical) ordering that -our GNDS Standard Interface code autogeneration tool produces. -*/ - -private: - -// toNode() works with a conceptually const object but may update these to be -// consistent with vector data; so, mutable. -mutable struct { - // Any of these might or might not have appeared in a particular node that - // had body text. For uniformity, we have them all here, and with defaults. - std::size_t length = 0; - std::size_t start = 0; - std::string valueType = ""; -} vars; - - -// ----------------------------------------------------------------------------- -// Getters -// ----------------------------------------------------------------------------- - -public: - -// length -std::size_t length() const -{ - return vars.length; -} - -// start -std::size_t start() const -{ - return vars.start; -} - -// valueType -const std::string &valueType() const -{ - return vars.valueType; -} - - -// ----------------------------------------------------------------------------- -// Setters -// Builder pattern for all: return *this. -// Arguments of std::optional allow for more flexibility in derived classes. -// ----------------------------------------------------------------------------- - -// length -BodyText &length(const std::optional &opt) -{ - if (opt.has_value()) - vars.length = opt.value(); - return *this; -} - -// start -BodyText &start(const std::optional &opt) -{ - if (opt.has_value()) - vars.start = opt.value(); - return *this; -} - -// valueType -BodyText &valueType(const std::optional &opt) -{ - if (opt.has_value()) - vars.valueType = opt.value(); - return *this; -} diff --git a/src/GNDStk/BodyText/src/string.hpp b/src/GNDStk/BodyText/src/string.hpp deleted file mode 100644 index 6ffef6fca..000000000 --- a/src/GNDStk/BodyText/src/string.hpp +++ /dev/null @@ -1,25 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Getters and setters for the raw string -// ----------------------------------------------------------------------------- - -// getter -// string() -// Not to be confused with strings() (plural), which returns vector. -// Returns const &; the raw string can be *changed* only through the setter. -const std::string &string() const -{ - return rawstring; -} - -// setter -// string(new string) -// Builder pattern: return *this, so callers can use this function smoothly -// in conjunction with the setters for length, start, and valueType. -BodyText &string(const std::string &str) -{ - clear(); // <== the vector, because it's no longer considered meaningful - rawstring = str; - act = Active::string; - return *this; -} diff --git a/src/GNDStk/BodyText/src/sync.hpp b/src/GNDStk/BodyText/src/sync.hpp deleted file mode 100644 index 98fa02830..000000000 --- a/src/GNDStk/BodyText/src/sync.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// pullFromDerived(derived) -// Make this BodyText's length, start, and valueType be consistent with any or -// all such parameters that exist in the given object. Remember that this class, -// BodyText, is a base of Component, which is a base of some other class. -template -void pullFromDerived(const T &obj) -{ - if constexpr (detail::hasLength) - length(obj.content.length); - if constexpr (detail::hasStart) - start(obj.content.start); - if constexpr (detail::hasValueType) - valueType(obj.content.valueType); -} - -// pushToDerived(derived) -// The reverse of the above. -template -void pushToDerived(T &obj) const -{ - if constexpr (detail::hasLength) - obj.content.length = length(); - if constexpr (detail::hasStart) - obj.content.start = start(); - if constexpr (detail::hasValueType) - obj.content.valueType = valueType(); -} diff --git a/src/GNDStk/BodyText/src/toNode.hpp b/src/GNDStk/BodyText/src/toNode.hpp deleted file mode 100644 index 3f9dde5dc..000000000 --- a/src/GNDStk/BodyText/src/toNode.hpp +++ /dev/null @@ -1,93 +0,0 @@ - -// ----------------------------------------------------------------------------- -// BodyText::toNode -// This is called by Component's conversion-to-Node (not toNode()) function. -// It's "toNode()" here, not a conversion, because we're simply writing text -// that Component's full conversion-to-Node will place into the Node itself. -// ----------------------------------------------------------------------------- - -// Use either (1) the original raw string, or (2) the variant of vectors or the -// vector (depending on DATA ==/!= void), based on whether or not the string -// is active. length, start, and valueType might be computed too, in which case -// they're also changed in the derived class in order to keep things consistent. -template -void toNode(std::string &text, DERIVED &derived) const -{ - // Use the raw string? - if (active() == Active::string) { - text = rawstring; - return; - } - - // Use the vector... - const bool isStringVector = - ( runtime && std::holds_alternative>(variant)) || - (!runtime && std::is_same_v); - - if constexpr ( - runtime || - (!runtime && std::is_same_v) - ) { - // the run-time if's get() calls below won't - // necessarily make sense without the above if-constexpr - if (isStringVector && !trim && - // only bother with the warning if trim would make a difference... - size() > 0 && - (get(0) == "" || get(size()-1) == "") - ) { - log::warning( - "BodyText.toNode() called with BodyText " - "trim flag == false, but active\n" - "data are in a vector. Printing " - "leading/trailing empty strings\n" - "won't preserve them, so we'll treat as if trim == true." - ); - } - } - - // Re: leading/trailing 0s - const auto bounds = - trim || isStringVector - ? runtime - ? std::visit([](auto &&vec) { return detail::getBounds(vec); }, variant) - : detail::getBounds(vector) - : std::make_pair(size_t(0),size()); - - // Compute length, start, and valueType - vars.length = size(); // independent of trim - vars.start = bounds.first; // dependent on trim, per the bounds computation - if constexpr (runtime) - vars.valueType = detail::visitMapTypeString(variant); - else - vars.valueType = detail::MapTypeString::value[0]; - pushToDerived(derived); - - // Values - std::ostringstream oss; - - const auto toNodeLambda = - [bounds,&oss](auto &&vec) - { - using T = std::decay_t; - std::size_t count = 0; - - for (auto i = bounds.first; i < bounds.second; ++i) { - oss << (count++ ? " " : ""); - if constexpr (std::is_floating_point_v) { - oss << detail::Precision< - detail::PrecisionContext::data, - T - >{}.write(vec[i]); - } else { - oss << vec[i]; - } - } - }; - - if constexpr (runtime) - std::visit(toNodeLambda,variant); - else - toNodeLambda(vector); - - text = oss.str(); -} diff --git a/src/GNDStk/BodyText/src/write.hpp b/src/GNDStk/BodyText/src/write.hpp deleted file mode 100644 index 98dbb4a64..000000000 --- a/src/GNDStk/BodyText/src/write.hpp +++ /dev/null @@ -1,72 +0,0 @@ - -// ----------------------------------------------------------------------------- -// write -// To an ostream (not to a Node; that a different thing) -// ----------------------------------------------------------------------------- - -std::ostream &write(std::ostream &os, const int level) const -{ - // If empty, don't even write a newline - if ((active() == Active::string && rawstring == "") || - (active() == Active::vector && size() == 0)) - return os; - - // ------------------------ - // If string is active - // ------------------------ - - if (active() == Active::string) { - // write the string exactly as-is, without our column formatting - // or any indentation; then also write a newline - GNDStk::color && GNDStk::colors::value != "" - ? os << colors::value << rawstring << colors::reset - : os << rawstring; - return os << std::endl; - } - - // ------------------------ - // If vector is active - // ------------------------ - - // Indentation (string, with some number of spaces) - const auto indent = std::string(GNDStk::indent*level,' '); - - const auto writeLambda = - [&os,&indent](auto &&alt) - { - std::size_t count = 0; - using T = std::decay_t; - - // use our column formatting - for (auto &element : alt) { - count == 0 - ? os << indent - : GNDStk::across == 0 || count % GNDStk::across != 0 - ? os << ' ' - : os << '\n' << indent; - - if (GNDStk::color && GNDStk::colors::value != "") - os << colors::value; - - if constexpr (std::is_floating_point_v) - os << detail::Precision< - detail::PrecisionContext::data, - T - >{}.write(element); - else - os << element; - - if (GNDStk::color && GNDStk::colors::value != "") - os << colors::reset; - - count++; - }; - }; - - if constexpr (runtime) - std::visit(writeLambda,variant); - else - writeLambda(vector); - - return os << std::endl; -} diff --git a/src/GNDStk/BodyText/test/BodyText.test.cpp b/src/GNDStk/BodyText/test/BodyText.test.cpp deleted file mode 100644 index 09cb28cc8..000000000 --- a/src/GNDStk/BodyText/test/BodyText.test.cpp +++ /dev/null @@ -1,192 +0,0 @@ - -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - -// ----------------------------------------------------------------------------- -// Scenario for DATA == void -// ----------------------------------------------------------------------------- - -SCENARIO("Testing GNDStk BodyText with DATA == void") { - // Most BodyText functionality is tested in the individual test files. - // There are just a few things we'll do here. - - // Ensure that we can make const and non-const and BodyText - // objects. Note that BodyText has only a default constructor. - - GIVEN("A const BodyText cbtextt") { - const BodyText cbtextt; - THEN("It constructed correctly, and its data are as expected") { - CHECK(cbtextt.length () == 0); - CHECK(cbtextt.size () == 0); - CHECK(cbtextt.valueType() == ""); - CHECK(cbtextt.string () == ""); - } - } - - GIVEN("A const BodyText cbtextf") { - const BodyText cbtextf; - THEN("It constructed correctly") { - // no data for - } - } - - GIVEN("A non-const BodyText nbtextt") { - BodyText nbtextt; - THEN("It constructed correctly, and its data are as expected") { - CHECK(nbtextt.length () == 0); - CHECK(nbtextt.size () == 0); - CHECK(nbtextt.valueType() == ""); - CHECK(nbtextt.string () == ""); - } - } - - GIVEN("A non-const BodyText nbtextf") { - BodyText nbtextf; - THEN("It constructed correctly") { - // no data for - } - } - - // clear() and size() are defined (at the time of this writing) in the - // BodyText.hpp file itself, so we'll test them here. size() actually - // was used in various tests, and thus was indirectly tested elsewhere. - - GIVEN("A BodyText") { - // clear - WHEN("We test clear()") { - BodyText b; - - // try int - THEN("size() works correctly for vector") { - b = std::vector{1,2,3,4,5}; - CHECK(b.size() == 5); - b.clear(); - CHECK(b.size() == 0); - } - - // try double - THEN("size() works correctly for vector") { - b = std::vector{1.1, 2.2, 3.3, 4.4, 5.5}; - CHECK(b.size() == 5); - b.clear(); - CHECK(b.size() == 0); - } - - // try string - THEN("size() works correctly for vector") { - b = std::vector{"one","two","three","four","five"}; - CHECK(b.size() == 5); - b.clear(); - CHECK(b.size() == 0); - } - } - - // size - WHEN("We test size()") { - BodyText b; - - // try int - THEN("size() works correctly for vector") { - b = std::vector{1,2,3,4,5}; - CHECK(b.size() == 5); - b = std::vector{1}; - CHECK(b.size() == 1); - b = std::vector{}; - CHECK(b.size() == 0); - } - - // try double - THEN("size() works correctly for vector") { - b = std::vector{1.1, 2.2, 3.3, 4.4, 5.5}; - CHECK(b.size() == 5); - b = std::vector{1.1}; - CHECK(b.size() == 1); - b = std::vector{}; - CHECK(b.size() == 0); - } - - // try string - THEN("size() works correctly for vector") { - b = std::vector{"one","two","three","four","five"}; - CHECK(b.size() == 5); - b = std::vector{"one"}; - CHECK(b.size() == 1); - b = std::vector{}; - CHECK(b.size() == 0); - } - } - } -} // SCENARIO - - -// ----------------------------------------------------------------------------- -// Scenario for DATA != void -// ----------------------------------------------------------------------------- - -SCENARIO("Testing GNDStk BodyText with DATA != void") { - - GIVEN("A const BodyText cbtextt") { - const BodyText cbtextt; - THEN("It constructed correctly, and its data are as expected") { - CHECK(cbtextt.length () == 0); - CHECK(cbtextt.size () == 0); - CHECK(cbtextt.valueType() == ""); - CHECK(cbtextt.string () == ""); - } - } - - GIVEN("A const BodyText cbtextf") { - const BodyText cbtextf; - THEN("It constructed correctly") { - // no data for - } - } - - GIVEN("A non-const BodyText nbtextt") { - BodyText nbtextt; - THEN("It constructed correctly, and its data are as expected") { - CHECK(nbtextt.length () == 0); - CHECK(nbtextt.size () == 0); - CHECK(nbtextt.valueType() == ""); - CHECK(nbtextt.string () == ""); - } - } - - GIVEN("A non-const BodyText nbtextf") { - BodyText nbtextf; - THEN("It constructed correctly") { - // no data for - } - } - - GIVEN("A BodyText") { - // clear - WHEN("We test clear()") { - BodyText b; - THEN("size() works correctly") { - b = std::vector{1,2,3,4,5}; - CHECK(b.size() == 5); - b.clear(); - CHECK(b.size() == 0); - } - } - - // size - WHEN("We test size()") { - BodyText b; - THEN("size() works correctly") { - b = std::vector{"one","two","three","four","five"}; - CHECK(b.size() == 5); - b = std::vector{"one"}; - CHECK(b.size() == 1); - b = std::vector{}; - CHECK(b.size() == 0); - } - } - } -} // SCENARIO diff --git a/src/GNDStk/BodyText/test/CMakeLists.txt b/src/GNDStk/BodyText/test/CMakeLists.txt deleted file mode 100644 index 37cdf9076..000000000 --- a/src/GNDStk/BodyText/test/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ - -add_executable( GNDStk.BodyText.test - BodyText.test.cpp - assign.test.cpp - detail.test.cpp - fromNode.test.cpp - get.test.cpp - params.test.cpp - string.test.cpp - sync.test.cpp - toNode.test.cpp - types.test.cpp - write.test.cpp ) -target_compile_options( GNDStk.BodyText.test PRIVATE ${${PREFIX}_common_flags} -$<$:${${PREFIX}_strict_flags}>$<$: -${${PREFIX}_DEBUG_flags} -$<$:${${PREFIX}_coverage_flags}>> -$<$: -${${PREFIX}_RELEASE_flags} -$<$:${${PREFIX}_link_time_optimization_flags}> -$<$:${${PREFIX}_nonportable_optimization_flags}>> - -${CXX_appended_flags} ${GNDStk_appended_flags} ) -target_link_libraries( GNDStk.BodyText.test PUBLIC GNDStk ) -add_test( NAME GNDStk.BodyText COMMAND GNDStk.BodyText.test ) diff --git a/src/GNDStk/BodyText/test/detail.test.cpp b/src/GNDStk/BodyText/test/detail.test.cpp deleted file mode 100644 index 5083a4f2e..000000000 --- a/src/GNDStk/BodyText/test/detail.test.cpp +++ /dev/null @@ -1,421 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; -inline std::string bar = "bar"; - -// ----------------------------------------------------------------------------- -// Scenario -// ----------------------------------------------------------------------------- - -SCENARIO("Testing various BodyText-related detail:: constructs") { - - // ------------------------ - // scalarize - // ------------------------ - - GIVEN("Some variants of vectors") { - using vc = std::variant< - std::vector - >; - using vci = std::variant< - std::vector, - std::vector - >; - using vcid = std::variant< - std::vector, - std::vector, - std::vector - >; - - // Double parenthesis are needed for the CHECK macro, - // because of the commas... - THEN("detail::scalarize() works correctly") { - CHECK(( - std::is_same_v< - decltype(detail::scalarize(vc{})), - std::variant - > - )); - CHECK(( - std::is_same_v< - decltype(detail::scalarize(vci{})), - std::variant - > - )); - CHECK(( - std::is_same_v< - decltype(detail::scalarize(vcid{})), - std::variant - > - )); - } - } // GIVEN - - - // ------------------------ - // decays - // ------------------------ - - GIVEN("Testing detail::decays") { - using tup1 = std::tuple<>; - using tup2 = std::tuple; - using tup3 = std::tuple; - using tup4 = std::tuple; - using tup5 = std::tuple; - - CHECK((std::is_same_v, std::tuple<>>)); - CHECK((std::is_same_v, std::tuple>)); - CHECK((std::is_same_v, std::tuple>)); - CHECK((std::is_same_v, std::tuple>)); - CHECK((std::is_same_v, std::tuple>)); - } // GIVEN - - - // ------------------------ - // hasLength, hasStart, - // hasValueType - // ------------------------ - - GIVEN("Testing detail::hasLength, hasStart, and hasValueType") { - WHEN("A struct's content has length, start, and valueType") { - struct { - struct { - int length; - const double start = 0; - const std::string &valueType = bar; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == true)); - CHECK((detail::hasStart == true)); - CHECK((detail::hasValueType == true)); - } - } - - WHEN("A struct's content has start and valueType") { - struct { - struct { - const double start = 0; - const std::string &valueType = bar; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == false)); - CHECK((detail::hasStart == true)); - CHECK((detail::hasValueType == true)); - } - } - - WHEN("A struct's content has length and valueType") { - struct { - struct { - int length; - const std::string &valueType = bar; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == true)); - CHECK((detail::hasStart == false)); - CHECK((detail::hasValueType == true)); - } - } - - WHEN("A struct's content has length and start") { - struct { - struct { - int length; - const double start = 0; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == true)); - CHECK((detail::hasStart == true)); - CHECK((detail::hasValueType == false)); - } - } - - WHEN("A struct's content has length") { - struct { - struct { - int length; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == true)); - CHECK((detail::hasStart == false)); - CHECK((detail::hasValueType == false)); - } - } - - WHEN("A struct's content has start") { - struct { - struct { - const double start = 0; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == false)); - CHECK((detail::hasStart == true)); - CHECK((detail::hasValueType == false)); - } - } - - WHEN("A struct's content has valueType") { - struct { - struct { - const std::string &valueType = bar; - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == false)); - CHECK((detail::hasStart == false)); - CHECK((detail::hasValueType == true)); - } - } - - WHEN("A struct's content has none of length, start, or valueType") { - struct { - struct { - } content; - } foo; - THEN("Our SFINAE helpers detect this") { - CHECK((detail::hasLength == false)); - CHECK((detail::hasStart == false)); - CHECK((detail::hasValueType == false)); - } - } - } // GIVEN - - - // ------------------------ - // element2element - // ------------------------ - - GIVEN("Testing detail::element2element") { - WHEN("We use element2element(from int, to string)") { - const int from = 123; - std::string to; - detail::element2element(from,to); - CHECK(to == "123"); - } - - WHEN("We use element2element(from double, to string)") { - const double from = 4.56; - std::string to; - detail::element2element(from,to); - CHECK(to == "4.56"); - } - - WHEN("We use element2element(from string, to int)") { - const std::string from = "987"; - int to; - detail::element2element(from,to); - CHECK(to == 987); - } - - WHEN("We use element2element(from string, to double)") { - const std::string from = "6.54"; - double to; - detail::element2element(from,to); - CHECK(Approx(to) == 6.54); - } - - WHEN("We use element2element(from int, to double)") { - const int from = 345; - double to; - detail::element2element(from,to); - CHECK(to == double(345)); - } - - WHEN("We use element2element(from double, to int)") { - const double from = 6.78; - int to; - detail::element2element(from,to); - CHECK(to == 6); - } - } - - - // ------------------------ - // getBounds - // ------------------------ - - GIVEN("Testing detail::getBounds") { - - // ------------------------ - // Various vectors - // ------------------------ - - WHEN("We try vectors of varying sizes") { - - THEN("Bounds are correct when size == 0") { - std::vector v = {}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 0); - } - - THEN("Bounds are correct when size == 1, with a 0") { - std::vector v = {0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 1); - CHECK(bounds.second == 1); - } - - THEN("Bounds are correct when size == 2, all 0") { - std::vector v = {0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 2); - } - - THEN("Bounds are correct when size == 3, all non-0") { - std::vector v = {2, 3, 5}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 3); - } - - THEN("Bounds are correct when there are trailing 0s") { - std::vector v = {2, 3, 5, 0, 0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 3); - } - - THEN("Bounds are correct when there are leading 0s") { - std::vector v = {0, 0, 2, 3, 5}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 5); - } - - THEN("Bounds are correct when there are leading and trailing 0s") { - std::vector v = {0, 0, 2, 3, 5, 0, 0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 5); - } - - } // WHEN - - - // ------------------------ - // Various vectors - // ------------------------ - - WHEN("We try vectors of varying sizes") { - - THEN("Bounds are correct when size == 0") { - std::vector v = {}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 0); - } - - THEN("Bounds are correct when size == 1, with a 0") { - std::vector v = {0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 1); - CHECK(bounds.second == 1); - } - - THEN("Bounds are correct when size == 3, all 0") { - std::vector v = {0, 0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 3); - CHECK(bounds.second == 3); - } - - THEN("Bounds are correct when size == 3, all non-0") { - std::vector v = {1.2, 3.4, 5.6}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 3); - } - - THEN("Bounds are correct when there are trailing 0s") { - std::vector v = {1.2, 3.4, 5.6, 0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 3); - } - - THEN("Bounds are correct when there are leading 0s") { - std::vector v = {0, 0, 0, 1.2, 3.4, 5.6}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 3); - CHECK(bounds.second == 6); - } - - THEN("Bounds are correct when there are leading and trailing 0s") { - std::vector v = {0, 0, 0, 1.2, 3.4, 5.6, 0, 0}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 3); - CHECK(bounds.second == 6); - } - - } - - - // ------------------------ - // Various vectors - // ------------------------ - - WHEN("We try vectors of varying sizes") { - - THEN("Bounds are correct when size == \"\"") { - std::vector v = {}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 0); - } - - THEN("Bounds are correct when size == 1, with a \"\"") { - std::vector v = {""}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 1); - CHECK(bounds.second == 1); - } - - THEN("Bounds are correct when size == 2, all \"\"") { - std::vector v = {"", ""}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 2); - } - - THEN("Bounds are correct when size == 2, all non-\"\"") { - std::vector v = {"abc", "def"}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 2); - } - - THEN("Bounds are correct when there are trailing \"\"s") { - std::vector v = {"abc", "def", "", "", ""}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 0); - CHECK(bounds.second == 2); - } - - THEN("Bounds are correct when there are leading \"\"s") { - std::vector v = {"", "", "abc", "def"}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 4); - } - - THEN("Bounds are correct when there are leading and trailing \"\"s") { - std::vector v = {"", "", "abc", "def", "", "", ""}; - const auto bounds = detail::getBounds(v); - CHECK(bounds.first == 2); - CHECK(bounds.second == 4); - } - - } // WHEN - } // GIVEN - -} // SCENARIO diff --git a/src/GNDStk/BodyText/test/fromNode.test.cpp b/src/GNDStk/BodyText/test/fromNode.test.cpp deleted file mode 100644 index 25e6c5059..000000000 --- a/src/GNDStk/BodyText/test/fromNode.test.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - -// ----------------------------------------------------------------------------- -// Scenario for DATA == void -// ----------------------------------------------------------------------------- - -SCENARIO("BodyText fromNode()") { - - GIVEN("A Node with no \"body text\"") { - WHEN("BodyText.fromNode(the node) is called") { - THEN("The BodyText's raw string is \"\", as expected") { - BodyText b; - b.string("This string should be replaced"); - CHECK(b.string() != ""); - - Node node; - node << ""; - b.fromNode(node); - CHECK(b.string() == ""); - } - } - } - - GIVEN("A Node with some \"body text\"") { - WHEN("BodyText.fromNode(the node) is called") { - THEN("The BodyText's raw string equals the text from the Node") { - BodyText b; - b.string("This string should be replaced"); - CHECK(b.string() != ""); - - Node node; - - node << "some plain character data"; - b.fromNode(node); - CHECK(b.string() == "some plain character data"); - - // it shouldn't matter, but leading spaces are preserved - node << " pcdata with leading spaces"; - b.fromNode(node); - CHECK(b.string() == " pcdata with leading spaces"); - - // ditto for trailing spaces - node << "pcdata with trailing spaces "; - b.fromNode(node); - CHECK(b.string() == "pcdata with trailing spaces "); - - // ditto for both together - node << " pcdata "; - b.fromNode(node); - CHECK(b.string() == " pcdata "); - } - } - } - -} // SCENARIO - - -// ----------------------------------------------------------------------------- -// Scenario for DATA != void -// ----------------------------------------------------------------------------- - -SCENARIO("BodyText fromNode()") { - - GIVEN("A Node with no \"body text\"") { - WHEN("BodyText.fromNode(the node) is called") { - THEN("The BodyText's raw string is \"\", as expected") { - BodyText b; - b.string("This string should be replaced"); - CHECK(b.string() != ""); - - Node node; - node << ""; - b.fromNode(node); - CHECK(b.string() == ""); - } - } - } - - GIVEN("A Node with some \"body text\"") { - WHEN("BodyText.fromNode(the node) is called") { - THEN("The BodyText's raw string equals the text from the Node") { - BodyText b; - b.string("This string should be replaced"); - CHECK(b.string() != ""); - - Node node; - - node << "some plain character data"; - b.fromNode(node); - CHECK(b.string() == "some plain character data"); - - // it shouldn't matter, but leading spaces are preserved - node << " pcdata with leading spaces"; - b.fromNode(node); - CHECK(b.string() == " pcdata with leading spaces"); - - // ditto for trailing spaces - node << "pcdata with trailing spaces "; - b.fromNode(node); - CHECK(b.string() == "pcdata with trailing spaces "); - - // ditto for both together - node << " pcdata "; - b.fromNode(node); - CHECK(b.string() == " pcdata "); - } - } - } - -} // SCENARIO diff --git a/src/GNDStk/BodyText/test/get.test.cpp b/src/GNDStk/BodyText/test/get.test.cpp deleted file mode 100644 index 4179ce9af..000000000 --- a/src/GNDStk/BodyText/test/get.test.cpp +++ /dev/null @@ -1,693 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// 1. Scenario: get() -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_get_vector() -{ - // We'll deal with these vector types for the test. They should cover - // sufficient cases (int, double, string, and none of the above) - // that we get good coverage, without this test being excessively long. - using ivec = std::vector; - using fvec = std::vector; - using svec = std::vector; - using uvec = std::vector; - - // We'll leave valueType at its default of "", which is compatible with - // every possible get type T. This simply means we won't get spammed - // with warnings about the asked-for T possibly being incompatible with - // valueType. Either way - with or without a "" for valueType - get - // gives us back a vector. - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); - CHECK((b.template get() == ivec{})); } - { BodyText b; b.start(0).length(4).string(""); - CHECK((b.template get() == ivec{{0,0,0,0}})); } - { BodyText b; b.start(1).length(5).string(""); - CHECK((b.template get() == ivec{{0,0,0,0,0}})); } - { BodyText b; b.start(2).length(6).string(""); - CHECK((b.template get() == ivec{{0,0,0,0,0,0}})); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("-12"); - CHECK((b.template get() == ivec(1,-12))); } - { BodyText b; b.start(0).length(4).string("-12"); - CHECK((b.template get() == ivec{{-12,0,0,0}})); } - { BodyText b; b.start(1).length(5).string("-12"); - CHECK((b.template get() == ivec{{0,-12,0,0,0}})); } - { BodyText b; b.start(2).length(6).string("-12"); - CHECK((b.template get() == ivec{{0,0,-12,0,0,0}})); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("-12 34 -56"); - CHECK((b.template get() == ivec{{-12,34,-56}})); } - { BodyText b; b.start(0).length(4).string("-12 34 -56"); - CHECK((b.template get() == ivec{{-12,34,-56,0}})); } - { BodyText b; b.start(1).length(5).string("-12 34 -56"); - CHECK((b.template get() == ivec{{0,-12,34,-56,0}})); } - { BodyText b; b.start(2).length(6).string("-12 34 -56"); - CHECK((b.template get() == ivec{{0,0,-12,34,-56,0}})); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); - CHECK((b.template get() == fvec{})); } - { BodyText b; b.start(0).length(4).string(""); - CHECK((b.template get() == fvec{{0,0,0,0}})); } - { BodyText b; b.start(1).length(5).string(""); - CHECK((b.template get() == fvec{{0,0,0,0,0}})); } - { BodyText b; b.start(2).length(6).string(""); - CHECK((b.template get() == fvec{{0,0,0,0,0,0}})); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("1.2"); - CHECK((b.template get() == fvec(1,1.2))); } - { BodyText b; b.start(0).length(4).string("1.2"); - CHECK((b.template get() == fvec{{1.2,0,0,0}})); } - { BodyText b; b.start(1).length(5).string("1.2"); - CHECK((b.template get() == fvec{{0,1.2,0,0,0}})); } - { BodyText b; b.start(2).length(6).string("1.2"); - CHECK((b.template get() == fvec{{0,0,1.2,0,0,0}})); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("1.2 3.4 5.6"); - CHECK((b.template get() == fvec{{1.2,3.4,5.6}})); } - { BodyText b; b.start(0).length(4).string("1.2 3.4 5.6"); - CHECK((b.template get() == fvec{{1.2,3.4,5.6,0}})); } - { BodyText b; b.start(1).length(5).string("1.2 3.4 5.6"); - CHECK((b.template get() == fvec{{0,1.2,3.4,5.6,0}})); } - { BodyText b; b.start(2).length(6).string("1.2 3.4 5.6"); - CHECK((b.template get() == fvec{{0,0,1.2,3.4,5.6,0}})); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); - CHECK((b.template get() == svec{})); } - { BodyText b; b.start(0).length(4).string(""); - CHECK((b.template get() == svec{{"","","",""}})); } - { BodyText b; b.start(1).length(5).string(""); - CHECK((b.template get() == svec{{"","","","",""}})); } - { BodyText b; b.start(2).length(6).string(""); - CHECK((b.template get() == svec{{"","","","","",""}})); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("ab"); - CHECK((b.template get() == svec(1,"ab"))); } - { BodyText b; b.start(0).length(4).string("ab"); - CHECK((b.template get() == svec{{"ab","","",""}})); } - { BodyText b; b.start(1).length(5).string("ab"); - CHECK((b.template get() == svec{{"","ab","","",""}})); } - { BodyText b; b.start(2).length(6).string("ab"); - CHECK((b.template get() == svec{{"","","ab","","",""}})); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("ab cd ef"); - CHECK((b.template get() == svec{{"ab","cd","ef"}})); } - { BodyText b; b.start(0).length(4).string("ab cd ef"); - CHECK((b.template get() == svec{{"ab","cd","ef",""}})); } - { BodyText b; b.start(1).length(5).string("ab cd ef"); - CHECK((b.template get() == svec{{"","ab","cd","ef",""}})); } - { BodyText b; b.start(2).length(6).string("ab cd ef"); - CHECK((b.template get() == svec{{"","","ab","cd","ef",""}})); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); - CHECK((b.template get() == uvec{})); } - { BodyText b; b.start(0).length(4).string(""); - CHECK((b.template get() == uvec{{0,0,0,0}})); } - { BodyText b; b.start(1).length(5).string(""); - CHECK((b.template get() == uvec{{0,0,0,0,0}})); } - { BodyText b; b.start(2).length(6).string(""); - CHECK((b.template get() == uvec{{0,0,0,0,0,0}})); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("12"); - CHECK((b.template get() == uvec(1,12))); } - { BodyText b; b.start(0).length(4).string("12"); - CHECK((b.template get() == uvec{{12,0,0,0}})); } - { BodyText b; b.start(1).length(5).string("12"); - CHECK((b.template get() == uvec{{0,12,0,0,0}})); } - { BodyText b; b.start(2).length(6).string("12"); - CHECK((b.template get() == uvec{{0,0,12,0,0,0}})); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("12 34 56"); - CHECK((b.template get() == uvec{{12,34,56}})); } - { BodyText b; b.start(0).length(4).string("12 34 56"); - CHECK((b.template get() == uvec{{12,34,56,0}})); } - { BodyText b; b.start(1).length(5).string("12 34 56"); - CHECK((b.template get() == uvec{{0,12,34,56,0}})); } - { BodyText b; b.start(2).length(6).string("12 34 56"); - CHECK((b.template get() == uvec{{0,0,12,34,56,0}})); } -} - -// For BodyText -SCENARIO("BodyText get()") { - GIVEN("A BodyText object") { - scenario_get_vector(); - } -} - -// For BodyText -SCENARIO("BodyText get()") { - GIVEN("A BodyText object") { - scenario_get_vector(); - } -} - - - -// ----------------------------------------------------------------------------- -// 2. Scenario: get(n) -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_get_template_n() -{ - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); /* no elements */ } - { BodyText b; b.start(0).length(4).string(""); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string(""); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string(""); - CHECK(b.template get(3) == 0); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("-12"); - CHECK(b.template get(0) == -12); } - { BodyText b; b.start(0).length(4).string("-12"); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string("-12"); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string("-12"); - CHECK(b.template get(3) == 0); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("-12 34 -56"); - CHECK(b.template get(0) == -12); } - { BodyText b; b.start(0).length(4).string("-12 34 -56"); - CHECK(b.template get(1) == 34); } - { BodyText b; b.start(1).length(5).string("-12 34 -56"); - CHECK(b.template get(2) == 34); } - { BodyText b; b.start(2).length(6).string("-12 34 -56"); - CHECK(b.template get(3) == 34); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); /* no elements */ } - { BodyText b; b.start(0).length(4).string(""); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string(""); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string(""); - CHECK(b.template get(3) == 0); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("1.2"); - CHECK(b.template get(0) == 1.2); } - { BodyText b; b.start(0).length(4).string("1.2"); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string("1.2"); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string("1.2"); - CHECK(b.template get(3) == 0); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("1.2 3.4 5.6"); - CHECK(b.template get(0) == 1.2); } - { BodyText b; b.start(0).length(4).string("1.2 3.4 5.6"); - CHECK(b.template get(1) == 3.4); } - { BodyText b; b.start(1).length(5).string("1.2 3.4 5.6"); - CHECK(b.template get(2) == 3.4); } - { BodyText b; b.start(2).length(6).string("1.2 3.4 5.6"); - CHECK(b.template get(3) == 3.4); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); /* no elements */ } - { BodyText b; b.start(0).length(4).string(""); - CHECK(b.template get(1) == ""); } - { BodyText b; b.start(1).length(5).string(""); - CHECK(b.template get(2) == ""); } - { BodyText b; b.start(2).length(6).string(""); - CHECK(b.template get(3) == ""); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("ab"); - CHECK(b.template get(0) == "ab"); } - { BodyText b; b.start(0).length(4).string("ab"); - CHECK(b.template get(1) == ""); } - { BodyText b; b.start(1).length(5).string("ab"); - CHECK(b.template get(2) == ""); } - { BodyText b; b.start(2).length(6).string("ab"); - CHECK(b.template get(3) == ""); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("ab cd ef"); - CHECK(b.template get(0) == "ab"); } - { BodyText b; b.start(0).length(4).string("ab cd ef"); - CHECK(b.template get(1) == "cd"); } - { BodyText b; b.start(1).length(5).string("ab cd ef"); - CHECK(b.template get(2) == "cd"); } - { BodyText b; b.start(2).length(6).string("ab cd ef"); - CHECK(b.template get(3) == "cd"); } - - // ------------------------ - // vector - // ------------------------ - - // 0 elements in string - { BodyText b; b.start(0).length(0).string(""); /* no elements */ } - { BodyText b; b.start(0).length(4).string(""); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string(""); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string(""); - CHECK(b.template get(3) == 0); } - - // 1 element in string - { BodyText b; b.start(0).length(0).string("12"); - CHECK(b.template get(0) == 12); } - { BodyText b; b.start(0).length(4).string("12"); - CHECK(b.template get(1) == 0); } - { BodyText b; b.start(1).length(5).string("12"); - CHECK(b.template get(2) == 0); } - { BodyText b; b.start(2).length(6).string("12"); - CHECK(b.template get(3) == 0); } - - // 3 elements in string - { BodyText b; b.start(0).length(0).string("12 34 56"); - CHECK(b.template get(0) == 12); } - { BodyText b; b.start(0).length(4).string("12 34 56"); - CHECK(b.template get(1) == 34); } - { BodyText b; b.start(1).length(5).string("12 34 56"); - CHECK(b.template get(2) == 34); } - { BodyText b; b.start(2).length(6).string("12 34 56"); - CHECK(b.template get(3) == 34); } -} - -// For BodyText -SCENARIO("BodyText get(n)") { - GIVEN("A BodyText object") { - scenario_get_template_n(); - } -} - -// For BodyText -SCENARIO("BodyText get(n)") { - GIVEN("A BodyText object") { - scenario_get_template_n(); - } -} - - - -// ----------------------------------------------------------------------------- -// 3. Scenario: get() -// ----------------------------------------------------------------------------- - -// For BodyText -SCENARIO("BodyText get()") { - GIVEN("A BodyText object") { - - using ivec = std::vector; - using fvec = std::vector; - using svec = std::vector; - - BodyText b; - - b.start(2).length(6).string("-12 34 -56"); - b.valueType("Integer32"); - CHECK(( std::holds_alternative(b.get()))); - CHECK((!std::holds_alternative(b.get()))); - CHECK((!std::holds_alternative(b.get()))); - CHECK((std::get(b.get()) == ivec{{0,0,-12,34,-56,0}})); - - b.start(2).length(6).string("1.2 3.4 5.6"); - b.valueType("Float64"); - CHECK((!std::holds_alternative(b.get()))); - CHECK(( std::holds_alternative(b.get()))); - CHECK((!std::holds_alternative(b.get()))); - CHECK((std::get(b.get()) == fvec{{0,0,1.2,3.4,5.6,0}})); - - b.start(2).length(6).string("ab cd ef"); - b.valueType(""); - CHECK((!std::holds_alternative(b.get()))); - CHECK((!std::holds_alternative(b.get()))); - CHECK(( std::holds_alternative(b.get()))); - CHECK((std::get(b.get()) == svec{{"","","ab","cd","ef",""}})); - - } // GIVEN -} // SCENARIO - - -// For BodyText -SCENARIO("BodyText get()") { - GIVEN("A BodyText object") { - - using ivec = std::vector; - using fvec = std::vector; - using svec = std::vector; - - { - BodyText b; - b.start(2).length(6).string("-12 34 -56"); - CHECK((b.get() == ivec{{0,0,-12,34,-56,0}})); - } - - { - BodyText b; - b.start(2).length(6).string("1.2 3.4 5.6"); - CHECK((b.get() == fvec{{0,0,1.2,3.4,5.6,0}})); - } - - { - BodyText b; - b.start(2).length(6).string("ab cd ef"); - CHECK((b.get() == svec{{"","","ab","cd","ef",""}})); - } - - } // GIVEN -} // SCENARIO - - - -// ----------------------------------------------------------------------------- -// 4. Scenario: get(n) -// ----------------------------------------------------------------------------- - -// For BodyText -SCENARIO("BodyText get(n)") { - GIVEN("A BodyText object") { - - BodyText b; - - // ------------------------ - // get(n) form - // ------------------------ - - b.start(2).length(6).string("-12 34 -56"); - b.valueType("Integer32"); - CHECK(( std::holds_alternative(b.get(0)))); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK(( std::get( b.get(0) ) == 0 )); - CHECK(( std::get( b.get(1) ) == 0 )); - CHECK(( std::get( b.get(2) ) == -12 )); - CHECK(( std::get( b.get(3) ) == 34 )); - CHECK(( std::get( b.get(4) ) == -56 )); - CHECK(( std::get( b.get(5) ) == 0 )); - // test type changes (inefficient, but they work)... - CHECK(b.get(2) == -12); - CHECK(b.get(3) == double(34)); - CHECK(b.get(4) == "-56"); - - b.start(2).length(6).string("1.2 3.4 5.6"); - b.valueType("Float64"); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK(( std::holds_alternative(b.get(0)))); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK(( std::get( b.get(0) ) == 0 )); - CHECK(( std::get( b.get(1) ) == 0 )); - CHECK(( std::get( b.get(2) ) == 1.2 )); - CHECK(( std::get( b.get(3) ) == 3.4 )); - CHECK(( std::get( b.get(4) ) == 5.6 )); - CHECK(( std::get( b.get(5) ) == 0 )); - // test type changes... - CHECK(b.get(2) == 1); // truncated from 1.2 - // having converted to vector, the .#s aren't there any longer... - CHECK(b.get(2) == "1"); - CHECK(b.get(3) == 3); - CHECK(b.get(4) == "5"); - - b.start(2).length(8).string("ab cd ef 123 4.5"); - b.valueType(""); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK((!std::holds_alternative(b.get(0)))); - CHECK(( std::holds_alternative(b.get(0)))); - CHECK(( std::get( b.get(0) ) == "" )); - CHECK(( std::get( b.get(1) ) == "" )); - CHECK(( std::get( b.get(2) ) == "ab" )); - CHECK(( std::get( b.get(3) ) == "cd" )); - CHECK(( std::get( b.get(4) ) == "ef" )); - CHECK(( std::get( b.get(5) ) == "123")); - CHECK(( std::get( b.get(6) ) == "4.5")); - CHECK(( std::get( b.get(7) ) == "" )); - - // ------------------------ - // operator[] form - // ------------------------ - - b.start(2).length(6).string("-12 34 -56"); - b.valueType("Integer32"); - CHECK(( std::holds_alternative(b[0]))); - CHECK((!std::holds_alternative(b[0]))); - CHECK((!std::holds_alternative(b[0]))); - CHECK(( std::get( b[0] ) == 0 )); - CHECK(( std::get( b[1] ) == 0 )); - CHECK(( std::get( b[2] ) == -12 )); - CHECK(( std::get( b[3] ) == 34 )); - CHECK(( std::get( b[4] ) == -56 )); - CHECK(( std::get( b[5] ) == 0 )); - - b.start(2).length(6).string("1.2 3.4 5.6"); - b.valueType("Float64"); - CHECK((!std::holds_alternative(b[0]))); - CHECK(( std::holds_alternative(b[0]))); - CHECK((!std::holds_alternative(b[0]))); - CHECK(( std::get( b[0] ) == 0 )); - CHECK(( std::get( b[1] ) == 0 )); - CHECK(( std::get( b[2] ) == 1.2 )); - CHECK(( std::get( b[3] ) == 3.4 )); - CHECK(( std::get( b[4] ) == 5.6 )); - CHECK(( std::get( b[5] ) == 0 )); - - b.start(2).length(6).string("ab cd ef"); - b.valueType(""); - CHECK((!std::holds_alternative(b[0]))); - CHECK((!std::holds_alternative(b[0]))); - CHECK(( std::holds_alternative(b[0]))); - CHECK(( std::get( b[0] ) == "" )); - CHECK(( std::get( b[1] ) == "" )); - CHECK(( std::get( b[2] ) == "ab" )); - CHECK(( std::get( b[3] ) == "cd" )); - CHECK(( std::get( b[4] ) == "ef" )); - CHECK(( std::get( b[5] ) == "" )); - - } // GIVEN -} // SCENARIO - - -// For BodyText -SCENARIO("BodyText get(n)") { - GIVEN("A BodyText object") { - - // ------------------------ - // get(n) form - // ------------------------ - - { - BodyText b; - b.start(2).length(6).string("-12 34 -56"); - CHECK(( b.get(0) == 0 )); - CHECK(( b.get(1) == 0 )); - CHECK(( b.get(2) == -12 )); - CHECK(( b.get(3) == 34 )); - CHECK(( b.get(4) == -56 )); - CHECK(( b.get(5) == 0 )); - } - - { - BodyText b; - b.start(2).length(6).string("1.2 3.4 5.6"); - CHECK(( b.get(0) == 0 )); - CHECK(( b.get(1) == 0 )); - CHECK(( b.get(2) == 1.2 )); - CHECK(( b.get(3) == 3.4 )); - CHECK(( b.get(4) == 5.6 )); - CHECK(( b.get(5) == 0 )); - } - - { - BodyText b; - b.start(2).length(8).string("ab cd ef 123 4.5"); - CHECK(( b.get(0) == "" )); - CHECK(( b.get(1) == "" )); - CHECK(( b.get(2) == "ab" )); - CHECK(( b.get(3) == "cd" )); - CHECK(( b.get(4) == "ef" )); - CHECK(( b.get(5) == "123")); - CHECK(( b.get(6) == "4.5")); - CHECK(( b.get(7) == "" )); - } - - // ------------------------ - // operator[] form - // ------------------------ - - { - BodyText b; - b.start(2).length(6).string("-12 34 -56"); - CHECK(( b[0] == 0 )); - CHECK(( b[1] == 0 )); - CHECK(( b[2] == -12 )); - CHECK(( b[3] == 34 )); - CHECK(( b[4] == -56 )); - CHECK(( b[5] == 0 )); - } - - { - BodyText b; - b.start(2).length(6).string("1.2 3.4 5.6"); - CHECK(( b[0] == 0 )); - CHECK(( b[1] == 0 )); - CHECK(( b[2] == 1.2 )); - CHECK(( b[3] == 3.4 )); - CHECK(( b[4] == 5.6 )); - CHECK(( b[5] == 0 )); - } - - { - BodyText b; - b.start(2).length(6).string("ab cd ef"); - CHECK(( b[0] == "" )); - CHECK(( b[1] == "" )); - CHECK(( b[2] == "ab" )); - CHECK(( b[3] == "cd" )); - CHECK(( b[4] == "ef" )); - CHECK(( b[5] == "" )); - } - - } // GIVEN -} // SCENARIO - - - -// ----------------------------------------------------------------------------- -// 5. Scenario: doubles() etc. -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_get_named() -{ - { - BodyText b; - - b.start(2).length(6).string("-12 34 -56"); - auto result = b.ints(); - CHECK((std::is_same_v>)); - - CHECK(result[0] == 0 ); - CHECK(result[1] == 0 ); - CHECK(result[2] == -12 ); - CHECK(result[3] == 34 ); - CHECK(result[4] == -56 ); - CHECK(result[5] == 0 ); - - CHECK(result[0] == b.ints(0) ); - CHECK(result[1] == b.ints(1) ); - CHECK(result[2] == b.ints(2) ); - CHECK(result[3] == b.ints(3) ); - CHECK(result[4] == b.ints(4) ); - CHECK(result[5] == b.ints(5) ); - } - - { - BodyText b; - - b.start(2).length(6).string("1.2 3.4 5.6"); - const BodyText &bconst = b; // ensure it works with const - const auto result = bconst.doubles(); - CHECK((std::is_same_v>)); - - CHECK(result[0] == 0 ); - CHECK(result[1] == 0 ); - CHECK(result[2] == 1.2 ); - CHECK(result[3] == 3.4 ); - CHECK(result[4] == 5.6 ); - CHECK(result[5] == 0 ); - - CHECK(result[0] == bconst.doubles(0) ); - CHECK(result[1] == bconst.doubles(1) ); - CHECK(result[2] == bconst.doubles(2) ); - CHECK(result[3] == bconst.doubles(3) ); - CHECK(result[4] == bconst.doubles(4) ); - CHECK(result[5] == bconst.doubles(5) ); - } - - { - BodyText b; - - b.start(2).length(6).string("ab cd ef"); - const auto &result = b.strings(); - CHECK((std::is_same_v &>)); - - CHECK(result[0] == "" ); - CHECK(result[1] == "" ); - CHECK(result[2] == "ab" ); - CHECK(result[3] == "cd" ); - CHECK(result[4] == "ef" ); - CHECK(result[5] == "" ); - - CHECK(result[0] == b.strings(0) ); - CHECK(result[1] == b.strings(1) ); - CHECK(result[2] == b.strings(2) ); - CHECK(result[3] == b.strings(3) ); - CHECK(result[4] == b.strings(4) ); - CHECK(result[5] == b.strings(5) ); - } -} - -// For BodyText -SCENARIO("BodyText type-specific get functions: doubles() etc.") { - GIVEN("A BodyText object") { - scenario_get_named(); - } -} - -// For BodyText -SCENARIO("BodyText type-specific get functions: doubles() etc.") { - GIVEN("A BodyText object") { - scenario_get_named(); - } -} diff --git a/src/GNDStk/BodyText/test/sync.test.cpp b/src/GNDStk/BodyText/test/sync.test.cpp deleted file mode 100644 index 24df290c7..000000000 --- a/src/GNDStk/BodyText/test/sync.test.cpp +++ /dev/null @@ -1,295 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - -// ----------------------------------------------------------------------------- -// Scenario: pull -// content == any of {length,start,valueType} -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_pull() -{ - WHEN("pullFromDerived() is called") { - // none of length, start, valueType - THEN("Push to content{} works") { - const struct { - struct { - } content; - } derived; - BodyText b; - b.length(100).start(200).valueType("300"); - b.pullFromDerived(derived); // should do nothing here - CHECK(b.length() == 100); - CHECK(b.start() == 200); - CHECK(b.valueType() == "300"); - } - - // length only - THEN("Push to content{length} works") { - const struct { - struct { - int length = 10; - } content; - } derived; - BodyText b; - b.length(11).start(12).valueType("13"); - b.pullFromDerived(derived); - CHECK(b.length() == 10); - CHECK(b.start() == 12); - CHECK(b.valueType() == "13"); - } - - // start only - THEN("Push to content{start} works") { - const struct { - struct { - int start = 14; - } content; - } derived; - BodyText b; - b.length(15).start(16).valueType("17"); - b.pullFromDerived(derived); - CHECK(b.length() == 15); - CHECK(b.start() == 14); - CHECK(b.valueType() == "17"); - } - - // valueType only - THEN("Push to content{valueType} works") { - const struct { - struct { - std::string valueType = "18"; - } content; - } derived; - BodyText b; - b.length(19).start(20).valueType("21"); - b.pullFromDerived(derived); - CHECK(b.length() == 19); - CHECK(b.start() == 20); - CHECK(b.valueType() == "18"); - } - - // all but length - THEN("Push to content{start,valueType} works") { - const struct { - struct { - int start = 22; - std::string valueType = "23"; - } content; - } derived; - BodyText b; - b.length(24).start(25).valueType("26"); - b.pullFromDerived(derived); - CHECK(b.length() == 24); - CHECK(b.start() == 22); - CHECK(b.valueType() == "23"); - } - - // all but start - THEN("Push to content{length,valueType} works") { - const struct { - struct { - int length = 27; - std::string valueType = "28"; - } content; - } derived; - BodyText b; - b.length(29).start(30).valueType("31"); - b.pullFromDerived(derived); - CHECK(b.length() == 27); - CHECK(b.start() == 30); - CHECK(b.valueType() == "28"); - } - - // all but valueType - THEN("Push to content{length,start} works") { - const struct { - struct { - int length = 32; - int start = 33; - } content; - } derived; - BodyText b; - b.length(34).start(35).valueType("36"); - b.pullFromDerived(derived); - CHECK(b.length() == 32); - CHECK(b.start() == 33); - CHECK(b.valueType() == "36"); - } - - // all three - THEN("Push to content{length,start,valueType} works") { - const struct { - struct { - int length = 37; - int start = 38; - std::string valueType = "39"; - } content; - } derived; - BodyText b; - b.length(40).start(41).valueType("42"); - b.pullFromDerived(derived); - CHECK(b.length() == 37); - CHECK(b.start() == 38); - CHECK(b.valueType() == "39"); - } - } -} - - -SCENARIO("BodyText pull from content") { - GIVEN("A BodyText object") { - scenario_pull(); - } -} - -SCENARIO("BodyText pull from content") { - GIVEN("A BodyText object") { - scenario_pull(); - } -} - - -// ----------------------------------------------------------------------------- -// Scenario: push -// content == any of {length,start,valueType} -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_push() -{ - WHEN("pushToDerived() is called") { - // none of length, start, valueType - THEN("Push to content{} works") { - struct { - struct { - int ignored = 123456; // not length, start, or valueType - } content; - } derived; - BodyText b; - b.length(0).start(0).valueType("0"); - b.pushToDerived(derived); // should do nothing here - CHECK(derived.content.ignored == 123456); - } - - // length only - THEN("Push to content{length} works") { - struct { - struct { - int length = 10; - } content; - } derived; - BodyText b; - b.length(11).start(12).valueType("13"); - b.pushToDerived(derived); - CHECK(derived.content.length == 11); - } - - // start only - THEN("Push to content{start} works") { - struct { - struct { - int start = 14; - } content; - } derived; - BodyText b; - b.length(15).start(16).valueType("17"); - b.pushToDerived(derived); - CHECK(derived.content.start == 16); - } - - // valueType only - THEN("Push to content{valueType} works") { - struct { - struct { - std::string valueType = "18"; - } content; - } derived; - BodyText b; - b.length(19).start(20).valueType("21"); - b.pushToDerived(derived); - CHECK(derived.content.valueType == "21"); - } - - // all but length - THEN("Push to content{start,valueType} works") { - struct { - struct { - int start = 22; - std::string valueType = "23"; - } content; - } derived; - BodyText b; - b.length(24).start(25).valueType("26"); - b.pushToDerived(derived); - CHECK(derived.content.start == 25); - CHECK(derived.content.valueType == "26"); - } - - // all but start - THEN("Push to content{length,valueType} works") { - struct { - struct { - int length = 27; - std::string valueType = "28"; - } content; - } derived; - BodyText b; - b.length(29).start(30).valueType("31"); - b.pushToDerived(derived); - CHECK(derived.content.length == 29); - CHECK(derived.content.valueType == "31"); - } - - // all but valueType - THEN("Push to content{length,start} works") { - struct { - struct { - int length = 32; - int start = 33; - } content; - } derived; - BodyText b; - b.length(34).start(35).valueType("36"); - b.pushToDerived(derived); - CHECK(derived.content.length == 34); - CHECK(derived.content.start == 35); - } - - // all three - THEN("Push to content{length,start,valueType} works") { - struct { - struct { - int length = 37; - int start = 38; - std::string valueType = "39"; - } content; - } derived; - BodyText b; - b.length(40).start(41).valueType("42"); - b.pushToDerived(derived); - CHECK(derived.content.length == 40); - CHECK(derived.content.start == 41); - CHECK(derived.content.valueType == "42"); - } - } -} - - -SCENARIO("BodyText push to content") { - GIVEN("A BodyText object") { - scenario_push(); - } -} - -SCENARIO("BodyText push to content") { - GIVEN("A BodyText object") { - scenario_push(); - } -} diff --git a/src/GNDStk/BodyText/test/toNode.test.cpp b/src/GNDStk/BodyText/test/toNode.test.cpp deleted file mode 100644 index c54fb43ad..000000000 --- a/src/GNDStk/BodyText/test/toNode.test.cpp +++ /dev/null @@ -1,367 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - -// ----------------------------------------------------------------------------- -// Helper -// ----------------------------------------------------------------------------- - -// Tests use either void for each template parameter, or int, double, -// std::string, and char, in that order. In the former case, we're testing -// toNode() for the generic BodyText<...,void>. In the latter case, we're -// testing toNode() for non-generic BodyText. -template -void scenario_toNode() -{ - // Default-constructed BodyText - GIVEN("A default-constructed BodyText") { - WHEN("toNode() is called") { - THEN("The computed text string is empty") { - const BodyText b; - - std::string text = "abc"; - struct { - struct { - } content; - } derived; - // w/trim == true (shouldn't matter here; applies to vector) - b.trim = true; - b.toNode(text,derived); - CHECK(text == ""); - - // w/trim == false (shouldn't matter here; applies to vector) - b.trim = false; - b.toNode(text,derived); - CHECK(text == ""); - } - } - } - - // BodyText, after being given a particular raw string and parameters - GIVEN("A BodyText, with given raw string and parameters") { - WHEN("toNode() is called") { - THEN("The computed text string is as expected, " - "and the parameters remain as given" - ) { - BodyText b; - b.string("0 12 34 56 0 0") - .start(100).length(200).valueType("hello"); - - std::string text = "abc"; - struct { - struct { - } content; - } derived; - - // Someone who sets the raw string directly (as opposed to using - // a vector) is stating that they want *exactly* that raw string, - // including any 0s or anything else. To have BodyText's trim flag - // be relevant, use a vector. - - // w/trim == true (shouldn't matter here; applies to vector) - b.trim = true; - b.toNode(text,derived); - CHECK(text == "0 12 34 56 0 0"); - CHECK(b.start() == 100); - CHECK(b.length() == 200); - CHECK(b.valueType() == "hello"); - - // w/trim == false (shouldn't matter here; applies to vector) - b.trim = false; - b.toNode(text,derived); - CHECK(text == "0 12 34 56 0 0"); - CHECK(b.start() == 100); - CHECK(b.length() == 200); - CHECK(b.valueType() == "hello"); - } - } - } - - // BodyText, after being given a particular vector - GIVEN("A BodyText, assigned from a particular vector") { - WHEN("toNode() is called") { - THEN("The computed text string is as expected, " - "and the parameters were computed properly" - ) { - BodyText b; - // what's set here should be replaced upon assignment from vector - b.string("a b c").start(10).length(20).valueType("foobar"); - - // assign from vector - b = std::vector{{0, 0, 12, 34, 56, 78, 0, 0, 0, 0, 0}}; - - std::string text = "this should be replaced"; - struct { - struct { - } content; - } derived; - - // w/trim == true - b.trim = true; - b.toNode(text,derived); - CHECK(text == "12 34 56 78"); - CHECK(b.start() == 2); - CHECK(b.length() == 11); - CHECK(b.valueType() == "Integer32"); - - // w/trim == false - b.trim = false; - b.toNode(text,derived); - CHECK(text == "0 0 12 34 56 78 0 0 0 0 0"); - CHECK(b.start() == 0); - CHECK(b.length() == 11); - CHECK(b.valueType() == "Integer32"); - } - } - } - - // BodyText, after being given a particular vector - GIVEN("A BodyText, assigned from a particular vector") { - WHEN("toNode() is called") { - THEN("The computed text string is as expected, " - "and the parameters were computed properly" - ) { - BodyText b; - // what's set here should be replaced upon assignment from vector - b.string("d e f").start(100).length(200).valueType("foobar"); - - // assign from vector - b = std::vector{{0, 0, 0, 1.234, 5.678, 0, 0 }}; - - std::string text = "this should be replaced"; - struct { - struct { - } content; - } derived; - - // w/trim == true - b.trim = true; - b.toNode(text,derived); - CHECK(text == "1.234 5.678"); - CHECK(b.start() == 3); - CHECK(b.length() == 7); - CHECK(b.valueType() == "Float64"); - - // w/trim == false - b.trim = false; - b.toNode(text,derived); - CHECK(text == "0 0 0 1.234 5.678 0 0"); - CHECK(b.start() == 0); - CHECK(b.length() == 7); - CHECK(b.valueType() == "Float64"); - } - } - } - - // BodyText, after being given a particular vector - // A key point here is to ensure that ""s (string "zeros") are properly - // trimmed at the beginning and end. - GIVEN("A BodyText, assigned from a particular vector") { - WHEN("toNode() is called") { - THEN("The computed text string is as expected, " - "and the parameters were computed properly" - ) { - BodyText b; - // what's set here should be replaced upon assignment from vector - b.string("d e f").start(100).length(200).valueType("foobar"); - - // assign from vector - b = std::vector{{"","","","foo","bar","baz","",""}}; - - std::string text = "this should be replaced"; - struct { - struct { - } content; - } derived; - - // w/trim == true - b.trim = true; - b.toNode(text,derived); - CHECK(text == "foo bar baz"); - CHECK(b.start() == 3); - CHECK(b.length() == 8); - CHECK(b.valueType() == "UTF8Text"); - - // w/trim == false - // toNode() should treat this (the std::string) case as if trim - // were true. If it didn't, we'd end up with, well, leading and - // trailing *empty* strings, which, well, amount to leading and - // trailing nothing. - b.trim = false; - b.toNode(text,derived); - CHECK(text == "foo bar baz"); - CHECK(b.start() == 3); - CHECK(b.length() == 8); - CHECK(b.valueType() == "UTF8Text"); - } - } - } - - // BodyText, after being given a particular vector - // For T something other than int, double, and std::string - GIVEN("A BodyText, assigned from a particular vector") { - WHEN("toNode() is called") { - THEN("The computed text string is as expected, " - "and the parameters were computed properly" - ) { - BodyText b; - // what's set here should be replaced upon assignment from vector - b.string("x y z").start(100).length(200).valueType("foobar"); - - // assign from vector - b = std::vector{{0,0,0,0,0,'a','b','c','d',0}}; - - std::string text = "this should be replaced"; - struct { - struct { - } content; - } derived; - - b.toNode(text,derived); - CHECK(text == "a b c d"); - CHECK(b.start() == 5); - CHECK(b.length() == 10); - CHECK(b.valueType() == "char"); - } - } - } - - // Test various configurations of content{} when calling toNode(). Basically, - // these test whether toNode properly updates whichever of length, start, and - // valueType are in .content of toNode()'s second argument. - GIVEN("A BodyText, with vector") { - WHEN("toNode() is called") { - - // none of length, start, valueType - THEN("Push to content{} works") { - struct { - struct { - int ignored = 12345; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - // toNode doesn't care about what's *not* length/start/valueType... - CHECK(derived.content.ignored == 12345); // same as before toNode() - } - - // length only - THEN("Push to content{length} works") { - struct { - struct { - int length = 0; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.length == 8); - } - - // start only - THEN("Push to content{start} works") { - struct { - struct { - int start = 0; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.start == 2); - } - - // valueType only - THEN("Push to content{valueType} works") { - struct { - struct { - std::string valueType = ""; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.valueType == "Integer32"); - } - - // all but length - THEN("Push to content{start,valueType} works") { - struct { - struct { - int start = 0; - std::string valueType = ""; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.start == 2); - CHECK(derived.content.valueType == "Integer32"); - } - - // all but start - THEN("Push to content{length,valueType} works") { - struct { - struct { - int length = 0; - std::string valueType = ""; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.length == 8); - CHECK(derived.content.valueType == "Integer32"); - } - - // all but valueType - THEN("Push to content{length,start} works") { - struct { - struct { - int length = 0; - int start = 0; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.length == 8); - CHECK(derived.content.start == 2); - } - - // all three - THEN("Push to content{length,start,valueType} works") { - struct { - struct { - int length = 0; - int start = 0; - std::string valueType = ""; - } content; - } derived; - BodyText b; std::string text; - b = std::vector{{0,0,10,20,30,0,0,0}}; - b.toNode(text,derived); - CHECK(derived.content.length == 8); - CHECK(derived.content.start == 2); - CHECK(derived.content.valueType == "Integer32"); - } - } - } -} - - -// ----------------------------------------------------------------------------- -// Scenario -// ----------------------------------------------------------------------------- - -SCENARIO("BodyText toNode()") { - scenario_toNode(); -} - -SCENARIO("BodyText toNode()") { - scenario_toNode(); -} diff --git a/src/GNDStk/BodyText/test/types.test.cpp b/src/GNDStk/BodyText/test/types.test.cpp deleted file mode 100644 index 57274301f..000000000 --- a/src/GNDStk/BodyText/test/types.test.cpp +++ /dev/null @@ -1,121 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - -// ----------------------------------------------------------------------------- -// Scenario -// ----------------------------------------------------------------------------- - -SCENARIO("BodyText data types") { - GIVEN("std::vector for certain specific Ts") { - - WHEN("Via BodyText, we make variants of vectors and of scalars") { - // vector type - using vv = BodyText::VariantOfVectors; - THEN("The variant-of-vector size should be correct") { - CHECK(std::variant_size_v == 15); - } - vv vectors; - - // scalar type - using vs = BodyText::VariantOfScalars; - THEN("The variant-of-scalar size should be correct") { - CHECK(std::variant_size_v == 15); - } - vs scalars; - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,"a"); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == "a"); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,'b'); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 'b'); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-100); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -100); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-200); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -200); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-300); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -300); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-400); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -400); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-500); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -500); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,100); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 100); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,200); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 200); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,300); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 300); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,400); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 400); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,500); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 500); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-1.2f); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -1.2f); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,3.4); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == 3.4); - } - - THEN("Transformation to vector, and access, work") { - vectors = std::vector(10,-5.6); - scalars = std::get>(vectors)[0]; - CHECK(std::get(scalars) == -5.6); - } - } // WHEN - - } // GIVEN -} // SCENARIO diff --git a/src/GNDStk/BodyText/test/write.test.cpp b/src/GNDStk/BodyText/test/write.test.cpp deleted file mode 100644 index ac0095b27..000000000 --- a/src/GNDStk/BodyText/test/write.test.cpp +++ /dev/null @@ -1,226 +0,0 @@ - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk::core; - - -// ----------------------------------------------------------------------------- -// Scenario: raw string -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_write_string_active() -{ - GIVEN("A BodyText with an empty raw string") { - WHEN("BodyText.write() is called") { - THEN("Nothing is printed") { - BodyText b; - b = std::vector{{'a','b','c'}}; - b.string(""); // should make string (not vector) active - std::ostringstream oss; - b.write(oss,0); - CHECK(oss.str() == ""); - - // same (nothing printed) if indentation is non-0 - b.write(oss,2); - CHECK(oss.str() == ""); - } - } - } - - GIVEN("A BodyText with a non-empty raw string") { - WHEN("BodyText.write() is called") { - THEN("The raw string and a newline are printed") { - BodyText b; - b = std::vector{{'a','b','c'}}; - b.string("foo bar"); // should make string (not vector) active - - std::ostringstream oss; - b.write(oss,0); - CHECK(oss.str() == "foo bar\n"); - - // indentation isn't applied when the raw string is active - oss.str(""); - b.write(oss,2); - CHECK(oss.str() == "foo bar\n"); - } - } - } -} - -// For DATA == void -SCENARIO("BodyText write(), when the raw string is active") { - scenario_write_string_active(); -} - -// For DATA != void -SCENARIO("BodyText write(), when the raw string is active") { - scenario_write_string_active(); -} - - -// ----------------------------------------------------------------------------- -// Scenario: vector -// ----------------------------------------------------------------------------- - -// Helper -template -void scenario_write_vector_active() -{ - GIVEN("A BodyText with an empty vector") { - WHEN("BodyText.write() is called") { - THEN("Nothing is printed") { - BodyText b; - b.string("should be ignored"); // because vector is forthcoming... - b = std::vector{}; - std::ostringstream oss; - b.write(oss,0); - CHECK(oss.str() == ""); - - // same (nothing printed) if indentation is non-0 - b.write(oss,2); - CHECK(oss.str() == ""); - } - } - } - - GIVEN("A BodyText with a non-empty vector") { - WHEN("BodyText.write() is called") { - THEN("The vector and a newline are printed") { - BodyText b; - b.string("should be ignored"); // because vector is forthcoming... - b = std::vector{{2,3,5,7,11,13,17,19,21,23}}; - std::ostringstream oss; - - // Cases: - // indent: 0, 3 (number of spaces per indentation level) - // across: 0, 1, 2, 5, 10, 11 (note that 10 == vector size) - // level: 0, 1, 2 (indentation level) - // Note: across == 0 ==> unlimited. - // Lots of cases, but we want to check that our pretty-printing - // functionality works perfectly, and doesn't do anything that's - // unexpected around "boundaries" like across==10 with 10 values. - - oss.str(""); indent = 0; across = 0; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 0; b.write(oss,1); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 0; b.write(oss,2); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 1; b.write(oss,0); - CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); - - oss.str(""); indent = 0; across = 1; b.write(oss,1); - CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); - - oss.str(""); indent = 0; across = 1; b.write(oss,2); - CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); - - oss.str(""); indent = 0; across = 2; b.write(oss,0); - CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); - - oss.str(""); indent = 0; across = 2; b.write(oss,1); - CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); - - oss.str(""); indent = 0; across = 2; b.write(oss,2); - CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); - - oss.str(""); indent = 0; across = 5; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 5; b.write(oss,1); - CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 5; b.write(oss,2); - CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 10; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 10; b.write(oss,1); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 10; b.write(oss,2); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 11; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 11; b.write(oss,1); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 0; across = 11; b.write(oss,2); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 0; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 0; b.write(oss,1); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 0; b.write(oss,2); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 1; b.write(oss,0); - CHECK(oss.str() == "2\n3\n5\n7\n11\n13\n17\n19\n21\n23\n"); - - oss.str(""); indent = 3; across = 1; b.write(oss,1); - CHECK(oss.str() == " 2\n 3\n 5\n 7\n 11\n 13\n 17\n 19\n 21\n 23\n"); - - oss.str(""); indent = 3; across = 1; b.write(oss,2); - CHECK(oss.str() == " 2\n 3\n 5\n 7\n 11\n 13\n 17\n 19\n 21\n 23\n"); - - oss.str(""); indent = 3; across = 2; b.write(oss,0); - CHECK(oss.str() == "2 3\n5 7\n11 13\n17 19\n21 23\n"); - - oss.str(""); indent = 3; across = 2; b.write(oss,1); - CHECK(oss.str() == " 2 3\n 5 7\n 11 13\n 17 19\n 21 23\n"); - - oss.str(""); indent = 3; across = 2; b.write(oss,2); - CHECK(oss.str() == " 2 3\n 5 7\n 11 13\n 17 19\n 21 23\n"); - - oss.str(""); indent = 3; across = 5; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11\n13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 5; b.write(oss,1); - CHECK(oss.str() == " 2 3 5 7 11\n 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 5; b.write(oss,2); - CHECK(oss.str() == " 2 3 5 7 11\n 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 10; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 10; b.write(oss,1); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 10; b.write(oss,2); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 11; b.write(oss,0); - CHECK(oss.str() == "2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 11; b.write(oss,1); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - - oss.str(""); indent = 3; across = 11; b.write(oss,2); - CHECK(oss.str() == " 2 3 5 7 11 13 17 19 21 23\n"); - } - } - } -} - -// For DATA == void -SCENARIO("BodyText write(), when a vector is active") { - scenario_write_vector_active(); -} - -// For DATA != void -SCENARIO("BodyText write(), when a vector is active") { - scenario_write_vector_active(); -} diff --git a/src/GNDStk/CInterface.hpp b/src/GNDStk/CInterface.hpp new file mode 100644 index 000000000..83023ac34 --- /dev/null +++ b/src/GNDStk/CInterface.hpp @@ -0,0 +1,3 @@ + +// Miscellaneous helper constructs +#include "GNDStk/CInterface/src/detail.hpp" diff --git a/src/GNDStk/CInterface/src/detail.hpp b/src/GNDStk/CInterface/src/detail.hpp new file mode 100644 index 000000000..d8ddd9b20 --- /dev/null +++ b/src/GNDStk/CInterface/src/detail.hpp @@ -0,0 +1,702 @@ + +namespace detail { + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +// ------------------------ +// tocpp +// ------------------------ + +// const +template +const CPP &tocpp(const C *const self) +{ + if (self == nullptr) { + log::error( + "detail::tocpp(pointer to const): pointer is null; " + "it cannot be dereferenced" + ); + throw std::exception{}; + } + return reinterpret_cast(*self); +} + +// non-const +template +CPP &tocpp(C *const self) +{ + if (self == nullptr) { + log::error( + "detail::tocpp(pointer): pointer is null; " + "it cannot be dereferenced" + ); + throw std::exception{}; + } + return reinterpret_cast(*self); +} + +// ------------------------ +// getAllHandles +// findHandle +// ------------------------ + +// getAllHandles +// Returns a container +template +auto &getAllHandles() +{ + try { + static std::set> pointers; + return pointers; + } catch (...) { + log::error("Exception thrown in detail::getAllHandles()"); + throw; + } +} + +// findHandle +// Returns an iterator +template +auto findHandle(const C *const want) +{ + try { + auto &pointers = getAllHandles(); + return std::find_if( + pointers.begin(), pointers.end(), + [want](const std::shared_ptr &have) + { + return have.get() == &tocpp(want); + } + ); + } catch (...) { + log::error("Exception thrown in detail::findHandle()"); + throw; + } +} + + +// ----------------------------------------------------------------------------- +// create, assign, delete +// ----------------------------------------------------------------------------- + +// createHandle +template +C *createHandle( + const std::string &classname, + const std::string &funname, + ARGS &&...args +) { + try { + return reinterpret_cast( + &(**getAllHandles().insert( + std::make_shared(std::forward(args)...) + ).first) + ); + } catch (...) { + log::error("Unable to create {} handle", classname); + log::function("{}", funname); + return nullptr; + } +} + +// assignHandle +template +void assignHandle( + const std::string &classname, + const std::string &funname, + C *const lhs, const C *const rhs +) { + static const std::string remark = + "\nIgnoring the assignment and continuing (but you should" + "\nprobably look into this, and fix something)."; + + static const std::string + bothNull = "The \"to\" and \"from\" {} handles are null." + remark, + leftNull = "The \"to\" {} handle is null." + remark, + rightNull = "The \"from\" {} handle is null." + remark, + leftUnk = "Unknown \"to\" {} handle {}." + remark, + rightUnk = "Unknown \"from\" {} handle {}." + remark; + + try { + auto &pointers = getAllHandles(); + bool good = true; + + // nullptr anywhere? + if (lhs == nullptr && rhs == nullptr) { + good = false; log::error(bothNull, classname); + } else if (lhs == nullptr) { + good = false; log::error(leftNull, classname); + } else if (rhs == nullptr) { + good = false; log::error(rightNull, classname); + } + + // check lhs + if (lhs && findHandle(lhs) == pointers.end()) { + log::error(leftUnk, classname, reinterpret_cast(lhs)); + good = false; + } + + // check rhs + if (rhs && findHandle(rhs) == pointers.end()) { + log::error(rightUnk, classname, reinterpret_cast(rhs)); + good = false; + } + + if (!good) + throw std::exception{}; + + tocpp(lhs) = tocpp(rhs); + + } catch (...) { + log::function("{}(to,from)", funname); + } +} + +// deleteHandle +template +void deleteHandle( + const std::string &classname, + const std::string &funname, + const C *const ptr +) { + static const std::string ignore = "Ignoring call to delete {} handle {}."; + + if (ptr == nullptr) { + log::warning( + ignore + "\nHandle is null.", + classname, reinterpret_cast(ptr) + ); + return; + } + + try { + auto &pointers = getAllHandles(); + const auto iter = findHandle(ptr); + + if (iter != pointers.end()) { + pointers.erase(iter); + } else { + log::warning( + ignore + "\nHandle is unknown, or was already deleted.", + classname, reinterpret_cast(ptr) + ); + } + } catch (...) { + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + } +} + + +// ----------------------------------------------------------------------------- +// read, write, print +// ----------------------------------------------------------------------------- + +// readHandle +template +int readHandle( + const std::string &classname, + const std::string &funname, + C *const ptr, const std::string &filename +) { + try { + tocpp(ptr).baseComponent().read(filename); + return 1; // success + } catch (...) { + log::context( + "C function for reading {} from file. " + "File name is \"{}\".", classname, filename + ); + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return 0; // failure + } +} + +// writeHandle +template +int writeHandle( + const std::string &classname, + const std::string &funname, + const C *const ptr, const std::string &filename +) { + try { + tocpp(ptr).baseComponent().write(filename); + return 1; // success + } catch (...) { + log::context( + "C function for writing {} to file.\n" + "File name is \"{}\".", classname, filename + ); + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return 0; // failure + } +} + +// printHandle +template +int printHandle( + const std::string &classname, + const std::string &funname, + const C *const ptr, const std::string &format = "" +) { + try { + if (format == "") { + tocpp(ptr).baseComponent().print(); + // Component's print() already prints a newline + } else { + tocpp(ptr).baseComponent().write(std::cout,format); + // Component's write() intentionally doesn't already print a newline. + // For this print(), for our C language interface, print one. + std::cout << std::endl; + } + return 1; // success + } catch (...) { + if (format == "") { + log::context( + "C function for printing {}.", classname); + } else { + log::context( + "C function for printing {} in {} format.", classname, format); + } + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return 0; // failure + } +} + + +// ----------------------------------------------------------------------------- +// has, get, set +// ----------------------------------------------------------------------------- + +// hasField +template +bool hasField( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const EXTRACT &extract +) { + try { + const auto &field = *extract(tocpp(ptr)); + return field.has(); + } catch (...) { + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return false; + } +} + +// getField +template +auto getField( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const EXTRACT &extract +) { + using T = std::decay_t(ptr))->value())>; + + try { + const auto &field = *extract(tocpp(ptr)); + const T &ret = field.value(); // .value() gets us into any optional + if constexpr (std::is_same_v) { + // metadatum + if constexpr (std::is_same_v) { + return ret.c_str(); + } else { + return ret; + } + } else { + // child + return (HANDLE)(&ret); + } + } catch (...) { + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + if constexpr (std::is_same_v) { + // metadatum + if constexpr (std::is_same_v) { + return ""; + } else { + return T{}; + } + } else { + // child + return (HANDLE)nullptr; + } + } +} + +// setField +template +void setField( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract, + const T &newvalue +) { + try { + auto &field = *extract(tocpp(ptr)); + if constexpr (std::is_same_v) { + // metadatum + field.replace(newvalue); + } else { + // child + field.replace(tocpp(newvalue)); + } + } catch (...) { + log::function( + "{}({} handle = {}, value)", funname, classname, (void *)ptr); + } +} + + +// ----------------------------------------------------------------------------- +// clear, size +// ----------------------------------------------------------------------------- + +// clearContainer +template +void clearContainer( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract +) { + try { + auto &container = (*extract(tocpp(ptr)))(); + if constexpr (isOptional) { + if (container) + container->clear(); + } else + container.clear(); + } catch (...) { + log::error("Exception thrown in detail::clearContainer"); + log::function( + "{}({} handle = {})", funname, classname, (void *)ptr); + } +} + +// sizeOfContainer +template +size_t sizeOfContainer( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract +) { + try { + auto &container = (*extract(tocpp(ptr)))(); + if constexpr (isOptional) + return container ? container->size() : 0; + else + return container.size(); + } catch (...) { + log::error("Exception thrown in detail::sizeOfContainer"); + log::function( + "{}({} handle = {})", funname, classname, (void *)ptr); + return 0; + } +} + + +// ----------------------------------------------------------------------------- +// add +// ----------------------------------------------------------------------------- + +// addToContainer +template +void addToContainer( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract, + const T &value +) { + try { + auto &field = *extract(tocpp(ptr)); + field.add(tocpp(value)); + } catch (...) { + log::error("Exception thrown in detail::addToContainer"); + log::function( + "{}({} handle = {}, value)", funname, classname, (void *)ptr); + } +} + + +// ----------------------------------------------------------------------------- +// getByIndex +// setByIndex +// ----------------------------------------------------------------------------- + +// getByIndex +template +HANDLE getByIndex( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const EXTRACT &extract, + const size_t index +) { + try { + const auto &field = *extract(tocpp(ptr)); + return (HANDLE)&field(index); + } catch (...) { + log::function( + "{}({} handle = {}, index = {})", funname, classname, + (void *)ptr, index + ); + return (HANDLE)nullptr; + } +} + +// setByIndex +template +void setByIndex( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract, + const size_t index, + const V *const newvalue +) { + try { + auto &field = *extract(tocpp(ptr)); + field.replace(index,tocpp(newvalue)); + } catch (...) { + log::function( + "{}({} handle = {}, value)", funname, classname, (void *)ptr); + } +} + + +// ----------------------------------------------------------------------------- +// hasByMetadatum +// getByMetadatum +// setByMetadatum +// ----------------------------------------------------------------------------- + +// hasByMetadatum +template +bool hasByMetadatum( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const EXTRACT &extract, + const META &meta, + const T &value +) { + try { + const auto &field = *extract(tocpp(ptr)); + return field.has(meta(value)); + } catch (...) { + log::function("{}({} handle = {}, value)", funname, classname, + (void *)ptr); + return false; + } +} + +// getByMetadatum +template +HANDLE getByMetadatum( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const EXTRACT &extract, + const META &meta, + const T &value +) { + try { + const auto &field = *extract(tocpp(ptr)); + return (HANDLE)&field(meta(value)); + } catch (...) { + log::function( + "{}({} handle = {}, value)", funname, classname, (void *)ptr); + return (HANDLE)nullptr; + } +} + +// setByMetadatum +template< + class CPP, class CLASS, class C, + class EXTRACT, class META, class V, class T +> +void setByMetadatum( + const std::string &classname, + const std::string &funname, + C *const ptr, + const EXTRACT &extract, + const META &meta, + const T &value, + const V *const newvalue +) { + try { + auto &field = *extract(tocpp(ptr)); + field.replace(meta(value),tocpp(newvalue)); + } catch (...) { + log::function( + "{}({} handle = {}, value)", funname, classname, (void *)ptr); + } +} + + +// ----------------------------------------------------------------------------- +// Re: data vectors +// For when a Component-derived class has BlockData +// ----------------------------------------------------------------------------- + +// ------------------------ +// clear, size +// ------------------------ + +// clear +template +void vectorClear( + const std::string &classname, + const std::string &funname, + C *const ptr +) { + try { + tocpp(ptr).clear(); + } catch (...) { + log::error("Exception thrown in detail::vectorClear"); + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + } +} + +// size +template +size_t vectorSize( + const std::string &classname, + const std::string &funname, + const C *const ptr +) { + try { + return tocpp(ptr).size(); + } catch (...) { + log::error("Exception thrown in detail::vectorSize"); + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return 0; + } +} + +// ------------------------ +// get, set +// One value +// ------------------------ + +// get +template +T vectorGet( + const std::string &classname, + const std::string &funname, + const C *const ptr, + const size_t index +) { + using VECTOR = std::vector; + bool rangeErr = false; + + try { + const VECTOR &vec = tocpp(ptr).template get(); + if (index < vec.size()) + return vec[index]; + + rangeErr = true; + log::error( + "Vector index {} not in range 0..size-1 (0..{})", + index, vec.size()-1 + ); + throw std::exception{}; + } catch (...) { + if (!rangeErr) // else error was already printed + log::error("Exception thrown in detail::vectorGet"); + log::function( + "{}({} handle = {}, index = {})", + funname, classname, (void *)ptr, index + ); + return T{}; + } +} + +// set +template +void vectorSet( + const std::string &classname, + const std::string &funname, + C *const ptr, + const size_t index, + const T &value +) { + using VECTOR = std::vector; + bool rangeErr = false; + + try { + VECTOR &vec = tocpp(ptr).template get(); + if (index < vec.size()) + vec[index] = value; + else { + rangeErr = true; + log::error( + "Vector index {} not in range 0..size-1 (0..{})", + index, vec.size()-1 + ); + throw std::exception{}; + } + } catch (...) { + if (!rangeErr) // else error was already printed + log::error("Exception thrown in detail::vectorSet"); + log::function( + "{}({} handle = {}, index = {}, value)", + funname, classname, (void *)ptr, index + ); + } +} + +// ------------------------ +// get, set +// All values +// ------------------------ + +// get +template +auto *vectorGet( + const std::string &classname, + const std::string &funname, + C *const ptr +) { + using VECTOR = std::vector; + using RETURN = decltype(&(tocpp(ptr).template get())[0]); + + try { + auto &vec = tocpp(ptr).template get(); + return vec.size() ? &vec[0] : nullptr; + } catch (...) { + log::error("Exception thrown in detail::vectorGet"); + log::function("{}({} handle = {})", funname, classname, (void *)ptr); + return RETURN(nullptr); + } +} + +// set +template +void vectorSet( + const std::string &classname, + const std::string &funname, + C *const ptr, + const size_t size, + const T *const values +) { + using VECTOR = std::vector; + + try { + tocpp(ptr).template get().assign(values,values+size); + } catch (...) { + log::error("Exception thrown in detail::vectorSet"); + log::function( + "{}({} handle = {}, size = {}, values*)", + funname, classname, (void *)ptr, size + ); + } +} + +} // namespace detail diff --git a/src/GNDStk/Child.hpp b/src/GNDStk/Child.hpp index 4cb0bc77c..815fd21b4 100644 --- a/src/GNDStk/Child.hpp +++ b/src/GNDStk/Child.hpp @@ -10,9 +10,9 @@ TYPE - The type to which GNDStk should convert a Node that's extracted from a Tree - with the Child object. If TYPE is void, then GNDStk uses Node - the child - node, in its original form in the tree. + The type to which GNDStk should convert a Node that's extracted, via our + query system, with the Child object. If TYPE is void, then GNDStk uses + type Node - the child node in its original form. ALLOW @@ -29,13 +29,13 @@ ALLOW In other words: there are (or can be) any number of nodes within an enclosing context (here, ). ALLOW is a template parameter because - it affects the *type* that's pulled from the Tree when the Child object - is used for a query. For example, + it affects the *type* that's extracted when the Child object is used for a + query. For example, tree(...,axes,axis) gives back a container of axis objects, not a single axis object, because - our Child axis keyword has ALLOW == Allow::any. Note that axes, not to be + our Child axis object has ALLOW == Allow::many. Note that axes, not to be confused with axis, has ALLOW == Allow::one because it's expected just once. CONVERTER @@ -49,7 +49,6 @@ FILTER */ - // ----------------------------------------------------------------------------- // default // ----------------------------------------------------------------------------- @@ -57,7 +56,7 @@ FILTER template< class TYPE = void, // default means current Node type Allow ALLOW = Allow::one, // one, or any number allowed? - class CONVERTER = typename detail::default_converter::type, + class CONVERTER = detail::default_converter_t, class FILTER = detail::noFilter > class Child { @@ -67,56 +66,25 @@ class Child { // data // ------------------------ - // name, object, converter, filter + // name, converter, filter std::string name; - const TYPE object; CONVERTER converter; // optional custom converter; needs operator() FILTER filter; // optional custom filter; needs operator() -private: - // allowable as top-level? - // We make this private, with a setter and a getter, so that the setter - // can register the name as "allowable as top-level" if we set to true. - bool canBeTopLevel; -public: // ------------------------ // constructors // ------------------------ // name - // name, type - // name, type, converter - // name, type, converter, filter - // name, type, converter, filter, top + // name, converter + // name, converter, filter explicit Child( const std::string &n, - const TYPE &t = TYPE{}, - const CONVERTER &c = CONVERTER{}, - const FILTER &f = FILTER{}, - const bool canbetop = false + const CONVERTER &c = detail::make_once(), + const FILTER &f = detail::make_once() ) : - name(n), object(t), converter(c), filter(f) - { - top(canbetop); - } - - // ------------------------ - // top(): allowable - // as a top-level node? - // ------------------------ - - // top() - bool top() const - { - return canBeTopLevel; - } - - // top(bool) - void top(const bool t) - { - if (t) detail::AllowedTop.insert(name); - canBeTopLevel = t; - } + name(n), converter(c), filter(f) + { } // ------------------------ // simple functions @@ -127,32 +95,26 @@ class Child { // See remarks for Meta's basic(); similar remarks apply here auto basic() const { - return Child( - name, filter, canBeTopLevel // converter not possible here - ); + // converter isn't possible here + return Child(name, filter); } // one() // Produce an equivalent Child, but formulated as Allow::one auto one() const { - return Child( - name, object, converter, filter, canBeTopLevel - ); + return Child(name, converter, filter); } // many() // Produce an equivalent Child, but formulated as Allow::many auto many() const { - return Child( - name, object, converter, filter, canBeTopLevel - ); + return Child(name, converter, filter); } }; - // ----------------------------------------------------------------------------- // void // ----------------------------------------------------------------------------- @@ -173,10 +135,6 @@ class Child { // name, filter std::string name; FILTER filter; // optional custom filter; needs operator() -private: - // allowable as top-level? - bool canBeTopLevel; -public: // ------------------------ // constructors @@ -184,34 +142,12 @@ class Child { // name // name, filter - // name, filter, top explicit Child( const std::string &n, - const FILTER &f = FILTER{}, - const bool t = false + const FILTER &f = detail::make_once() ) : name(n), filter(f) - { - top(t); - } - - // ------------------------ - // top(): allowable - // as a top-level node? - // ------------------------ - - // top() - bool top() const - { - return canBeTopLevel; - } - - // top(bool) - void top(const bool t) - { - if (t) detail::AllowedTop.insert(name); - canBeTopLevel = t; - } + { } // ------------------------ // simple functions @@ -222,43 +158,40 @@ class Child { // we're already void; this is here for consistency with the general case. auto basic() const { - return Child(name,filter,canBeTopLevel); + return Child(name,filter); } // one() // Produce an equivalent Child, but formulated as Allow::one auto one() const { - return Child(name,filter,canBeTopLevel); + return Child(name,filter); } // many() // Produce an equivalent Child, but formulated as Allow::many auto many() const { - return Child(name,filter,canBeTopLevel); + return Child(name,filter); } }; - // ----------------------------------------------------------------------------- // Macro // ----------------------------------------------------------------------------- -// For Child building. This macro doesn't handle the optional "top-level" -// flag, the converter, or the filter; we don't believe those will be needed -// very often. If you do need to provide one or both, construct a Child -// in some other way than by using this macro. +// For Child building. This macro doesn't handle the converter or the filter; +// we don't believe those will be needed very often. If you do need to provide +// one or both, construct a Child in some other way than by using this macro. #define GNDSTK_MAKE_CHILD(TYPE,name,ALLOW) \ - inline const Child name(#name) + inline const njoy::GNDStk::Child name(#name) // Note: we don't #undef this after we use it within GNDStk, as we might // normally do, because users might find it handy. - // ----------------------------------------------------------------------------- // Operators // ----------------------------------------------------------------------------- diff --git a/src/GNDStk/Child/src/operator.hpp b/src/GNDStk/Child/src/operator.hpp index 0bbe2c677..12c3ae001 100644 --- a/src/GNDStk/Child/src/operator.hpp +++ b/src/GNDStk/Child/src/operator.hpp @@ -15,43 +15,6 @@ inline auto operator-(const Child &kwd) } - -// ----------------------------------------------------------------------------- -// operator~: Allow as top-level -// operator!: Disallow as top-level -// -// We don't expect much use of these, but someone may occasionally find the -// first (more likely) or the second (less likely) to be helpful. The unary -// operators that we chose for these purposes seemed like the best, given a -// limited selection. One could think: (T)ilde for (T)op; Not for Not. -// ----------------------------------------------------------------------------- - -// operator~ -template -inline auto operator~(const Child &kwd) -{ - auto ret = kwd; - ret.top(true); - return ret; -} - -// operator! -// fixme This switches off the canBeTopLevel flag in an individual Child, -// but we actually use the namespace-scope set AllowedTop when we -// determine if a particular name is allowed as a top-level node. So, turning -// of a Child's previously-true top-level designator does not, at the moment, -// have any meaningful effect anywhere. We'll look at this more carefully -// sometime. For now, this just isn't a super important issue. -template -inline auto operator!(const Child &kwd) -{ - auto ret = kwd; - ret.top(false); - return ret; -} - - - // ----------------------------------------------------------------------------- // T/Child // Change type to T @@ -61,36 +24,31 @@ inline auto operator!(const Child &kwd) // T/Child template inline auto operator/( - const T &object, + const T &, const Child &kwd ) { return Child( kwd.name, - object, kwd.converter, - kwd.filter, - kwd.top() + kwd.filter ); } // T/Child template inline auto operator/( - const T &object, + const T &, const Child &kwd ) { - using CONVERTER = typename detail::default_converter::type; + using CONVERTER = detail::default_converter_t; return Child( kwd.name, - object, CONVERTER{}, // because the input Child didn't have one - kwd.filter, - kwd.top() + kwd.filter ); } - // ----------------------------------------------------------------------------- // Child/string // Child/char* @@ -139,7 +97,6 @@ inline auto operator/( } - // ----------------------------------------------------------------------------- // * // regex match-anything @@ -152,7 +109,6 @@ inline auto operator*(const Child &kwd) } - // ----------------------------------------------------------------------------- // Child/C // Change converter to C @@ -172,10 +128,8 @@ inline Child< ) { return Child( kwd.name, - kwd.object, converter, // the new one; not kwd.converter! - kwd.filter, - kwd.top() + kwd.filter ); } @@ -198,7 +152,6 @@ inline Child< } - // ----------------------------------------------------------------------------- // post-- // Change converter to its default @@ -210,13 +163,11 @@ inline auto operator--( const Child &kwd, const int ) { - using C = typename detail::default_converter::type; + using C = detail::default_converter_t; return Child( kwd.name, - kwd.object, C{}, - kwd.filter, - kwd.top() + kwd.filter ); } @@ -230,7 +181,6 @@ inline auto operator--( } - // ----------------------------------------------------------------------------- // --pre, ++pre // Downgrade/upgrade to Allow::one/many @@ -251,7 +201,6 @@ inline auto operator++(const Child &kwd) } - // ----------------------------------------------------------------------------- // Child + F // Change filter to F @@ -265,10 +214,8 @@ inline auto operator+( ) { return Child( kwd.name, - kwd.object, kwd.converter, - filter, // the new one - kwd.top() + filter // the new one ); } @@ -280,13 +227,11 @@ inline auto operator+( ) { return Child( kwd.name, - filter, // the new one - kwd.top() + filter // the new one ); } - // ----------------------------------------------------------------------------- // Child || Child // Create a Child that represents one or the other of two children @@ -305,9 +250,7 @@ inline auto operator||( // both names, space-separated; this gets special treatment elsewhere a.name + " " + b.name, // need a filter; use the first Child's - a.filter, - // if either is top-level enabled - a.top() || b.top() + a.filter ); } @@ -328,9 +271,8 @@ inline auto operator||( return Child,ALLOW,CONVERTER,FILTER>( // both names, space-separated; this gets special treatment elsewhere a.name + " " + b.name, - // need an object, converter, and filter; use the first Child's - a.object, a.converter, a.filter, - // if either is top-level enabled - a.top() || b.top() + // we need a converter and a filter; use the first Child's + a.converter, + a.filter ); } diff --git a/src/GNDStk/Child/test/Child.test.cpp b/src/GNDStk/Child/test/Child.test.cpp index ac43846b9..176d689e5 100644 --- a/src/GNDStk/Child/test/Child.test.cpp +++ b/src/GNDStk/Child/test/Child.test.cpp @@ -24,28 +24,18 @@ SCENARIO("Testing GNDStk Child") { const Child foo("foo"); CHECK(foo.name == "foo"); - CHECK(!foo.top()); } WHEN("Constructed with (name,converter)") { const Child - foo("foo", 0.0, converter{}); + foo("foo", converter{}); CHECK(foo.name == "foo"); - CHECK(!foo.top()); } WHEN("Constructed with (name,converter,filter)") { const Child - foo("foo", 0.0, converter{}, filter); + foo("foo", converter{}, filter); CHECK(foo.name == "foo"); - CHECK(!foo.top()); - } - - WHEN("Constructed with (name,converter,filter,top)") { - const Child - foo("foo", 0.0, converter{}, filter, true); - CHECK(foo.name == "foo"); - CHECK(foo.top()); } } @@ -55,21 +45,18 @@ SCENARIO("Testing GNDStk Child") { const Child foo("foo"); CHECK(foo.name == "foo"); - CHECK(!foo.top()); } WHEN("Constructed with (name,filter)") { const Child foo("foo", filter); CHECK(foo.name == "foo"); - CHECK(!foo.top()); } WHEN("Constructed with (name,filter,top)") { const Child - foo("foo", filter, true); + foo("foo", filter); CHECK(foo.name == "foo"); - CHECK(foo.top()); } } } diff --git a/src/GNDStk/Child/test/operator.test.cpp b/src/GNDStk/Child/test/operator.test.cpp index 1ec2af774..af7646875 100644 --- a/src/GNDStk/Child/test/operator.test.cpp +++ b/src/GNDStk/Child/test/operator.test.cpp @@ -128,45 +128,6 @@ SCENARIO("Testing GNDStk Child operators") { } } - // ------------------------ - // ~Child - // !Child - // top() - // top(bool) - // ------------------------ - - GIVEN("Some Child objects") { - const Child foo("foo"); - const Child bar("bar"); - Child one("one"); - one.top(true); - Child two("two"); - two.top(true); - - CHECK(!foo.top()); - CHECK(!bar.top()); - CHECK(one.top()); - CHECK(two.top()); - - WHEN("We apply ~Child") { - THEN("Top-level is enabled") { - CHECK((~foo).top()); - CHECK((~bar).top()); - CHECK((~one).top()); - CHECK((~two).top()); - } - } - - WHEN("We apply !Child") { - THEN("Top-level is disabled") { - CHECK(!(!foo).top()); - CHECK(!(!bar).top()); - CHECK(!(!one).top()); - CHECK(!(!two).top()); - } - } - } - // ------------------------ // type/Child // ------------------------ diff --git a/src/GNDStk/Component.hpp b/src/GNDStk/Component.hpp index 942acea86..4e62fd23f 100644 --- a/src/GNDStk/Component.hpp +++ b/src/GNDStk/Component.hpp @@ -2,45 +2,74 @@ // General helper constructs #include "GNDStk/Component/src/detail.hpp" -// Map from some term/subject to its documentation, -// for use by classes that derive from Component, -// and in particular for use in the Python bindings. +// Map from some term/subject to its documentation. For use by classes that +// derive from Component, and in particular for use in Python bindings. using helpMap = std::map; +// ----------------------------------------------------------------------------- +// Noop +// noop +// Class and object representing "no-op[eration]". +// ----------------------------------------------------------------------------- + +// At the moment, this is designed to provide a "do-nothing converter" that +// might be used in Component-based classes. We might eventually extend its +// contents in a way that supports other uses of the "no-op" concept. + +struct Noop { + template + bool operator()(const FROM &, TO &) const + { + // No action. And, in the context of Node's add() functions, a + // return value of false means nothing will be added after all. + return false; + } +}; + +inline const Noop noop; + // ----------------------------------------------------------------------------- // Component // ----------------------------------------------------------------------------- -template -class Component : public BodyText +template +class Component : public BlockData { // For convenience - using body = BodyText; - using typename body::VariantOfVectors; - using typename body::VariantOfScalars; + using BLOCKDATA = BlockData; + using typename BLOCKDATA::VariantOfVectors; + using typename BLOCKDATA::VariantOfScalars; + + // Keys() + static const auto &Keys() + { + static const auto value = makeKeyTuple(DERIVED::KEYS()); + return value; + } // Links to fields in the object of the derived class. I can't find a way - // to do this in a decltype(DERIVED::keys())-aware manner, because DERIVED + // to do this in a decltype(DERIVED::KEYS())-aware manner, because DERIVED // is generally an incomplete type *here* - outside of Component's member // functions. So, we'll do it the old-fashioned way. std::vector links; // This class cannot have copy or move construction. Its constructor MUST - // know about the fields in the specific instance that's derived from it. + // know about the fields in the specific instance that derives from it. Component(const Component &) = delete; Component(Component &&) = delete; // Copy and move *assignments* have the right behavior, however. Component &operator=(const Component &other) { - body::operator=(other); + BLOCKDATA::operator=(other); return *this; } + Component &operator=(Component &&other) { - body::operator=(std::move(other)); + BLOCKDATA::operator=(std::move(other)); return *this; } @@ -48,47 +77,119 @@ class Component : public BodyText #include "GNDStk/Component/src/ctor.hpp" // finish - // See comments in finish.hpp + // Helpers for the constructors #include "GNDStk/Component/src/finish.hpp" - // Intermediaries between derived-class getters, and getter functions - // in detail::. These shorten the code in the derived classes. + // Helpers for derived-class getters and setters. + // These allow us to shorten some other code. #include "GNDStk/Component/src/getter.hpp" + #include "GNDStk/Component/src/setter.hpp" // Fallback for documentation() if DERIVED doesn't have help static inline helpMap help; public: + #include "GNDStk/Component/src/read.hpp" + #include "GNDStk/Component/src/write.hpp" + #include "GNDStk/Component/src/print.hpp" #include "GNDStk/Component/src/fromNode.hpp" #include "GNDStk/Component/src/sort.hpp" - #include "GNDStk/Component/src/toNode.hpp" // conversion to Node - #include "GNDStk/Component/src/write.hpp" + #include "GNDStk/Component/src/toNode.hpp" + #include "GNDStk/Component/src/convert.hpp" + + // Access to vector base of DERIVED, if applicable + template< + class D = DERIVED, + class = std::enable_if_t> + > + auto &vector() + { + using VECTOR = typename detail::isDerivedFromVector::type; + return static_cast(derived()); + } - // You can (but don't need to) override the following in DERIVED - static std::string namespaceName() { return ""; } + // Forwards, where viable and unambiguous, to certain capabilities + // in DERIVED's fields + #include "GNDStk/Component/src/forward.hpp" - // derived - // Convenient access to the derived class - DERIVED &derived() - { return static_cast(*this); } - const DERIVED &derived() const - { return static_cast(*this); } + // Wrapper for derived-class fields + #include "GNDStk/Component/src/field.hpp" + + // Namespace, Class + static std::string Namespace() { return DERIVED::NAMESPACE(); } + static std::string Class() { return DERIVED::CLASS(); } // documentation static std::string documentation(const std::string &subject = "") { try { return DERIVED::help.at(subject); - } - catch ( ... ) { + } catch (...) { return "No help information is available"; } } - // Component << std::string - // Meaning: read the string's content (currently XML or JSON) into an object - // of the Component's DERIVED class. Uses Node's << std::string capability. + // ------------------------ + // Shorthand access... + // ------------------------ + + // To the BlockData base class + BLOCKDATA &baseBlockData() { return *this; } + const BLOCKDATA &baseBlockData() const { return *this; } + + // To the Component base class (of the derived class) + Component &baseComponent() { return *this; } + const Component &baseComponent() const { return *this; } + + // To the derived class + DERIVED &derived() + { return static_cast(*this); } + const DERIVED &derived() const + { return static_cast(*this); } + + // ------------------------ + // has + // ------------------------ + + // Usable in C++ "compile-time if" (a.k.a. "if constexpr") statements + + template< + class EXTRACTOR, class THIS = DERIVED, + class = decltype(std::declval()(THIS{})) + > + static constexpr bool has(const Lookup &) + { + return true; + } + + template< + class EXTRACTOR, bool F, + class = std::enable_if_t + > + static constexpr bool has(const Lookup &) + { + return false; + } + + // ------------------------ + // String (not stream) I/O + // ------------------------ + + // Component >> string + // Like Node >> string, but for Component's derived class. + void operator>>(std::string &str) const + { + try { + Node(*this) >> str; + } catch (...) { + log::function("{} >> string", Class()); + throw; + } + } + + // Component << string + // Like Node << string, but for Component's derived class. void operator<<(const std::string &str) { try { @@ -96,22 +197,41 @@ class Component : public BodyText node << str; derived() = DERIVED(node); } catch (...) { - log::function(std::string(DERIVED::className()) + " << string"); + log::function("{} << string", Class()); throw; } } - }; // class Component // ----------------------------------------------------------------------------- -// ostream << Component +// Stream I/O // ----------------------------------------------------------------------------- -template +// operator>> +template +std::istream &operator>>( + std::istream &is, + Component &comp +) { + try { + return comp.read(is); + } catch (...) { + log::function("istream >> {}", comp.Class()); + throw; + } +} + +// operator<< +template std::ostream &operator<<( std::ostream &os, - const Component &obj + const Component &comp ) { - return obj.write(os); + try { + return comp.print(os,0); + } catch (...) { + log::function("ostream << {}", comp.Class()); + throw; + } } diff --git a/src/GNDStk/Component/src/convert.hpp b/src/GNDStk/Component/src/convert.hpp new file mode 100644 index 000000000..b8d5678d3 --- /dev/null +++ b/src/GNDStk/Component/src/convert.hpp @@ -0,0 +1,217 @@ + +// ----------------------------------------------------------------------------- +// CommentConverter +// Core Interface "converter" to support comments. +// ----------------------------------------------------------------------------- + +struct CommentConverter { + // query: Node ==> string + void operator()(const Node &node, std::string &str) const + { + bool found = false; + str = node.meta(special::text,found); + + #ifdef GNDSTK_INSTRUMENT + // Must do directly here, because we're handling #text directly + for (auto &m : node.metadata) + if (m.first == special::text) + detail::instrument::mark(m.first); + #endif + + if (!found) { + log::warning( + "Cannot find a \"{}\" metadatum in Node \"{}\".\n" + "The Node appears to be ill-formed.\n" + "Returning an empty string, \"\", for the comment.", + special::text, node.name); + log::context( + "Node-to-string conversion for comments in class {}." + + detail::fullName(Namespace(), Class())); + str = ""; + } + } + + // write: string ==> Node + void operator()(const std::string &str, Node &node) const + { + node.add(special::text, str); + } +}; + + +// ----------------------------------------------------------------------------- +// DataConverter +// Core Interface "converter" to support "cdata" (as in XML) and plain data. +// ----------------------------------------------------------------------------- + +struct DataConverter { + + // ------------------------ + // query vector + // ------------------------ + + // Node ==> DataNode> + template + void operator()( + const Node &self, + DataNode, preferCDATA> &vec + ) const { + vec.clear(); + + // We'll consider it to be fine, in this context, if a "cdata" + // or "pcdata" node isn't actually in the present node. This would + // be the case if, for example, we encountered something like this: + // + // where we might expect something like one of these: + // 1.23 4.56 7.89 + // + // So, we accept the case where the outer node doesn't explicitly + // have the expected vector-like inner node, and simply produce an + // empty vector in this situation. + bool found = false; + const Node &data = self.one(special::anydata,found); + if (!found) + return; // fine; the vector - clear()'d above - is appropriate + + // Remember whether the vector is arriving here in cdata or plain data. + vec.cdata = data.name == special::cdata; + + // We did find a data node (as opposed to encountering the situation + // described earlier), and the Core Interface should always have put + // a text metadatum into it, to store the data node's contents. + found = false; + const std::string &str = data.meta(special::text,found); + + #ifdef GNDSTK_INSTRUMENT + // Must do directly here, because we're handling #text directly + for (auto &m : data.metadata) + if (m.first == special::text) + detail::instrument::mark(m.first); + #endif + + if (found) { + if constexpr (std::is_floating_point_v) + detail::Precision{}.read(str,vec); + else { + // The above read ultimately does the following for non-floating- + // point T, but only after extra logic that we might as well avoid. + std::istringstream iss(str); + T element; + while (iss >> element) + vec.push_back(element); + } + } else { + log::warning( + "Cannot find a \"{}\" metadatum in Node \"{}\".\n" + "The Node appears to be ill-formed.\n" + "Returning an empty vector.", + special::text, data.name); + log::context( + "Node-to-vector conversion for data in class {}.", + detail::fullName(Namespace(), Class())); + } + + // Must do directly here, because we're handling the data child directly + detail::instrument::mark(data); + } + + // ------------------------ + // write vector + // ------------------------ + + // DataNode> ==> Node + template + void operator()( + const DataNode, preferCDATA> &vec, + Node &self + ) const { + // If the data vector is empty, we won't create a data node inside of the + // current node at all. This is essentially the reverse of the "no data + // node" situation described in a comment in the other operator() above. + if (vec.size() == 0) + return; + + // Depending on the status of our cdata flag, give the Node that's being + // created the correct name. + Node &data = self.add(vec.cdata ? special::cdata : special::data); + + std::ostringstream oss; + { + std::size_t count = 0; + using namespace detail; + for (const T &element : vec) { + oss << (count++ ? " " : ""); + if constexpr (std::is_floating_point_v) + oss << Precision{}.write(element); + else + oss << element; + } + } + data.add(special::text, oss.str()); + } + + // ------------------------ + // query string + // ------------------------ + + // Node ==> DataNode + template + void operator()( + const Node &self, + DataNode &str + ) const { + str = ""; + + // Remark as with the Node ==> DataNode> case earlier. + bool found = false; + const Node &data = self.one(special::anydata,found); + if (!found) + return; // fine; the string - set to "" above - is appropriate + + // Remember whether the string is arriving here in cdata or plain data. + str.cdata = data.name == special::cdata; + + found = false; + str = data.meta(special::text,found); + + #ifdef GNDSTK_INSTRUMENT + // Must do directly here, because we're handling #text directly + for (auto &m : data.metadata) + if (m.first == special::text) + detail::instrument::mark(m.first); + #endif + + if (!found) { + log::warning( + "Cannot find a \"{}\" metadatum in Node \"{}\".\n" + "The Node appears to be ill-formed.\n" + "Returning an empty string, \"\", for the value.", + special::text, data.name); + log::context( + "Node-to-string conversion for data in class {}." + + detail::fullName(Namespace(), Class())); + str = ""; // ensure "" after node.meta() call above + } + + // Must do directly here, because we're handling the data child directly + detail::instrument::mark(data); + } + + // ------------------------ + // write string + // ------------------------ + + // DataNode ==> Node + template + void operator()( + const DataNode &str, + Node &self + ) const { + if (str == "") + return; + + // Remark as in the DataNode case above. + Node &data = self.add(str.cdata ? special::cdata : special::data); + data.add(special::text, str); + } +}; diff --git a/src/GNDStk/Component/src/ctor.hpp b/src/GNDStk/Component/src/ctor.hpp index f289a5058..dec66b874 100644 --- a/src/GNDStk/Component/src/ctor.hpp +++ b/src/GNDStk/Component/src/ctor.hpp @@ -6,41 +6,28 @@ friend DERIVED; -// ctor: fields +// ctor: BlockData<...>, fields template -Component(const body &other, ARGS &...args) : body(other) +Component(const BLOCKDATA &other, ARGS &...args) : BLOCKDATA(other) { - // static_assert needs string literal - #define pairing_error \ - "The number and/or types of the fields sent to Component's " \ - "constructor is inconsistent with the query result implied " \ - "by the derived class' keys()" - // I'd have preferred to achieve the following check by using SFINAE // in the constructor's signature, but couldn't find a way to do that // without again running into the issue of DERIVED being incomplete. - // The parameters that are sent to this constructor must EXACTLY reflect - // what we'd get from a DERIVED::keys() multi-query. - if constexpr (std::is_same_v>) { - // keys is "empty" (std::tuple<>); that's OK, as long as ARGS is too - static_assert( - std::is_same_v, std::tuple<>>, - pairing_error - ); - } else { - // keys are *not* empty, so... - // The following is the *type* that a multi-query with DERIVED::keys() - // will produce. - using multi_t = - detail::decays_t; - static_assert( - std::is_same_v, multi_t>, - pairing_error - ); - // Create links - (links.push_back(&args), ...); - } + // Type that a multi-query with DERIVED::KEYS() will produce. + using multi_t = typename detail::queryResult::type; + + // The types in ARGS should exactly reflect what we'd get from + // a DERIVED::KEYS() multi-query, except that an ARG of Field + // is accepted in place of a T. + static_assert( + std::is_same_v::type...>, multi_t>, + "The number and/or types of the fields sent to Component's " + "constructor is inconsistent with the query result implied " + "by the KEYS() function in the derived class" + ); - #undef pairing_error + // Create links + links.reserve(sizeof...(args)); + (links.push_back(fieldAddress(args)), ...); } diff --git a/src/GNDStk/Component/src/detail-getter.hpp b/src/GNDStk/Component/src/detail-getter.hpp new file mode 100644 index 000000000..f0deb40f1 --- /dev/null +++ b/src/GNDStk/Component/src/detail-getter.hpp @@ -0,0 +1,466 @@ + +// ----------------------------------------------------------------------------- +// getter(vector, index, names...) +// Element of the vector that has .index() == index. +// Or, use C++ [index] if the element type doesn't have an .index() getter. +// ----------------------------------------------------------------------------- + +template +const T &getter( + const std::vector &vec, + const std::size_t &index, + // for the Component-derived class: names of namespace, class, relevant field + const std::string &nname, const std::string &cname, const std::string &fn +) { + static const std::string context = "getter {}::{}.{}({}) on vector"; + const std::string fname = fn != "" ? fn : ""; + + try { + + if constexpr (hasIndex) { + // hasIndex + // T (or at least one of its alternatives, if T is a variant) has + // a metadatum called "index". In this case, this function's index + // parameter is interpreted to mean: find the object with an "index" + // metadatum that matches the parameter. Importantly, then, index + // in this case is ***NOT*** a C++ [index] index! + + // fixme Make this more efficient, e.g. by assuming that the vector's + // elements are sorted by index, so that the wanted value is probably + // at [index], even though a vector [index] is not the interpretation. + const T *object = nullptr; + + for (auto &elem : vec) { + const T *ptr = nullptr; + + if constexpr (isVariant_v) { + // T == variant + std::visit( + [&elem,&index,&ptr](auto &&alternative) + { + if constexpr (hasIndex) + if (alternative.index() == index) + ptr = &elem; + }, + elem + ); + } else { + // T != variant + if constexpr (hasIndex) + if (elem.index() == index) + ptr = &elem; + } + + if (ptr) { + if (object) { + log::warning( + "Element with metadatum \"index\" {} was already found " + "in the vector.\n" + "Keeping the first element that was found.", + index + ); + log::member(context, nname, cname, fname, index); + } else + object = ptr; + } + } // for + + if (object) + return *object; + + log::error( + "Element with metadatum index == {} was not found in the vector" + + std::string(vec.size() ? "." : ";\nin fact the vector is empty."), + index + ); + throw std::exception{}; + + } else { + // !hasIndex + // No "index" is anywhere to be found in T. Here, then, we interpret + // this function's index parameter to be a C++ vector [index]. + // zzz Really need to rethink "index" and "label" interpretations. + if (index < vec.size()) + return vec[index]; + + if (vec.size() == 0) + log::error( + "Index {} is out of range; vector is empty.", + index); + else + log::error( + "Index {} is out of range; vector has [0..{}].", + index, vec.size()-1); + + throw std::exception{}; + } + + } catch (...) { + // context + log::member(context, nname, cname, fname, index); + throw; + } +} + + +// ----------------------------------------------------------------------------- +// getter(vector, label, names...) +// Element of the vector that has .label() == label. +// Assumes that the element type has a .label() getter. +// ----------------------------------------------------------------------------- + +template +const T &getter( + const std::vector &vec, + const std::string &label, + const std::string &nname, const std::string &cname, const std::string &fn +) { + static const std::string context = "getter {}::{}.{}(\"{}\") on vector"; + const std::string fname = fn != "" ? fn : ""; + + try { + const T *object = nullptr; + + for (auto &elem : vec) { + const T *ptr = nullptr; + + if constexpr (isVariant_v) { + // T == variant + std::visit( + [&elem,&label,&ptr](auto &&alternative) + { + if constexpr (hasLabel) + if (alternative.label() == label) + ptr = &elem; + }, + elem + ); + } else { + // T != variant + if constexpr (hasLabel) + if (elem.label() == label) + ptr = &elem; + } + + if (ptr) { + if (object) { + log::warning( + "Element with label \"{}\" was already found in the vector.\n" + "Keeping the first element that was found.", + label + ); + log::member(context, nname, cname, fname, label); + } else + object = ptr; + } + } // for + + if (object) + return *object; + + log::error( + "Element with metadatum label == \"{}\" was not found in the vector" + + std::string(vec.size() ? "." : ";\nin fact the vector is empty."), + label + ); + throw std::exception{}; + + } catch (...) { + // context + log::member(context, nname, cname, fname, label); + throw; + } +} + + +// ----------------------------------------------------------------------------- +// getter(vector, Lookup, names...) +// ----------------------------------------------------------------------------- + +template +bool getter( + const std::vector &vec, + const Lookup &look, + const std::string &nname, const std::string &cname, const std::string &fn +) { + const std::string fname = fn != "" ? fn : ""; + + try { + for (auto &elem : vec) + if constexpr (isVariant_v) { + // T == variant + if (std::visit( + [&look](auto &&alternative) + { + return look.extractor(alternative) == look.placeholder; + }, + elem + )) + return true; + } else + // T != variant + if (look.extractor(elem) == look.placeholder) + return true; + } catch (...) { + // context + log::member( + "getter {}::{}.{}(has({}({}))) on vector", + nname, cname, fname, look.name, look.placeholder); + throw; + } + + return false; +} + + +// ----------------------------------------------------------------------------- +// getter(vector, Lookup, names...) +// ----------------------------------------------------------------------------- + +template +const T &getter( + const std::vector &vec, + const Lookup &look, + const std::string &nname, const std::string &cname, const std::string &fn +) { + static const std::string context = "getter {}::{}.{}({}({})) on vector"; + const std::string fname = fn != "" ? fn : ""; + + try { + const T *object = nullptr; + + for (auto &elem : vec) { + const T *ptr = nullptr; + + if constexpr (isVariant_v) { + // T == variant + std::visit( + [&elem,&look,&ptr](auto &&alternative) + { + if (look.extractor(alternative) == look.placeholder) + ptr = &elem; + }, + elem + ); + } else { + // T != variant + if (look.extractor(elem) == look.placeholder) + ptr = &elem; + } + + if (ptr) { + if (object) { + log::warning( + "Element with {}({}) was already found in the vector.\n" + "Keeping the first element that was found.", + look.name, look.placeholder + ); + log::member(context, nname, cname, fname, look.name, + look.placeholder); + } else + object = ptr; + } + } // for + + if (object) + return *object; + + log::error( + "Element with metadatum {} == {} was not found in the vector" + + std::string(vec.size() ? "." : ";\nin fact the vector is empty."), + look.name, look.placeholder + ); + throw std::exception{}; + + } catch (...) { + // context + log::member(context, nname, cname, fname, look.name, look.placeholder); + throw; + } +} + + +// ----------------------------------------------------------------------------- +// getter(vector, Lookup, names...) +// ----------------------------------------------------------------------------- + +template +bool getter( + const std::vector &, + const Lookup &, + const std::string &, const std::string &, const std::string & +) { + return has_field::value; +} + + +// ----------------------------------------------------------------------------- +// getter(vector, Lookup, names...) +// ----------------------------------------------------------------------------- + +template +auto getter( + const std::vector &vec, + const Lookup &look, + const std::string &nname, const std::string &cname, const std::string &fn +) { + const std::string fname = fn != "" ? fn : ""; + + std::vector::type{})) + >> ret; + + try { + for (auto &elem : vec) { + if constexpr (isVariant_v) { + // T == variant + std::visit( + [&look,&ret](auto &&alternative) + { + ret.push_back(look.extractor(alternative)); + }, + elem + ); + } else { + // T != variant + ret.push_back(look.extractor(elem)); + } + } // for + } catch (...) { + // context + log::member( + "getter {}::{}.{}({}) on vector", + nname, cname, fname, look.name); + throw; + } + + return ret; +} + + +// ----------------------------------------------------------------------------- +// getter(optional, index/label/Lookup, names...) +// As earlier, but for optional data member. +// ----------------------------------------------------------------------------- + +template +decltype(auto) getter_helper( + const OPTVEC &optvec, const KEY &key, + const std::string &nname, const std::string &cname, const std::string &fn +) { + const std::string fname = fn != "" ? fn : ""; + + try { + // optional must have value + if (!optvec.has_value()) { + log::error("optional vector {} does not have a value", fname); + throw std::exception{}; + } + return getter(*optvec, key, nname, cname, fname); + } catch (...) { + // context + if constexpr (isLookup_v) { + // nname::cname.fname(field(value)) + if constexpr (!KEY::Has && !KEY::Void) + log::member("getter {}::{}.{}({}({})) on optional", + nname, cname, fname, key.name, key.placeholder); + // nname::cname.fname(has(field(value))) + if constexpr ( KEY::Has && !KEY::Void) + log::member("getter {}::{}.{}(has({}({}))) on optional", + nname, cname, fname, key.name, key.placeholder); + // nname::cname.fname(field) + if constexpr (!KEY::Has && KEY::Void) + log::member("getter {}::{}.{}({}) on optional", + nname, cname, fname, key.name); + // nname::cname.fname(has(field)) + if constexpr ( KEY::Has && KEY::Void) + log::member("getter {}::{}.{}(has({})) on optional", + nname, cname, fname, key.name); + } else { + log::member( + std::is_convertible_v + ? "getter {}::{}.{}({}) on optional" + : "getter {}::{}.{}(\"{}\") on optional", + nname, cname, fname, key); + } + throw; + } +} + +// std::optional +template> +decltype(auto) getter( + const std::optional> &optvec, const KEY &key, + const std::string &nname, const std::string &cname, const std::string &fn +) { + return getter_helper(optvec, key, nname, cname, fn); +} + +// GNDStk::Optional +template> +decltype(auto) getter( + const GNDStk::Optional> &optvec, const KEY &key, + const std::string &nname, const std::string &cname, const std::string &fn +) { + return getter_helper(optvec, key, nname, cname, fn); +} + + +// ----------------------------------------------------------------------------- +// getter(variant, names...) +// ----------------------------------------------------------------------------- + +template< + class T, class... Ts, + class = std::enable_if_t>> +> +const T *getter( + const std::variant &var, + const std::string &nname, const std::string &cname, const std::string &fn +) { + const std::string fname = fn != "" ? fn : ""; + + try { + return std::holds_alternative(var) + ? &std::get(var) + : nullptr; + } catch (...) { + // context + log::member("getter {}::{}.{}() on variant", nname, cname, fname); + throw; + } +} + + +// ----------------------------------------------------------------------------- +// getter(vector, index/label/Lookup, names...) +// ----------------------------------------------------------------------------- + +template< + class T, class KEY, class... Ts, + class = isSearchKey, + class = std::enable_if_t>> +> +const T *getter( + const std::vector> &vecvar, + const KEY &key, + const std::string &nname, const std::string &cname, const std::string &fn +) { + const std::string fname = fn != "" ? fn : ""; + + try { + return getter( + // no , so it calls getter(generic vector); it isn't recursive + getter(vecvar, key, nname, cname, fname), // scalar variant + nname, cname, fname + ); + } catch (...) { + // context + log::member( + std::is_convertible_v + ? "getter {}::{}.{}({}) on vector" + : "getter {}::{}.{}(\"{}\") on vector", + nname, cname, fname, key); + throw; + } +} diff --git a/src/GNDStk/Component/src/detail-sfinae.hpp b/src/GNDStk/Component/src/detail-sfinae.hpp new file mode 100644 index 000000000..53631a003 --- /dev/null +++ b/src/GNDStk/Component/src/detail-sfinae.hpp @@ -0,0 +1,391 @@ + +// ----------------------------------------------------------------------------- +// Re: [optional] vector [of variant] +// ----------------------------------------------------------------------------- + +// ------------------------ +// isVector +// ------------------------ + +// general +template +struct isVector + : public std::false_type +{ }; + +// for std::vector +template +struct isVector> + : public std::true_type +{ }; + +// isVector_v +template +inline constexpr bool isVector_v = isVector::value; + +// isVector_t +template +using isVector_t = std::enable_if_t>; + +// ------------------------ +// isOptionalVector +// ------------------------ + +// general +template +struct isOptionalVector + : public std::false_type +{ }; + +// for std::optional +template +struct isOptionalVector>> + : public std::true_type +{ }; + +// for GNDStk::Optional +template +struct isOptionalVector>> + : public std::true_type +{ }; + +// isOptionalVector_v +template +inline constexpr bool isOptionalVector_v = isOptionalVector::value; + +// isOptionalVector_t +template +using isOptionalVector_t = std::enable_if_t>; + +// ------------------------ +// isVectorOrOptionalVector +// ------------------------ + +// general +template +struct isVectorOrOptionalVector + : public std::false_type +{ }; + +// for std::vector +template +struct isVectorOrOptionalVector> + : public std::true_type +{ + using value_type = T; +}; + +// for std::optional +template +struct isVectorOrOptionalVector>> + : public std::true_type +{ + using value_type = T; +}; + +// for GNDStk::Optional +template +struct isVectorOrOptionalVector>> + : public std::true_type +{ + using value_type = T; +}; + +// isVectorOrOptionalVector_v +template +inline constexpr bool isVectorOrOptionalVector_v = + isVectorOrOptionalVector::value; + +// isVectorOrOptionalVector_t +template +using isVectorOrOptionalVector_t = + std::enable_if_t>; + +// ------------------------ +// isVectorVariant +// ------------------------ + +// general +template +struct isVectorVariant + : public std::false_type +{ }; + +// for std::vector> +template +struct isVectorVariant,Alloc>> + : public std::true_type +{ }; + +// isVectorVariant_t +template +using isVectorVariant_t = std::enable_if_t::value>; + + +// ----------------------------------------------------------------------------- +// Re: Defaulted +// ----------------------------------------------------------------------------- + +// ------------------------ +// isDefaulted +// ------------------------ + +// general +template +struct isDefaulted + : public std::false_type +{ }; + +// for Defaulted +template +struct isDefaulted> + : public std::true_type +{ }; + +// isDefaulted_t +template +using isDefaulted_t = std::enable_if_t::value>; + + +// ----------------------------------------------------------------------------- +// Re: Lookup +// ----------------------------------------------------------------------------- + +// ------------------------ +// isLookup +// ------------------------ + +// general +template +struct isLookup + : public std::false_type +{ }; + +// for Lookup +template +struct isLookup> + : public std::true_type +{ }; + +// isLookup_v +template +inline constexpr bool isLookup_v = isLookup::value; + + +// ------------------------ +// isLookupRefReturn +// ------------------------ + +// general +template +struct isLookupRefReturn + : public std::false_type +{ }; + +// for Lookup, with TYPE != void wanted +template +struct isLookupRefReturn> +{ + static inline constexpr bool value = !isVoid; +}; + +// ------------------------ +// isLookupBoolReturn +// ------------------------ + +template +inline constexpr bool isLookupBoolReturn = + detail::isLookup_v && + !detail::isLookupRefReturn::value; + + +// ----------------------------------------------------------------------------- +// Re: SearchKey +// ----------------------------------------------------------------------------- + +// ------------------------ +// isSearchKey +// isSearchKeyRefReturn +// ------------------------ + +// isSearchKey +// Type is one of: +// - convertible to std::size_t, for use as an index +// - convertible to std::string, for use as a label +// - of type Lookup<...> +template +using isSearchKey = std::enable_if_t< + std::is_convertible_v || + std::is_convertible_v || + isLookup_v // any Lookup +>; + +// isSearchKeyRefReturn +// Like the above, but allowing only a Lookup that triggers a reference return +template +using isSearchKeyRefReturn = std::enable_if_t< + std::is_convertible_v || + std::is_convertible_v || + isLookupRefReturn::value // not any Lookup; must give a reference return +>; + + +// ----------------------------------------------------------------------------- +// Re: Component's "forwards" +// ----------------------------------------------------------------------------- + +// ------------------------ +// isMatchExact +// ------------------------ + +// general +template +struct isMatchExact { + static constexpr int count = 0; +}; + +// FROM, vector +template +struct isMatchExact> { + static constexpr int count = 1; +}; + +// FROM, std::optional> +template +struct isMatchExact>> + : public isMatchExact> +{ }; + +// FROM, GNDStk::Optional> +template +struct isMatchExact>> + : public isMatchExact> +{ }; + +// ------------------------ +// MatchesExact +// ------------------------ + +// general +template +struct MatchesExact { + static constexpr std::size_t count = 0; +}; + +// FROM, tuple<...> +template +struct MatchesExact> { + static constexpr std::size_t count = ( + isMatchExact< + FROM, + std::decay_t()))> + >::count + + ... + ); +}; + +// ------------------------ +// isMatchViable +// ------------------------ + +// general +template +struct isMatchViable { + static constexpr int count = 0; +}; + +// FROM, vector +template +struct isMatchViable> { + static constexpr int count = std::is_convertible_v; +}; + +// FROM, std::optional> +template +struct isMatchViable>> + : public isMatchViable> +{ }; + +// FROM, GNDStk::Optional> +template +struct isMatchViable>> + : public isMatchViable> +{ }; + +// ------------------------ +// MatchesViable +// ------------------------ + +// general +template +struct MatchesViable { + static constexpr std::size_t count = 0; +}; + +// FROM, tuple<...> +template +struct MatchesViable> { + static constexpr std::size_t count = ( + isMatchViable< + FROM, + std::decay_t()))> + >::count + + ... + ); +}; + + +// ----------------------------------------------------------------------------- +// Miscellaneous +// ----------------------------------------------------------------------------- + +// ------------------------ +// firstOrOnly +// ------------------------ + +// general +template +struct firstOrOnly { + using type = T; +}; + +// for variant +template +struct firstOrOnly> { + using type = T; +}; + +// ------------------------ +// has_field +// Compare with has_index, +// as defined elsewhere +// ------------------------ + +// default +template +struct has_field + : std::false_type { }; + +// general +template +struct has_field< + EXTRACTOR, + T, + decltype( + (void)std::declval()( + std::conditional_t,void,T>{} + ), + 0 + ) +> + : std::true_type { }; + +// for variant +template +struct has_field< + EXTRACTOR, + std::variant +> { + // does any alternative have the field? + static constexpr bool value = (has_field::value || ...); +}; diff --git a/src/GNDStk/Component/src/detail.hpp b/src/GNDStk/Component/src/detail.hpp index 05cf4322d..f9e59d809 100644 --- a/src/GNDStk/Component/src/detail.hpp +++ b/src/GNDStk/Component/src/detail.hpp @@ -1,55 +1,47 @@ -// Forward declaration, needed by some things later -template +// A forward declaration of Component is needed by some constructs here +template class Component; - namespace detail { -// ----------------------------------------------------------------------------- -// colorize_*(text) -// ----------------------------------------------------------------------------- - -#define gndstkPaste(one,two) one ## two -#define gndstkColorFun(part) \ - inline std::string gndstkPaste(colorize_,part)(const std::string &text) \ - { \ - return GNDStk::color && colors::part != "" \ - ? colors::part + text + colors::reset \ - : text; \ - } - - // colorize_label() etc. - gndstkColorFun(label) - gndstkColorFun(colon) - gndstkColorFun(component) - gndstkColorFun(brace) - gndstkColorFun(bracket) - gndstkColorFun(comment) - -#undef gndstkColorFun -#undef gndstkPaste +// Various helper constructs +#include "GNDStk/Component/src/detail-sfinae.hpp" +// getter() +// Various cases. +// Intended for use in our Standard Interface classes. +#include "GNDStk/Component/src/detail-getter.hpp" // ----------------------------------------------------------------------------- // Functions: miscellaneous // ----------------------------------------------------------------------------- +// indentString +inline void indentString( + std::ostream &os, const int level, const std::string &str = "" +) { + os << std::string(GNDStk::indent * level, ' ') << str; +} + + // ------------------------ // getName // ------------------------ // Meta template -std::string getName(const Meta &m) +const std::string & +getName(const Meta &m) { return m.name; } // Child template -std::string getName(const Child &c) +const std::string & +getName(const Child &c) { return c.name; } @@ -59,662 +51,534 @@ template< class TYPE, Allow ALLOW, class CONVERTER, class FILTER, class T, class = std::enable_if_t::value> > -std::string getName(const std::pair,T> &p) +const std::string & +getName(const std::pair,T> &p) { return getName(p.first); } // ------------------------ -// colorize +// Various // ------------------------ -inline std::string colorize( - const std::string &label, - const std::string &color -) { - // no coloring in the first place? - if (!GNDStk::color) - return label; - - // normal label color? - if (color == "") - return colorize_label(label); - - // override, e.g. for optional - return color + label + colors::reset; -} - - -// ------------------------ // fullName -// ------------------------ - inline std::string fullName( - const std::string &nsname, - const std::string &clname + const std::string &nname, // name of namespace + const std::string &cname // name of class ) { - return (nsname == "" ? "" : nsname + "::") + clname; + return (nname == "" ? "" : nname + "::") + cname; } +// isDerivedFromComponent +// Adapted from an answer here: +// https://stackoverflow.com/questions/34672441 +// The issue is that Component is a class *template*. +template +struct isDerivedFromComponent { +private: + template + static constexpr std::true_type test(Component *); + static constexpr std::false_type test(...); + using type = decltype(test(std::declval())); +public: + static constexpr bool value = type::value; +}; + +template +inline constexpr bool isDerivedFromComponent_v = + isDerivedFromComponent::value; -// ------------------------ -// indentString -// ------------------------ +// isDerivedFromVector +template +struct isDerivedFromVector { +private: + template + static constexpr std::pair,std::true_type> + test(std::vector *); + static constexpr std::pair + test(...); + using ret = decltype(test(std::declval())); +public: + static constexpr bool value = ret::second_type::value; + using type = std::conditional_t; +}; -inline void indentString( - std::ostream &os, const int level, const std::string &str = "" -) { - os << std::string(GNDStk::indent * level,' ') << str; -} +template +inline constexpr bool isDerivedFromVector_v = + isDerivedFromVector::value; // ------------------------ -// hasWriteOneArg -// hasWriteTwoArg +// hasPrint* // ------------------------ // These are adapted from an answer here: // https://stackoverflow.com/questions/87372 -// class +// hasPrintOneArg template -class HasWriteOneArg +class HasPrintOneArg { template< class U, std::ostream &(U::*)(std::ostream &) const > struct SFINAE {}; - template static char test(SFINAE *); + template static char test(SFINAE *); template static long test(...); public: - static const bool has = sizeof(test(0)) == sizeof(char); + static constexpr bool has = sizeof(test(0)) == sizeof(char); }; -// variable - use this -template -inline constexpr bool hasWriteOneArg = HasWriteOneArg::has; - -// class +// HasPrintTwoArg template -class HasWriteTwoArg +class HasPrintTwoArg { template< class U, std::ostream &(U::*)(std::ostream &, const int) const > struct SFINAE {}; - template static char test(SFINAE *); + template static char test(SFINAE *); template static long test(...); public: - static const bool has = sizeof(test(0)) == sizeof(char); + static constexpr bool has = sizeof(test(0)) == sizeof(char); }; -// variable - use this +// Variable templates for the above; prefer these template -inline constexpr bool hasWriteTwoArg = HasWriteTwoArg::has; +inline constexpr bool hasPrintOneArg = HasPrintOneArg::has; +template +inline constexpr bool hasPrintTwoArg = HasPrintTwoArg::has; // ----------------------------------------------------------------------------- -// writeComponentPart +// printComponentPart // ----------------------------------------------------------------------------- // Cases: -// std::string -// T -// std::optional -// Defaulted -// std::vector - -bool writeComponentPart( - std::ostream &os, const int level, const std::string &str, - const std::string &label, const std::size_t maxlen, - const std::string &color = "" -); - -template -bool writeComponentPart( - std::ostream &os, const int level, const T &value, - const std::string &label, const std::size_t maxlen, - const std::string &color = "" -); - -template -bool writeComponentPart( - std::ostream &os, const int level, const std::optional &opt, - const std::string &label, const std::size_t maxlen -); - -template -bool writeComponentPart( - std::ostream &os, const int level, const Defaulted &def, - const std::string &label, const std::size_t maxlen -); - -template -bool writeComponentPart( - std::ostream &os, const int level, const std::vector &vec, - const std::string &label, const std::size_t maxlen, - const std::string &color = "" -); - +// 1. string +// 2. DataNode +// 3. DataNode> +// 4. T +// 5. vector +// 6. std::optional, GNDStk::Optional +// 7. Defaulted // ------------------------ -// for string +// 1. string // ------------------------ -inline bool writeComponentPart( - std::ostream &os, const int level, const std::string &str, - const std::string &label, const std::size_t maxlen, - const std::string &color +inline bool printComponentPart( + std::ostream &os, const int level, const std::size_t maxlen, + const std::string &label, + const std::string &value, + const std::string &labelColor = color::label, + const std::string &valueColor = color::value ) { indentString(os,level); if (label != "") { - os << colorize(label,color); - if (maxlen != 0) - os << std::string(maxlen-label.size(),' '); - os << " " << colorize_colon(":"); - // assuming the string to be printed isn't empty - which we don't really - // anticipate would happen - then print a space after the ":" and before - // the soon-to-be-printed string - if (str != "") + // label + os << colorize(label,labelColor); + + // alignment + if (maxlen != 0) { + assert(maxlen >= label.size()); + os << std::string(maxlen-label.size(), ' '); + } + + // space, :, space + os << ' ' << colorize(":",labelColor); + // Assuming the string to be printed isn't empty - which we don't really + // anticipate it would be - print a space after the ":", i.e. just before + // the soon-to-be-printed string. + if (value != "") os << ' '; } - for (auto &ch : str) { + // Nothing to print. + if (value == "") + return true; + + // Print, indenting after any internal newlines the string might contain. + const bool hascolor = GNDStk::colors && valueColor != ""; + bool start = true; + + for (auto &ch : value) { + if (start && hascolor) os << valueColor; + start = ch == '\n'; + if (start && hascolor) os << color::reset; // before os << \n... os << ch; - // indent after any internal newlines the string might happen to have; - // but callers probably shouldn't *end* such strings with newlines - if (ch == '\n') + if (start) { // after \n, indent for additional content + os << std::flush; indentString(os,level); + } } + if (hascolor) os << color::reset; return true; } // ------------------------ -// for T +// 2. DataNode // ------------------------ -// helper -// is_base_of_Component -// Adapted from an answer here: -// https://stackoverflow.com/questions/34672441 -template -class is_base_of_Component { - template - static constexpr std::true_type test(Component *); - static constexpr std::false_type test(...); - using type = decltype(test(std::declval())); -public: - static constexpr bool value = type::value; -}; - -template -bool writeComponentPart( - std::ostream &os, const int level, const T &value, - const std::string &label, const std::size_t maxlen, - const std::string &color +template +bool printComponentPart( + std::ostream &os, const int level, const std::size_t, + const std::string &, + const DataNode &value, + const std::string & = "", + const std::string &valueColor = color::data::string ) { - if constexpr (is_base_of_Component::value) { - // T is derived from Component, and thus inherits a write() - value.write(os,level); - } else { - // T is any old type, not derived from Component - if constexpr (std::is_floating_point_v) { - writeComponentPart( - os, level, - detail::Precision< - detail::PrecisionContext::metadata, - T - >{}.write(value), - label, maxlen, color - ); - } else { - // The string intermediary allows us to indent properly - // if the printed value has internal newlines. - std::string str; - convert_t{}(value,str); - writeComponentPart(os, level, str, label, maxlen, color); - } - } - return true; + // If empty, don't even print a newline + if (value == "") + return false; + + // Forward to printComponentPart(string). The way we're printing + // a DataNode, maxlen, label, and labelColor aren't used. + return printComponentPart( + os, level, 0, "", + static_cast(value), + "", + valueColor + ); } // ------------------------ -// for optional +// 3. DataNode // ------------------------ -template -bool writeComponentPart( - std::ostream &os, const int level, const std::optional &opt, - const std::string &label, const std::size_t maxlen +template +bool printComponentPart( + std::ostream &os, const int level, const std::size_t, + const std::string &, + const DataNode,preferCDATA> &vec, + const std::string & = "", + const std::string &valueColor = color::data::vector ) { - if (opt.has_value()) - writeComponentPart( - os, level, opt.value(), - label, maxlen, colors::optional - ); - else if (comments) - writeComponentPart( - os, level, colorize_comment("// optional; has no value"), - label, maxlen, colors::optional + // The way we're printing a DataNode, maxlen, label, + // and labelColor aren't used. + + // If empty, don't even print a newline + const std::size_t size = vec.size(); + if (size == 0) + return false; + + // Coloring? + const bool hascolor = + (colors && valueColor != "") || + (shades && std::is_arithmetic_v); + + // Indentation (string, with some number of spaces) + const std::string indent(GNDStk::indent * level, ' '); + + // End, given the requested truncation + const std::size_t end = GNDStk::elements < 0 + ? size + : std::min(size, std::size_t(GNDStk::elements)); + + // Compute the minimum and maximum values in the data vector, if we'll need + // them. Our use of std::conditional_t allows us to avoid constructing two + // possibly large and complex T values (given that T could be, for example, + // a large Component-based object) if T isn't of arithmetic type. + std::conditional_t,T,int> min, max; + if constexpr (std::is_arithmetic_v) + if (shades) { + min = max = vec[0]; // vec.size() == 0 was ruled out above + for (std::size_t i = 1; i < size; ++i) { + min = std::min(min,vec[i]); + max = std::max(max,vec[i]); + } + } + + // Print, using column formatting + for (std::size_t i = 0; i < end; ++i) { + // element's whitespace prefix + i == 0 + // at the very beginning + ? os << indent + : GNDStk::columns <= 0 || i % std::size_t(GNDStk::columns) != 0 + // still on the current line + ? os << ' ' + // starting the next line + : os << (hascolor ? color::reset : "") << std::endl << indent; + + // color, if applicable + if constexpr (std::is_arithmetic_v) + if (shades) + os << color::blue2red(min,vec[i],max); + if (hascolor && !(std::is_arithmetic_v && shades)) + os << valueColor; + + // element + if constexpr (std::is_floating_point_v) + os << Precision{}.write(vec[i]); + else + os << vec[i]; + }; + if (hascolor) os << color::reset; + + // If applicable, print a message saying the data were truncated + if (end < size) { + if (end > 0) + os << std::endl; // we printed *something*; go to the next line, then: + os << indent << colorize_comment( + "truncated; actual #elements == " + std::to_string(size), + valueColor ); - else - return false; // <== caller won't print newline + } + return true; } // ------------------------ -// for Defaulted +// 4. T (general) // ------------------------ template -bool writeComponentPart( - std::ostream &os, const int level, const Defaulted &def, - const std::string &label, const std::size_t maxlen +bool printComponentPart( + std::ostream &os, const int level, const std::size_t maxlen, + const std::string &label, + const T &value, + const std::string &labelColor = isDerivedFromComponent_v + ? color::component + : color::label, + const std::string &valueColor = color::value ) { - if (def.has_value()) { - writeComponentPart( - os, level, def.value(), - label, maxlen, colors::defaulted + // If value is derived from Component, we'll call its .print() function. + // Otherwise, we'll forward to printComponentPart(string), after creating + // some sort of string representation of the value. + + if constexpr (isDerivedFromComponent_v) { + value.baseComponent().print(os,level,label,labelColor); + } else if constexpr (std::is_floating_point_v) { + // T is floating-point. Use our floating-point printing mechanism. + printComponentPart( + os, level, maxlen, label, + Precision{}.write(value), + labelColor, valueColor ); - } else if (comments) { + } else { + // T is not floating-point. + // A string intermediary allows us to indent properly if the printed + // value has internal newlines. std::string str; - convert_t{}(def.get_default(),str); - writeComponentPart( - os, level, - colorize_comment("// defaulted; is its default (" + str + ")"), - label, maxlen, colors::defaulted - ); - } else - return false; // <== caller won't print newline - return true; -} - + convert_t{}(value,str); -// ------------------------ -// for vector -// ------------------------ - -// label [ -// element -// element -// ... -// ] -template -bool writeComponentPart( - std::ostream &os, const int level, const std::vector &vec, - const std::string &label, const std::size_t maxlen, - const std::string &color -) { - (void)maxlen; // doesn't use; formats with [...] - - indentString( - os, level, - colorize( - label, - color != "" ? color : colors::vector - ) - + " " + colorize_bracket("[") + "\n" - ); - - for (auto &value : vec) { - writeComponentPart(os, level+1, value, "", 0); - os << '\n'; // between elements + printComponentPart( + os, level, maxlen, label, + str, + labelColor, valueColor + ); } - indentString( - os, level, - colorize_bracket("]") - ); - return true; } +// ------------------------ +// 5. vector +// ------------------------ -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -// getter() -// Various cases. -// Intended for use in our auto-generated Standard Interface classes. -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// getter(vector, index, ...) -// Index into vector data member of class. -// ----------------------------------------------------------------------------- - -// const template -const T &getter( +bool printComponentPart( + std::ostream &os, const int level, const std::size_t, + const std::string &label, const std::vector &vec, - const std::size_t index, - const std::string &nsname, // enclosing class' namespace - const std::string &clname, // enclosing class - const std::string &field // enclosing class' field we're accessing + const std::string &labelColor = color::vector, + const std::string & = "" ) { - static const std::string context = "getter {}::{}.{}({}) on vector"; - - try { - // todo Make this more efficient, e.g. by assuming that the vector's - // elements are sorted by index, so that the wanted value is likely - // to be found at [index]. - - const T *selected = nullptr; - - for (auto &v : vec) { - const T *ptr = nullptr; - - if constexpr (isVariant::value) { - // T == variant - std::visit( - [&v,&index,&ptr](auto &&alternative) - { - if constexpr (hasIndex) - if (alternative.index() == index) - ptr = &v; - }, - v - ); - } else { - // T != variant - if constexpr (hasIndex) - if (v.index() == index) - ptr = &v; - } - - if (!ptr) - continue; - - if (selected) { - log::warning( - "Element with index {} was already found in the vector.\n" - "Keeping the first element that was found.", - index - ); - log::member(context, nsname, clname, field, index); - } else - selected = ptr; - } // for - - if (!selected) { - log::error( - "Element with index {} was not found in the vector" + - std::string(vec.size() ? "." : ";\nin fact the vector is empty."), - index + // Forward to some printComponentPart() for each element. Note that here, + // in the vector context, maxlen isn't applicable. As for valueColor (the + // last parameter), the forwarded-to printComponentPart() will use what's + // appropriate for the vector's elements. + + // To avoid user confusion in prettyprinted output, we'll change our special + // name "#comment" (which identifies comment nodes to be transformed into the + // form when writing to XML), to the name "comment" instead. + // Also, because our code generator creates the comment vector field + // automatically, in generated classes, we won't print it here at all if the + // vector is empty. That is, we won't write "comment [(nothing)]"). This way, + // users won't wonder where it came from. (It was created automatically.) + const bool isComment = label == special::comment; + if ((isComment || isDerivedFromComponent_v) && vec.size() == 0) + return false; // <== so that the caller won't print a newline + + const std::string lab = isComment ? "comment" : label; + + if constexpr (isDerivedFromComponent_v) { + std::size_t index = 0; + + // elements + for (const auto &element : vec) { + if (index) + os << std::endl; // between elements + printComponentPart( + os, level, 0, + lab + '[' + std::to_string(index++) + ']', + element, + color::vector, + "" ); - throw std::exception{}; + } + } else { + // [ + indentString(os, level, colorize(lab + " [", labelColor)); + os << std::endl; + + // elements + for (const auto &element : vec) { + printComponentPart( + os, level+1, 0, + "", + element, + "", + isComment ? color::data::comment : "" + ); + os << std::endl; // between elements } - return *selected; - - } catch (...) { - // context - // Example: prints "getter containers::Axes.axis(100)" - log::member(context, nsname, clname, field, index); - throw; + // ] + indentString( + os, level, + comments + ? colorize("] " + colorize_comment(lab), labelColor) + : colorize("]", labelColor) + ); } -} -// non-const -template -T &getter( - std::vector &vec, - const std::size_t index, - const std::string &nsname, - const std::string &clname, - const std::string &field -) { - return const_cast( - getter(std::as_const(vec), index, nsname, clname, field) - ); + return true; } +// ------------------------ +// 6. optional +// ------------------------ -// ----------------------------------------------------------------------------- -// getter(vector, label, ...) -// Element of the vector that has .label() == label. -// Assumes that the element type has a .label() getter. -// ----------------------------------------------------------------------------- - -// const -template -const T &getter( - const std::vector &vec, +template +bool printComponentPart_helper( + std::ostream &os, const int level, const std::size_t maxlen, const std::string &label, - const std::string &nsname, - const std::string &clname, - const std::string &field + const OPT &value, + const std::string &labelColor = "", + const std::string &valueColor = "" ) { - static const std::string context = "getter {}::{}.{}(\"{}\") on vector"; - - try { - const T *selected = nullptr; - - for (auto &v : vec) { - const T *ptr = nullptr; - - if constexpr (isVariant::value) { - // T == variant - std::visit( - [&v,&label,&ptr](auto &&alternative) - { - if constexpr (hasLabel) - if (alternative.label() == label) - ptr = &v; - }, - v - ); - } else { - // T != variant - if constexpr (hasLabel) - if (v.label() == label) - ptr = &v; - } + using T = typename OPT::value_type; + + if (!value.has_value()) + return false; // <== so that the caller won't print a newline + + // label color + std::string clabel = labelColor; + if (clabel == "") { + if constexpr (isDerivedFromComponent_v) + clabel = color::optional::component; + else if constexpr (isVector_v) + clabel = color::optional::vector; + else + clabel = color::optional::label; + } - if (!ptr) - continue; - - if (selected) { - log::warning( - "Element with label \"{}\" was already found in the vector.\n" - "Keeping the first element that was found.", - label - ); - log::member(context, nsname, clname, field, label); - } else - selected = ptr; - } // for - - if (!selected) { - log::error( - "Element with label \"{}\" was not found in the vector" + - std::string(vec.size() ? "." : ";\nin fact the vector is empty."), - label - ); - throw std::exception{}; - } + // value color + std::string cvalue = valueColor; + if (cvalue == "") + cvalue = color::optional::value; - return *selected; + // print + printComponentPart( + os, level, maxlen, label, + value.value(), + clabel + ); - } catch (...) { - // context - log::member(context, nsname, clname, field, label); - throw; - } + return true; } -// non-const +// std::optional template -T &getter( - std::vector &vec, +bool printComponentPart( + std::ostream &os, const int level, const std::size_t maxlen, const std::string &label, - const std::string &nsname, - const std::string &clname, - const std::string &field + const std::optional &value, + const std::string &labelColor = "", + const std::string &valueColor = "" ) { - return const_cast( - getter(std::as_const(vec), label, nsname, clname, field) - ); + return printComponentPart_helper( + os, level, maxlen, label, value, labelColor, valueColor); } - - -// ----------------------------------------------------------------------------- -// getter(optional, index or label, ...) -// As earlier, but for optional data member. -// ----------------------------------------------------------------------------- - -// const -template< - class T, class LOOKUP, - class = std::enable_if_t< - std::is_convertible_v || - std::is_convertible_v - > -> -const T &getter( - const std::optional> &opt, - const LOOKUP &index_or_label, - const std::string &nsname, - const std::string &clname, - const std::string &field -) { - try { - // optional must have value - if (!opt.has_value()) { - log::error("optional vector {} does not have a value", field); - throw std::exception{}; - } - return getter((*opt), index_or_label, nsname, clname, field); - } catch (...) { - // context - log::member( - std::is_convertible_v - ? "getter {}::{}.{}({}) on optional" - : "getter {}::{}.{}(\"{}\") on optional", - nsname, clname, field, index_or_label); - throw; - } -} - -// non-const -template< - class T, class LOOKUP, - class = std::enable_if_t< - std::is_convertible_v || - std::is_convertible_v - > -> -T &getter( - std::optional> &opt, - const LOOKUP &index_or_label, - const std::string &nsname, - const std::string &clname, - const std::string &field +// GNDStk::Optional +template +bool printComponentPart( + std::ostream &os, const int level, const std::size_t maxlen, + const std::string &label, + const GNDStk::Optional &value, + const std::string &labelColor = "", + const std::string &valueColor = "" ) { - return const_cast( - getter(std::as_const(opt), index_or_label, nsname, clname, field) - ); + return printComponentPart_helper( + os, level, maxlen, label, value, labelColor, valueColor); } - -// ----------------------------------------------------------------------------- -// getter(...) -// With caller-specified type, when variant is involved -// ----------------------------------------------------------------------------- - // ------------------------ -// variant,... +// 7. Defaulted // ------------------------ -template< - class T, - class... Ts, - class = std::enable_if_t>> -> -const T *getter( - const std::variant &var, - const std::string &nsname, - const std::string &clname, - const std::string &field +template +bool printComponentPart( + std::ostream &os, const int level, const std::size_t maxlen, + const std::string &label, + const Defaulted &value, + const std::string &labelColor = "", + const std::string &valueColor = "" ) { - try { - return std::holds_alternative(var) - ? &std::get(var) - : nullptr; - } catch (...) { - // context - log::member( - "getter {}::{}.{}() on variant", - nsname, clname, field); - throw; + // label color + std::string clabel = labelColor; + if (clabel == "") { + if constexpr (isDerivedFromComponent_v) + clabel = color::optional::component; + else if constexpr (isVector_v) + clabel = color::optional::vector; + else + clabel = color::optional::label; } -} + // value color + std::string cvalue = valueColor; + if (cvalue == "") + cvalue = color::optional::value; -// ------------------------ -// vector, -// index or label, -// ... -// ------------------------ + // print + printComponentPart( + os, level, maxlen, label, + value.value(), + clabel, cvalue + ); -// The (size_t index) and (string label) cases were similar enough that -// we were able to combine them into one function. + // comment + if (comments) + os << ' ' << colorize_comment("its default",cvalue); -template< - class T, class LOOKUP, - class = std::enable_if_t< - std::is_convertible_v || - std::is_convertible_v - >, - class... Ts -> -const T *getter( - const std::vector> &vec, - const LOOKUP &index_or_label, - const std::string &nsname, - const std::string &clname, - const std::string &field -) { - try { - return getter( - // no , so it calls getter(generic vector); it isn't recursive - getter(vec, index_or_label, nsname, clname, field), // scalar variant - nsname, clname, field - ); - } catch (...) { - // context - log::member( - std::is_convertible_v - ? "getter {}::{}.{}({}) on vector" - : "getter {}::{}.{}(\"{}\") on vector", - nsname, clname, field, index_or_label); - throw; - } + return true; } - // ----------------------------------------------------------------------------- // For sorting derived-class fields based on index and label, if and when one // or the other of those is determined to be present. That determination hinges -// on both a compile-time check that the classes involved even *have* index or -// label fields in their content struct, and if they do, if either of those is -// possibly a std::optional that may or may not contain a value at the moment. +// on both a compile-time check that the classes involved even *have* index +// or label fields, and, if they do, if either of those is possibly an optional +// that may or may not contain a value at the moment. // ----------------------------------------------------------------------------- // ------------------------ @@ -731,46 +595,46 @@ bool compareRegular(const A &a, const B &b) // index? std::size_t aindex = 0; bool ahasindex = false; if constexpr (hasIndex) { - if constexpr (isOptional) { - if ((ahasindex = a.content.index.has_value())) - aindex = a.content.index.value(); + if constexpr (isOptional) { + if ((ahasindex = a.index().has_value())) + aindex = a.index().value(); } else { ahasindex = true; - aindex = a.content.index; + aindex = a.index(); } } std::size_t bindex = 0; bool bhasindex = false; if constexpr (hasIndex) { - if constexpr (isOptional) { - if ((bhasindex = b.content.index.has_value())) - bindex = b.content.index.value(); + if constexpr (isOptional) { + if ((bhasindex = b.index().has_value())) + bindex = b.index().value(); } else { bhasindex = true; - bindex = b.content.index; + bindex = b.index(); } } // label? std::string alabel = ""; bool ahaslabel = false; if constexpr (hasLabel) { - if constexpr (isOptional) { - if ((ahaslabel = a.content.label.has_value())) - alabel = a.content.label.value(); + if constexpr (isOptional) { + if ((ahaslabel = a.label().has_value())) + alabel = a.label().value(); } else { ahaslabel = true; - alabel = a.content.label; + alabel = a.label(); } } std::string blabel = ""; bool bhaslabel = false; if constexpr (hasLabel) { - if constexpr (isOptional) { - if ((bhaslabel = b.content.label.has_value())) - blabel = b.content.label.value(); + if constexpr (isOptional) { + if ((bhaslabel = b.label().has_value())) + blabel = b.label().value(); } else { bhaslabel = true; - blabel = b.content.label; + blabel = b.label(); } } @@ -783,7 +647,7 @@ bool compareRegular(const A &a, const B &b) : ahaslabel && bhaslabel ? alabel < blabel : ahaslabel ? true : bhaslabel ? false - // equal + // equal (so, not <, for strict weak ordering purposes) : false; } @@ -840,7 +704,7 @@ void sort(std::vector> &vec) std::sort(vec.begin(), vec.end(), compareVariant); } -// optional +// std::optional template void sort(std::optional> &opt) { @@ -848,4 +712,92 @@ void sort(std::optional> &opt) sort(opt.value()); } +// GNDStk::Optional +template +void sort(GNDStk::Optional> &opt) +{ + if (opt.has_value()) + sort(opt.value()); +} + + +// ----------------------------------------------------------------------------- +// Miscellaneous helper constructs +// ----------------------------------------------------------------------------- + +// ------------------------ +// queryResult +// ------------------------ + +// general +template +struct queryResult { + using type = std::decay_t()))>; +}; + +// for Meta +// Needed, because Node{}(std::declval()) in the above "general" case +// doesn't instantiate for Defaulted, which has no default constructor. +template +struct queryResult,CONVERTER>> { + using type = Defaulted; +}; + +// for std::tuple +template +struct queryResult> { + using type = std::tuple::type...>; +}; + +// ------------------------ +// isDataNode +// ------------------------ + +// general +template +struct isDataNode { + static constexpr bool value = false; +}; + +// for DataNode +template +struct isDataNode> { + static constexpr bool value = true; +}; + +// ------------------------ +// pprintAlign +// ------------------------ + +// Component::print() - the prettyprinter - uses the following in order to +// include certain constructs in Component-derived classes from its alignment +// computation, and exclude other constructs. We believe that the alignment +// just looks better, and has fewer spurious-looking spaces, when some types +// of constructs are excluded. + +struct pprintAlign { + template + bool operator()(const KEY &, const void *const link) const + { + using RESULT = typename queryResult::type; + + // [optional] vectors, component-derived classes, and data nodes + // print in their own special manner; so, no key:value alignment. + if constexpr ( + isVector_v || + isOptionalVector_v || + isDerivedFromComponent_v || + isDataNode::value) + return false; + + // if optional (with a non-vector value, or already handled above), + // align iff optional has value, and value isn't component-derived + if constexpr (isOptional) + return ((const RESULT *)link)->has_value() && + !isDerivedFromComponent_v; + + return true; + } +}; + } // namespace detail diff --git a/src/GNDStk/Component/src/field.hpp b/src/GNDStk/Component/src/field.hpp new file mode 100644 index 000000000..d637462c2 --- /dev/null +++ b/src/GNDStk/Component/src/field.hpp @@ -0,0 +1,963 @@ + +template +class FieldPart { + // Nothing; see the partial specialization later in this file +}; + + +// ----------------------------------------------------------------------------- +// Field +// Note that this class is defined inside of class Component. We do this because +// it uses type Component itself (the particular Component<...> that it's in) as +// well as type DERIVED (the class that derives from this Component via CRTP). +// ----------------------------------------------------------------------------- + +template +class Field { + + // friends + friend DERIVED; + + template + friend class FieldPart; + + // data + DERIVED &parent; + T wrappedValue; + +public: + + // ------------------------ + // Constructors + // ------------------------ + + // Because parent would be wrong + Field(const Field &) = delete; // no copy + Field(Field &&) = delete; // no move + + // The following accept DERIVED*, not DERIVED&, so that we can write "this", + // not "*this", where Field objects are constructed. It's just a bit shorter. + + // parent + // This could be rolled into the (parent, value) constructor below, but the + // compiler seems to be better able to optimize the construction of objects + // with class Field data members if we split it out. + explicit Field(DERIVED *const parent) : + parent(*parent), + wrappedValue(T{}) + { } + + // parent, value + explicit Field(DERIVED *const parent, const T &v) : + parent(*parent), + wrappedValue(v) + { } + + // parent, other Field object + Field(DERIVED *const parent, const Field &other) : + parent(*parent), + wrappedValue(other.wrappedValue) + { } + + // parent, default value, current value (std::optional) + // If T == Defaulted + template> + Field( + DERIVED *const parent, const typename TEE::value_type &def, + const std::optional &v = {} + ) : + parent(*parent), + wrappedValue(def,v) + { } + + /* + // parent, default value, current value (GNDStk::Optional) + // If T == Defaulted + template> + Field( + DERIVED *const parent, const typename TEE::value_type &def, + const GNDStk::Optional &v = {} + ) : + parent(*parent), + wrappedValue(def,v) + { } + */ + + // ------------------------ + // has + // ------------------------ + + // has() + // With no arguments. + // Relates to std::optional/GNDStk::Optional, not to the question of what + // metadata or metadata values the present Field might contain. (See the + // below function for that.) Returns true iff T is either *not* optional, + // or is optional *and* has a value. + bool has() const + { + if constexpr (detail::isOptional) + return wrappedValue.has_value(); + else + return true; + } + + // has() + // With one argument. + // Forwards to [operator()(const KEY &key) const], below, essentially to + // provide an alternative form of a "has" query. Instead of, for example, + // H.isotope(has(mass_number(2))) + // to inquire as to whether element H's vector of isotopes has one with + // a mass number of 2, one could instead write: + // H.isotope.has(mass_number(2)) + // to make exactly the same query. (The example assumes that H is of a + // class - say, Element - that contains a vector of isotopes, and that + // the Isotope class contains an integer metadatum called mass_number.) + // Note: the SFINAE is such that this function is enabled iff a call to + // operator()(key) of the present class would be valid and return bool. + template< + class KEY, + class = std::enable_if_t()(GNDStk::has(std::declval()))), + bool + >> + > + bool has(const KEY &key) const + { + return (*this)(GNDStk::has(key)); + } + + // ------------------------ + // value() + // Get past optional + // where necessary + // ------------------------ + + // Note: the parentheses in "return (wrappedValue)" are necessary in + // these, so that the decltype(auto) return types produce references! + + // const + decltype(auto) value() const + { + if constexpr (detail::isOptional) + return wrappedValue.value(); + else + return (wrappedValue); + } + + // non-const + decltype(auto) value() + { + if constexpr (detail::isOptional) + return wrappedValue.value(); + else + return (wrappedValue); + } + + // ------------------------ + // Getters + // ------------------------ + + // () + // Get exactly the Field-wrapped value, whatever it is (including optional) + const T &operator()() const { return wrappedValue; } + T &operator()() { return wrappedValue; } + + // (index/label/Lookup), including Lookup (via the "has" function) + // If T == vector + template< + class KEY, class = detail::isSearchKey, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + decltype(auto) operator()(const KEY &key) const + { return parent.getter(wrappedValue,key); } + + template< + class KEY, class = detail::isSearchKey, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + decltype(auto) operator()(const KEY &key) + { return parent.getter(wrappedValue,key); } + + // [index/label/Lookup] + // If T == vector + template< + class KEY, class = detail::isSearchKey, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + decltype(auto) operator[](const KEY &key) const + { return (*this)(key); } + + template< + class KEY, class = detail::isSearchKey, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + decltype(auto) operator[](const KEY &key) + { return (*this)(key); } + + // size() + // If T == vector + template< + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + std::size_t size() const + { + if constexpr (detail::isOptional) + return wrappedValue.has_value() ? wrappedValue->size() : 0; + else + return wrappedValue.size(); + } + + // ------------------------ + // Conversions + // ------------------------ + + // To T + // Same as () + operator const T &() const { return (*this)(); } + operator T &() { return (*this)(); } + + // To vector, if T == optional + template> + operator const typename TEE::value_type &() const + { + if (!wrappedValue) { + log::error( + "Cannot give valueless optional a vector value\n" + "when the object is const"); + log::member("Field:: conversion to vector"); + throw std::exception{}; + } + return *wrappedValue; + } + + template> + operator typename TEE::value_type &() + { + return *( + wrappedValue + ? wrappedValue + : wrappedValue = typename TEE::value_type{} + ); + } + + // ------------------------ + // Setters: general + // ------------------------ + + // replace(T) + // Replace existing value with another. + // Provides a "builder pattern" for DERIVED. + DERIVED &replace(const T &val) + { + wrappedValue = val; + return parent; + } + + // operator()(T) + // Provides a "builder pattern" for DERIVED. Note that no ambiguity should + // arise with Field's operator() that accepts an index, a label, or + // a Lookup object, because the parameter here is also a T (and thus is a + // vector if we're in a Field). + DERIVED &operator()(const T &val) + { + return replace(val); + } + + // operator=(T) + // Returns the left-hand side, as one would probably expect. For assignment, + // a builder pattern for DERIVED would just be goofy. + Field &operator=(const T &val) + { + return replace(val), *this; + } + + // ------------------------ + // Setters: for Defaulted; + // remarks as above + // ------------------------ + + // replace(optional) + // Replace existing Defaulted's value with the given value. + // Provides a "builder pattern" for DERIVED. + template> + DERIVED &replace(const std::optional &opt) + { + return wrappedValue = opt, parent; + } + template> + DERIVED &replace(const GNDStk::Optional &opt) + { + return wrappedValue = opt, parent; + } + + // operator()(optional) + // As above. + template> + DERIVED &operator()(const std::optional &opt) + { + return replace(opt); + } + template> + DERIVED &operator()(const GNDStk::Optional &opt) + { + return replace(opt); + } + + // operator=(optional) + // As above, except returns Field, as expected for assignment. + template> + Field &operator=(const std::optional &opt) + { + return replace(opt), *this; + } + template> + Field &operator=(const GNDStk::Optional &opt) + { + return replace(opt), *this; + } + + // ------------------------ + // Setters: add to vector + // ------------------------ + + // add(element) + // If T == [optional] vector + // Add (via push_back()) to this->wrappedValue, which in this context + // is a vector. + template> + Field &add( + const typename detail::isVectorOrOptionalVector::value_type &elem + ) { + Component::setter(wrappedValue, elem); + return *this; + } + + // Here, we actually don't want an operator() that forwards to add(), like + // the operator()s that forwarded to replace() in earlier setters. Imagine + // that this Field wrapped, say, a vector. If someone used the above + // add() function and wrote field.add(123), the meaning is clearly that 123 + // is to be added (think push_back()) to the vector. But if we allowed + // for an operator() that forwards to add(), and someone used it to write + // field(123), they *might* want 123 added to the vector - or they might + // be intending to retrieve vector[123]. In the *getter* functions defined + // earlier, note that we do indeed allow both operator() and operator[] for + // retrieving vector elements (by index, label, or Lookup object). I suppose + // we could allow only the operator[] form for getting, and then be able to + // have an operator() setter here, with the same meaning as add(). However, + // we believe that the getter's use of the operator() in question provides + // for the better and more-expected meaning. + + // operator+=(element) + template> + Field &operator+=( + const typename detail::isVectorOrOptionalVector::value_type &elem + ) { + return add(elem); + } + + // ------------------------ + // Setters: for vector or + // optional vector, replace + // an element + // ------------------------ + + // The following may not see too much use. They mostly have the same effect + // as indexing into the vector and then doing an assignment. The difference + // is that these functions endow the operation with a "builder pattern" for + // DERIVED, and in that respect are analogous to replace(T) and operator()(T) + // as defined earlier. Indexing+assignment, in contrast, returns a reference + // to the assignment's left-hand side (as one would expect from assignment), + // which is the current Field, not its parent DERIVED. + + // replace(index/label/Lookup, element) + // Find the vector's element that has the given index, label, or Lookup, + // and replace it with the given replacement element. + template< + class KEY, class = detail::isSearchKeyRefReturn, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + DERIVED &replace( + const KEY &key, + const typename detail::isVectorOrOptionalVector::value_type &elem + ) { + (*this)(key) = elem; + return parent; + } + + // operator()(index/label/Lookup, element) + template< + class KEY, class = detail::isSearchKeyRefReturn, + class TEE = T, class = detail::isVectorOrOptionalVector_t + > + DERIVED &operator()( + const KEY &key, + const typename detail::isVectorOrOptionalVector::value_type &elem + ) { + return replace(key,elem); + } + + // ------------------------ + // Assignment + // ------------------------ + + // copy + Field &operator=(const Field &other) + { + wrappedValue = other.wrappedValue; + return *this; + } + + // move + Field &operator=(Field &&other) + { + wrappedValue = std::move(other.wrappedValue); + return *this; + } +}; // class Field + + +// ----------------------------------------------------------------------------- +// FieldPart +// As with class Field, this is intentionally defined within class Component. +// ----------------------------------------------------------------------------- + +template +class FieldPart,PART> { + Field &whole; + + static_assert( + detail::isVariant_v || detail::isVectorVariant::value, + "FieldPart,PART>: " + "WHOLE must be variant or vector" + ); + +public: + + // ------------------------ + // Constructors + // ------------------------ + + // Because [Field &whole] would be wrong + FieldPart(const FieldPart &) = delete; // no copy + FieldPart(FieldPart &&) = delete; // no move + + explicit FieldPart(Field &whole) : + whole(whole) + { } + + // ------------------------ + // Getters: + // If WHOLE == variant + // ------------------------ + + // ptr() + // Get as PART * + template> + const PART *ptr() const + { + return whole.parent.template getter(whole()); + } + + template> + PART *ptr() + { + return whole.parent.template getter(whole()); + } + + // ref() + // Get as PART & + template> + const PART &ref() const + { + const PART *const p = ptr(); + if (p) return *p; + log::error( + "Cannot get reference; variant contains a different alternative"); + log::member("FieldPart::ref()"); + throw std::exception{}; + } + + template> + PART &ref() + { + return const_cast(std::as_const(*this).template ref()); + } + + // opt() + // Makes a std::optional. So, we must return by value, + // and then only the const version is needed. + template> + const std::optional opt() const + { + const PART *const p = ptr(); + return p ? std::optional{*p} : std::optional{}; + } + + // Opt() + // As above, except makes a GNDStk::Optional. + template> + const GNDStk::Optional Opt() const + { + const PART *const p = ptr(); + return p ? GNDStk::Optional{*p} : GNDStk::Optional{}; + } + + // operator() + // Get as PART & + template> + const PART &operator()() const + { + try { + return ref(); + } catch (...) { + log::member("FieldPart::operator()"); + throw; + } + } + + template> + PART &operator()() + { + return const_cast(std::as_const(*this)()); + } + + // ------------------------ + // Conversions + // If WHOLE == variant + // ------------------------ + + // To PART * + template> + operator const PART *() const { return ptr(); } + + template> + operator PART *() { return ptr(); } + + // To PART & + template> + operator const PART &() const + { + try { + return ref(); + } catch (...) { + log::member("FieldPart:: conversion to variant alternative"); + throw; + } + } + + template> + operator PART &() + { + return const_cast(std::as_const(*this).operator const PART &()); + } + + // To std::optional + template> + operator std::optional() const { return opt(); } + + // To GNDStk::Optional + template> + operator GNDStk::Optional() const { return Opt(); } + + // ------------------------ + // has + // Similar to Field's + // ------------------------ + + /* + // todo I'm not sure that this would have a clear meaning for FieldPart. + // For Field, it means whether or not a value exists - either it's not + // optional, or is optional but has a value. Here, that meaning could be + // confused with the concept of whether or not the variant contains the + // "PART" represented by this FieldPart. Think about this. + + // has() + bool has() const + { + if constexpr (detail::isOptional) + return wrappedValue.has_value(); + else + return true; + } + */ + + // has(key) + template< + class KEY, + class = std::enable_if_t()(GNDStk::has(std::declval()))), + bool + >> + > + bool has(const KEY &key) const + { + return (*this)(GNDStk::has(key)); + } + + // ------------------------ + // Getters: + // If WHOLE == vector + // ------------------------ + + // ptr(index/label/Lookup) + // Get as PART * + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + const PART *ptr(const KEY &key) const + { + return whole.parent.template getter(whole(),key); + } + + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + PART *ptr(const KEY &key) + { + return whole.parent.template getter(whole(),key); + } + + // ref(index/label/Lookup) + // Get as PART & + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + const PART &ref(const KEY &key) const + { + const PART *const p = ptr(key); + if (p) return *p; + log::error( + "Cannot get reference; variant contains a different alternative"); + log::member("FieldPart::ref(key)"); + throw std::exception{}; + } + + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + PART &ref(const KEY &key) + { + return const_cast(std::as_const(*this).template ref(key)); + } + + // opt(index/label/Lookup) + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + const std::optional opt(const KEY &key) const + { + const PART *const p = ptr(key); + return p ? std::optional{*p} : std::optional{}; + } + + // Opt(index/label/Lookup) + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t + > + const GNDStk::Optional Opt(const KEY &key) const + { + const PART *const p = ptr(key); + return p ? GNDStk::Optional{*p} : GNDStk::Optional{}; + } + + // (index/label/Lookup), including Lookup (via the "has" function) + template< + class KEY, class = detail::isSearchKey, + class T = WHOLE, class = detail::isVector_t + > + decltype(auto) operator()(const KEY &key) const + { + if constexpr (detail::isLookupBoolReturn) { + // a bool + return whole(key); + } else { + // a reference + try { + return ref(key); + } catch (...) { + log::member("FieldPart::operator()(key)"); + throw; + } + } + } + + template< + class KEY, class = detail::isSearchKey, + class T = WHOLE, class = detail::isVector_t + > + decltype(auto) operator()(const KEY &key) + { + if constexpr (detail::isLookupBoolReturn) { + // a bool + return whole(key); + } else { + // a reference + return const_cast(std::as_const(*this)(key)); + } + } + + // [index/label/Lookup] + template< + class KEY, class = detail::isSearchKey, + class T = WHOLE, class = detail::isVector_t + > + decltype(auto) operator[](const KEY &key) const + { return (*this)(key); } + + template< + class KEY, class = detail::isSearchKey, + class T = WHOLE, class = detail::isVector_t + > + decltype(auto) operator[](const KEY &key) + { return (*this)(key); } + + // size() + // If T == vector + template< + class T = WHOLE, class = detail::isVector_t + > + std::size_t size() const + { + return whole.size(); + } + + // ------------------------ + // Setters + // Using std::optional + // ------------------------ + + // replace(value) + // If WHOLE == variant + template> + DERIVED &replace(const std::optional &opt) + { + if (opt) whole.replace(opt.value()); + return whole.parent; + } + + // operator()(value) + template, int> = 0> + DERIVED &operator()(const std::optional &opt) + { + return replace(opt); + } + + // operator=(value) + template, int> = 0> + FieldPart &operator=(const std::optional &opt) + { + return replace(opt), *this; + } + + // add(value) + // If WHOLE == vector + template> + FieldPart &add(const std::optional &opt) + { + if (opt) whole.add(opt.value()); + return *this; + } + + // operator+=(value) + template> + DERIVED &operator+=(const std::optional &opt) + { + return add(opt); + } + + // replace(index/label/Lookup, element) + // If WHOLE == vector + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t> + DERIVED &replace(const KEY &key, const std::optional &opt) + { + if (opt) whole(key,opt.value()); + return whole.parent; + } + + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t> + DERIVED &operator()(const KEY &key, const std::optional &opt) + { + return replace(key,opt); + } + + // ------------------------ + // Setters + // Using GNDStk::Optional + // ------------------------ + + // replace(value) + // If WHOLE == variant + template> + DERIVED &replace(const GNDStk::Optional &opt) + { + if (opt) whole.replace(opt.value()); + return whole.parent; + } + + // operator()(value) + template, int> = 0> + DERIVED &operator()(const GNDStk::Optional &opt) + { + return replace(opt); + } + + // operator=(value) + template, int> = 0> + FieldPart &operator=(const GNDStk::Optional &opt) + { + return replace(opt), *this; + } + + // add(value) + // If WHOLE == vector + template> + FieldPart &add(const GNDStk::Optional &opt) + { + if (opt) whole.add(opt.value()); + return *this; + } + + // operator+=(value) + template> + DERIVED &operator+=(const GNDStk::Optional &opt) + { + return add(opt); + } + + // replace(index/label/Lookup, element) + // If WHOLE == vector + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t> + DERIVED &replace(const KEY &key, const GNDStk::Optional &opt) + { + if (opt) whole(key,opt.value()); + return whole.parent; + } + + template< + class KEY, class = detail::isSearchKeyRefReturn, + class T = WHOLE, class = detail::isVector_t> + DERIVED &operator()(const KEY &key, const GNDStk::Optional &opt) + { + return replace(key,opt); + } + + // ------------------------ + // Assignment + // ------------------------ + + // Intentional: don't assign [referenced] whole; doing so would be wrong + FieldPart &operator=(const FieldPart &) { return *this; } + FieldPart &operator=(FieldPart &&) { return *this; } +}; // class FieldPart + + +// ----------------------------------------------------------------------------- +// wrapper +// This doesn't really need to be defined within class Component, but it's used +// only in that context, so might as well be. +// ----------------------------------------------------------------------------- + +// This class is used in the context of parameters in certain constructors +// of Component-derived classes that we create with the GNDStk Code Generator. +// It helps to regularize and simplify the process of providing default values +// to those parameters, and in doing so, it gives the constructors in question +// a more streamlined, less bulky look and feel. We could do without it, but +// we like the improved appearance it facilitates. Note: wrapper is formulated +// in such a way that it shouldn't cause any issues with the py::init<...> and +// py::arg(...) material in our pybind11-based Python binding code. If it ever +// proves to cause any trouble in that respect, we'll reconsider using it. + +template +struct wrapper { + T value; + + // wrapper(from) + template< + class FROM = T, + class = std::enable_if_t< + std::is_constructible_v || std::is_convertible_v + > + > + wrapper(const FROM &v = FROM{}) : + value(T(v)) + { } + + // wrapper(initializer_list) + // If T == vector + template< + class TEE = T, + class = std::enable_if_t::value> + > + wrapper(const std::initializer_list &v) : + value(v) + { } + + // wrapper(optional::value_type) + // If T == std::optional or T == GNDStk::Optional + template>> + wrapper(const typename TEE::value_type &v) : + value(v) + { } + + // wrapper(nullopt_t) + // If T == std::optional or T == GNDStk::Optional + template>> + wrapper(const std::nullopt_t &v) : + value(v) + { } + + // Conversions + operator const T &() const { return value; } + operator T &() { return value; } +}; // class wrapper + + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +private: + +// ------------------------ +// fieldAddress +// ------------------------ + +template +void *fieldAddress(T &value) +{ + return &value; +} + +template +void *fieldAddress(Field &field) +{ + return &field(); +} + +// ------------------------ +// stripField +// ------------------------ + +template +struct stripField { + using type = T; +}; + +template +struct stripField> { + using type = T; +}; + +public: diff --git a/src/GNDStk/Component/src/finish.hpp b/src/GNDStk/Component/src/finish.hpp index 864f5d5bf..1f5c759f9 100644 --- a/src/GNDStk/Component/src/finish.hpp +++ b/src/GNDStk/Component/src/finish.hpp @@ -18,8 +18,8 @@ advised to call a finish() as well, or to achieve the necessary effect in some other manner. 2. These also provide a means by which derived-class constructors that are built -by our autogeneration tool can run additional code that someone's customization -of the autogenerated class might need. +by our autogeneration tool can run additional code that someone's customizations +of their autogenerated classes might need. The second thing is achieved in the following way. Autogenerated constructors each call one of the finish() functions. Each finish() function first does what @@ -32,9 +32,9 @@ thus can, but does not need to, provide a construct(). Arguments are received where (1) the derived-class constructor receives the argument, but (2) the argument is transitory - it's used in the constructor, -but it doesn't go into the autogenerated "content" struct in the derived class. -(If it did go into the content struct then we'd simply extract it from there, -instead of having finish() receive it as a parameter.) +but it doesn't go into a generated field in the derived class. (If it did go +into a generated field, then we'd simply extract it from there, instead of +having finish() receive it as a parameter.) Specifically, the constructors in the auto-generated classes call: @@ -48,11 +48,11 @@ Specifically, the constructors in the auto-generated classes call: Constructor from a Node: Component::finish(the Node) - Constructors involving a vector of "body text" data: + Constructors involving a vector of block data: Component::finish(the vector) Note: In the last case, we're speaking of a vector that's specifically for -body text, not a vector that might be there for a different reason. +block data, not a vector that might be there for a different reason. */ @@ -61,20 +61,13 @@ body text, not a vector that might be there for a different reason. // construct() stubs // Override in a derived-class customization, to have custom code be run. // Cases: (), (DERIVED), (Node), (vector). -// Derived-class customizations should always return void. // ----------------------------------------------------------------------------- void construct() { } -void construct(const DERIVED &) { } -void construct(const Node &) { } - -// The next one returns bool, but customizations in DERIVED should return void, -// just as customizations to the above three construct() function variations -// return void. We use bool, here, for technical reasons, relating to the test -// used in the template finish() function (as opposed to the non-template cases) -// to determine whether or not someone has provided a custom construct(). -template>> -bool construct(const std::vector &) { return true; } +void construct(const DERIVED &) { derived().construct(); } +void construct(const Node &) { derived().construct(); } +template +void construct(const std::vector &) { derived().construct(); } @@ -88,13 +81,13 @@ bool construct(const std::vector &) { return true; } void finish() { - // If hasBodyText == true (else no-op), have Component's BodyText base + // If hasBlockData == true (else no-op), have Component's BlockData base // get length, start, and valueType, as available, from the derived class - if constexpr (hasBodyText) - body::pullFromDerived(derived()); + if constexpr (hasBlockData) + BLOCKDATA::pullFromDerived(derived()); - // Based on the derived class' keys(), locate and sort derived-class fields - // that are vectors, with vector elements that have index and/or label. + // Automatically locate and sort derived-class fields that are vectors + // with elements that have index and/or label. sort(); // construct @@ -109,19 +102,14 @@ void finish() void finish(const DERIVED &other) { // length, start, valueType - if constexpr (hasBodyText) - body::pullFromDerived(derived()); + if constexpr (hasBlockData) + BLOCKDATA::pullFromDerived(derived()); // derived-class vector fields sort(); // construct - void (Component::*stub)(const DERIVED &) = &Component::construct; - void (DERIVED::*custom)(const DERIVED &) = &DERIVED::construct; - if (custom != stub) - derived().construct(other); - else - derived().construct(); + derived().construct(other); } @@ -131,28 +119,7 @@ void finish(const DERIVED &other) void finish(const Node &node) { - // Read fields from the Node into the derived object. This applies the keys() - // multi-query in the derived class, and also runs BodyText::fromNode() if - // the Node has body text, in order to get the Node's string of "body text". - fromNode(node); - - if constexpr (hasBodyText) { - // length, start, valueType - body::pullFromDerived(derived()); - // make vector - body::get(); - } - - // derived-class vector fields - sort(); - - // construct - void (Component::*stub)(const Node &) = &Component::construct; - void (DERIVED::*custom)(const Node &) = &DERIVED::construct; - if (custom != stub) - derived().construct(node); - else - derived().construct(); + read(node); } @@ -160,22 +127,24 @@ void finish(const Node &node) // finish(vector) // ------------------------ -template>> +template< + class T, + class = std::enable_if_t> +> void finish(const std::vector &vector) { - // assign from the vector - body::operator=(vector); + if constexpr (hasBlockData) { + // assign from the vector + BLOCKDATA::operator=(vector); - // length, start, valueType: push back up to derived, - // as they would have been computed above in operator=. - body::pushToDerived(derived()); + // length, start, valueType: push back up to derived, + // as they would have been computed above in operator=. + BLOCKDATA::pushToDerived(derived()); + } // derived-class vector fields sort(); // construct - if constexpr (std::is_same_v) - derived().construct(vector); - else - derived().construct(); + derived().construct(vector); } diff --git a/src/GNDStk/Component/src/forward.hpp b/src/GNDStk/Component/src/forward.hpp new file mode 100644 index 000000000..4886f7f2a --- /dev/null +++ b/src/GNDStk/Component/src/forward.hpp @@ -0,0 +1,187 @@ + +/* +Remark about terminology. + +Elsewhere in GNDStk, we often refer to objects of type Meta or Child as "keys". + +However, in the context of classes generated by our code generator, and in +general when working with classes that derive from Component, we sometimes use +the term "key" to mean some kind of "lookup key". + +Code that appears later in this file involves both of the above contexts. So, +in order to keep confusion to a minimum, we'll write "MC" or "mc" (where we +might otherwise write "KEY" or "key") when Meta/Child are involved, and KEY +or "key" where lookup keys are involved. + +Optionally continue reading, if you care.... + +Example. Say that an object of class Element has a vector, where each +object of type Isotope contains an int called mass_number. In this scenario, the +code generator will create mechanisms by which we can look up a specific Isotope +in an Element's vector, given the wanted Isotope's mass_number. + +We'll also get functionality, via functions called replace(), to look up and +replace an isotope, given a lookup key like mass_number. Here's an admittedly +very contrived example of how such a replace function might be called: + + // Helium! + Element He("He",2); // element #2 + + // Give it some Isotopes + He += Isotope(2); // <== oops, Helium 2 doesn't really exist + He += Isotope(4); + + // We meant to create Helium 3, not Helium 2, so let's replace the bad value + He.isotope.replace(mass_number(2),Isotope(3)); + +The last line will search through He.isotope (a vector), find the +element (the Isotope) with mass_number == 2, and replace that entire Isotope +with an Isotope that has the correct mass_number. (While the above example is +very contrived, one could imagine a real-world example in which we look up an +object that's known to have faulty data, and replace it with a fixed object.) + +The replace() function later in this file allows the last line of code, above, +to be rewritten with something shorter: + + // He.replace, not He.isotope.replace + He.replace(mass_number(2),Isotope(3)); + +in the event that the code can determine, unambiguously, via some SFINAE +shenanigans, that we must mean He.isotope, not other member data that an +Element (like He) might happen to contain. + +To make a long story short (glossing over the fact that the above story is +perhaps already somewhat long :-/), the term "key" will relate to the mass +number lookup here. Whereas, Meta/Child objects are involved in the process +of examining what metadatum and child-node member data appear in class Element, +this examination being to determine that He.isotope is intended. +*/ + + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +private: + +// Matches +template +static inline constexpr bool Matches = + detail::MatchesExact ::count == 1 || + detail::MatchesViable::count == 1; + +// added +// MC = Meta or Child +template +bool added( + const FROM &elem, const MC &mc, + const bool exact, const std::size_t n +) { + // Silence warnings that seem to crop up with some compilers, when neither + // of the below constexpr ifs passes. + (void)n; + + // Remark. The below conditional code (involving both runtime and constexpr + // ifs) doesn't simplify in what may seem like obvious ways. Note that bool + // exact is runtime, and came from looking over all types in the caller's + // fold expression. For a given type from the fold expression, either or both + // of the following constexpr ifs may fail, and their bodies not make sense + // or not be something we'd necessarily want to call. (Specifically, if exact + // and viable matches both == 1, and the viable match is found before the + // exact one, we want to skip the [return setter] and wait for the exact.) + using T = std::decay_t; + if ( exact) if constexpr (detail::isMatchExact ::count) + return setter(*(T *)links[n],elem), true; + if (!exact) if constexpr (detail::isMatchViable::count) + return setter(*(T *)links[n],elem), true; + return false; +} + +// replaced +template +bool replaced( + const KEY &key, const FROM &elem, const MC &mc, + const bool exact, const std::size_t n +) { + using T = std::decay_t; + if ( exact) if constexpr (detail::isMatchExact ::count) + return getter(*(T *)links[n],key) = elem, true; + if (!exact) if constexpr (detail::isMatchViable::count) + return getter(*(T *)links[n],key) = elem, true; + return false; +} + +public: + + +// ----------------------------------------------------------------------------- +// add(element) +// ----------------------------------------------------------------------------- + +// add +template>> +DERIVED &add(const FROM &elem) +{ + // match exact? (else viable, per SFINAE requirement) + using TUP = decltype(Keys().tup); + const bool exact = detail::MatchesExact::count == 1; + + // scan until match + std::apply( + [this,&elem,exact](const auto &... mc) { + std::size_t n = 0; bool found = false; + ((found || (found = this->added(elem,mc,exact,n++))), ...); + }, + Keys().tup + ); + + // done + return derived(); +} + +// () +template>> +DERIVED &operator()(const FROM &elem) { return add(elem); } + +// += +template>> +DERIVED &operator+=(const FROM &elem) { return add(elem); } + + +// ----------------------------------------------------------------------------- +// replace(index/label/Lookup, element) +// ----------------------------------------------------------------------------- + +// replace +template< + class KEY, class = detail::isSearchKeyRefReturn, + class FROM, class = std::enable_if_t> +> +DERIVED &replace(const KEY &key, const FROM &elem) +{ + // match exact? (else viable, per SFINAE requirement) + using TUP = decltype(Keys().tup); + const bool exact = detail::MatchesExact::count == 1; + + // scan until match + std::apply( + [this,&key,&elem,exact](const auto &... mc) { + std::size_t n = 0; bool found = false; + ((found || (found = this->replaced(key,elem,mc,exact,n++))), ...); + }, + Keys().tup + ); + + // done + return derived(); +} + +// () +template< + class KEY, class = detail::isSearchKeyRefReturn, + class FROM, class = std::enable_if_t> +> +DERIVED &operator()(const KEY &key, const FROM &elem) +{ + return replace(key,elem); +} diff --git a/src/GNDStk/Component/src/fromNode.hpp b/src/GNDStk/Component/src/fromNode.hpp index f7760b4ca..091d417a6 100644 --- a/src/GNDStk/Component/src/fromNode.hpp +++ b/src/GNDStk/Component/src/fromNode.hpp @@ -1,8 +1,124 @@ +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +private: + +// ------------------------ +// Transfer Meta +// ------------------------ + +template +void transferMeta( + const Node &node, DEST &to, + const Meta &key +) { + node.meta(to, key); +} + + +// ------------------------ +// Transfer Child +// ------------------------ + +template +void transferChild( + const Node &node, DEST &to, + const Child &key +) { + // Absolutely respect any non-default converter in the Child key, by doing + // a Core Interface child-node query in the usual manner. Note that we can + // still use the more-efficient "node.child(to,key)" rather than the less- + // efficient "to = node(key)", because, in the present context, we do have + // a specific destination for the query result. + if constexpr (!std::is_same_v) { + node.child(to, key); + return; + } + + // In the following conditionals, assume that Foo derives from Component, + // while Bar does not, i.e.: + // Foo: Component + // Bar + // Remarks, below, reflect various situations. + + if constexpr (detail::isDerivedFromComponent_v) { + // *** Foo + // Derives from Component, so we know that it has, via Component, + // a .read(node) function, which should be most efficient to use + // for "conversion" of the Node to a Foo. + node.child(to, key/[](const Node &n, DEST &to) { to.read(n); }); + + } else if constexpr (detail::isOptional) { + using OPT = typename DEST::value_type; // type the optional may contain + + if constexpr (detail::isVector_v) { + using ELEM = typename OPT::value_type; // vector element type + if constexpr (detail::isDerivedFromComponent_v) { + // *** optional> + if (!to.has_value()) + to = OPT{}; + node.child(to, key/[](const Node &n, ELEM &e) { e.read(n); }); + } else { + // *** optional> + node.child(to, key); + } + } else { + if constexpr (detail::isDerivedFromComponent_v) { + // *** optional + node.child(to, key/[](const Node &n, OPT &to) { to.read(n); }); + } else { + // *** optional + node.child(to, key); + } + } + } else if constexpr (detail::isVector_v) { + using ELEM = typename DEST::value_type; // vector element type + if constexpr (detail::isDerivedFromComponent_v) { + // *** vector + node.child(to, key/[](const Node &n, ELEM &e) { e.read(n); }); + } else { + // *** vector + node.child(to, key); + } + } else { + // *** Bar + node.child(to, key); + } +} + + +// ------------------------ +// Transfer +// ------------------------ + +template +void transfer(const std::size_t n, const Node &node, const KEY &key) +{ + using DEST = typename detail::queryResult::type; + DEST &to = *(DEST *)links[n]; + + if constexpr (detail::IsMeta::value) + transferMeta(node, to, key); + else if constexpr (detail::IsChild::value) + transferChild(node, to, key); + else { + // todo Does this situation involve only the pair case? + // I think that may be true, given the way keys are placed into keytuples; + // see or.hh. In this case, are there some optimizations we can do here, + // as we do in transferChild above? + to = node(key); + } +} + + // ----------------------------------------------------------------------------- // Component::fromNode(Node) // ----------------------------------------------------------------------------- +public: + // Retrieve a Node's data, and, via the links, get it into the fields in the // derived-class object. We'd have preferred to call this in the constructor, // so that users wouldn't need to call it directly in the constructors @@ -21,41 +137,62 @@ void fromNode(const Node &node) { try { // does the node have the name we expect? - if (node.name != DERIVED::GNDSName()) { + if (node.name != DERIVED::NODENAME()) { log::error( - "Name \"{}\" in Node sent to Component::fromNode() is not the " - "expected GNDS name \"{}\"", - node.name, DERIVED::GNDSName() + "Node name \"{}\" is not the expected name \"{}\"", + node.name, DERIVED::NODENAME() ); throw std::exception{}; } - if constexpr (std::is_same_v>) { - // consistency check; then nothing further to do - assert(0 == links.size()); - } else { - // retrieve the node's data by doing a multi-query - const auto tup = node(toKeywordTup(DERIVED::keys())); - - // consistency check - assert(std::tuple_size::value == links.size()); - - // apply links: - // Node ==> derived-class data - // Below, each apply'd "result" is one particular element - one - // retrieved value - from the above multi-query on the node. - std::apply( - [this](const auto &... result) { - std::size_t n = 0; - ((*(std::decay_t *)links[n++] = result), ...); - }, - tup - ); - } + // consistency check + assert(std::tuple_size_v == links.size()); + + // apply links: + // Node ==> derived-class data + std::apply( + [this,&node](const auto &... key) { + std::size_t n = 0; (this->transfer(n++, node, key), ...); + }, + Keys().tup + ); + + // block data + if constexpr (hasBlockData) + BLOCKDATA::fromNode(node); - // body text, a.k.a. XML "pcdata" (plain character data), if any - if constexpr (hasBodyText) - body::fromNode(node); + // ------------------------ + // If we're putting certain + // instrumentation into the + // Component interface... + // ------------------------ + + #ifdef GNDSTK_INSTRUMENT + { + // context + std::vector ancestors; + for (const Node *n = &node; n; n = &n->parent()) + ancestors.push_back(n->name); + + // metadata + for (const auto &m : node.metadata) + if (!beginsin(m.first, "marked-")) { + std::cout << color::custom::green << "missed: metadatum "; + for (size_t i = ancestors.size(); i--; ) + std::cout << ancestors[i] << "."; + std::cout << m.first << color::reset << std::endl; + } + + // children + for (const auto &c : node.children) + if (!c->marked) { + std::cout << color::custom::blue << "missed: child node "; + for (size_t i = ancestors.size(); i--; ) + std::cout << ancestors[i] << "."; + std::cout << c->name << color::reset << std::endl; + } + } + #endif } catch (...) { log::member("Component.fromNode(Node(\"{}\"))", node.name); diff --git a/src/GNDStk/Component/src/getter.hpp b/src/GNDStk/Component/src/getter.hpp index 1f8228830..3c0738bc5 100644 --- a/src/GNDStk/Component/src/getter.hpp +++ b/src/GNDStk/Component/src/getter.hpp @@ -1,117 +1,121 @@ -// The getter() functions of class Component get some names from the derived -// class (those are used when printing diagnostics, if applicable), and then -// call getter() functions in the detail:: namespace to do most of the work. -// -// The motivation for having the following at all is to simplify the retrieval, -// in the derived-class getters, of certain information in the content{} struct -// of the derived class object. For simple data, e.g. an int or a std::string -// in the derived class' content struct, a derived-class getter will simply -// do a "return content.something", because nothing more complicated is needed. -// So, the below functions involve circumstances where something more involved -// needs to be done. See the various remarks below for more information. +// Component::getter() +// These retrieve names from the derived class (for use in printing diagnostics, +// if applicable), then call detail::getter() functions to do most of the work. // ----------------------------------------------------------------------------- -// (field, key, name) -// FIELD in this context is either a vector or an optional, and KEY -// is either an integral index or a string label. (If FIELD were just a plain -// data type, not an [optional] vector, then there would be no reason to bother -// with a getter() function for it; we'd just return content.field in the -// derived class, instead of calling getter() to do something more complicated. -// And, besides, the fact that we're looking up by index or label suggests that -// we're dealing with a vector, not something simple like an int or a string.) +// getter(vector, key) +// getter(optional, key) +// Remark: while two getter() functions that appear later in this file work +// specifically on a vector, those require that the caller provide +// a template argument. The following two can, in fact, also be called with +// vector. Also, note that depending on which detail::getter() these +// forward to, the return type might be a reference to something, or might be +// a bool. Hence the decltype(auto) return type. // ----------------------------------------------------------------------------- // const -template // KEY: for index or label -const auto &getter( - const FIELD &field, - const KEY &key, - const std::string &fieldName +template< + class VEC, class KEY, class = detail::isSearchKey, + class = std::enable_if_t< + detail::isVector_v || + detail::isOptionalVector_v> +> +decltype(auto) getter( + const VEC &vec, // vector, or optional vector + const KEY &key, // index, label, or Lookup + const std::string &fieldName = "" ) const { - return detail::getter( - field, key, - DERIVED::namespaceName(), DERIVED::className(), fieldName - ); + return detail::getter(vec, key, Namespace(), Class(), fieldName); } // non-const -template -auto &getter( - FIELD &field, +template< + class VEC, class KEY, class = detail::isSearchKey, + class = std::enable_if_t< + detail::isVector_v || + detail::isOptionalVector_v> +> +decltype(auto) getter( + VEC &vec, const KEY &key, - const std::string &fieldName + const std::string &fieldName = "" ) { - return detail::getter( - field, key, - DERIVED::namespaceName(), DERIVED::className(), fieldName - ); + using RET = decltype( + std::as_const(*this).template getter(vec, key, fieldName)); + + if constexpr (std::is_reference_v) + return const_cast &>( + std::as_const(*this).template getter(vec, key, fieldName)); + else + return std::as_const(*this).template getter(vec, key, fieldName); } // ----------------------------------------------------------------------------- -// (variant, name) -// These, in contrast to the getter()s above, don't involve a vector or an -// optional vector, or an index or a label. We bother having these only because -// of the (admittedly small, in this case) extra complexity of checking that -// the variant holds the requested alternative, and of producing diagnostics -// if it doesn't. +// getter(variant) +// The caller must specify RETURN // ----------------------------------------------------------------------------- // const -template +template< + class RETURN, class... Ts, + class = std::enable_if_t>> +> const RETURN *getter( const std::variant &var, - const std::string &fieldName + const std::string &fieldName = "" ) const { - return detail::getter( - var, - DERIVED::namespaceName(), DERIVED::className(), fieldName - ); + return detail::getter(var, Namespace(), Class(), fieldName); } // non-const -template +template< + class RETURN, class... Ts, + class = std::enable_if_t>> +> RETURN *getter( std::variant &var, - const std::string &fieldName + const std::string &fieldName = "" ) { return const_cast( - std::as_const(*this).template - getter(std::as_const(var), fieldName) + std::as_const(*this).template getter(var, fieldName) ); } // ----------------------------------------------------------------------------- -// (vector, key, name) -// The motivation for these essentially amounts to the combined motivations -// for the above two sets of getter() functions. +// getter(vector, key) +// The caller must specify RETURN // ----------------------------------------------------------------------------- // const -template +template< + class RETURN, class KEY, class... Ts, + class = detail::isSearchKey, + class = std::enable_if_t>> +> const RETURN *getter( - const std::vector> &var, + const std::vector> &vecvar, const KEY &key, - const std::string &fieldName + const std::string &fieldName = "" ) const { - return detail::getter( - var, key, - DERIVED::namespaceName(), DERIVED::className(), fieldName - ); + return detail::getter(vecvar, key, Namespace(), Class(), fieldName); } // non-const -template +template< + class RETURN, class KEY, class... Ts, + class = detail::isSearchKey, + class = std::enable_if_t>> +> RETURN *getter( - std::vector> &var, + std::vector> &vecvar, const KEY &key, - const std::string &fieldName -) const { + const std::string &fieldName = "" +) { return const_cast( - std::as_const(*this).template - getter(std::as_const(var), key, fieldName) + std::as_const(*this).template getter(vecvar, key, fieldName) ); } diff --git a/src/GNDStk/Component/src/print.hpp b/src/GNDStk/Component/src/print.hpp new file mode 100644 index 000000000..d210ef78d --- /dev/null +++ b/src/GNDStk/Component/src/print.hpp @@ -0,0 +1,332 @@ + +// ----------------------------------------------------------------------------- +// REMARK +// Regarding "write" vs. "print", and newlines +// ----------------------------------------------------------------------------- + +/* +Python has print(), and we anticipate having many Python-aware users. First and +foremost, this is why we provide these print() functions. + +Elsewhere, we've given Component a set of write() (not print()) functions that +mirror Node's functions of the same name. These first make use of Component's +ability to convert objects of its derived classes to Node, then they call Node's +write() functions. Node's write() functions can do a number of things, such as +writing to XML, or to GNDStk's debug format. + +Someone who wishes to print the contents of a Component-derived class may prefer +to see our print() function's "prettyprinting" output. Not XML, certainly not +our internal debug format, and not other formats our Node's write()s support. + +The name print(), then, not only aligns with what Python users might expect, but +also reflects a difference from Node's write() functions. In particular, write() +behaves as it does for Node, while print() does something completely different: +it prettyprints to standard output. + +Our print() functions also print a newline at the end - which a user probably +expects to see when prettyprinting. + +The write() functions, being arguably more "low level", don't emit that newline, +and shouldn't. Just as C++ doesn't automatically print something basic (an int, +for example, or a floating-point number) with a newline, neither should a well- +mannered system for writing class objects. Whether a newline is really wanted, +or not wanted, depends on context. + +If you write std::cout << 1.23 << std::endl, you expect one line, with "1.23", +followed by a newline via std::endl, then the cursor ready at the beginning of +the very next line. Write std::cout << obj << std::endl, where obj is of some +user-defined type whose stream output operator already prints its own newline, +and the cursor will end up *two* lines down, after an intervening blank line. +It may seem convenient for "large" objects to print with their own newline, but +doing so creates inconsistent behavior between them and more-basic object types. +Inconsistencies beget unpredictability. + +Moreover, Component-derived classes often contain instances of other Component- +derived classes. An enclosing object should place its own newlines - only where +appropriate, and not where not appropriate - between its constituent parts. If +those parts did their own thing in this respect, they'd stymie the ability of +the enclosing class to do the right thing. +*/ + +// Helper +template +const std::string getName(const KEY &key, const std::size_t n) const +{ + return detail::getName(key) == special::comment + ? special::comment + : printMode == PrintMode::cpp + ? derived(). FIELDNAMES()[n] + : derived().PYTHONNAMES()[n]; +} + + +// ----------------------------------------------------------------------------- +// print(ostream,level) +// Low-level version, possibly building on other Component-derived objects. +// Doesn't print a trailing newline. +// ----------------------------------------------------------------------------- + +std::ostream &print( + std::ostream &os, const int level, + const std::string &label = "", + const std::string &labelColor = color::component +) const { + // Name of the class is as follows, in case we want to use it for anything... + // const std::string type = detail::fullName(Namespace(), Class()); + + try { + // Consistency check + // todo Eventually remove this, or make it a proper error, + // as it really shouldn't happen at all. + assert(std::tuple_size_v == links.size()); + + // ------------------------ + // Indent, header, newline + // ------------------------ + + detail::indentString( + os, + level, + detail::colorize(label == "" ? "{" : label+" {", labelColor) + ); + os << std::endl; + + // ------------------------ + // For alignment + // ------------------------ + + // Compute maximum length of key names, if aligning. Note that we + // could - but don't - take into account that keys associated with + // optional or Defaulted values *might* not in fact show up in the + // final printed text. In such cases, and if values of those types + // happen to have longer names, then the printing that does appear + // might use more spacing than it really needs to. By choosing not + // to factor this in, on a case-by-case basis, all objects of this + // particular Component<...> type will print with consistent spacing. + // We prefer this behavior, and its code is also slightly simpler. + std::size_t maxlen = 0; + + if (GNDStk::align) { + std::apply( + [this,&maxlen](const auto &... key) + { + using namespace detail; + std::size_t n = 0; + (( + n++, + maxlen = std::max( + maxlen, + pprintAlign{}(key,links[n-1]) + ? this->getName(key,n-1).size() + : 0 + ) + ), ... ); + }, + Keys().tup + ); + } + + // ------------------------ + // Apply links + // ------------------------ + + // derived-class fields ==> print + std::apply( + [this,&os,&level,maxlen](const auto &... key) + { + using namespace detail; + std::size_t n = 0; + ((( + n++, // not in any [n-1] below, lest undefined evaluation order + // indent, value, newline + printComponentPart( + // os + os, + // level + level+1, + // maxlen + pprintAlign{}(key,links[n-1]) + ? maxlen + : 0, + // label + this->getName(key,n-1), + // value + *( + typename queryResult>::type + *)links[n-1] + ) + ) && (os << std::endl) // no if()s in fold expressions :-/ + ), ... ); + }, + Keys().tup + ); + + // ------------------------ + // Customizations, if any + // ------------------------ + + // Custom derived-class print()s. + // To be recognized here, derived-class print() functions must be public, + // and have signatures that are *exactly* as we expect, including their + // constness. + if constexpr (detail::hasPrintTwoArg) { + // Derived class has: + // std::ostream &print(std::ostream &os, const int level) const; + // and handles the indentation level in its own way; we won't here. + std::ostringstream tmp; + derived().print(tmp,level+1); + const std::string &str = tmp.str(); + + std::size_t size = str.size(); + if (size) { + // expect that customizations may have spurious newlines :-/ + if (str[size-1] == '\n') size--; + for (std::size_t i = 0; i < size; ++i) + os << str[i]; + os << std::endl; + } + } else if constexpr (detail::hasPrintOneArg) { + // Derived class has: + // std::ostream &print(std::ostream &os) const; + // and we'll detect newlines and handle indentation automatically. + std::ostringstream tmp; + derived().print(tmp); + const std::string &str = tmp.str(); + + std::size_t size = str.size(); + if (size) { + // remark as above + if (str[size-1] == '\n') size--; + if (size) + os << indentTo(level+1); + for (std::size_t i = 0; i < size; ++i) + os << str[i] << (str[i] == '\n' ? indentTo(level+1) : ""); + os << std::endl; + } + } + + // ------------------------ + // BlockData, if any + // ------------------------ + + if constexpr (hasBlockData) + BLOCKDATA::print(os,level+1); + + // ------------------------ + // Indent, footer, + // NO trailing newline + // ------------------------ + + using namespace detail; + indentString( + os, level, + comments && label != "" + ? colorize("} " + colorize_comment(label), labelColor) + : colorize("}", labelColor) + ); + + } catch (...) { + log::member("Component.print() for {}", label); + throw; + } + + return os; +} + + +// ----------------------------------------------------------------------------- +// print() +// print(ostream) +// Print trailing newlines. +// ----------------------------------------------------------------------------- + +// We'll give these const and non-const versions (one would normally expect only +// const versions of print functions), and with a "builder pattern" that mirrors +// that of the setters that GNDStk's code generator gives its generated classes. +// This way, someone can prettyprint an object while it's being built, builder +// style. Some users may find this to be useful for visualizing what's happening +// as they create an object. + +// const +const DERIVED &print(std::ostream &os = std::cout) const +{ + print(os,0) << std::endl; + return *static_cast(this); +} + +// non-const +DERIVED &print(std::ostream &os = std::cout) +{ + print(os,0) << std::endl; + return *static_cast(this); +} + + +// ----------------------------------------------------------------------------- +// Component::xml() +// Component::json() +// Component::hdf5() +// Component::debug() +// Print trailing newlines. +// +// Shortcuts: like write(), but (1) in the given format, (2) to std::cout +// by default, and (3) with a trailing newline, print()-style. In view of +// points (2) and (3), these resemble print() more than write(), so I put +// them here, not in the file that defines the write() functions. +// ----------------------------------------------------------------------------- + +// ------------------------ +// ostream, decl +// ------------------------ + +// xml +std::ostream &xml(std::ostream &os = std::cout, const bool decl = false) const +{ + return write(os,"xml",decl) << std::endl, os; +} + +// json +std::ostream &json(std::ostream &os = std::cout, const bool decl = false) const +{ + return write(os,"json",decl) << std::endl, os; +} + +// hdf5 +std::ostream &hdf5(std::ostream &os = std::cout, const bool decl = false) const +{ + return write(os,"hdf5",decl) << std::endl, os; +} + +// debug +std::ostream &debug(std::ostream &os = std::cout, const bool decl = false) const +{ + return write(os,"debug",decl) << std::endl, os; +} + +// ------------------------ +// decl, ostream +// ------------------------ + +// xml +std::ostream &xml(const bool decl, std::ostream &os = std::cout) const +{ + return xml(os,decl); +} + +// json +std::ostream &json(const bool decl, std::ostream &os = std::cout) const +{ + return json(os,decl); +} + +// hdf5 +std::ostream &hdf5(const bool decl, std::ostream &os = std::cout) const +{ + return hdf5(os,decl); +} + +// debug +std::ostream &debug(const bool decl, std::ostream &os = std::cout) const +{ + return debug(os,decl); +} diff --git a/src/GNDStk/Component/src/read.hpp b/src/GNDStk/Component/src/read.hpp new file mode 100644 index 000000000..bb9489acc --- /dev/null +++ b/src/GNDStk/Component/src/read.hpp @@ -0,0 +1,92 @@ + +// ----------------------------------------------------------------------------- +// Read this object, in-place, from a Node +// ----------------------------------------------------------------------------- + +void read(const Node &node) +{ + // todo Maybe we don't really need/want a separate fromNode() function...? + + // Read fields from the Node into the derived object. This applies the KEYS() + // multi-query in the derived class, and also runs BlockData::fromNode() - if + // the Node has block data - in order to get the Node's string of block data. + fromNode(node); + + if constexpr (hasBlockData) { + // length, start, valueType + BLOCKDATA::pullFromDerived(derived()); + // make vector + BLOCKDATA::get(); + } + + // derived-class vector fields + sort(); + + // construct + derived().construct(node); +} + + +// ----------------------------------------------------------------------------- +// Component::read() +// Via Node, and using Node's available read() functions. +// So, autogenerated classes can directly use .read(...). +// ----------------------------------------------------------------------------- + +// ------------------------ +// stream, with enum- or +// string-based file type +// ------------------------ + +// read(istream, FileType) +std::istream &read( + std::istream &is, + const FileType format = FileType::guess, + const bool decl = false +) { + Node node; + std::istream &ret = node.read(is, format, decl); + read(node); + return ret; +} + +// read(istream, string) +std::istream &read( + std::istream &is, + const std::string &format, + const bool decl = false +) { + Node node; + std::istream &ret = node.read(is, format, decl); + read(node); + return ret; +} + +// ------------------------ +// filename, with enum- or +// string-based file type +// ------------------------ + +// read(filename, FileType) +bool read( + const std::string &filename, + const FileType format = FileType::guess, + const bool decl = false +) { + Node node; + bool ret = node.read(filename, format, decl); + read(node); + return ret; +} + +// read(filename, string) +bool read( + const std::string &filename, + const std::string &format, + const bool decl = false +) { + Node node; + bool ret = node.read(filename, format, decl); + read(node); + return ret; +} diff --git a/src/GNDStk/Component/src/setter.hpp b/src/GNDStk/Component/src/setter.hpp new file mode 100644 index 000000000..a03cb1a57 --- /dev/null +++ b/src/GNDStk/Component/src/setter.hpp @@ -0,0 +1,54 @@ + +// Like getter.hpp, but to help with *setters* in Component-derived classes. + +// ------------------------ +// vector +// ------------------------ + +// push_back into the vector. +template< + class T, class FROM, + class = std::enable_if_t< + std::is_constructible_v || std::is_convertible_v + > +> +static void setter(std::vector &vec, const FROM &value) +{ + vec.push_back(T(value)); +} + + +// ------------------------ +// optional +// ------------------------ + +// Create an empty vector in the optional if it has no value, then +// push_back into the vector. + +// std::optional +template< + class T, class FROM, + class = std::enable_if_t< + std::is_constructible_v || std::is_convertible_v + > +> +static void setter(std::optional> &opt, const FROM &value) +{ + if (!opt.has_value()) + opt = std::vector{}; + opt->push_back(T(value)); +} + +// GNDStk::Optional +template< + class T, class FROM, + class = std::enable_if_t< + std::is_constructible_v || std::is_convertible_v + > +> +static void setter(GNDStk::Optional> &opt, const FROM &value) +{ + if (!opt.has_value()) + opt = std::vector{}; + opt->push_back(T(value)); +} diff --git a/src/GNDStk/Component/src/sort.hpp b/src/GNDStk/Component/src/sort.hpp index 68dd7b309..5e4bf9b1b 100644 --- a/src/GNDStk/Component/src/sort.hpp +++ b/src/GNDStk/Component/src/sort.hpp @@ -5,31 +5,31 @@ void sort() { + if (!njoy::GNDStk::sort) + return; + try { - if constexpr (std::is_same_v>) { - // Consistency check; then nothing further to do - assert(0 == links.size()); - } else { - // Make tuple (of individual keys) from DERIVED::keys() - const auto tup = toKeywordTup(DERIVED::keys()).tup; + // Consistency check + assert(std::tuple_size_v == links.size()); - // Consistency check - assert(std::tuple_size::value == links.size()); + // Apply links + std::apply( + [this](const auto &... key) { + std::size_t n = 0; + ( + detail::sort( + *( + typename detail::queryResult< + std::decay_t + >::type + *)links[n++] + ), + ... + ); + }, + Keys().tup + ); - // Apply links - std::apply( - [this](const auto &... key) { - std::size_t n = 0; - ( - detail::sort( - *(std::decay_t *)links[n++] - ), - ... - ); - }, - tup - ); - } } catch (...) { log::member("Component.sort()"); throw; diff --git a/src/GNDStk/Component/src/toNode.hpp b/src/GNDStk/Component/src/toNode.hpp index 52c291d5b..e9a571b6d 100644 --- a/src/GNDStk/Component/src/toNode.hpp +++ b/src/GNDStk/Component/src/toNode.hpp @@ -1,43 +1,100 @@ +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +private: + +template +void node_add( + Node &node, const KEY &key, + const std::size_t n +) const { + using TYPE = typename detail::queryResult::type; + node.add(key, *(TYPE *)links[n]); +} + +// todo See if Child|"string" can be formulated without this std::pair +// business; doing so may simplify some things here and there, and we'll +// no longer need this... +template +void node_add( + Node &node, const std::pair &pair, + const std::size_t n +) const { + node_add(node,pair.first,n); +} + + // ----------------------------------------------------------------------------- // Component -// conversion to Node +// Conversion to Node. // ----------------------------------------------------------------------------- -// Normally we'd need just a const version of a conversion operator, and, if -// we needed a non-const version at all, it could build on the const version. -// A glitch in the present circumstances is that BodyText::toNode(), which is -// called from within these, splits const and non-const cases, and that needs -// to be preserved here. So, then, why does BodyText::toNode() have a non-const -// version? The issue is that in the non-const case, BodyText::toNode() may -// need to deal with a vector (not just an original "body text" string as may -// have been read into a const BodyText). And, dealing with a vector means -// computing a proper length, start, and valueType while doing toNode() - and -// pushing those up to the class derived from Component, as it's from that -// class that those fields are written to the Node. The need to compute proper -// values for those parameters is why we need the non-const case. (And we can't -// just make length etc. mutable in BodyText, as the length etc. in the derived -// class come into play too.) Maybe we'll work out a different way to handle -// all this, but for now, we have the following. - -// const -operator Node() const +public: + +explicit operator Node() const { + // Initialize a Node, with the necessary name + Node node(DERIVED::NODENAME()); + try { - #include "GNDStk/Component/src/toNodeBody.hpp" + // Handle block data, if applicable + if constexpr (hasBlockData) { + // GNDStk uses a #text metadatum of a #data child node for this + std::string &text = + node.add(special::data).add(special::text,"").second; + BLOCKDATA::toNode(text); + } + + // Write fields... + + // consistency check + assert(std::tuple_size_v == links.size()); + + // apply links: + // derived-class data ==> Node + // Below, each apply'd "key" is one value from DERIVED::KEYS(), and + // is a Meta, Child, or pair. The cast gives the + // underlying raw data type - int, say, or std::string - so that we + // can correctly use our generic void* link to a derived-class field. + std::apply( + [this,&node](const auto &... key) { + std::size_t n = 0; + ( + /* + node.add( + key, + *( + typename detail::queryResult< + std::decay_t + >::type + *)links[n++] + ), + */ + this->node_add(node,key,n++), ... + ); + }, + Keys().tup + ); } catch (...) { log::member("Component.operator Node() const"); throw; } + + return node; } -// non-const -operator Node() + +// ----------------------------------------------------------------------------- +// Component +// Conversion to Tree. +// Like conversion to Node, but with a proper root Node. +// ----------------------------------------------------------------------------- + +explicit operator Tree() const { - try { - #include "GNDStk/Component/src/toNodeBody.hpp" - } catch (...) { - log::member("Component.operator Node()"); - throw; - } + Tree tree; + tree.add(Node(*this)); + return tree; } diff --git a/src/GNDStk/Component/src/toNodeBody.hpp b/src/GNDStk/Component/src/toNodeBody.hpp deleted file mode 100644 index a5182a737..000000000 --- a/src/GNDStk/Component/src/toNodeBody.hpp +++ /dev/null @@ -1,40 +0,0 @@ - -// 1. Initialize a Node, with the necessary name -Node node(DERIVED::GNDSName()); - -// 2. Body text, if applicable -if constexpr (hasBodyText) { - // GNDStk uses a "text" metadatum of a "pcdata" child node for this - std::string &text = node.add("pcdata").add("text","").second; - // Note: the following call might compute length, start, and valueType; - // so we need all of this before the upcoming writing of fields. - body::toNode(text,derived().content); -} - -// 3. Write fields -if constexpr (std::is_same_v>) { - // consistency check - assert(0 == links.size()); -} else { - // make tuple (of individual keys) from DERIVED::keys() - const auto tup = toKeywordTup(DERIVED::keys()).tup; - - // consistency check - assert(std::tuple_size::value == links.size()); - - // apply links: - // derived-class data ==> Node - // Below, each apply'd "key" is one value from DERIVED::keys(), and - // is a Meta, Child, or pair. The cast gives the - // underlying raw data type - int, say, or std::string - so that we - // can correctly use our generic void* link to a derived-class field. - std::apply( - [this,&node](const auto &... key) { - std::size_t n = 0; - (node.add(key,*(std::decay_t*)links[n++]), ...); - }, - tup - ); -} - -return node; diff --git a/src/GNDStk/Component/src/write.hpp b/src/GNDStk/Component/src/write.hpp index a2a8507bb..06e2e98cc 100644 --- a/src/GNDStk/Component/src/write.hpp +++ b/src/GNDStk/Component/src/write.hpp @@ -1,126 +1,52 @@ // ----------------------------------------------------------------------------- // Component::write() +// Via Node, and using Node's write()s. +// So, Component-derived classes can use .write(...) directly. // ----------------------------------------------------------------------------- -std::ostream &write(std::ostream &os = std::cout, const int level = 0) const -{ - try { - // Indent, write header, newline - detail::indentString( - os, level, - detail::colorize_component( - detail::fullName(DERIVED::namespaceName(), DERIVED::className()) - ) + " " + - detail::colorize_brace("{") + - (comments - ? " " + - detail::colorize_comment( - std::string("// GNDS: ") + DERIVED::GNDSName() - ) - : "" - ) + "\n" - ); - - if constexpr (std::is_same_v>) { - // Consistency check - assert(0 == links.size()); - } else { - // Make tuple (of individual keys) from DERIVED::keys() - const auto tup = toKeywordTup(DERIVED::keys()).tup; - - // Consistency check - assert(std::tuple_size::value == links.size()); - - // Compute maximum length of key names, if aligning. Note that we - // could - but don't - take into account that keys associated with - // optional or Defaulted values *might* not in fact show up in the - // final printed text. In such cases, and if values of those types - // happen to have longer names, then the printing that does appear - // might use more spacing than it really needs to. By choosing not - // to factor this in, on a case-by-case basis, all objects of this - // particular Component<...> type will print with consistent spacing. - // We prefer this behavior, and it's also slightly simpler to write. - std::size_t maxlen = 0; - if (GNDStk::align) - std::apply( - [&maxlen](const auto &... key) { - ((maxlen=std::max(maxlen,detail::getName(key).size())), ...); - }, - tup - ); - - // Apply links: - // derived-class data ==> print - std::apply( - [this,&os,&level,maxlen](const auto &... key) { - std::size_t n = 0; - ( - ( - // indent, write internal value, newline - detail::writeComponentPart( - os, - level+1, - *(std::decay_t *)links[n++], - detail::getName(key), - maxlen - ) && (os << '\n') // no if()s in fold expressions :-/ - ), - ... - ); - }, - tup - ); - } - - // Derived class write()s, if any. - // Note that neither, either, or both can be provided. - // To be recognized here, signatures must be exactly what we expect. - if constexpr (detail::hasWriteOneArg) { - // DERIVED::write() doesn't take an indentation level; we handle here - std::ostringstream tmp; - derived().write(tmp); - if (tmp.str().size() != 0) - os << indentTo(level+1); - for (char c : tmp.str()) - os << c << (c == '\n' ? indentTo(level+1) : ""); - if (tmp.str().size()) - os << std::endl; - } - if constexpr (detail::hasWriteTwoArg) { - // DERIVED::write() takes an indentation level - std::ostringstream tmp; - derived().write(tmp,level+1); - os << tmp.str(); - if (tmp.str().size()) - os << std::endl; - } - - // BodyText, if any - if constexpr (hasBodyText) - body::write(os,level+1); +// ------------------------ +// stream, with enum- or +// string-based file type +// ------------------------ + +// write(ostream, FileType) +std::ostream &write( + std::ostream &os = std::cout, + const FileType format = FileType::guess, + const bool decl = false +) const { + return Node(*this).write(os, format, decl); +} - // Indent, write footer, NO newline - detail::indentString( - os, level, - detail::colorize_brace("}") - + (comments - ? " " + - detail::colorize_comment( - std::string("// ") + - detail::fullName( - DERIVED::namespaceName(), - DERIVED::className() - ) - ) - : "" - ) - ); +// write(ostream, string) +std::ostream &write( + std::ostream &os, + const std::string &format, + const bool decl = false +) const { + return Node(*this).write(os, format, decl); +} - return os; +// ------------------------ +// filename, with enum- or +// string-based file type +// ------------------------ + +// write(filename, FileType) +bool write( + const std::string &filename, + const FileType format = FileType::guess, + const bool decl = false +) const { + return Node(*this).write(filename, format, decl); +} - } catch (...) { - log::member("Component.write()"); - throw; - } +// write(filename, string) +bool write( + const std::string &filename, + const std::string &format, + const bool decl = false +) const { + return Node(*this).write(filename, format, decl); } diff --git a/src/GNDStk/Component/test/CMakeLists.txt b/src/GNDStk/Component/test/CMakeLists.txt index a81b982ff..178fbe81a 100644 --- a/src/GNDStk/Component/test/CMakeLists.txt +++ b/src/GNDStk/Component/test/CMakeLists.txt @@ -7,7 +7,7 @@ add_executable( GNDStk.Component.test fromNode.test.cpp getter.test.cpp toNode.test.cpp - write.test.cpp ) + print.test.cpp ) target_compile_options( GNDStk.Component.test PRIVATE ${${PREFIX}_common_flags} $<$:${${PREFIX}_strict_flags}>$<$: ${${PREFIX}_DEBUG_flags} diff --git a/src/GNDStk/Component/test/Component.test.cpp b/src/GNDStk/Component/test/Component.test.cpp index 5c524cc2c..44864033b 100644 --- a/src/GNDStk/Component/test/Component.test.cpp +++ b/src/GNDStk/Component/test/Component.test.cpp @@ -4,7 +4,7 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; @@ -21,11 +21,11 @@ class DerivedT : public Component { "", "class DerivedT" }, { "foo", "Help for foo" } }; - static auto namespaceName() { return "hello"; } - static auto className() { return "DerivedT"; } - static auto GNDSName() { return "none"; } - static auto keys() { return std::tuple<>{}; } - DerivedT() : Component(BodyText{}) { } + static auto NAMESPACE() { return "hello"; } + static auto CLASS() { return "DerivedT"; } + static auto NODENAME() { return "none"; } + static auto KEYS() { return std::tuple<>{}; } + DerivedT() : Component(BlockData{}) { } }; @@ -38,27 +38,27 @@ class DerivedF : public Component { "", "class DerivedF" }, { "bar", "Help for bar" } }; - static auto namespaceName() { return "world"; } - static auto className() { return "DerivedF"; } - static auto GNDSName() { return "none"; } - static auto keys() { return std::tuple<>{}; } - DerivedF() : Component(BodyText{}) { } + static auto NAMESPACE() { return "world"; } + static auto CLASS() { return "DerivedF"; } + static auto NODENAME() { return "none"; } + static auto KEYS() { return std::tuple<>{}; } + DerivedF() : Component(BlockData{}) { } }; // DerivedData // A Component-derived class with some data in it. -// Note that this class doesn't have help or namespaceName(); so we'll also use -// this class to test that Component's functionality that uses those still works -// properly, as it should in that case. +// Note that this class doesn't have help. So, we'll also use this class +// to test that Component's functionality that uses it still works properly, +// as it should in that case. class DerivedData : public Component { public: friend class Component; - static auto className() { return "DerivedData"; } - static auto GNDSName() { return "data"; } - - static auto keys() + static auto NAMESPACE() { return ""; } + static auto CLASS() { return "DerivedData"; } + static auto NODENAME() { return "data"; } + static auto KEYS() { return int {} / Meta<>("foo") | @@ -66,25 +66,48 @@ class DerivedData : public Component ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "foo", + "bar" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "foo", + "bar" + }; + return names; + } + struct { int foo; double bar; - } content; + } Content; + + const int &foo() const { return Content.foo; } + int &foo() { return Content.foo; } + const double &bar() const { return Content.bar; } + double &bar() { return Content.bar; } DerivedData() : Component( - BodyText{}, - content.foo, - content.bar + BlockData{}, + foo(), + bar() ) { } DerivedData(const Node &node) : Component( - BodyText{}, - content.foo, - content.bar + BlockData{}, + foo(), + bar() ) { Component::finish(node); @@ -140,17 +163,15 @@ SCENARIO("Testing GNDStk Component") { CHECK(der.documentation("bar") == "No help information is available"); } - // namespaceName() - WHEN("We test namespaceName()") { + // NAMESPACE() + WHEN("We test NAMESPACE()") { // For these two we need the std::string() only because the functions // were written (above, in the class definitions) with an auto return - // of a plain character string. Where Component needs namespaceName(), - // it converts to std::string, so it's fine to write it that way. Here, - // though, in this test file, it means we need the std::string(). - CHECK(der1.namespaceName() == std::string("hello")); - CHECK(der2.namespaceName() == std::string("world")); + // of a plain character string. + CHECK(der1.NAMESPACE() == std::string("hello")); + CHECK(der2.NAMESPACE() == std::string("world")); DerivedData der; - CHECK(der.namespaceName() == ""); + CHECK(der.NAMESPACE() == std::string("")); } // Component << string @@ -158,23 +179,23 @@ SCENARIO("Testing GNDStk Component") { // // Don't confuse the above two. Component << string reads from an XML // or JSON snippet into an object of the class that's derived from - // Component. ostream << Component writes (to the ostream) the object. + // Component. ostream << Component prints the object to the ostream. WHEN("We test (Component << string) and (ostream << Component)") { DerivedData der; - color = false; // avoid cluttering the checked output below + colors = false; // avoid cluttering the checked output below const std::string expected = - "DerivedData { // GNDS: data\n" + "{\n" " foo : 12\n" " bar : 34.56\n" - "} // DerivedData" + "}" ; // from XML WHEN("We read a Component-derived object << XML text") { der << ""; - // write & check + // print, check THEN("The result is as expected") { std::ostringstream oss; oss << der; @@ -187,14 +208,14 @@ SCENARIO("Testing GNDStk Component") { der << "{" " \"data\": {" - " \"attributes\": {" + " \"#metadata\": {" " \"foo\": \"12\"," " \"bar\": \"34.56\"" " }" " }" "}"; - // write & check + // print, check THEN("The result is as expected") { std::ostringstream oss; oss << der; diff --git a/src/GNDStk/Component/test/ctor.test.cpp b/src/GNDStk/Component/test/ctor.test.cpp index 74e5ed7b0..a0e2f7b22 100644 --- a/src/GNDStk/Component/test/ctor.test.cpp +++ b/src/GNDStk/Component/test/ctor.test.cpp @@ -2,7 +2,7 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- @@ -17,7 +17,7 @@ using namespace njoy::GNDStk::core; // situations mentioned below: a class with no fields, and a class with fields. // We don't anticipate that people will need Component-derived classes that have // no fields, but still illustrate such a beast, for completeness. Note that the -// keys() function should return a std::tuple<>{} in that situation. +// KEYS() function should return a std::tuple<>{} in that situation. // ----------------------------------------------------------------------------- // DerivedNothing @@ -26,14 +26,16 @@ class DerivedNothing : public Component { friend class Component; - static auto keys() + static auto NAMESPACE() { return ""; } + static auto CLASS() { return "DerivedNothing"; } + static auto KEYS() { return std::tuple<>{}; } public: - DerivedNothing() : Component(BodyText{}) + DerivedNothing() : Component(BlockData{}) { Component::finish(); } @@ -46,7 +48,9 @@ class DerivedSomething : public Component { friend class Component; - static auto keys() + static auto NAMESPACE() { return ""; } + static auto CLASS() { return "DerivedSomething"; } + static auto KEYS() { return int {} / Meta<>("foo") | @@ -56,15 +60,20 @@ class DerivedSomething : public Component struct { int foo; double bar; - } content; + } Content; + + const int &foo() const { return Content.foo; } + int &foo() { return Content.foo; } + const double &bar() const { return Content.bar; } + double &bar() { return Content.bar; } public: DerivedSomething() : Component( - BodyText{}, - content.foo, - content.bar + BlockData{}, + foo(), + bar() ) { Component::finish(); diff --git a/src/GNDStk/Component/test/detail.test.cpp b/src/GNDStk/Component/test/detail.test.cpp index 3011e0182..dba8ab3c3 100644 --- a/src/GNDStk/Component/test/detail.test.cpp +++ b/src/GNDStk/Component/test/detail.test.cpp @@ -2,21 +2,21 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- -// Classes for testing the hasWrite*() functions +// Classes for testing the hasPrint*() functions // ----------------------------------------------------------------------------- struct Neither { - // has neither of the write()s seen in the upcoming classes + // has neither of the print()s seen in the upcoming classes }; struct One { // (ostream) only - std::ostream &write(std::ostream &os) const + std::ostream &print(std::ostream &os) const { return os; } @@ -24,7 +24,7 @@ struct One { struct Two { // (ostream,int) only - std::ostream &write(std::ostream &os, const int) const + std::ostream &print(std::ostream &os, const int) const { return os; } @@ -32,12 +32,12 @@ struct Two { struct Both { // (ostream) - std::ostream &write(std::ostream &os) const + std::ostream &print(std::ostream &os) const { return os; } // (ostream,int) - std::ostream &write(std::ostream &os, const int) const + std::ostream &print(std::ostream &os, const int) const { return os; } @@ -57,7 +57,12 @@ struct FooBar { struct { int foo; double bar; - } content; + } Content; + + const int &foo() const { return Content.foo; } + int &foo() { return Content.foo; } + const double &bar() const { return Content.bar; } + double &bar() { return Content.bar; } }; @@ -65,17 +70,18 @@ struct FooBar { // ----------------------------------------------------------------------------- // class Derived // Is derived from Component -// Used in the tests of writeComponentPart() +// Used in the tests of printComponentPart() // ----------------------------------------------------------------------------- class Derived : public Component { public: friend class Component; - static auto className() { return "Derived"; } - static auto GNDSName() { return "none"; } + static auto NAMESPACE() { return ""; } + static auto CLASS() { return "Derived"; } + static auto NODENAME() { return "none"; } - static auto keys() + static auto KEYS() { return // metadata @@ -84,10 +90,28 @@ class Derived : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "foo", + "bar" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "foo", + "bar" + }; + return names; + } + int foo = 56; double bar = 7.8; - Derived() : Component(BodyText{},foo,bar) { } + Derived() : Component(BlockData{},foo,bar) { } }; @@ -103,7 +127,7 @@ class NonDerived { double bar = 3.4; }; -// Needs << in order to participate in writeComponentPart() - which it does, +// Needs << in order to participate in printComponentPart() - which it does, // because we're using it as a test subject there. inline std::ostream &operator<<(std::ostream &s, const NonDerived &obj) @@ -149,34 +173,36 @@ SCENARIO("Testing Component detail:: miscellaneous functions") { // colorize GIVEN("Function: colorize()") { - WHEN("Called with GNDStk::color == true and color == \"\"") { + WHEN("Called with GNDStk::colors == true and color == \"\"") { THEN("It returns the expected result") { - njoy::GNDStk::color = true; - // coloring is on, but we don't give a color + njoy::GNDStk::colors = true; + // coloring is on, but we don't provide a color, + // and the default label color is set to "" + color::label = ""; CHECK(detail::colorize("one","") == "one"); } } - WHEN("Called with GNDStk::color == true and color != \"\"") { + WHEN("Called with GNDStk::colors == true and color != \"\"") { THEN("It returns the expected result") { - njoy::GNDStk::color = true; - // coloring is on, and we give a color + njoy::GNDStk::colors = true; + // coloring is on, and we provide a color CHECK(detail::colorize("two","[color]") == "[color]two\033[0m"); } } - WHEN("Called with GNDStk::color == false and color == \"\"") { + WHEN("Called with GNDStk::colors == false and color == \"\"") { THEN("It returns the expected result") { - njoy::GNDStk::color = false; - // coloring is off, and we don't give a color anyway + njoy::GNDStk::colors = false; + // coloring is off, and we don't provide a color anyway CHECK(detail::colorize("three","") == "three"); } } - WHEN("Called with GNDStk::color == false and color != \"\"") { + WHEN("Called with GNDStk::colors == false and color != \"\"") { THEN("It returns the expected result") { - njoy::GNDStk::color = false; - // coloring is off, and we give a color (but it isn't used, + njoy::GNDStk::colors = false; + // coloring is off, and we provide a color (but it isn't used, // because coloring is off) CHECK(detail::colorize("four","[color]") == "four"); } @@ -228,20 +254,20 @@ SCENARIO("Testing Component detail:: miscellaneous functions") { CHECK(oss.str() == " foo"); } // GIVEN - // hasWrite* + // hasPrint* // Test some SFINAE constructs - GIVEN("Functions: hasWriteOneArg(), hasWriteTwoArg()") { - CHECK(detail::hasWriteOneArg == false); - CHECK(detail::hasWriteTwoArg == false); + GIVEN("Functions: hasPrintOneArg(), hasPrintTwoArg()") { + CHECK(detail::hasPrintOneArg == false); + CHECK(detail::hasPrintTwoArg == false); - CHECK(detail::hasWriteOneArg == true); - CHECK(detail::hasWriteTwoArg == false); + CHECK(detail::hasPrintOneArg == true); + CHECK(detail::hasPrintTwoArg == false); - CHECK(detail::hasWriteOneArg == false); - CHECK(detail::hasWriteTwoArg == true); + CHECK(detail::hasPrintOneArg == false); + CHECK(detail::hasPrintTwoArg == true); - CHECK(detail::hasWriteOneArg == true); - CHECK(detail::hasWriteTwoArg == true); + CHECK(detail::hasPrintOneArg == true); + CHECK(detail::hasPrintTwoArg == true); } // GIVEN } @@ -260,66 +286,66 @@ SCENARIO("Testing Component detail:: miscellaneous functions") { // ostream, level, vector, label, maxlen, color = "" // All return bool. -SCENARIO("Testing Component detail:: writeComponentPart()") { +SCENARIO("Testing Component detail:: printComponentPart()") { // for clarity below int level; std::size_t maxlen; std::ostringstream oss; indent = 2; - using detail::writeComponentPart; + using detail::printComponentPart; // For string - GIVEN("writeComponentPart() for string") { + GIVEN("printComponentPart() for string") { oss.str(""); - writeComponentPart(oss, level=2, "foo\nbar", "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", "foo\nbar"); CHECK(oss.str() == " label : foo\n" " bar"); oss.str(""); - writeComponentPart(oss, level=2, "foo\nbar", "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", "foo\nbar"); CHECK(oss.str() == " label : foo\n" " bar"); oss.str(""); - writeComponentPart(oss, level=2, "foo\nbar", "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", "foo\nbar"); CHECK(oss.str() == " foo\n" " bar"); oss.str(""); - writeComponentPart(oss, level=2, "foo\nbar", "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", "foo\nbar"); CHECK(oss.str() == " foo\n" " bar"); } // GIVEN // For general types T - GIVEN("writeComponentPart() for T") { + GIVEN("printComponentPart() for T") { // For double WHEN("T is double") { double value = 1.234; oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", value); CHECK(oss.str() == " label : 1.234"); oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", value); CHECK(oss.str() == " label : 1.234"); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", value); CHECK(oss.str() == " 1.234"); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", value); CHECK(oss.str() == " 1.234"); } - // writeComponentPart() for general T has an if-constexpr that + // printComponentPart() for general T has an if-constexpr that // distinguished classes that *are* derived from Component from // those that aren't, so we'll test both cases. (double, above, // in fact falls into the latter category.) ... @@ -330,29 +356,34 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { // label and maxlen don't get used in this case. // The Component-derived nature of the class causes - // value.write(stream,level) to be called instead. + // value.print(stream,level) to be called instead. // So we get the same result from each call. - const std::string expected = - " Derived { // GNDS: none\n" + const std::string expected1 = + " label {\n" + " foo : 56\n" + " bar : 7.8\n" + " } // label"; + const std::string expected2 = + " {\n" " foo : 56\n" " bar : 7.8\n" - " } // Derived"; + " }"; oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=0); - CHECK(oss.str() == expected); + printComponentPart(oss, level=2, maxlen= 0, "label", value); + CHECK(oss.str() == expected1); oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=10); - CHECK(oss.str() == expected); + printComponentPart(oss, level=2, maxlen=10, "label", value); + CHECK(oss.str() == expected1); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=0); - CHECK(oss.str() == expected); + printComponentPart(oss, level=2, maxlen= 0, "", value); + CHECK(oss.str() == expected2); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=10); - CHECK(oss.str() == expected); + printComponentPart(oss, level=2, maxlen=10, "", value); + CHECK(oss.str() == expected2); } // For "NonDerived" @@ -360,42 +391,42 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { NonDerived value; oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", value); CHECK(oss.str() == " label : {12,3.4}"); oss.str(""); - writeComponentPart(oss, level=2, value, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", value); CHECK(oss.str() == " label : {12,3.4}"); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", value); CHECK(oss.str() == " {12,3.4}"); oss.str(""); - writeComponentPart(oss, level=2, value, "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", value); CHECK(oss.str() == " {12,3.4}"); } } // GIVEN // For optional - GIVEN("writeComponentPart() for optional") { + GIVEN("printComponentPart() for optional") { WHEN("The optional has a value") { std::optional opt = 1.234; oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", opt); CHECK(oss.str() == " label : 1.234"); oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", opt); CHECK(oss.str() == " label : 1.234"); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", opt); CHECK(oss.str() == " 1.234"); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", opt); CHECK(oss.str() == " 1.234"); } @@ -405,19 +436,19 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { comments = false; oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", opt); CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", opt); CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", opt); CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", opt); CHECK(oss.str() == ""); } @@ -427,25 +458,25 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { comments = true; oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=0); - CHECK(oss.str() == " label : // optional; has no value"); + printComponentPart(oss, level=2, maxlen= 0, "label", opt); + CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "label", maxlen=10); - CHECK(oss.str() == " label : // optional; has no value"); + printComponentPart(oss, level=2, maxlen=10, "label", opt); + CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=0); - CHECK(oss.str() == " // optional; has no value"); + printComponentPart(oss, level=2, maxlen= 0, "", opt); + CHECK(oss.str() == ""); oss.str(""); - writeComponentPart(oss, level=2, opt, "", maxlen=10); - CHECK(oss.str() == " // optional; has no value"); + printComponentPart(oss, level=2, maxlen=10, "", opt); + CHECK(oss.str() == ""); } } // GIVEN // For Defaulted - GIVEN("writeComponentPart() for Defaulted") { + GIVEN("printComponentPart() for Defaulted") { WHEN("The Defaulted has an explicitly provided value") { // For the following: // 5.6 is the default @@ -453,20 +484,20 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { Defaulted def(5.6,7.8); oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=0); - CHECK(oss.str() == " label : 7.8"); + printComponentPart(oss, level=2, maxlen= 0, "label", def); + CHECK(oss.str() == " label : 7.8 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=10); - CHECK(oss.str() == " label : 7.8"); + printComponentPart(oss, level=2, maxlen=10, "label", def); + CHECK(oss.str() == " label : 7.8 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=0); - CHECK(oss.str() == " 7.8"); + printComponentPart(oss, level=2, maxlen= 0, "", def); + CHECK(oss.str() == " 7.8 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=10); - CHECK(oss.str() == " 7.8"); + printComponentPart(oss, level=2, maxlen=10, "", def); + CHECK(oss.str() == " 7.8 // its default"); } WHEN("The Defaulted has its default, and comments == false") { @@ -475,20 +506,20 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { comments = false; oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=0); - CHECK(oss.str() == ""); + printComponentPart(oss, level=2, maxlen= 0, "label", def); + CHECK(oss.str() == " label : 3.14"); oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=10); - CHECK(oss.str() == ""); + printComponentPart(oss, level=2, maxlen=10, "label", def); + CHECK(oss.str() == " label : 3.14"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=0); - CHECK(oss.str() == ""); + printComponentPart(oss, level=2, maxlen= 0, "", def); + CHECK(oss.str() == " 3.14"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=10); - CHECK(oss.str() == ""); + printComponentPart(oss, level=2, maxlen=10, "", def); + CHECK(oss.str() == " 3.14"); } WHEN("The Defaulted has its default, and comments == true") { @@ -497,49 +528,52 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { comments = true; oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=0); - CHECK(oss.str() == " label : // defaulted; is its default (2.72)"); + printComponentPart(oss, level=2, maxlen= 0, "label", def); + CHECK(oss.str() == + " label : 2.72 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "label", maxlen=10); - CHECK(oss.str() == " label : // defaulted; is its default (2.72)"); + printComponentPart(oss, level=2, maxlen=10, "label", def); + CHECK(oss.str() == + " label : 2.72 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=0); - CHECK(oss.str() == " // defaulted; is its default (2.72)"); + printComponentPart(oss, level=2, maxlen= 0, "", def); + CHECK(oss.str() == " 2.72 // its default"); oss.str(""); - writeComponentPart(oss, level=2, def, "", maxlen=10); - CHECK(oss.str() == " // defaulted; is its default (2.72)"); + printComponentPart(oss, level=2, maxlen=10, "", def); + CHECK(oss.str() == " 2.72 // its default"); } } // GIVEN // For variant - GIVEN("writeComponentPart() for variant") { + GIVEN("printComponentPart() for variant") { oss.str(""); std::variant var(9.87); oss.str(""); - writeComponentPart(oss, level=2, var, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", var); CHECK(oss.str() == " label : 9.87"); oss.str(""); - writeComponentPart(oss, level=2, var, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", var); CHECK(oss.str() == " label : 9.87"); oss.str(""); - writeComponentPart(oss, level=2, var, "", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "", var); CHECK(oss.str() == " 9.87"); oss.str(""); - writeComponentPart(oss, level=2, var, "", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "", var); CHECK(oss.str() == " 9.87"); } // GIVEN // For vector - GIVEN("writeComponentPart() for vector") { + GIVEN("printComponentPart() for vector") { oss.str(""); const std::vector vec{{"a","b","c","d","e"}}; + comments = false; const std::string expected = " label [\n" @@ -551,11 +585,11 @@ SCENARIO("Testing Component detail:: writeComponentPart()") { " ]"; oss.str(""); - writeComponentPart(oss, level=2, vec, "label", maxlen=0); + printComponentPart(oss, level=2, maxlen= 0, "label", vec); CHECK(oss.str() == expected); oss.str(""); - writeComponentPart(oss, level=2, vec, "label", maxlen=10); + printComponentPart(oss, level=2, maxlen=10, "label", vec); CHECK(oss.str() == expected); } // GIVEN } @@ -658,13 +692,14 @@ SCENARIO("Testing Component detail:: getter() functions") { GIVEN("A vector of objects that have both index and label") { // look for specific index THEN("getter() based on index works properly") { - CHECK((detail::getter(vec,0,"name","class","field").value() == "0a")); - CHECK((detail::getter(vec,1,"name","class","field").value() == "1b")); - CHECK((detail::getter(vec,2,"name","class","field").value() == "2c")); - CHECK((detail::getter(vec,3,"name","class","field").value() == "3d")); - CHECK((detail::getter(vec,4,"name","class","field").value() == "4e")); + using detail::getter; + CHECK((getter(vec, 0, "name", "class", "field").value() == "0a")); + CHECK((getter(vec, 1, "name", "class", "field").value() == "1b")); + CHECK((getter(vec, 2, "name", "class", "field").value() == "2c")); + CHECK((getter(vec, 3, "name", "class", "field").value() == "3d")); + CHECK((getter(vec, 4, "name", "class", "field").value() == "4e")); try { - detail::getter(vec,100,"name","class","field"); + getter(vec, 100, "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { @@ -673,13 +708,14 @@ SCENARIO("Testing Component detail:: getter() functions") { // look for specific label THEN("getter() based on label works properly") { - CHECK((detail::getter(vec,"a","name","class","field").value() == "0a")); - CHECK((detail::getter(vec,"b","name","class","field").value() == "1b")); - CHECK((detail::getter(vec,"c","name","class","field").value() == "2c")); - CHECK((detail::getter(vec,"d","name","class","field").value() == "3d")); - CHECK((detail::getter(vec,"e","name","class","field").value() == "4e")); + using detail::getter; + CHECK((getter(vec, "a", "name", "class", "field").value() == "0a")); + CHECK((getter(vec, "b", "name", "class", "field").value() == "1b")); + CHECK((getter(vec, "c", "name", "class", "field").value() == "2c")); + CHECK((getter(vec, "d", "name", "class", "field").value() == "3d")); + CHECK((getter(vec, "e", "name", "class", "field").value() == "4e")); try { - detail::getter(vec,"z","name","class","field"); + getter(vec, "z", "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { @@ -698,13 +734,14 @@ SCENARIO("Testing Component detail:: getter() functions") { // look for specific index THEN("getter() based on index works properly") { - CHECK((detail::getter(opt,0UL,"name","class","field").value() == "0a")); - CHECK((detail::getter(opt,1UL,"name","class","field").value() == "1b")); - CHECK((detail::getter(opt,2UL,"name","class","field").value() == "2c")); - CHECK((detail::getter(opt,3UL,"name","class","field").value() == "3d")); - CHECK((detail::getter(opt,4UL,"name","class","field").value() == "4e")); + using detail::getter; + CHECK((getter(opt, 0UL, "name", "class", "field").value() == "0a")); + CHECK((getter(opt, 1UL, "name", "class", "field").value() == "1b")); + CHECK((getter(opt, 2UL, "name", "class", "field").value() == "2c")); + CHECK((getter(opt, 3UL, "name", "class", "field").value() == "3d")); + CHECK((getter(opt, 4UL, "name", "class", "field").value() == "4e")); try { - detail::getter(opt,100UL,"name","class","field"); + getter(opt, 100UL, "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { @@ -713,13 +750,14 @@ SCENARIO("Testing Component detail:: getter() functions") { // look for specific label THEN("getter() based on label works properly") { - CHECK((detail::getter(opt,"a","name","class","field").value() == "0a")); - CHECK((detail::getter(opt,"b","name","class","field").value() == "1b")); - CHECK((detail::getter(opt,"c","name","class","field").value() == "2c")); - CHECK((detail::getter(opt,"d","name","class","field").value() == "3d")); - CHECK((detail::getter(opt,"e","name","class","field").value() == "4e")); + using detail::getter; + CHECK((getter(opt, "a", "name", "class", "field").value() == "0a")); + CHECK((getter(opt, "b", "name", "class", "field").value() == "1b")); + CHECK((getter(opt, "c", "name", "class", "field").value() == "2c")); + CHECK((getter(opt, "d", "name", "class", "field").value() == "3d")); + CHECK((getter(opt, "e", "name", "class", "field").value() == "4e")); try { - detail::getter(opt,"z","name","class","field"); + getter(opt, "z", "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { @@ -739,7 +777,7 @@ SCENARIO("Testing Component detail:: getter() functions") { // look for specific index THEN("getter() based on index works properly") { try { - detail::getter(opt,0,"name","class","field"); + detail::getter(opt, 0, "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { @@ -749,7 +787,7 @@ SCENARIO("Testing Component detail:: getter() functions") { // look for specific label THEN("getter() based on label works properly") { try { - detail::getter(opt,"a","name","class","field"); + detail::getter(opt, "a", "name", "class", "field"); // the above should throw, so we shouldn't get here... CHECK(false); } catch (...) { diff --git a/src/GNDStk/Component/test/finish.test.cpp b/src/GNDStk/Component/test/finish.test.cpp index 59d7edab3..459f50424 100644 --- a/src/GNDStk/Component/test/finish.test.cpp +++ b/src/GNDStk/Component/test/finish.test.cpp @@ -2,13 +2,13 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- // DerivedValue -// Has body text +// Has block data // ----------------------------------------------------------------------------- namespace test { @@ -17,14 +17,17 @@ namespace test { struct IndexStruct { struct { std::size_t index; - } content; - IndexStruct(const std::size_t i = 0) { content.index = i; } + } Content; + const std::size_t &index() const { return Content.index; } + std::size_t &index() { return Content.index; } + + IndexStruct(const std::size_t i = 0) { index() = i; } IndexStruct(const Node &) : IndexStruct(0) { } }; inline bool operator==(const IndexStruct &one, const IndexStruct &two) { - return one.content.index == two.content.index; + return one.index() == two.index(); } @@ -42,12 +45,12 @@ class DerivedValue : public Component friend class Component; // names - static auto namespaceName() { return "test"; } - static auto className() { return "DerivedValue"; } - static auto GNDSName() { return "value"; } + static auto NAMESPACE() { return "test"; } + static auto CLASS() { return "DerivedValue"; } + static auto NODENAME() { return "value"; } // keys - static auto keys() + static auto KEYS() { return int{} / Meta<>("length") | @@ -59,12 +62,13 @@ class DerivedValue : public Component public: - // content + // Content // Typically doesn't need to be public, but we make it public here because // one of the tests involves checking these struct { // Initialize these to specific values, so that we can ensure that - // Component's finish() functions properly call body::pullFromDerived() + // Component's finish() functions properly call + // BLOCKDATA::pullFromDerived() int length = 11; int start = 3; std::string valueType = "foobar"; @@ -73,7 +77,21 @@ class DerivedValue : public Component // functions detect and sort it. std::optional> indices = {{3,2,17,7,5,9,13,11}}; - } content; + } Content; + + const int &length() const { return Content.length; } + int &length() { return Content.length; } + + const int &start() const { return Content.start; } + int &start() { return Content.start; } + + const std::string &valueType() const { return Content.valueType; } + std::string &valueType() { return Content.valueType; } + + const std::optional> &indices() const + { return Content.indices; } + std::optional> &indices() + { return Content.indices; } private: @@ -106,8 +124,8 @@ class DerivedValue : public Component // ctor: default DerivedValue() : Component( - BodyText{}, - content.length, content.start, content.valueType, content.indices + BlockData{}, + length(), start(), valueType(), indices() ) { // finish() @@ -118,9 +136,9 @@ class DerivedValue : public Component DerivedValue(const DerivedValue &other) : Component{ other, - content.length, content.start, content.valueType, content.indices + length(), start(), valueType(), indices() }, - content{other.content} + Content{other.Content} { // finish(derived) Component::finish(other); @@ -129,8 +147,8 @@ class DerivedValue : public Component // ctor: node DerivedValue(const Node &node) : Component{ - BodyText{}, - content.length, content.start, content.valueType, content.indices + BlockData{}, + length(), start(), valueType(), indices() } { // finish(node) @@ -140,8 +158,8 @@ class DerivedValue : public Component // ctor: vector DerivedValue(const std::vector &vec) : Component{ - BodyText{}, - content.length, content.start, content.valueType, content.indices + BlockData{}, + length(), start(), valueType(), indices() } { // finish(vector) @@ -155,7 +173,7 @@ class DerivedValue : public Component // ----------------------------------------------------------------------------- // DerivedPlain -// Does not have body text +// Does not have block data // ----------------------------------------------------------------------------- namespace test { @@ -164,18 +182,21 @@ namespace test { struct LabelStruct { struct { std::string label; - } content; + } Content; + const std::string &label() const { return Content.label; } + std::string &label() { return Content.label; } + // apparently need a char* ctor for initializer-list initialization to work - LabelStruct(const char *const str = "") { content.label = str; } + LabelStruct(const char *const str = "") { label() = str; } LabelStruct(const Node &node) { - content.label = node(std::string{}/Meta<>("label")); + label() = node(std::string{}/Meta<>("label")); } }; inline bool operator==(const LabelStruct &one, const LabelStruct &two) { - return one.content.label == two.content.label; + return one.label() == two.label(); } @@ -191,12 +212,12 @@ class DerivedPlain : public Component friend class Component; // names - static auto namespaceName() { return "test"; } - static auto className() { return "DerivedPlain"; } - static auto GNDSName() { return "plain"; } + static auto NAMESPACE() { return "test"; } + static auto CLASS() { return "DerivedPlain"; } + static auto NODENAME() { return "plain"; } // keys - static auto keys() + static auto KEYS() { return int {} / Meta<>("foo") | @@ -207,7 +228,7 @@ class DerivedPlain : public Component public: - // content + // Content struct { int foo; double bar; @@ -216,7 +237,18 @@ class DerivedPlain : public Component // functions detect and sort it. std::optional> labels = {{"bc","a","p","efg","d","hi","no","jklm"}}; - } content; + } Content; + + const int &foo() const { return Content.foo; } + int &foo() { return Content.foo; } + + const double &bar() const { return Content.bar; } + double &bar() { return Content.bar; } + + const std::optional> &labels() const + { return Content.labels; } + std::optional> &labels() + { return Content.labels; } private: @@ -243,8 +275,8 @@ class DerivedPlain : public Component // ctor: default DerivedPlain() : Component( - BodyText{}, - content.foo, content.bar, content.labels + BlockData{}, + foo(), bar(), labels() ) { // finish() @@ -255,9 +287,9 @@ class DerivedPlain : public Component DerivedPlain(const DerivedPlain &other) : Component{ other, - content.foo, content.bar, content.labels + foo(), bar(), labels() }, - content{other.content} + Content{other.Content} { // finish(derived) Component::finish(other); @@ -266,8 +298,8 @@ class DerivedPlain : public Component // ctor: node DerivedPlain(const Node &node) : Component{ - BodyText{}, - content.foo, content.bar, content.labels + BlockData{}, + foo(), bar(), labels() } { // finish(node) @@ -288,8 +320,9 @@ class DerivedPlain : public Component // Detailed tests of those other functions aren't done *here*. SCENARIO("Component finish()") { + njoy::GNDStk::sort = true; - GIVEN("A component-derived class that has body text") { + GIVEN("A component-derived class that has block data") { const std::vector sorted = {{2,3,5,7,9,11,13,17}}; @@ -300,15 +333,15 @@ SCENARIO("Component finish()") { // Ensure that finish() called the construct() in the derived class... CHECK(test::construct1DerivedValue == true); - // Ensure that finish() did a BodyText::pullFromDerived() + // Ensure that finish() did a BlockData::pullFromDerived() CHECK(d.length() == 11); CHECK(d.start() == 3); CHECK(d.valueType() == "foobar"); // Ensure that finish() did a sort() - CHECK(d.content.indices.has_value() == true); - CHECK(d.content.indices->size() == 8); - CHECK(*d.content.indices == sorted); + CHECK(d.indices().has_value() == true); + CHECK(d.indices()->size() == 8); + CHECK(*d.indices() == sorted); } // ctor: copy @@ -340,9 +373,9 @@ SCENARIO("Component finish()") { CHECK(d.valueType() == "foobar"); // Ensure that finish() did a sort() - CHECK(d.content.indices.has_value() == true); - CHECK(d.content.indices->size() == 8); - CHECK(*d.content.indices == sorted); + CHECK(d.indices().has_value() == true); + CHECK(d.indices()->size() == 8); + CHECK(*d.indices() == sorted); } // ctor: from node @@ -357,7 +390,7 @@ SCENARIO("Component finish()") { test::DerivedValue d(node); CHECK(test::construct3DerivedValue == true); - // Here, the following values in the underlying BodyText should + // Here, the following values in the underlying BlockData should // reflect those that were brought in through the above string. CHECK(d.length() == 10); CHECK(d.start() == 2); @@ -375,9 +408,9 @@ SCENARIO("Component finish()") { CHECK(d.get(8) == 0); CHECK(d.get(9) == 0); - // The node from which we read had body text, not child nodes, + // The node from which we read had block data, not child nodes, // and thus would give us nothing for (std::optional) indices... - CHECK(d.content.indices.has_value() == false); + CHECK(d.indices().has_value() == false); } // ctor: from vector @@ -388,7 +421,7 @@ SCENARIO("Component finish()") { CHECK(test::construct4DerivedValue == true); // Here, the finish(vector) function was called, which in turn called - // BodyText's operator=(vector), which sets the following according + // BlockData's operator=(vector), which sets the following according // to what's actually in the vector CHECK(d.length() == 3); CHECK(d.start() == 0); // <== always the case in this context @@ -400,22 +433,22 @@ SCENARIO("Component finish()") { CHECK(Approx(d.get(1)) == 2.71828); CHECK(Approx(d.get(2)) == 1.41421); - // And, BodyText's operator=(vector) as mentioned above should also + // And, BlockData's operator=(vector) as mentioned above should also // have changed the corresponding values back up in the derived class - CHECK(d.content.length == 3); - CHECK(d.content.start == 0); - CHECK(d.content.valueType == "Float64"); + CHECK(d.length() == 3); + CHECK(d.start() == 0); + CHECK(d.valueType() == "Float64"); // Ensure that finish() did a sort() - CHECK(d.content.indices.has_value() == true); - CHECK(d.content.indices->size() == 8); - CHECK(*d.content.indices == sorted); + CHECK(d.indices().has_value() == true); + CHECK(d.indices()->size() == 8); + CHECK(*d.indices() == sorted); } } // GIVEN - GIVEN("A component-derived class that does not have body text") { + GIVEN("A component-derived class that does not have block data") { const std::vector sorted = {{"a","bc","d","efg","hi","jklm","no","p"}}; @@ -425,22 +458,22 @@ SCENARIO("Component finish()") { test::DerivedPlain d; CHECK(test::construct1DerivedPlain == true); - CHECK(d.content.labels.has_value() == true); - CHECK(d.content.labels->size() == 8); - CHECK(*d.content.labels == sorted); + CHECK(d.labels().has_value() == true); + CHECK(d.labels()->size() == 8); + CHECK(*d.labels() == sorted); } // ctor: copy WHEN("We call the copy constructor") { CHECK(test::construct2DerivedPlain == false); - // Comment as for the one regarding DerivedValue test + // Remark as for the one regarding DerivedValue test test::DerivedPlain dfrom; test::DerivedPlain d(dfrom); CHECK(test::construct2DerivedPlain == true); - CHECK(d.content.labels.has_value() == true); - CHECK(d.content.labels->size() == 8); - CHECK(*d.content.labels == sorted); + CHECK(d.labels().has_value() == true); + CHECK(d.labels()->size() == 8); + CHECK(*d.labels() == sorted); } // ctor: from node, case 1 @@ -454,7 +487,7 @@ SCENARIO("Component finish()") { test::DerivedPlain d(node); CHECK(test::construct3DerivedPlain == true); - CHECK(d.content.labels.has_value() == false); + CHECK(d.labels().has_value() == false); } // ctor: from node, case 2 @@ -472,10 +505,10 @@ SCENARIO("Component finish()") { test::DerivedPlain d(node); CHECK(test::construct3DerivedPlain == true); - CHECK(d.content.labels.has_value() == true); - CHECK(d.content.labels->size() == 4); + CHECK(d.labels().has_value() == true); + CHECK(d.labels()->size() == 4); CHECK(( - *d.content.labels == + *d.labels() == std::vector{{"abc","def","ghi","jkl"}} )); } diff --git a/src/GNDStk/Component/test/fromNode.test.cpp b/src/GNDStk/Component/test/fromNode.test.cpp index 55a9e5cae..9c1bf456c 100644 --- a/src/GNDStk/Component/test/fromNode.test.cpp +++ b/src/GNDStk/Component/test/fromNode.test.cpp @@ -3,9 +3,12 @@ #include "GNDStk.hpp" #include "prototype.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; using namespace GNDStk::proto; +#include "GNDStk/test/keys.hpp" +using namespace basic; + // ----------------------------------------------------------------------------- // DISCUSSION @@ -19,9 +22,9 @@ Component does the following: - Calls Component's fromNode() function to read known fields from the Node into the derived class object. - - If the Node has "body text," syncs certain fields in the BodyText (base + - If the Node has block data, syncs certain fields in the BlockData (base of Component) class, with fields in the derived class. Then, converts a - raw body-text string into a vector of values. + raw block data string into a vector of values. - Performs a sort() of derived-class vectors that are known to Component, and that have an index and/or a label. @@ -35,7 +38,7 @@ The tests in this file make use of a particular GNDS file with a reactionSuite. We use a prototype ReactionSuite class (with content that's pared down from what's in the full GNDS spec) that's derived from Component. -The reaction suite itself doesn't (directly) have any body text or sort-able +The reaction suite itself doesn't (directly) have any block data or sort-able fields, and doesn't have a construct(). So, our first test (1) constructs from a Node, (2) uses fromNode() to read from @@ -53,10 +56,10 @@ give different results: the former sorts, the latter doesn't. After the results from (2) are sorted, however, the two Reactions objects are the same. Finally, our third test works with Values objects. Objects of this type have -body text. Construction from Node does a get(), which takes the original, raw -body text in the Node, and makes a vector (in this case vector) from +block data. Construction from Node does a get(), which takes the original, raw +block data in the Node, and makes a vector (in this case vector) from it. fromNode() doesn't do that until, and unless, we ask for it by calling get() -directly. Values objects with only raw text write differently than those with +directly. Values objects with only raw text print differently than those with text that was processed into a vector. So, this test first ensures that the two Values objects print differently. Then it does an explicit get() for the object that used fromNode(), and ensures that the results are identical thereafter. @@ -162,7 +165,7 @@ SCENARIO("Component fromNode()") { oss2 << values2; CHECK(oss1.str() != oss2.str()); // not equal (yet) - // *** Apply get() *** to transform the raw string of body-text + // *** Apply get() *** to transform the raw string of block data // values into a vector values2.get(); oss2.str(""); diff --git a/src/GNDStk/Component/test/getter.test.cpp b/src/GNDStk/Component/test/getter.test.cpp index 46e815e43..e55f877be 100644 --- a/src/GNDStk/Component/test/getter.test.cpp +++ b/src/GNDStk/Component/test/getter.test.cpp @@ -3,7 +3,7 @@ #include "GNDStk.hpp" #include "indexnlabel.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- @@ -18,9 +18,10 @@ class TestGetter : public Component { friend class Component; - static auto className() { return "TestGetter"; } - // static auto GNDSName() - not actually needed here - static auto keys() + static auto NAMESPACE() { return ""; } + static auto CLASS() { return "TestGetter"; } + // static auto NODENAME() - not actually needed here + static auto KEYS() { return std::tuple<>{}; } @@ -31,6 +32,32 @@ class TestGetter : public Component IndexLabel >; + static const auto &FIELDNAMES() + { + static const std::vector names = { + "vecIndex", + "vecLabel", + "vecIndexLabel", + "varA", + "varB", + "vecVariant" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "vec_index", + "vec_label", + "vec_index_label", + "var_a", + "var_b", + "vec_variant" + }; + return names; + } + public: // ------------------------ @@ -38,7 +65,7 @@ class TestGetter : public Component // ------------------------ // See earlier remark. We don't bother linking these with GNDS fields, via - // Component's capabilities and the keys() function, because doing so isn't + // Component's capabilities and the KEYS() function, because doing so isn't // necessary for the present tests. // some vectors @@ -46,7 +73,7 @@ class TestGetter : public Component std::vector // One could argue that the second comment here really isn't important. // However, GNDStk is careful to maintain ALL information that's present // in a GNDS file it reads; it does not make decisions about importance. @@ -197,7 +204,8 @@ comments(bool &found = detail::default_bool) const CONTAINER container; const std::string *text; for (auto &c : children) - if (c->name == "comment" && (text = &c->meta("text",found),found)) + if (c->name == special::comment && + (text = &c->meta(special::text,found), found)) container.push_back(*text); return container; } diff --git a/src/GNDStk/Node/src/string.hpp b/src/GNDStk/Node/src/string.hpp new file mode 100644 index 000000000..d5dc0ab86 --- /dev/null +++ b/src/GNDStk/Node/src/string.hpp @@ -0,0 +1,35 @@ + +// ----------------------------------------------------------------------------- +// I/O with respect to a string +// These are conveniences for reading and writing, for instance, XML or JSON +// content from/to a string. +// ----------------------------------------------------------------------------- + +// Node << string +// Remark: we return void, not the Node. This way, users don't incorrectly think +// that the <> string +void operator>>(std::string &str) const +{ + try { + std::ostringstream oss; + write(oss); + str = oss.str(); + } catch (...) { + log::function("Node >> string"); + throw; + } +} diff --git a/src/GNDStk/Node/src/write.hpp b/src/GNDStk/Node/src/write.hpp index d0a585cfe..a47966d75 100644 --- a/src/GNDStk/Node/src/write.hpp +++ b/src/GNDStk/Node/src/write.hpp @@ -3,26 +3,23 @@ // Node.write() // ----------------------------------------------------------------------------- -// Cases for our FileType::text "plain text" format: -// write(ostream, int level) -// write(file name, int level) -// The "level" parameter keeps track of the indentation level. -// These print exactly what's in the Node, even, say, if the Node's name -// is the empty string. -// -// General cases: -// 1. write(ostream, FileType) -// 2. write(file name, FileType) calls 1 after making ostream from file name -// 3. write(ostream, string ) calls 1 after making FileType from string -// 4. write(file name, string ) calls 2 after making FileType from string - +// Cases: +// 0. Helper for writing in the FileType::debug format +// 1. write(ostream, FileType) +// 2. write(filename, FileType) calls 1 after making ostream from filename +// 3. write(ostream, string ) calls 1 after making FileType from string +// 4. write(filename, string ) calls 2 after making FileType from string // ----------------------------------------------------------------------------- +// 0. Helper // write(ostream, int level) -// For FileType::text +// For FileType::debug, our internal "debug format". // ----------------------------------------------------------------------------- +private: + +// The level parameter keeps track of the indentation level. std::ostream &write(std::ostream &os, const int level) const { // indentation: spaces for current and next levels @@ -64,70 +61,51 @@ std::ostream &write(std::ostream &os, const int level) const } - -// ----------------------------------------------------------------------------- -// write(file name, int level) -// For FileType::text -// ----------------------------------------------------------------------------- - -bool write(const std::string &filename, const int level) const -{ - // open file - std::ofstream ofs(filename); - if (!ofs) { - log::error("Could not open file \"{}\" for output", filename); - log::member("Node.write(\"{}\")", filename); - return false; - } - - // write to ostream - if (!write(ofs,level)) { - log::member("Node.write(\"{}\")", filename); - return false; - } - - // done - return true; -} - - - // ----------------------------------------------------------------------------- // 1. write(ostream, FileType) // ----------------------------------------------------------------------------- +public: + std::ostream &write( std::ostream &os = std::cout, - const FileType format = FileType::null, - const bool decl = false + const FileType format = FileType::guess, + const bool &DECL = detail::default_bool, + // If circumstances are such that we end up writing as HDF5, the following + // may be != "" if the ostream is from an ofstream. In that case, the HDF5 + // writer can produce output directly into the intended file, bypassing the + // need to create a temporary file and transfer its contents to the ostream. + const std::string &filename = "" ) const { // Discussion. // - // This function might have been called through the file name write(). - // Or, it might have been called through the string (in place of FileType) - // format write, through ostream << Node, or perhaps just called directly. + // This function might have been called through the file write(). Or, it + // might have been called through the string (in place of FileType) format + // write, through ostream << Node, or perhaps just called directly. // - // In the former case, a file name was involved, and thus the caller had - // the opportunity to examine the file name and, if appropriate, try to - // make a decision (based on any file name extension) of what output format - // was intended. The decision would have arrived here via FileType format. + // In the former case, a file was involved, and thus the caller had the + // opportunity to examine the file name and, if appropriate, try to make + // a decision (based on any file extension) of what output format was + // intended. The decision would have arrived here via FileType format. // // In the latter cases, only an ostream was/is involved; there's neither - // a file name whose extension can be examined, nor an existing file (that - // we care about, at least - we're doing *output*) whose file magic number + // a file extension that can be examined, nor an existing file (that we + // care about, at least - we're doing *output*) whose file magic number // we can examine in order to guess at the file type. We therefore have - // our else { } catchall, below, write the Node in our plain text format, - // whether FileType::null or FileType::text arrived as the format. + // our else { } catchall, below, write the Node in our debugging format, + // whether FileType::guess or FileType::debug arrived as the format. // // A case could be made that this function should *require* that a format - // be given, considering that we don't, here, have a file or a file name + // be given, considering that we don't, here, have a file or file extension // to examine. On the other hand, we like having format be optional, so // our various Node I/O functions are as consistent with one another as // reasonably possible. Note also that if the user calls operator<<, then - // there's no opportunity to explicitly provide a format. + // there's no opportunity to provide a format explicitly. try { + const bool decl = detail::getDecl(*this,DECL); + if (format == FileType::xml) { // write via a temporary xml object... XML(*this).write(os,decl); @@ -136,10 +114,14 @@ std::ostream &write( JSON(*this).write(os,decl); } else if (format == FileType::hdf5) { // write via a temporary hdf5 object... - log::error("Node.write() for HDF5 is not implemented yet"); - throw std::exception{}; + if (filename == "") + HDF5(*this).write(os,decl); + else { + HDF5 tmp; + convert(*this,tmp,filename); + } } else { - // null or text: use our plain text format + // guess or debug: use our debugging format return write(os,0); } @@ -157,23 +139,23 @@ std::ostream &write( } - // ----------------------------------------------------------------------------- -// 2. write(file name, FileType) +// 2. write(filename, FileType) // ----------------------------------------------------------------------------- bool write( const std::string &filename, - FileType format = FileType::null, - const bool decl = false + const FileType FORMAT = FileType::guess, + const bool &DECL = detail::default_bool ) const { + FileType format = FORMAT; // non-const; may change // ------------------------ - // FileType::null - // Decide from file name + // FileType::guess + // Decide from extension // ------------------------ - if (format == FileType::null) { + if (format == FileType::guess) { if (has_extension(filename) && endsin_xml(filename)) format = FileType::xml; else if (has_extension(filename) && endsin_json(filename)) @@ -181,8 +163,8 @@ bool write( else if (has_extension(filename) && endsin_hdf5(filename)) format = FileType::hdf5; else { - // fallback: our plain text format - format = FileType::text; + // fallback: our debugging format + format = FileType::debug; } } @@ -191,9 +173,9 @@ bool write( // Check: consistent name? // ------------------------ - // The above code block might have changed format via automagick file type - // detection, but wouldn't have changed it in a manner that would cause any - // of the following warnings. + // Remark. The above code block might have changed the [format] variable, + // but not in a manner that would trigger any of the following warnings + // where they wouldn't have otherwise existed. So, print them if warranted. // Caller asked for XML, but there's an extension that isn't XML... if (format == FileType::xml && has_extension(filename) @@ -213,6 +195,23 @@ bool write( // Open and write // ------------------------ + // Say we've decided we're actually writing an HDF5 file. (Independent of + // weird things that may have been reported on above, such as giving a file + // name of foo.xml, but a format of "hdf5", in which case we'll write HDF5 + // but print a warning about the file name's ".xml" bit.) If we're really + // writing an HDF5 file, but the file extension is ".hdf" or ".HDF", then + // we'll note that those aren't officially HDF5 extensions. (The official + // ones always require the "5" in some form.) + if (format == FileType::hdf5 && + (endsin(filename,".hdf") || endsin(filename,".HDF") + )) { + log::info( + "Writing file \"{}\" in HDF5 format, but we'll note that .hdf\n" + "and .HDF aren't official HDF5 file extensions.\n" + "Consider using .hdf5, .he5, or .h5 instead.", filename + ); + } + try { std::ofstream ofs(filename); if (!ofs) { @@ -221,8 +220,26 @@ bool write( } // Call write(ostream) to do the remaining work. - if (!write(ofs, format, decl)) + const bool decl = detail::getDecl(*this,DECL); + if (!write(ofs, format, decl, filename)) throw std::exception{}; + + // If the file is some type of text file (so, here, anything other than + // HDF5, which is binary), we'll also give the file a trailing newline. + // Note that throughout GNDStk, we generally *don't* write such newlines, + // because whether newlines are really wanted, or not wanted, depends on + // context. If, for example, someone is writing an xml representation into + // a string, via an ostringstream, a trailing newline is probably neither + // wanted nor expected. Right here, however, we're dealing specifically + // with the case of a caller having provided a file name. (The file was + // opened, a few lines above, as an ofstream.) We know, then, that we're + // writing to a file, and most people would expect a newline at the end + // of the last line with actual text. So, we'll add the newline after the + // above call to write(ostream,...) - which emits no newline - finishes. + if (format != FileType::hdf5) + ofs << std::endl; + + // Done. return bool(ofs); } catch (...) { log::member("Node.write(\"{}\")", filename); @@ -231,7 +248,6 @@ bool write( } - // ----------------------------------------------------------------------------- // 3. write(ostream, string) // ----------------------------------------------------------------------------- @@ -239,24 +255,24 @@ bool write( std::ostream &write( std::ostream &os, const std::string &format, - const bool decl = false + const bool &DECL = detail::default_bool ) const { try { - if (eq_null(format)) return write(os, FileType::null, decl); - if (eq_text(format)) return write(os, FileType::text, decl); - if (eq_xml (format)) return write(os, FileType::xml, decl); - if (eq_json(format)) return write(os, FileType::json, decl); - if (eq_hdf5(format)) return write(os, FileType::hdf5, decl); + const bool decl = detail::getDecl(*this,DECL); + bool matched; + const FileType type = string2filetype(format,matched); + if (matched) + return write(os, type, decl); // unrecognized file format log::warning( "Unrecognized file format in call to Node.write(ostream,\"{}\").\n" - "We'll use our plain text format", + "We'll use our debugging format", format ); - // fallback: automagick - return write(os, FileType::null, decl); + // fallback: guess, from file extension + return write(os, FileType::guess, decl); } catch (...) { log::member("Node.write(ostream,\"{}\")", format); throw; @@ -264,33 +280,32 @@ std::ostream &write( } - // ----------------------------------------------------------------------------- -// 4. write(file name, string) +// 4. write(filename, string) // ----------------------------------------------------------------------------- bool write( const std::string &filename, const std::string &format, - const bool decl = false + const bool &DECL = detail::default_bool ) const { try { - if (eq_null(format)) return write(filename, FileType::null, decl); - if (eq_text(format)) return write(filename, FileType::text, decl); - if (eq_xml (format)) return write(filename, FileType::xml, decl); - if (eq_json(format)) return write(filename, FileType::json, decl); - if (eq_hdf5(format)) return write(filename, FileType::hdf5, decl); + const bool decl = detail::getDecl(*this,DECL); + bool matched; + const FileType type = string2filetype(format,matched); + if (matched) + return write(filename, type, decl); // unrecognized file format log::warning( "Unrecognized file format in call to Node.write(\"{}\",\"{}\").\n" - "We'll guess from the file extension, or use our plain text\n" + "We'll guess from the file extension, or use our debugging\n" "format if that fails", filename, format ); - // fallback: automagick - return write(filename, FileType::null, decl); + // fallback: guess, from file extension + return write(filename, FileType::guess, decl); } catch (...) { log::member("Node.write(\"{}\",\"{}\")", filename, format); throw; diff --git a/src/GNDStk/Node/test/Node.test.cpp b/src/GNDStk/Node/test/Node.test.cpp index 864aee8d6..3d286d456 100644 --- a/src/GNDStk/Node/test/Node.test.cpp +++ b/src/GNDStk/Node/test/Node.test.cpp @@ -9,7 +9,7 @@ SCENARIO("Testing GNDStk Node") { GIVEN("A Node") { Node n; CHECK(n.empty()); - CHECK(n.name == ""); + CHECK(n.name == emptyNodeName); CHECK(n.metadata.size() == 0); CHECK(n.children.size() == 0); } diff --git a/src/GNDStk/Node/test/add.test.cpp b/src/GNDStk/Node/test/add.test.cpp index 7a4b926b4..84752d81f 100644 --- a/src/GNDStk/Node/test/add.test.cpp +++ b/src/GNDStk/Node/test/add.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; @@ -70,10 +71,10 @@ SCENARIO("Testing GNDStk Node add()") { n.add("4",dimensions2d(12,34)); // metadata, Meta key - auto v = keyword.meta("AStringViaVoid"); - auto str = keyword.meta("AString"); - auto dbl = keyword.meta("ADouble"); - auto dim = keyword.meta("Dimensions"); + auto v = Meta("AStringViaVoid"); + auto str = Meta("AString"); + auto dbl = Meta("ADouble"); + auto dim = Meta("Dimensions"); n.add(v); n.add(v,"fred"); n.add(str); @@ -85,8 +86,8 @@ SCENARIO("Testing GNDStk Node add()") { // these need the = TYPE on class T in the metadata Node.add() functions: n.add(dim,{321,987}); CHECK(n.metadata.back().second == "321,987"); - auto optdim = keyword.meta>("OptDim"); - auto defdim = Defaulted({1,2})/keyword.meta<>("DefDim"); + auto optdim = Meta>("OptDim"); + auto defdim = Defaulted({1,2})/Meta<>("DefDim"); n.add(optdim,{321,987}); CHECK(n.metadata.back().second == "321,987"); n.add(defdim,{321,987}); @@ -105,13 +106,13 @@ SCENARIO("Testing GNDStk Node add()") { // ------------------------ // ------------------------ - auto foo = keyword.child("foo"); - auto numbers = keyword.child< + auto foo = Child("foo"); + auto numbers = Child< std::vector, Allow::one - >("pcdata",std::vector{},detail::convert_pcdata_text_t{}); + >(special::data)/detail::convert_data_text_t{}; - auto nrepeat = keyword.child("repeated node"); + auto nrepeat = Child("repeated node"); Node node1; node1.name = "aa11"; Node node2; node2.name = "bb22"; Node node3; node3.name = "cc33"; @@ -125,10 +126,8 @@ SCENARIO("Testing GNDStk Node add()") { n.add(nrepeat,vec); n.add(nrepeat,node5); - // dim2d doesn't happen to have a default constructor, so we'll need - // to give it a value in the following Child. For just the .add()s, - // the value isn't used. - auto drepeat = keyword.child("dimension",dim2d{0,0}); + // dim2d doesn't have a default constructor. That fine in the following. + auto drepeat = Child("dimension"); const dim2d a(1,2), b(3,4), c(5,6), d(7,8), e(9,10); n.add(drepeat,{a,b,c,d}); n.add(drepeat,e); diff --git a/src/GNDStk/Node/test/assign.test.cpp b/src/GNDStk/Node/test/assign.test.cpp index 9279b1baa..e1ced3192 100644 --- a/src/GNDStk/Node/test/assign.test.cpp +++ b/src/GNDStk/Node/test/assign.test.cpp @@ -7,7 +7,7 @@ SCENARIO("Testing GNDStk Node assignment") { GIVEN("A tree read from a GNDS file") { Tree tree("n-008_O_016.xml"); - WHEN("We assign: Node = tree.top") { + WHEN("We assign: Node = tree.top()") { Node node; // put some initial content into the node... diff --git a/src/GNDStk/Node/test/call.test.cpp b/src/GNDStk/Node/test/call.test.cpp index 9e3349b33..3763e65fc 100644 --- a/src/GNDStk/Node/test/call.test.cpp +++ b/src/GNDStk/Node/test/call.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; @@ -257,20 +258,21 @@ R"***(1e-05 // ----------------------------------------------------------------------------- // Scenario +// Test operator() cases; except multi-queries are in another scenario. // ----------------------------------------------------------------------------- -SCENARIO("Testing GNDStk Node operator()") { +SCENARIO("Testing GNDStk::Node's operator()") { // tree Tree tree("n-008_O_016.xml"); // Child objects with Allow::one - auto temperature = keyword.child("temperature"); - auto styles = keyword.child("styles"); + auto temperature = Child("temperature"); + auto styles = Child("styles"); // Child objects with Allow::many - auto isotope = keyword.child("isotope"); - auto isotope_node = keyword.child("isotope"); + auto isotope = Child("isotope"); + auto isotope_node = Child("isotope"); GIVEN("The top-level node from a tree object") { @@ -978,3 +980,308 @@ SCENARIO("Testing GNDStk Node operator()") { CHECK(oss.str() == numeric_string); } // GIVEN } + + +// ----------------------------------------------------------------------------- +// Scenario +// Test multi-query operator(). +// ----------------------------------------------------------------------------- + +// test string +static const std::string xmlstring = +R"***( + + + + + + + + +)***"; + +// SCENARIO +SCENARIO("Testing GNDStk::Node's operator() for multi-queries") { + + // A Node + Node node; + node << xmlstring; + std::cout << node << std::endl; + + // Meta objects + const Meta a("a"); + const Meta b("b"); + const Meta label("label"); + const Meta x("x"); + const Meta y("y"); + const Meta z("z"); + const Meta i("i"); + const Meta j("j"); + const Meta k("k"); + const Meta l("l"); + const Meta m("m"); + const Meta n("n"); + + // Child objects + const Child<> bar("bar"); + const Child<> baz("baz"); + const Child<> boo("boo"); + + /* + ------------------------------------+------------------------------------ + Meta/Child | Meta/Child | + a. Meta | Meta | KeyTuple + b. Meta | Child | KeyTuple + c. Child | Meta | KeyTuple + d. Child | Child | KeyTuple + ------------------------------------+------------------------------------ + Child | string/regex | + a. Child | string | KeyTuple> + b. Child | char * | KeyTuple> + c. Child | regex | KeyTuple> + ------------------------------------+------------------------------------ + KeyTuple<...> | Meta/Child | + a. KeyTuple<...> | Meta | KeyTuple<...,Meta> + b. KeyTuple<...> | Child | KeyTuple<...,Child> + ------------------------------------+------------------------------------ + KeyTuple<...,Child> | string/regex | + a. KeyTuple<...,Child> | string | KeyTuple<...,pair> + b. KeyTuple<...,Child> | char * | KeyTuple<...,pair> + c. KeyTuple<...,Child> | regex | KeyTuple<...,pair> + ------------------------------------+------------------------------------ + */ + + // ------------------------ + // or.hpp operator|, case 1 + // ------------------------ + + GIVEN("Meta | Meta") + { + const auto tup = node(a | b); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup) == 123); + CHECK(std::get<1>(tup) == 4.56); + } + + GIVEN("Meta | Child") + { + const auto tup = node(a | bar); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup) == 123); + CHECK(std::get<1>(tup).name == "bar"); + } + + GIVEN("Child | Meta") + { + const auto tup = node(bar | a); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<1>(tup) == 123); + } + + GIVEN("Child | Child") + { + const auto tup = node(bar | baz); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<1>(tup).name == "baz"); + } + + // ------------------------ + // or.hpp operator|, case 2 + // ------------------------ + + GIVEN("Child | string") + { + const auto tup = node(bar | std::string("xyz")); + CHECK(std::tuple_size_v == 1); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<0>(tup)(label) == "xyz"); + } + + GIVEN("Child | char *") + { + const auto tup = node(baz | "lmn"); + CHECK(std::tuple_size_v == 1); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "lmn"); + } + + GIVEN("Child | regex") + { + const auto tup = node(boo | std::regex("j[au]ne")); + CHECK(std::tuple_size_v == 1); + CHECK(std::get<0>(tup).name == "boo"); + CHECK(std::get<0>(tup)(label) == "jane"); + } + + // ------------------------ + // or.hpp operator|, case 3 + // ------------------------ + + GIVEN("KeyTuple<...> | Meta") + { + const auto tup = node(a | b | a); + CHECK(std::tuple_size_v == 3); + CHECK(std::get<0>(tup) == 123); + CHECK(std::get<1>(tup) == 4.56); + CHECK(std::get<2>(tup) == 123); + } + + GIVEN("KeyTuple<...> | Child") + { + const auto tup = node(a | b | bar); + CHECK(std::tuple_size_v == 3); + CHECK(std::get<0>(tup) == 123); + CHECK(std::get<1>(tup) == 4.56); + CHECK(std::get<2>(tup).name == "bar"); + } + + GIVEN("KeyTuple<...,pair> | Meta") + { + const auto tup = node(baz | std::string("ijk") | a); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "ijk"); + CHECK(std::get<1>(tup) == 123); + } + + GIVEN("KeyTuple<...,pair> | Meta") + { + const auto tup = node(baz | "lmn" | a); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "lmn"); + CHECK(std::get<0>(tup)(m) == 'm'); + CHECK(std::get<0>(tup)(n) == 'n'); + CHECK(std::get<1>(tup) == 123); + } + + GIVEN("KeyTuple<...,pair> | Meta") + { + const auto tup = node(baz | std::regex("[kji]+") | a); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "ijk"); + CHECK(std::get<1>(tup) == 123); + } + + GIVEN("KeyTuple<...,pair> | Child") + { + const auto tup = node(baz | std::string("ijk") | bar); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "ijk"); + CHECK(std::get<1>(tup).name == "bar"); + } + + GIVEN("KeyTuple<...,pair> | Child") + { + const auto tup = node(baz | "lmn" | bar); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "lmn"); + CHECK(std::get<1>(tup).name == "bar"); + } + + GIVEN("KeyTuple<...,pair> | Child") + { + const auto tup = node(baz | std::regex("[kji]+") | bar); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "baz"); + CHECK(std::get<0>(tup)(label) == "ijk"); + CHECK(std::get<1>(tup).name == "bar"); + } + + // ------------------------ + // or.hpp operator|, case 4 + // ------------------------ + + GIVEN("KeyTuple<...,Child> | string") + { + const auto tup = node(bar | baz | std::string("ijk")); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<1>(tup).name == "baz"); + CHECK(std::get<1>(tup)(label) == "ijk"); + } + + GIVEN("KeyTuple<...,Child> | char *") + { + const auto tup = node(bar | baz | "lmn"); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<1>(tup).name == "baz"); + CHECK(std::get<1>(tup)(label) == "lmn"); + } + + GIVEN("KeyTuple<...,Child> | regex") + { + const auto tup = node(bar | baz | std::regex("[kji]+")); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup).name == "bar"); + CHECK(std::get<1>(tup).name == "baz"); + CHECK(std::get<1>(tup)(label) == "ijk"); + } + + // ------------------------ + // Miscellaneous fun stuff + // ------------------------ + + GIVEN("Various multi-queries") + { + { + const auto tup = node(a | b | bar | baz | boo); + CHECK(std::tuple_size_v == 5); + CHECK(std::get<0>(tup) == 123); + CHECK(std::get<1>(tup) == 4.56); + CHECK(std::get<2>(tup).name == "bar"); + CHECK(std::get<3>(tup).name == "baz"); + CHECK(std::get<4>(tup).name == "boo"); + } + { + const auto tup = node(bar,"xyz")(label | x | y | z); + CHECK(std::tuple_size_v == 4); + CHECK(std::get<0>(tup) == "xyz"); + CHECK(std::get<1>(tup) == "one"); + CHECK(std::get<2>(tup) == "two"); + CHECK(std::get<3>(tup) == 1); + } + { + const auto tup = node(bar,"zyx")(label | x | y | z); + CHECK(std::tuple_size_v == 4); + CHECK(std::get<0>(tup) == "zyx"); + CHECK(std::get<1>(tup) == "three"); + CHECK(std::get<2>(tup) == "four"); + CHECK(std::get<3>(tup) == 2); + } + { + const auto tup = node(baz,"ijk")(label | i | j | k); + CHECK(std::tuple_size_v == 4); + CHECK(std::get<0>(tup) == "ijk"); + CHECK(std::get<1>(tup) == "eye"); + CHECK(std::get<2>(tup) == "jay"); + CHECK(std::get<3>(tup) == "kay"); + } + { + const auto tup = node(baz,"lmn")(label | l | m | n); + CHECK(std::tuple_size_v == 4); + CHECK(std::get<0>(tup) == "lmn"); + CHECK(std::get<1>(tup) == "ell"); + CHECK(std::get<2>(tup) == 'm'); + CHECK(std::get<3>(tup) == 'n'); + } + { + const auto tup = node(boo,"jane")(label | a); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup) == "jane"); + CHECK(std::get<1>(tup) == 321); + } + { + const auto tup = node(boo,"john")(label | b); + CHECK(std::tuple_size_v == 2); + CHECK(std::get<0>(tup) == "john"); + CHECK(std::get<1>(tup) == 6.54); + } + } +} diff --git a/src/GNDStk/Node/test/child.test.cpp b/src/GNDStk/Node/test/child.test.cpp index 93943d4be..15e9140b9 100644 --- a/src/GNDStk/Node/test/child.test.cpp +++ b/src/GNDStk/Node/test/child.test.cpp @@ -1,8 +1,8 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" #include - using namespace njoy::GNDStk; @@ -75,19 +75,19 @@ inline void convert(const Node &n, isotope_t &iso) // Child objects with Allow::one auto temperature = - keyword.child("temperature"); + Child("temperature"); auto styles = - keyword.child("styles"); + Child("styles"); auto documentations = - keyword.child,Allow::one>("documentations"); + Child,Allow::one>("documentations"); // Child objects with Allow::many auto isotope = - keyword.child("isotope"); + Child("isotope"); auto isotope_node = - keyword.child("isotope"); + Child("isotope"); auto nuclide_foo_or_bar_node = - keyword.child,Allow::many>("nuclide"); + Child,Allow::many>("nuclide"); // ----------------------------------------------------------------------------- @@ -195,7 +195,7 @@ SCENARIO("Testing GNDStk Node child()") { basic::child::reactionSuite, basic::child::documentations, basic::child::documentation, - misc::child::cdata + misc::child::CDATA ); CHECK(0 == strncmp(descr.data(), "\n 8-O - 16 LANL", 16)); } diff --git a/src/GNDStk/Node/test/compare.test.cpp b/src/GNDStk/Node/test/compare.test.cpp index b50d2a78e..79c9d03a8 100644 --- a/src/GNDStk/Node/test/compare.test.cpp +++ b/src/GNDStk/Node/test/compare.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; SCENARIO("Testing GNDStk Node operator==() and operator!=") { Tree oh("n-008_O_016.xml"); diff --git a/src/GNDStk/Node/test/count.test.cpp b/src/GNDStk/Node/test/count.test.cpp index 87780a262..2d5dedf5e 100644 --- a/src/GNDStk/Node/test/count.test.cpp +++ b/src/GNDStk/Node/test/count.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; SCENARIO("Testing GNDStk Node count()") { const Tree tree("n-008_O_016.xml"); diff --git a/src/GNDStk/Node/test/ctor.test.cpp b/src/GNDStk/Node/test/ctor.test.cpp index 6c8529f79..027a1249f 100644 --- a/src/GNDStk/Node/test/ctor.test.cpp +++ b/src/GNDStk/Node/test/ctor.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; @@ -110,8 +111,8 @@ SCENARIO("Testing GNDStk Node constructors") { // ------------------------ WHEN("A Node is constructed from just a name (no metadata/children)") { - Node n("NodeName"); - CHECK(n.name == "NodeName"); + Node n("MyName"); + CHECK(n.name == "MyName"); CHECK(n.metadata.size() == 0); CHECK(n.children.size() == 0); } @@ -176,8 +177,8 @@ SCENARIO("Testing GNDStk Node constructors") { // ------------------------ GIVEN("Some Child objects") { - const Child ymd("YearMonthDay",yyyymmdd{0,0,0}); - const Child mdy("MonthDayYear",mmddyyyy{0,0,0}); + const Child ymd("YearMonthDay"); + const Child mdy("MonthDayYear"); WHEN("A Node is constructed with (Child,type)") { Node n(ymd,yyyymmdd{1776,7,4}); diff --git a/src/GNDStk/Node/test/has.test.cpp b/src/GNDStk/Node/test/has.test.cpp index a69232d7e..6b1360b9c 100644 --- a/src/GNDStk/Node/test/has.test.cpp +++ b/src/GNDStk/Node/test/has.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; // I'm arguably overdoing it in this file, testing so many different // permutations of essentially the same underlying capability. We do diff --git a/src/GNDStk/Node/test/many.test.cpp b/src/GNDStk/Node/test/many.test.cpp index 6f656e449..84f042e4e 100644 --- a/src/GNDStk/Node/test/many.test.cpp +++ b/src/GNDStk/Node/test/many.test.cpp @@ -4,6 +4,8 @@ #include using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" using namespace misc; SCENARIO("Testing GNDStk Node many()") { @@ -82,7 +84,7 @@ SCENARIO("Testing GNDStk Node many()") { } THEN("As above, with filter") { - // filter should be ignored when used with key=="" + // filter should be ignored when used with key == "" auto filter = [](const Node &n) { return false; }; bool found = false; CHECK(Rs.has_many("",filter)); diff --git a/src/GNDStk/Node/test/meta.test.cpp b/src/GNDStk/Node/test/meta.test.cpp index 45a17835b..cdc0aa72e 100644 --- a/src/GNDStk/Node/test/meta.test.cpp +++ b/src/GNDStk/Node/test/meta.test.cpp @@ -28,14 +28,14 @@ SCENARIO("Testing GNDStk Node meta()") { CHECK(consttop.meta("format") == "1.99"); } - auto format = keyword.meta("format"); + auto format = Meta("format"); CHECK(top.has_meta(format)); double f = top.meta(format); CHECK(f == 1.99); WHEN("Node.meta(\"key\",found) is called for a key that isn't there") { // try something that doesn't work - auto foobar = keyword.meta("foobar"); + auto foobar = Meta("foobar"); CHECK(!top.has_meta(foobar)); // doesn't have bool found = true; f = top.meta(foobar,found); // foobar isn't there @@ -47,8 +47,8 @@ SCENARIO("Testing GNDStk Node meta()") { WHEN("Node.meta(Meta) is called") { // string and void Meta ==> string - auto sstring = keyword.meta("evaluation"); - auto vstring = keyword.meta("evaluation"); + auto sstring = Meta("evaluation"); + auto vstring = Meta("evaluation"); std::string sstr = top.meta(sstring); std::string vstr = top.meta(vstring); CHECK(sstr == "ENDF/B-8.0"); @@ -56,7 +56,7 @@ SCENARIO("Testing GNDStk Node meta()") { // meta case should trigger a reference return... (void)&top.meta(vstring); - auto var = keyword.meta>("format"); + auto var = Meta>("format"); auto s = top.meta(var); auto d = top.meta(var); CHECK(s == "1.99"); diff --git a/src/GNDStk/Node/test/one.test.cpp b/src/GNDStk/Node/test/one.test.cpp index 3e93619ae..5f1c3b56a 100644 --- a/src/GNDStk/Node/test/one.test.cpp +++ b/src/GNDStk/Node/test/one.test.cpp @@ -1,8 +1,9 @@ #include "catch.hpp" #include "GNDStk.hpp" - using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" using namespace misc; SCENARIO("Testing GNDStk Node one()") { diff --git a/src/GNDStk/Node/test/sort.test.cpp b/src/GNDStk/Node/test/sort.test.cpp index f542a5262..2fa572172 100644 --- a/src/GNDStk/Node/test/sort.test.cpp +++ b/src/GNDStk/Node/test/sort.test.cpp @@ -23,8 +23,8 @@ R"***(covarianceSuite: compression: diagonal shape: 78,78 values: - pcdata: - text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012 + #data: + #text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012 parameters: parameterLink: href: $reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']/resonanceParameters/table diff --git a/src/GNDStk/Node/test/special.test.cpp b/src/GNDStk/Node/test/special.test.cpp index 86411c100..4e7abbf05 100644 --- a/src/GNDStk/Node/test/special.test.cpp +++ b/src/GNDStk/Node/test/special.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; SCENARIO("Testing certain special functions in GNDStk Node") { Tree t("n-008_O_016.xml"); @@ -14,8 +17,8 @@ SCENARIO("Testing certain special functions in GNDStk Node") { reactionSuite, documentations, documentation, - cdata, - text + CDATA, + TEXT ); CHECK(thedocs.size() == 46742); @@ -51,14 +54,14 @@ SCENARIO("Testing certain special functions in GNDStk Node") { CHECK(t(reactionSuite,documentations,documentation).doc() == thedocs); CHECK(c(reactionSuite,documentations,documentation).doc() == thedocs); - // works from the node... - CHECK(t(reactionSuite,documentations,documentation,cdata). + // works from the CDATA node... + CHECK(t(reactionSuite,documentations,documentation,CDATA). documentation() == thedocs); - CHECK(c(reactionSuite,documentations,documentation,cdata). + CHECK(c(reactionSuite,documentations,documentation,CDATA). documentation() == thedocs); - CHECK(t(reactionSuite,documentations,documentation,cdata). + CHECK(t(reactionSuite,documentations,documentation,CDATA). doc() == thedocs); - CHECK(c(reactionSuite,documentations,documentation,cdata). + CHECK(c(reactionSuite,documentations,documentation,CDATA). doc() == thedocs); // doesn't work from some other place... @@ -86,10 +89,10 @@ SCENARIO("Testing certain special functions in GNDStk Node") { } // ------------------------ - // pcdata() + // data() // ------------------------ - WHEN("Testing pcdata()") { + WHEN("Testing data()") { auto &valnode = t( reactionSuite, reactions, @@ -99,11 +102,11 @@ SCENARIO("Testing certain special functions in GNDStk Node") { ).one("values"); const auto &constvalnode = valnode; - const std::string vals = valnode(pcdata,text); + const std::string vals = valnode(DATA,TEXT); CHECK(vals.size() == 70254); - CHECK(valnode.pcdata() == vals); - CHECK(constvalnode.pcdata() == vals); + CHECK(valnode.data() == vals); + CHECK(constvalnode.data() == vals); } // ------------------------ diff --git a/src/GNDStk/Node/test/subscript.test.cpp b/src/GNDStk/Node/test/subscript.test.cpp index 2f968c0e2..ab713438c 100644 --- a/src/GNDStk/Node/test/subscript.test.cpp +++ b/src/GNDStk/Node/test/subscript.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; // ----------------------------------------------------------------------------- @@ -330,7 +333,7 @@ SCENARIO("Testing GNDStk Node operator[]") { // which of course leads to this sort of thing... CHECK(n.one("REACTIONSUITE").name == "REACTIONSUITE"); n[Child<>("REACTIONSUITE")].name = "reactionSuite"; - // try assigning the whole Node... + // try assigning the Node itself... n[reactionSuite] = c[reactionSuite]; } } diff --git a/src/GNDStk/Node/test/write.test.cpp b/src/GNDStk/Node/test/write.test.cpp index 032196f94..e7a339c3b 100644 --- a/src/GNDStk/Node/test/write.test.cpp +++ b/src/GNDStk/Node/test/write.test.cpp @@ -43,8 +43,8 @@ R"***(covarianceSuite: shape: 78,78 compression: diagonal values: - pcdata: - text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012)***"; + #data: + #text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012)***"; SCENARIO("Testing GNDStk Node write() and operator<<") { GIVEN("A top-level node from a tree object") { diff --git a/src/GNDStk/Optional.hpp b/src/GNDStk/Optional.hpp new file mode 100644 index 000000000..ac09bd7c5 --- /dev/null +++ b/src/GNDStk/Optional.hpp @@ -0,0 +1,50 @@ + +// ----------------------------------------------------------------------------- +// Optional +// This alternative to std::optional uses a pointer, not containment. With +// our Optional, therefore, someone could have, for example, classes X and +// Y, where an X optionally contains a Y, and a Y optionally contains an X. +// ----------------------------------------------------------------------------- + +template +class Optional { + + T *ptr = nullptr; + +public: + + using value_type = T; + + // construction, assignment + #include "GNDStk/Optional/src/ctor.hpp" + #include "GNDStk/Optional/src/assign.hpp" + + // value(), *, -> + #include "GNDStk/Optional/src/value.hpp" + + // reset() + void reset() + { + delete ptr; + ptr = nullptr; + } + + // clear() + // Same as reset(). We just prefer this name. + void clear() + { + reset(); + } + + // conversion to bool + operator bool() const + { + return ptr; + } + + // has_value + bool has_value() const + { + return ptr; + } +}; diff --git a/src/GNDStk/Optional/src/assign.hpp b/src/GNDStk/Optional/src/assign.hpp new file mode 100644 index 000000000..a2737398c --- /dev/null +++ b/src/GNDStk/Optional/src/assign.hpp @@ -0,0 +1,55 @@ + +// ----------------------------------------------------------------------------- +// Assignment operators +// ----------------------------------------------------------------------------- + +// = std::nullopt_t +Optional &operator=(const std::nullopt_t) +{ + reset(); + return *this; +} + +// = T +Optional &operator=(const T &val) +{ + if (ptr) + *ptr = val; + else + ptr = new T(val); + return *this; +} + +// copy +Optional &operator=(const Optional &other) +{ + if (this != &other) { + if (other.ptr) + *this = *other.ptr; + else + reset(); + } + return *this; +} + +// move +Optional &operator=(Optional &&other) +{ + if (this != &other) { + delete ptr; + ptr = other.ptr; + other.ptr = nullptr; + } + return *this; +} + +// template "copy" +template>> +Optional &operator=(const Optional &other) +{ + if (other.ptr) + *this = T(*other.ptr); + else + reset(); + return *this; +} diff --git a/src/GNDStk/Optional/src/ctor.hpp b/src/GNDStk/Optional/src/ctor.hpp new file mode 100644 index 000000000..e61354c88 --- /dev/null +++ b/src/GNDStk/Optional/src/ctor.hpp @@ -0,0 +1,41 @@ + +// ----------------------------------------------------------------------------- +// Constructors +// ----------------------------------------------------------------------------- + +// default +Optional() +{ } + +// std::nullopt_t +explicit Optional(const std::nullopt_t) +{ } + +// T +explicit Optional(const T &val) : + ptr(new T(val)) +{ } + +// copy +Optional(const Optional &other) : + ptr(other.ptr ? new T(*other.ptr) : nullptr) +{ } + +// move +Optional(Optional &&other) : + ptr(other.ptr) +{ + other.ptr = nullptr; +} + +// template "copy" +template>> +Optional(const Optional &other) : + ptr(other.ptr ? new T(*other.ptr) : nullptr) +{ } + +// destructor +~Optional() +{ + reset(); +} diff --git a/src/GNDStk/Optional/src/value.hpp b/src/GNDStk/Optional/src/value.hpp new file mode 100644 index 000000000..f0af39b18 --- /dev/null +++ b/src/GNDStk/Optional/src/value.hpp @@ -0,0 +1,46 @@ + +// ----------------------------------------------------------------------------- +// Get the value; various forms +// ----------------------------------------------------------------------------- + +// value(), const +const T &value() const +{ + if (ptr == nullptr) { + log::error("Call to .value() of a GNDStk::Optional with no value"); + throw std::exception{}; + } + return *ptr; +} + +// value() +T &value() +{ + return const_cast(std::as_const(*this).value()); +} + +// *, const +const T &operator*() const +{ + return *ptr; +} + +// * +T &operator*() +{ + return *ptr; +} + +// ->, const +// Helpful mainly if T is a nontrivial type. With a Optional +// object, for example, you could write object->size(). +const T *operator->() const +{ + return &value(); +} + +// -> +T *operator->() +{ + return &value(); +} diff --git a/src/GNDStk/Support.hpp b/src/GNDStk/Support.hpp index e384b8bc1..d5ffd8ea8 100644 --- a/src/GNDStk/Support.hpp +++ b/src/GNDStk/Support.hpp @@ -14,7 +14,6 @@ using UTF8Text = std::string; using XMLName = std::string; - // ----------------------------------------------------------------------------- // Fraction32 // ----------------------------------------------------------------------------- @@ -73,7 +72,6 @@ inline std::ostream &operator<<(std::ostream &os, const Fraction32 &obj) } - // ----------------------------------------------------------------------------- // IntegerTuple // ----------------------------------------------------------------------------- @@ -86,11 +84,6 @@ class IntegerTuple { // constructors // ------------------------ - // fixme - // The GNDS manual says that "any integer (0-9)" is allowed. If the 0-9 - // part is really correct, then I should probably throw an error, or at - // least print a warning) if a provided value is outside of that range. - IntegerTuple() { } diff --git a/src/GNDStk/Support/src/detail.hpp b/src/GNDStk/Support/src/detail.hpp index db43f50c9..5973171c7 100644 --- a/src/GNDStk/Support/src/detail.hpp +++ b/src/GNDStk/Support/src/detail.hpp @@ -1,12 +1,8 @@ -// fixme -// The "MapTypeString" and "MapStringType" terminology could probably be -// improved. For now this is detail material, so we won't worry about it. - namespace detail { // ----------------------------------------------------------------------------- -// MapTypeString +// Type2Names // ----------------------------------------------------------------------------- // ------------------------ @@ -14,12 +10,12 @@ namespace detail { // ------------------------ template -class MapTypeString { +class Type2Names { public: static inline const std::vector value = {""}; static bool find(const std::string &str) { - return std::find(value.begin(),value.end(),str) != value.end(); + return std::find(value.begin(), value.end(), str) != value.end(); } }; @@ -27,92 +23,91 @@ class MapTypeString { // For specific types // ------------------------ -#define makeMapTypeString(T,vec) \ +#define makeType2Names(T,vec) \ template<> \ - class MapTypeString { \ + class Type2Names { \ public: \ static inline const std::vector value = vec; \ static bool find(const std::string &str) \ { \ - return std::find(value.begin(),value.end(),str) != value.end(); \ + return std::find(value.begin(), value.end(), str) != value.end(); \ } \ } -makeMapTypeString(char, {"char"}); -makeMapTypeString(signed char, {"signed char"}); -makeMapTypeString(short, {"short"}); -makeMapTypeString(long, {"long"}); -makeMapTypeString(long long, {"long long"}); -makeMapTypeString(unsigned char, {"unsigned char"}); -makeMapTypeString(unsigned short, {"unsigned short"}); -makeMapTypeString(unsigned long, {"unsigned long"}); -makeMapTypeString(unsigned long long, {"unsigned long long"}); -makeMapTypeString(float, {"float"}); -makeMapTypeString(long double, {"long double"}); +makeType2Names(char, {"char"}); +makeType2Names(signed char, {"signed char"}); +makeType2Names(short, {"short"}); +makeType2Names(long, {"long"}); +makeType2Names(long long, {"long long"}); +makeType2Names(unsigned char, {"unsigned char"}); +makeType2Names(unsigned short, {"unsigned short"}); +makeType2Names(unsigned long, {"unsigned long"}); +makeType2Names(unsigned long long, {"unsigned long long"}); +makeType2Names(float, {"float"}); +makeType2Names(long double, {"long double"}); // COMMA idea: https://stackoverflow.com/questions/13842468 #define COMMA , -makeMapTypeString(std::string, +makeType2Names(std::string, {"UTF8Text" COMMA "string" COMMA "std::string"}); -makeMapTypeString(int, +makeType2Names(int, {"Integer32" COMMA "int"}); -makeMapTypeString(unsigned int, +makeType2Names(unsigned, {"UInteger32" COMMA "unsigned" COMMA "unsigned int"}); -makeMapTypeString(double, +makeType2Names(double, {"Float64" COMMA "double"}); #undef COMMA -#undef makeMapTypeString +#undef makeType2Names // ------------------------ // Based on variant visit // ------------------------ template -std::string visitMapTypeString(const VARIANT &variant) +std::string visitType2Names(const VARIANT &variant) { return std::visit( [](auto &&vec) { - return MapTypeString>::value[0]; + return Type2Names>::value[0]; }, variant ); } - // ----------------------------------------------------------------------------- -// MapStringType +// Names2Type // ----------------------------------------------------------------------------- template -void MapStringType(const std::string &str, const CALLBACK &call) +void Names2Type(const std::string &str, const CALLBACK &call) { // U helps when type T has spaces (e.g. T is long double) -#define makeMapStringType(T) \ - else if (MapTypeString::find(str)) { using U = T; call(U{}); } +#define makeNames2Type(T) \ + else if (Type2Names::find(str)) { using U = T; call(U{}); } if (false) { } // so macro's "else" always works - makeMapStringType(std::string) - makeMapStringType(char) - makeMapStringType(signed char) - makeMapStringType(short) - makeMapStringType(int) - makeMapStringType(long) - makeMapStringType(long long) - makeMapStringType(unsigned char) - makeMapStringType(unsigned short) - makeMapStringType(unsigned int) - makeMapStringType(unsigned long) - makeMapStringType(unsigned long long) - makeMapStringType(float) - makeMapStringType(double) - makeMapStringType(long double) + makeNames2Type(std::string) + makeNames2Type(char) + makeNames2Type(signed char) + makeNames2Type(short) + makeNames2Type(int) + makeNames2Type(long) + makeNames2Type(long long) + makeNames2Type(unsigned char) + makeNames2Type(unsigned short) + makeNames2Type(unsigned) + makeNames2Type(unsigned long) + makeNames2Type(unsigned long long) + makeNames2Type(float) + makeNames2Type(double) + makeNames2Type(long double) else call(std::string{}); -#undef makeMapStringType +#undef makeNames2Type } } // namespace detail diff --git a/src/GNDStk/Tree.hpp b/src/GNDStk/Tree.hpp index d675c8e1b..39b669ddb 100644 --- a/src/GNDStk/Tree.hpp +++ b/src/GNDStk/Tree.hpp @@ -35,23 +35,14 @@ class Tree : public Node { #include "GNDStk/Tree/src/ctor.hpp" #include "GNDStk/Tree/src/assign.hpp" - #include "GNDStk/Tree/src/read.hpp" - #include "GNDStk/Tree/src/write.hpp" - - // No-argument operator() returns the top-level Node. This overrides - // the base Node class' no-argument operator(), which returns itself. - const Node &operator()() const { return top(); } - Node &operator()() { return top(); } - using Node::operator(); // or the above would disappear Node's goodies - // ------------------------ // Comparison // ------------------------ // We pull out top() first, rather than deferring immediately to Node's // operator==, because Tree can contain a "declaration node" that might - // indicate properties such as whether the data came from an XML file or - // a JSON file. Those properties can be put to good use for other things, + // indicate properties such as whether the data came from an XML, JSON, + // or HDF5 file. Those properties can be put to good use for other things, // but won't play a role in a Tree comparison. // operator== @@ -77,45 +68,3 @@ class Tree : public Node { } }; // class Tree - - - -// ----------------------------------------------------------------------------- -// I/O -// ----------------------------------------------------------------------------- - -// operator>> -inline std::istream &operator>>(std::istream &is, Tree &tree) -{ - try { - return tree.read(is); - } catch (...) { - log::function("istream >> Tree"); - throw; - } -} - -// Tree << std::string -// Note that this is an INPUT operator to Tree! -// Other comments as for Node << std::string -inline void operator<<(Tree &tree, const std::string &str) -{ - try { - std::istringstream iss(str); - iss >> tree; - } catch (...) { - log::function("Tree << string"); - throw; - } -} - -// operator<< -inline std::ostream &operator<<(std::ostream &os, const Tree &tree) -{ - try { - return tree.write(os); - } catch (...) { - log::function("ostream << Tree"); - throw; - } -} diff --git a/src/GNDStk/Tree/src/ctor.hpp b/src/GNDStk/Tree/src/ctor.hpp index 2bbdfcfb2..f3048543c 100644 --- a/src/GNDStk/Tree/src/ctor.hpp +++ b/src/GNDStk/Tree/src/ctor.hpp @@ -4,13 +4,15 @@ // ----------------------------------------------------------------------------- // default -Tree() = default; +Tree() : Node("/") +{ +} // move Tree(Tree &&) = default; // copy -Tree(const Tree &other) : Node{} +Tree(const Tree &other) : Node("/") { try { if (!convert(other,*this)) @@ -24,11 +26,11 @@ Tree(const Tree &other) : Node{} // ----------------------------------------------------------------------------- -// From XML and JSON objects +// From XML, JSON, and HDF5 objects // ----------------------------------------------------------------------------- // XML -explicit Tree(const XML &x) +explicit Tree(const XML &x) : Node("/") { try { if (!convert(x,*this)) @@ -40,7 +42,7 @@ explicit Tree(const XML &x) } // JSON -explicit Tree(const JSON &j) +explicit Tree(const JSON &j) : Node("/") { try { if (!convert(j,*this)) @@ -51,6 +53,18 @@ explicit Tree(const JSON &j) } } +// HDF5 +explicit Tree(const HDF5 &h) : Node("/") +{ + try { + if (!convert(h,*this)) + throw std::exception{}; + } catch (...) { + log::ctor("Tree(HDF5)"); + throw; + } +} + // ----------------------------------------------------------------------------- @@ -58,32 +72,36 @@ explicit Tree(const JSON &j) // Compare with our Tree read() functions // ----------------------------------------------------------------------------- -// file name, FileType +// file, FileType // Example: // Tree t("n-008_O_016.xml", FileType::xml); explicit Tree( const std::string &filename, - const FileType format = FileType::null -) { + const FileType format = FileType::guess +) + : Node("/") +{ try { if (!read(filename,format)) throw std::exception{}; } catch (...) { - log::ctor("Tree(\"{}\")", filename); + log::ctor("Tree(\"{}\",format=\"{}\")", + filename, detail::printFormat(format)); throw; } } -// file name, string +// file, string // Example: // Tree t("n-008_O_016.xml", "xml"); Tree(const std::string &filename, const std::string &format) + : Node("/") { try { if (!read(filename,format)) throw std::exception{}; } catch (...) { - log::ctor("Tree(\"{}\",type=\"{}\")", filename, format); + log::ctor("Tree(\"{}\",format=\"{}\")", filename, format); throw; } } @@ -92,13 +110,14 @@ Tree(const std::string &filename, const std::string &format) // Example: // std::ifstream ifs("n-008_O_016.xml"); // Tree t(ifs, FileType::xml); -explicit Tree(std::istream &is, const FileType format = FileType::null) +explicit Tree(std::istream &is, const FileType format = FileType::guess) + : Node("/") { try { if (!read(is,format)) throw std::exception{}; } catch (...) { - log::ctor("Tree(istream,string)"); + log::ctor("Tree(istream,format=\"{}\")", detail::printFormat(format)); throw; } } @@ -108,12 +127,13 @@ explicit Tree(std::istream &is, const FileType format = FileType::null) // std::ifstream ifs("n-008_O_016.xml"); // Tree t(ifs, "xml"); Tree(std::istream &is, const std::string &format) + : Node("/") { try { if (!read(is,format)) throw std::exception{}; } catch (...) { - log::ctor("Tree(istream,format)", format); + log::ctor("Tree(istream,format=\"{}\")", format); throw; } } @@ -132,7 +152,7 @@ Tree(std::istream &is, const std::string &format) // or // Tree newtree(reactionSuite, "xml", "1.0", "UTF-8"); // -// Note that the first argument is NOT quoted (""). It isn't the name of the +// Note that the first argument is NOT in quotes. It isn't the name of the // top-level node that we want; rather, it's one of our Child "query objects." // These encode lots of information in them, including the quoted name that // we'd otherwise have expected above, and, importantly, a boolean value that @@ -152,7 +172,9 @@ Tree( // the names "version" and "encoding" make sense for XML at least... const std::string &version = detail::default_string, const std::string &encoding = detail::default_string -) { +) + : Node("/") +{ try { reset(kwd, format, version, encoding); } catch (...) { @@ -168,7 +190,9 @@ Tree( const std::string &format, const std::string &version = detail::default_string, const std::string &encoding = detail::default_string -) { +) + : Node("/") +{ try { reset(kwd, format, version, encoding); } catch (...) { diff --git a/src/GNDStk/Tree/src/decl.hpp b/src/GNDStk/Tree/src/decl.hpp index 793fab563..b6654a306 100644 --- a/src/GNDStk/Tree/src/decl.hpp +++ b/src/GNDStk/Tree/src/decl.hpp @@ -12,7 +12,9 @@ const Node &decl() const throw std::exception{}; } for (auto &c : this->children) - if (c->name == "xml" || c->name == "json" || c->name == "hdf5") + if (c->name == special::xml || + c->name == special::json || + c->name == special::hdf5) return *c; log::error("Tree's declaration node not found"); throw std::exception{}; diff --git a/src/GNDStk/Tree/src/has_decl.hpp b/src/GNDStk/Tree/src/has_decl.hpp index 2bd6aa6d8..d10d390a0 100644 --- a/src/GNDStk/Tree/src/has_decl.hpp +++ b/src/GNDStk/Tree/src/has_decl.hpp @@ -5,7 +5,9 @@ bool has_decl() const // Does the tree have something that looks like a declaration node? int count = 0; for (auto &c : this->children) - if (c->name == "xml" || c->name == "json" || c->name == "hdf5") + if (c->name == special::xml || + c->name == special::json || + c->name == special::hdf5) count++; // Ill-formed if there's more than one such node diff --git a/src/GNDStk/Tree/src/has_top.hpp b/src/GNDStk/Tree/src/has_top.hpp index 80c82d6eb..c16722ad0 100644 --- a/src/GNDStk/Tree/src/has_top.hpp +++ b/src/GNDStk/Tree/src/has_top.hpp @@ -10,7 +10,9 @@ bool has_top() const // defined as something that *doesn't* look like a declaration node? int count = 0; for (auto &c : this->children) - if (c->name != "xml" && c->name != "json" && c->name != "hdf5") + if (c->name != special::xml && + c->name != special::json && + c->name != special::hdf5) count++; // Ill-formed if there's more than one such node diff --git a/src/GNDStk/Tree/src/read.hpp b/src/GNDStk/Tree/src/read.hpp deleted file mode 100644 index 737249f8a..000000000 --- a/src/GNDStk/Tree/src/read.hpp +++ /dev/null @@ -1,58 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Tree.read() -// Cases are as for Node.read(), to which these defer with decl == true, -// meaning that, for Tree, we preserve any declaration node. -// ----------------------------------------------------------------------------- - -// 1. read(istream, FileType) -std::istream &read( - std::istream &is, - const FileType format = FileType::null -) { - try { - return this->Node::read(is, format, true); - } catch (...) { - log::member("Tree.read(istream)"); - throw; - } -} - -// 2. read(file name, FileType) -bool read( - const std::string &filename, - const FileType format = FileType::null -) { - try { - return this->Node::read(filename, format, true); - } catch (...) { - log::member("Tree.read(\"{}\")", filename); - throw; - } -} - -// 3. read(istream, string) -std::istream &read( - std::istream &is, - const std::string &format -) { - try { - return this->Node::read(is, format, true); - } catch (...) { - log::member("Tree.read(istream,\"{}\")", format); - throw; - } -} - -// 4. read(file name, string) -bool read( - const std::string &filename, - const std::string &format -) { - try { - return this->Node::read(filename, format, true); - } catch (...) { - log::member("Tree.read(\"{}\",\"{}\")", filename, format); - throw; - } -} diff --git a/src/GNDStk/Tree/src/reset.hpp b/src/GNDStk/Tree/src/reset.hpp index a5f56f3ea..595deb628 100644 --- a/src/GNDStk/Tree/src/reset.hpp +++ b/src/GNDStk/Tree/src/reset.hpp @@ -32,43 +32,30 @@ Tree &reset( // Begin a new tree clear(); - // Warn if the given Child doesn't look valid for a top-level GNDS node - if (!kwd.top()) { - log::warning( - "Tree.reset(" + detail::keyname(kwd) + ") called, " - "but the Node as given by the\n" - "Child object is not encoded as being suitable for a top-level\n" - "GNDS node (bool Child.top() is false)" - ); - } - try { - // Declaration node: "xml", etc. + // Declaration node: special::xml, etc. // This can specify an eventual intended file format // for the GNDS hierarchy. - if (format == FileType::xml - || format == FileType::null - || format == FileType::text + if (format == FileType::xml || + format == FileType::guess || + format == FileType::debug ) { - // xml, null, tree - add("xml"); + // xml, guess, tree + add(special::xml); decl().add("version", detail::sent(version ) ? version : "1.0" ); decl().add("encoding", detail::sent(encoding) ? encoding : "UTF-8"); } else if (format == FileType::json) { // json - add("json"); - // any use for version and encoding? + add(special::json); } else if (format == FileType::hdf5) { // hdf5 - add("hdf5"); - // any use for version and encoding? + add(special::hdf5); } else { log::error( - "Internal error in Tree.reset(" + detail::keyname(kwd) - + ",format,...):\n" - "Unrecognized file format; apparently, we missed something. " - "Please report this to us" - ); + "Internal error in Tree.reset(" + detail::keyname(kwd) + + ", format, ...):\n" + "Unrecognized file format; apparently, we missed something.\n" + "Please report this to us."); throw std::exception{}; } @@ -96,12 +83,10 @@ Tree &reset( const std::string &encoding = detail::default_string ) { try { - // recognized file formats - if (eq_null(format)) return reset(kwd, FileType::null, version, encoding); - if (eq_text(format)) return reset(kwd, FileType::text, version, encoding); - if (eq_xml (format)) return reset(kwd, FileType::xml, version, encoding); - if (eq_json(format)) return reset(kwd, FileType::json, version, encoding); - if (eq_hdf5(format)) return reset(kwd, FileType::hdf5, version, encoding); + bool matched; + const FileType type = string2filetype(format,matched); + if (matched) + return reset(kwd, type, version, encoding); // fallback: use XML // Note: we should consider making this an error diff --git a/src/GNDStk/Tree/src/top.hpp b/src/GNDStk/Tree/src/top.hpp index a6ad51904..6b910a36c 100644 --- a/src/GNDStk/Tree/src/top.hpp +++ b/src/GNDStk/Tree/src/top.hpp @@ -12,7 +12,9 @@ const Node &top() const throw std::exception{}; } for (auto &c : this->children) - if (c->name != "xml" && c->name != "json" && c->name != "hdf5") + if (c->name != special::xml && + c->name != special::json && + c->name != special::hdf5) return *c; log::error("Tree's top-level GNDS node not found"); throw std::exception{}; diff --git a/src/GNDStk/Tree/src/write.hpp b/src/GNDStk/Tree/src/write.hpp deleted file mode 100644 index a75f407a3..000000000 --- a/src/GNDStk/Tree/src/write.hpp +++ /dev/null @@ -1,61 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Tree.write() -// Forward to Node.write(), with decl == true. -// ----------------------------------------------------------------------------- - -// 1. write(ostream, FileType) -std::ostream &write( - std::ostream &os = std::cout, - const FileType format = FileType::null, - const bool decl = true -) const { - try { - return this->Node::write(os, format, decl); - } catch (...) { - log::member("Tree.write(ostream)"); - throw; - } -} - -// 2. write(file name, FileType) -bool write( - const std::string &filename, - const FileType format = FileType::null, - const bool decl = true -) const { - try { - return this->Node::write(filename, format, decl); - } catch (...) { - log::member("Tree.write(\"{}\")", filename); - throw; - } -} - -// 3. write(ostream, string) -std::ostream &write( - std::ostream &os, - const std::string &format, - const bool decl = true -) const { - try { - return this->Node::write(os, format, decl); - } catch (...) { - log::member("Tree.write(ostream,\"{}\")", format); - throw; - } -} - -// 4. write(file name, string) -bool write( - const std::string &filename, - const std::string &format, - const bool decl = true -) const { - try { - return this->Node::write(filename, format, decl); - } catch (...) { - log::member("Tree.write(\"{}\",\"{}\")", filename, format); - throw; - } -} diff --git a/src/GNDStk/Tree/test/call.test.cpp b/src/GNDStk/Tree/test/call.test.cpp index 3a20df864..49b78486f 100644 --- a/src/GNDStk/Tree/test/call.test.cpp +++ b/src/GNDStk/Tree/test/call.test.cpp @@ -1,8 +1,9 @@ #include "catch.hpp" #include "GNDStk.hpp" - using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" using namespace misc; @@ -27,7 +28,7 @@ inline void convert(const NODE &node, xml_t &out) out.encoding = node.meta(encoding); } -inline const Child xml("xml"); +inline const Child xml(special::xml); // ------------------------ diff --git a/src/GNDStk/Tree/test/child.test.cpp b/src/GNDStk/Tree/test/child.test.cpp index 2dbefb630..fa093a212 100644 --- a/src/GNDStk/Tree/test/child.test.cpp +++ b/src/GNDStk/Tree/test/child.test.cpp @@ -1,8 +1,9 @@ #include "catch.hpp" #include "GNDStk.hpp" - using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" using namespace misc; @@ -36,9 +37,9 @@ inline void convert(const NODE &node, xml_t &out) // keyword: my_xml_keyword // Users can write custom Child objects like this, and then use them in -// child() functions. Here, "xml" is what the keyword uses to look up nodes -// that can be converted to xml_t objects via the above convert(). -inline const Child my_xml_keyword("xml"); +// child() functions. Here, special::xml is what the keyword uses to look +// up nodes that can be converted to xml_t objects via the above convert(). +inline const Child my_xml_keyword(special::xml); diff --git a/src/GNDStk/Tree/test/ctor.test.cpp b/src/GNDStk/Tree/test/ctor.test.cpp index d045c84d3..406a22d20 100644 --- a/src/GNDStk/Tree/test/ctor.test.cpp +++ b/src/GNDStk/Tree/test/ctor.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; /* @@ -125,7 +126,7 @@ SCENARIO("Testing GNDStk tree constructors") { WHEN("We call: Tree(top-level node)") { Tree t(reactionSuite); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "1.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -139,7 +140,7 @@ SCENARIO("Testing GNDStk tree constructors") { WHEN("We call: Tree(top-level node, file format)") { Tree t(reactionSuite, FileType::json); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "json"); + CHECK(t.decl().name == special::json); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); CHECK(t.top().name == "reactionSuite"); @@ -149,9 +150,9 @@ SCENARIO("Testing GNDStk tree constructors") { } WHEN("We call: Tree(top-level node, file format, version)") { - Tree t(covarianceSuite, FileType::null, "2.0"); + Tree t(covarianceSuite, FileType::guess, "2.0"); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "2.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -165,7 +166,7 @@ SCENARIO("Testing GNDStk tree constructors") { WHEN("We call: Tree(top-level node, file format, version, encoding)") { Tree t(covarianceSuite, FileType::xml, "3.0", "UTF-9"); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "3.0"); CHECK(t.decl().meta("encoding") == "UTF-9"); @@ -179,7 +180,7 @@ SCENARIO("Testing GNDStk tree constructors") { WHEN("We call: Tree(top-level node, string)") { Tree t(PoPs, "hdf5"); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "hdf5"); + CHECK(t.decl().name == special::hdf5); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); CHECK(t.top().name == "PoPs"); @@ -189,9 +190,9 @@ SCENARIO("Testing GNDStk tree constructors") { } WHEN("We call: Tree(top-level node, string, version)") { - Tree t(PoPs, "text", "4.0"); + Tree t(PoPs, "debug", "4.0"); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "4.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -205,7 +206,7 @@ SCENARIO("Testing GNDStk tree constructors") { WHEN("We call: Tree(top-level node, string, version, encoding)") { Tree t(thermalScattering, "xml", "5.0", "UTF-10"); THEN("We can make various decl() and top() queries") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "5.0"); CHECK(t.decl().meta("encoding") == "UTF-10"); diff --git a/src/GNDStk/Tree/test/decl.test.cpp b/src/GNDStk/Tree/test/decl.test.cpp index eabd61fdf..9a58ef580 100644 --- a/src/GNDStk/Tree/test/decl.test.cpp +++ b/src/GNDStk/Tree/test/decl.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" SCENARIO("Testing GNDStk tree decl()") { using namespace njoy::GNDStk; @@ -9,7 +10,7 @@ SCENARIO("Testing GNDStk tree decl()") { GIVEN("A tree read from an XML file") { Tree t("n-069_Tm_170-covar.xml"); - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "1.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -21,7 +22,7 @@ SCENARIO("Testing GNDStk tree decl()") { WHEN("We call reset(reactionSuite)") { Tree t; t.reset(reactionSuite); - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "1.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -31,25 +32,26 @@ SCENARIO("Testing GNDStk tree decl()") { WHEN("We call reset(reactionSuite, FileType::json)") { Tree t; t.reset(reactionSuite, FileType::json); - CHECK(t.decl().name == "json"); + CHECK(t.decl().name == special::json); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); } - WHEN("We call reset(covarianceSuite, FileType::null, \"2.0\")") { + WHEN("We call reset(covarianceSuite, FileType::guess, \"2.0\")") { Tree t; - t.reset(covarianceSuite, FileType::null, "2.0"); - CHECK(t.decl().name == "xml"); + t.reset(covarianceSuite, FileType::guess, "2.0"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "2.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); CHECK(t.decl().children.size() == 0); } - WHEN("We call reset(covarianceSuite, FileType::xml, \"3.0\", \"UTF-9\")") { + WHEN("We call reset(covarianceSuite, FileType::xml, " + "\"3.0\", \"UTF-9\")") { Tree t; t.reset(covarianceSuite, FileType::xml, "3.0", "UTF-9"); - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "3.0"); CHECK(t.decl().meta("encoding") == "UTF-9"); @@ -59,16 +61,16 @@ SCENARIO("Testing GNDStk tree decl()") { WHEN("We call reset(PoPs, \"hdf5\")") { Tree t; t.reset(PoPs, "hdf5"); - CHECK(t.decl().name == "hdf5"); + CHECK(t.decl().name == special::hdf5); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); } - WHEN("We call reset(PoPs, \"tree\", \"4.0\")") { + WHEN("We call reset(PoPs, \"debug\", \"4.0\")") { Tree t; - t.reset(PoPs, "text", "4.0"); - CHECK(t.decl().name == "xml"); + t.reset(PoPs, "debug", "4.0"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "4.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -78,7 +80,7 @@ SCENARIO("Testing GNDStk tree decl()") { WHEN("We call reset(thermalScattering, \"xml\", \"5.0\", \"UTF-10\")") { Tree t; t.reset(thermalScattering, "xml", "5.0", "UTF-10"); - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "5.0"); CHECK(t.decl().meta("encoding") == "UTF-10"); diff --git a/src/GNDStk/Tree/test/many.test.cpp b/src/GNDStk/Tree/test/many.test.cpp index 6bf0f81a9..03003298b 100644 --- a/src/GNDStk/Tree/test/many.test.cpp +++ b/src/GNDStk/Tree/test/many.test.cpp @@ -18,23 +18,23 @@ SCENARIO("Testing GNDStk Tree many()") { // the top-level GNDS node (or both if they have the same name, which // really wouldn't be a correct state of affairs). - WHEN("We look for all \"xml\" nodes") { + WHEN("We look for all \"#xml\" nodes") { // Declaration node... // const found = false; - auto cnode = c.many("xml",found); + auto cnode = c.many(special::xml,found); CHECK(found); CHECK(cnode.size() == 1); - CHECK(cnode[0].name == "xml"); + CHECK(cnode[0].name == special::xml); CHECK(cnode[0].meta("version") == "1.0"); // non-const found = false; - auto tnode = t.many("xml",found); + auto tnode = t.many(special::xml,found); CHECK(found); CHECK(tnode.size() == 1); - CHECK(tnode[0].name == "xml"); + CHECK(tnode[0].name == special::xml); CHECK(tnode[0].meta("encoding") == "UTF-8"); } diff --git a/src/GNDStk/Tree/test/meta.test.cpp b/src/GNDStk/Tree/test/meta.test.cpp index 2cae9ebec..43f330ffe 100644 --- a/src/GNDStk/Tree/test/meta.test.cpp +++ b/src/GNDStk/Tree/test/meta.test.cpp @@ -1,8 +1,9 @@ #include "catch.hpp" #include "GNDStk.hpp" - using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" using namespace misc; SCENARIO("Testing GNDStk Tree meta()") { @@ -186,8 +187,8 @@ SCENARIO("Testing GNDStk Tree meta()") { CHECK(t.top() .meta("projectile") == "abc"); // verify that it changed WHEN("We try assignment: Tree.meta(keyword) = ...") { - // assignments "work" (don't cause a crash) for nonexistent metadata - // keys, but give back found == false + // assignments "work" (don't cause a crash) for nonexistent metadata, + // but give back found == false CHECK((found = true, t.meta("foo key",found) = "foo value", !found)); CHECK((found = true, t.meta("bar key",found) = "bar value", !found)); } diff --git a/src/GNDStk/Tree/test/one.test.cpp b/src/GNDStk/Tree/test/one.test.cpp index 1442ae639..9916c5792 100644 --- a/src/GNDStk/Tree/test/one.test.cpp +++ b/src/GNDStk/Tree/test/one.test.cpp @@ -18,21 +18,21 @@ SCENARIO("Testing GNDStk Tree one()") { // node, or the top-level GNDS node; we consider both of those to be // a Tree's children. - WHEN("We look for an \"xml\" node") { + WHEN("We look for an \"#xml\" node") { // Declaration node... // const found = false; - auto &cnode = c.one("xml",found); + auto &cnode = c.one(special::xml,found); CHECK(found); - CHECK(cnode.name == "xml"); + CHECK(cnode.name == special::xml); CHECK(cnode.meta("version") == "1.0"); // non-const found = false; - auto &tnode = t.one("xml",found); + auto &tnode = t.one(special::xml,found); CHECK(found); - CHECK(tnode.name == "xml"); + CHECK(tnode.name == special::xml); CHECK(tnode.meta("encoding") == "UTF-8"); } @@ -70,12 +70,12 @@ SCENARIO("Testing GNDStk Tree one()") { // Illustrate that Tree's one(string) functions return references, // even when the child isn't found... - (void)&c.one("xml"); + (void)&c.one(special::xml); (void)&c.one("covarianceSuite"); (void)&c.one("foo",found); CHECK(!found); - (void)&t.one("xml"); + (void)&t.one(special::xml); (void)&t.one("covarianceSuite"); (void)&t.one("bar",found); CHECK(!found); diff --git a/src/GNDStk/Tree/test/read.test.cpp b/src/GNDStk/Tree/test/read.test.cpp index 876bf38be..3b9727c4c 100644 --- a/src/GNDStk/Tree/test/read.test.cpp +++ b/src/GNDStk/Tree/test/read.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; @@ -9,7 +10,7 @@ using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- static const std::string correct_tree = -R"***(: +R"***( covarianceSuite: evaluation: ENDF/B-8.0 format: 1.9 @@ -29,8 +30,8 @@ R"***(: compression: diagonal shape: 78,78 values: - pcdata: - text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012 + #data: + #text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012 parameters: parameterLink: href: $reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']/resonanceParameters/table @@ -53,14 +54,14 @@ R"***(: value: 0.0)***"; static const std::string decl_xml = -R"***( - xml: +R"***(/: + #xml: encoding: UTF-8 version: 1.0)***"; static const std::string decl_json = -R"***( - json:)***"; +R"***(/: + #json:)***"; void compare(Tree &t, const std::string &correct) { @@ -86,13 +87,13 @@ SCENARIO("Testing GNDStk tree read() and operator>>") { WHEN("We read() one from an xml file") { const std::string filename = "n-069_Tm_170-covar.xml"; t1.read(filename); - compare(t1,correct_tree+decl_xml); + compare(t1, decl_xml + correct_tree); } WHEN("We read() one from an xml istream, specifically an ifstream") { std::ifstream ifs("n-069_Tm_170-covar.xml"); t2.read(ifs); - compare(t2,correct_tree+decl_xml); + compare(t2, decl_xml + correct_tree); } WHEN("We read() one from an xml istream, specifically a stringstream") { @@ -100,13 +101,13 @@ SCENARIO("Testing GNDStk tree read() and operator>>") { std::stringstream sstr; sstr << ifs.rdbuf(); t3.read(sstr); - compare(t3,correct_tree+decl_xml); + compare(t3, decl_xml + correct_tree); } WHEN("We stream-input one, specifically from an xml ifstream") { std::ifstream ifs("n-069_Tm_170-covar.xml"); ifs >> t4; - compare(t4,correct_tree+decl_xml); + compare(t4, decl_xml + correct_tree); } // ------------------------ @@ -116,13 +117,13 @@ SCENARIO("Testing GNDStk tree read() and operator>>") { WHEN("We read() one from a json file") { const std::string filename = "n-069_Tm_170-covar.json"; t1.read(filename); - compare(t1,correct_tree+decl_json); + compare(t1, decl_json + correct_tree); } WHEN("We read() one from a json istream, specifically an ifstream") { std::ifstream ifs("n-069_Tm_170-covar.json"); t2.read(ifs); - compare(t2,correct_tree+decl_json); + compare(t2, decl_json + correct_tree); } WHEN("We read() one from a json istream, specifically a stringstream") { @@ -130,21 +131,21 @@ SCENARIO("Testing GNDStk tree read() and operator>>") { std::stringstream sstr; sstr << ifs.rdbuf(); t3.read(sstr); - compare(t3,correct_tree+decl_json); + compare(t3, decl_json + correct_tree); } WHEN("We stream-input one, specifically from a json ifstream") { std::ifstream ifs("n-069_Tm_170-covar.json"); ifs >> t4; - compare(t4,correct_tree+decl_json); + compare(t4, decl_json + correct_tree); } } // Why not... GIVEN("Several trees, read differently, but ultimately from the same file") { - // While the present test file is about tree's read(), not about its - // write(), let's nevertheless do a simple write(), to tree's basic - // text-output file format, from each of the trees read in different ways + // While the present test file is about tree's read(), not its write(), + // let's nevertheless do a simple write(), in our debug output-file + // format, from each of the trees that were read in different ways // above, and be sure there are absolutely no differences between them. // In effect, this helps test the read(), because it gives confidence // that our various ways of reading the same files give the same results. @@ -169,76 +170,76 @@ SCENARIO("Testing GNDStk tree read() and operator>>") { WHEN("We test read(filename, file format") { // xml - tree.read(xfilename,FileType::null); - compare(tree,correct_tree+decl_xml); - tree.read(xfilename,FileType::xml ); - compare(tree,correct_tree+decl_xml); + tree.read(xfilename,FileType::guess); + compare(tree, decl_xml + correct_tree); + tree.read(xfilename,FileType::xml); + compare(tree, decl_xml + correct_tree); // json - tree.read(jfilename,FileType::null); - compare(tree,correct_tree+decl_json); + tree.read(jfilename,FileType::guess); + compare(tree, decl_json + correct_tree); tree.read(jfilename,FileType::json); - compare(tree,correct_tree+decl_json); + compare(tree, decl_json + correct_tree); } WHEN("We test read(filename, string") { // xml - tree.read(xfilename,"" ); - compare(tree,correct_tree+decl_xml); - tree.read(xfilename,"null"); - compare(tree,correct_tree+decl_xml); - tree.read(xfilename,"xml" ); - compare(tree,correct_tree+decl_xml); + tree.read(xfilename,""); + compare(tree, decl_xml + correct_tree); + tree.read(xfilename,"guess"); + compare(tree, decl_xml + correct_tree); + tree.read(xfilename,"xml"); + compare(tree, decl_xml + correct_tree); // json - tree.read(jfilename,"" ); - compare(tree,correct_tree+decl_json); - tree.read(jfilename,"null"); - compare(tree,correct_tree+decl_json); + tree.read(jfilename,""); + compare(tree, decl_json + correct_tree); + tree.read(jfilename,"guess"); + compare(tree, decl_json + correct_tree); tree.read(jfilename,"json"); - compare(tree,correct_tree+decl_json); + compare(tree, decl_json + correct_tree); } WHEN("We test read(istream, file format") { // xml xifs.seekg (0,std::ios::beg); - tree.read(xifs,FileType::null); - compare(tree,correct_tree+decl_xml); + tree.read(xifs,FileType::guess); + compare(tree, decl_xml + correct_tree); xifs.seekg (0,std::ios::beg); - tree.read(xifs,FileType::xml ); - compare(tree,correct_tree+decl_xml); + tree.read(xifs,FileType::xml); + compare(tree, decl_xml + correct_tree); // json jifs.seekg (0,std::ios::beg); - tree.read(jifs,FileType::null); - compare(tree,correct_tree+decl_json); + tree.read(jifs,FileType::guess); + compare(tree, decl_json + correct_tree); jifs.seekg (0,std::ios::beg); tree.read(jifs,FileType::json); - compare(tree,correct_tree+decl_json); + compare(tree, decl_json + correct_tree); } WHEN("We test read(istream, string") { // xml xifs.seekg (0,std::ios::beg); - tree.read(xifs,"" ); - compare(tree,correct_tree+decl_xml); + tree.read(xifs,""); + compare(tree, decl_xml + correct_tree); xifs.seekg (0,std::ios::beg); - tree.read(xifs,"null"); - compare(tree,correct_tree+decl_xml); + tree.read(xifs,"guess"); + compare(tree, decl_xml + correct_tree); xifs.seekg (0,std::ios::beg); - tree.read(xifs,"xml" ); - compare(tree,correct_tree+decl_xml); + tree.read(xifs,"xml"); + compare(tree, decl_xml + correct_tree); // json jifs.seekg (0,std::ios::beg); - tree.read(jifs,"" ); - compare(tree,correct_tree+decl_json); + tree.read(jifs,""); + compare(tree, decl_json + correct_tree); jifs.seekg (0,std::ios::beg); - tree.read(jifs,"null"); - compare(tree,correct_tree+decl_json); + tree.read(jifs,"guess"); + compare(tree, decl_json + correct_tree); jifs.seekg (0,std::ios::beg); tree.read(jifs,"json"); - compare(tree,correct_tree+decl_json); + compare(tree, decl_json + correct_tree); } } } diff --git a/src/GNDStk/Tree/test/reset.test.cpp b/src/GNDStk/Tree/test/reset.test.cpp index 41d3c0f91..b2ca7a4b6 100644 --- a/src/GNDStk/Tree/test/reset.test.cpp +++ b/src/GNDStk/Tree/test/reset.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" SCENARIO("Testing GNDStk tree reset()") { using namespace njoy::GNDStk; @@ -24,7 +25,7 @@ SCENARIO("Testing GNDStk tree reset()") { t.reset(reactionSuite); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "1.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -41,7 +42,7 @@ SCENARIO("Testing GNDStk tree reset()") { t.reset(reactionSuite, FileType::json); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "json"); + CHECK(t.decl().name == special::json); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); CHECK(t.top().name == "reactionSuite"); @@ -51,12 +52,12 @@ SCENARIO("Testing GNDStk tree reset()") { } WHEN("We call " - "Tree.reset(covarianceSuite, FileType::null, \"2.0\")") { + "Tree.reset(covarianceSuite, FileType::guess, \"2.0\")") { Tree t; - t.reset(covarianceSuite, FileType::null, "2.0"); + t.reset(covarianceSuite, FileType::guess, "2.0"); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "2.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -73,7 +74,7 @@ SCENARIO("Testing GNDStk tree reset()") { t.reset(covarianceSuite, FileType::xml, "3.0", "UTF-9"); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "3.0"); CHECK(t.decl().meta("encoding") == "UTF-9"); @@ -90,7 +91,7 @@ SCENARIO("Testing GNDStk tree reset()") { t.reset(PoPs, "hdf5"); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "hdf5"); + CHECK(t.decl().name == special::hdf5); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); CHECK(t.top().name == "PoPs"); @@ -101,12 +102,12 @@ SCENARIO("Testing GNDStk tree reset()") { } WHEN("We call " - "Tree.reset(PoPs, \"tree\", \"4.0\")") { + "Tree.reset(PoPs, \"debug\", \"4.0\")") { Tree t; - t.reset(PoPs, "text", "4.0"); + t.reset(PoPs, "debug", "4.0"); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "4.0"); CHECK(t.decl().meta("encoding") == "UTF-8"); @@ -123,7 +124,7 @@ SCENARIO("Testing GNDStk tree reset()") { t.reset(thermalScattering, "xml", "5.0", "UTF-10"); THEN("Declaration- and top-level-node queries can be made") { - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 2); CHECK(t.decl().meta("version") == "5.0"); CHECK(t.decl().meta("encoding") == "UTF-10"); diff --git a/src/GNDStk/Tree/test/resources/n-069_Tm_170-covar.json b/src/GNDStk/Tree/test/resources/n-069_Tm_170-covar.json index d23640cb5..91cb7e1a0 100644 --- a/src/GNDStk/Tree/test/resources/n-069_Tm_170-covar.json +++ b/src/GNDStk/Tree/test/resources/n-069_Tm_170-covar.json @@ -1,6 +1,6 @@ { "covarianceSuite": { - "attributes": { + "#metadata": { "evaluation": "ENDF/B-8.0", "format": "1.9", "projectile": "n", @@ -8,7 +8,7 @@ }, "externalFiles": { "externalFile": { - "attributes": { + "#metadata": { "label": "reactions", "path": "n-069_Tm_170.xml" } @@ -16,30 +16,30 @@ }, "parameterCovariances": { "parameterCovariance": { - "attributes": { + "#metadata": { "label": "resolved resonances" }, "parameterCovarianceMatrix": { "array": { - "attributes": { + "#metadata": { "compression": "diagonal", "shape": "78,78" }, "values": { - "pcdata": { - "attributes": { - "text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" + "#data": { + "#metadata": { + "#text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" } } } }, - "attributes": { + "#metadata": { "label": "eval", "type": "absolute" }, "parameters": { "parameterLink": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']/resonanceParameters/table", "label": "resonanceParameters", "nParameters": "78" @@ -48,7 +48,7 @@ } }, "rowData": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']" } } @@ -56,21 +56,21 @@ }, "styles": { "evaluated": { - "attributes": { + "#metadata": { "date": "2011-10-01", "label": "eval", "library": "ENDF/B", "version": "8.0.1" }, "projectileEnergyDomain": { - "attributes": { + "#metadata": { "max": "30000000.0", "min": "1e-05", "unit": "eV" } }, "temperature": { - "attributes": { + "#metadata": { "unit": "K", "value": "0.0" } diff --git a/src/GNDStk/Tree/test/special.test.cpp b/src/GNDStk/Tree/test/special.test.cpp index f5dbc5568..52e93f7be 100644 --- a/src/GNDStk/Tree/test/special.test.cpp +++ b/src/GNDStk/Tree/test/special.test.cpp @@ -1,7 +1,10 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; + +#include "GNDStk/test/keys.hpp" +using namespace basic; SCENARIO("Testing comment() and comments() in GNDStk Tree") { // Tree @@ -34,11 +37,11 @@ SCENARIO("Testing comment() and comments() in GNDStk Tree") { WHEN("Testing comment()") { // non-const - CHECK(n.comment( ) == title); + CHECK(n.comment() == title); CHECK(n.comment(0) == title); CHECK(n.comment(1) == width); // const - CHECK(c.comment( ) == title); + CHECK(c.comment() == title); CHECK(c.comment(0) == title); CHECK(c.comment(1) == width); } diff --git a/src/GNDStk/Tree/test/top.test.cpp b/src/GNDStk/Tree/test/top.test.cpp index b7853b164..2fc743e15 100644 --- a/src/GNDStk/Tree/test/top.test.cpp +++ b/src/GNDStk/Tree/test/top.test.cpp @@ -1,6 +1,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" SCENARIO("Testing GNDStk Tree top()") { using namespace njoy::GNDStk; @@ -40,9 +41,9 @@ SCENARIO("Testing GNDStk Tree top()") { } } - WHEN("We call reset(covarianceSuite, FileType::null, \"2.0\")") { + WHEN("We call reset(covarianceSuite, FileType::guess, \"2.0\")") { Tree t; - t.reset(covarianceSuite, FileType::null, "2.0"); + t.reset(covarianceSuite, FileType::guess, "2.0"); THEN("We can make various top() (top-level node) queries") { CHECK(t.top().name == "covarianceSuite"); CHECK(t.top().metadata.size() == 0); @@ -50,7 +51,8 @@ SCENARIO("Testing GNDStk Tree top()") { } } - WHEN("We call reset(covarianceSuite, FileType::xml, \"3.0\", \"UTF-9\")") { + WHEN("We call reset(covarianceSuite, FileType::xml, " + "\"3.0\", \"UTF-9\")") { Tree t; t.reset(covarianceSuite, FileType::xml, "3.0", "UTF-9"); THEN("We can make various top() (top-level node) queries") { @@ -70,9 +72,9 @@ SCENARIO("Testing GNDStk Tree top()") { } } - WHEN("We call reset(PoPs, \"tree\", \"4.0\")") { + WHEN("We call reset(PoPs, \"debug\", \"4.0\")") { Tree t; - t.reset(PoPs, "text", "4.0"); + t.reset(PoPs, "debug", "4.0"); THEN("We can make various top() (top-level node) queries") { CHECK(t.top().name == "PoPs"); CHECK(t.top().metadata.size() == 0); diff --git a/src/GNDStk/Tree/test/write.test.cpp b/src/GNDStk/Tree/test/write.test.cpp index 8df9f359d..97f480785 100644 --- a/src/GNDStk/Tree/test/write.test.cpp +++ b/src/GNDStk/Tree/test/write.test.cpp @@ -6,17 +6,16 @@ using namespace njoy::GNDStk; // ----------------------------------------------------------------------------- -// Strings: proper empty FileType::text/xml/json +// Strings: proper empty FileType::debug/xml/json // ----------------------------------------------------------------------------- // tree static const std::string string_empty_tree = -R"***(:)***"; +R"***(/:)***"; // xml static const std::string string_empty_xml = -R"***( -)***"; +R"***()***"; // json static const std::string string_empty_json = @@ -25,7 +24,7 @@ R"***(null)***"; // ----------------------------------------------------------------------------- -// Strings: gold-standard FileType::text/xml/json write()s for a particular +// Strings: gold-standard FileType::debug/xml/json write()s for a particular // file we'll read in. // ----------------------------------------------------------------------------- @@ -34,8 +33,8 @@ R"***(null)***"; // ------------------------ static const std::string string_real_tree = -R"***(: - xml: +R"***(/: + #xml: version: 1.0 encoding: UTF-8 covarianceSuite: @@ -77,8 +76,8 @@ R"***(: shape: 78,78 compression: diagonal values: - pcdata: - text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012)***"; + #data: + #text: 0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012)***"; @@ -111,8 +110,7 @@ R"***( - -)***"; +)***"; @@ -123,7 +121,7 @@ R"***( static const std::string string_real_json = R"***({ "covarianceSuite": { - "attributes": { + "#metadata": { "evaluation": "ENDF/B-8.0", "format": "1.9", "projectile": "n", @@ -131,7 +129,7 @@ R"***({ }, "externalFiles": { "externalFile": { - "attributes": { + "#metadata": { "label": "reactions", "path": "n-069_Tm_170.xml" } @@ -139,30 +137,30 @@ R"***({ }, "parameterCovariances": { "parameterCovariance": { - "attributes": { + "#metadata": { "label": "resolved resonances" }, "parameterCovarianceMatrix": { + "#metadata": { + "label": "eval", + "type": "absolute" + }, "array": { - "attributes": { + "#metadata": { "compression": "diagonal", "shape": "78,78" }, "values": { - "pcdata": { - "attributes": { - "text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" + "#data": { + "#metadata": { + "#text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" } } } }, - "attributes": { - "label": "eval", - "type": "absolute" - }, "parameters": { "parameterLink": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']/resonanceParameters/table", "label": "resonanceParameters", "nParameters": "78" @@ -171,7 +169,7 @@ R"***({ } }, "rowData": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']" } } @@ -179,21 +177,21 @@ R"***({ }, "styles": { "evaluated": { - "attributes": { + "#metadata": { "date": "2011-10-01", "label": "eval", "library": "ENDF/B", "version": "8.0.1" }, "projectileEnergyDomain": { - "attributes": { + "#metadata": { "max": "30000000.0", "min": "1e-05", "unit": "eV" } }, "temperature": { - "attributes": { + "#metadata": { "unit": "K", "value": "0.0" } @@ -221,31 +219,31 @@ SCENARIO("Testing GNDStk tree write() and operator<<") { // testing system is supposed to work when our intention is to actually // write *files*. - // FileType::text - WHEN("We write() the empty tree using FileType::text") { + // FileType::debug + WHEN("We write() the empty tree using FileType::debug") { // write() - THEN("We get an empty string (case: FileType::text)") { + THEN("We get an empty string (case: FileType::debug)") { std::ostringstream oss; - tree.write(oss, FileType::text); + tree.write(oss, FileType::debug); CHECK(oss.str() == string_empty_tree); } - THEN("We get an empty string (case: \"tree\")") { + THEN("We get an empty string (case: \"debug\")") { std::ostringstream oss; - tree.write(oss, "text"); + tree.write(oss, "debug"); CHECK(oss.str() == string_empty_tree); } } - WHEN("We write() the empty tree using FileType::null") { - // write(), using FileType::null (which defaults to tree) - THEN("We get an empty string (case: FileType::null)") { + WHEN("We write() the empty tree using FileType::guess") { + // write(), using FileType::guess + THEN("We get an empty string (case: FileType::guess)") { std::ostringstream oss; - tree.write(oss, FileType::null); + tree.write(oss, FileType::guess); CHECK(oss.str() == string_empty_tree); } - THEN("We get an empty string (case: \"null\")") { + THEN("We get an empty string (case: \"guess\")") { std::ostringstream oss; - tree.write(oss, "null"); + tree.write(oss, "guess"); CHECK(oss.str() == string_empty_tree); } THEN("We get an empty string (case: \"\")") { @@ -302,44 +300,44 @@ SCENARIO("Testing GNDStk tree write() and operator<<") { tree.read("n-069_Tm_170-covar.xml"); CHECK(!tree.empty()); - // FileType::text - WHEN("We write() the tree using FileType::text") { + // FileType::debug + WHEN("We write() the tree using FileType::debug") { // write() - THEN("We get the correct tree-format content") { + THEN("We get the correct debug-format content") { std::ostringstream oss; tree.write(oss); CHECK(oss.str() == string_real_tree); } - THEN("We get the correct tree-format content (case: FileType::text)") { + THEN("We get the correct debug-format content (case: FileType::debug)") { std::ostringstream oss; - tree.write(oss, FileType::text); + tree.write(oss, FileType::debug); CHECK(oss.str() == string_real_tree); } - THEN("We get the correct tree-format content (case: \"tree\")") { + THEN("We get the correct debug-format content (case: \"debug\")") { std::ostringstream oss; - tree.write(oss, "text"); + tree.write(oss, "debug"); CHECK(oss.str() == string_real_tree); } } - WHEN("We write() the tree using FileType::null") { - // write(), using FileType::null (which defaults to tree) - THEN("We get the correct tree-format content") { + WHEN("We write() the tree using FileType::guess") { + // write(), using FileType::guess + THEN("We get the correct debug-format content") { std::ostringstream oss; tree.write(oss); CHECK(oss.str() == string_real_tree); } - THEN("We get the correct tree-format content (case: FileType::null)") { + THEN("We get the correct debug-format content (case: FileType::guess)") { std::ostringstream oss; - tree.write(oss, FileType::null); + tree.write(oss, FileType::guess); CHECK(oss.str() == string_real_tree); } - THEN("We get the correct tree-format content (case: \"null\")") { + THEN("We get the correct debug-format content (case: \"guess\")") { std::ostringstream oss; - tree.write(oss, "null"); + tree.write(oss, "guess"); CHECK(oss.str() == string_real_tree); } - THEN("We get the correct tree-format content (case: \"\")") { + THEN("We get the correct debug-format content (case: \"\")") { std::ostringstream oss; tree.write(oss, ""); CHECK(oss.str() == string_real_tree); @@ -349,7 +347,7 @@ SCENARIO("Testing GNDStk tree write() and operator<<") { WHEN("We stream-output the tree") { // << std::ostringstream oss; - THEN("We get the correct tree-format content") { + THEN("We get the correct debug-format content") { oss << tree; CHECK(oss.str() == string_real_tree); } @@ -373,12 +371,16 @@ SCENARIO("Testing GNDStk tree write() and operator<<") { WHEN("We write() the tree using FileType::json") { THEN("We get the correct JSON content (case: FileType::json)") { std::ostringstream oss; - tree.write(oss, FileType::json); + JSON::reduced = false; + JSON::typed = false; + tree.sort().write(oss, FileType::json); CHECK(oss.str() == string_real_json); } THEN("We get the correct JSON content (case: \"json\")") { std::ostringstream oss; - tree.write(oss, "json"); + JSON::reduced = false; + JSON::typed = false; + tree.sort().write(oss, "json"); CHECK(oss.str() == string_real_json); } } diff --git a/src/GNDStk/XML.hpp b/src/GNDStk/XML.hpp index 65c4faeed..f2e6ccdb5 100644 --- a/src/GNDStk/XML.hpp +++ b/src/GNDStk/XML.hpp @@ -7,7 +7,6 @@ class XML { public: - // external XML-library document pugi::xml_document doc; // clear @@ -40,10 +39,10 @@ class XML { // ----------------------------------------------------------------------------- // operator>> -inline std::istream &operator>>(std::istream &is, XML &obj) +inline std::istream &operator>>(std::istream &is, XML &xml) { try { - return obj.read(is); + return xml.read(is); } catch (...) { log::function("istream >> XML"); throw; @@ -51,10 +50,10 @@ inline std::istream &operator>>(std::istream &is, XML &obj) } // operator<< -inline std::ostream &operator<<(std::ostream &os, const XML &obj) +inline std::ostream &operator<<(std::ostream &os, const XML &xml) { try { - return obj.write(os); + return xml.write(os); } catch (...) { log::function("ostream << XML"); throw; diff --git a/src/GNDStk/XML/src/assign.hpp b/src/GNDStk/XML/src/assign.hpp index 7389b8a42..5c01ee516 100644 --- a/src/GNDStk/XML/src/assign.hpp +++ b/src/GNDStk/XML/src/assign.hpp @@ -7,11 +7,12 @@ XML &operator=(XML &&) = default; // copy -// Note: pugi::xml_document's is inaccessible -XML &operator=(const XML &x) +// Note: pugi::xml_document's copy assignment is inaccessible; +// otherwise, we'd use it here. +XML &operator=(const XML &other) { try { - if (!convert(x,*this)) + if (!convert(other,*this)) throw std::exception{}; } catch (...) { log::assign("XML = XML"); diff --git a/src/GNDStk/XML/src/ctor.hpp b/src/GNDStk/XML/src/ctor.hpp index e2e035285..a8a9391cb 100644 --- a/src/GNDStk/XML/src/ctor.hpp +++ b/src/GNDStk/XML/src/ctor.hpp @@ -3,6 +3,10 @@ // XML Constructors // ----------------------------------------------------------------------------- +// ------------------------ +// Basics +// ------------------------ + // default XML() = default; @@ -10,11 +14,12 @@ XML() = default; XML(XML &&) = default; // copy -// Note: pugi::xml_document's is inaccessible -XML(const XML &x) +// Note: pugi::xml_document's copy constructor is inaccessible; +// otherwise, we'd use it here. +XML(const XML &other) { try { - if (!convert(x,*this)) + if (!convert(other,*this)) throw std::exception{}; } catch (...) { log::ctor("XML(XML)"); @@ -22,7 +27,12 @@ XML(const XML &x) } } -// JSON + +// ------------------------ +// From other classes +// ------------------------ + +// From JSON explicit XML(const JSON &j) { try { @@ -34,50 +44,55 @@ explicit XML(const JSON &j) } } -// Node -explicit XML(const Node &n) +// From HDF5 +explicit XML(const HDF5 &h) { try { - if (!convert(n,*this)) + if (!convert(h,*this)) throw std::exception{}; } catch (...) { - log::ctor("XML(Node)"); + log::ctor("XML(HDF5)"); throw; } } -// Tree -explicit XML(const Tree &t) +// From Node +explicit XML(const Node &n) { try { - if (!convert(t,*this)) + if (!convert(n,*this)) throw std::exception{}; } catch (...) { - log::ctor("XML(Tree)"); + log::ctor("XML(Node)"); throw; } } -// file name -explicit XML(const std::string &filename) + +// ------------------------ +// From istream and file +// ------------------------ + +// From istream +explicit XML(std::istream &is) { try { - if (!read(filename)) + if (!read(is)) throw std::exception{}; } catch (...) { - log::ctor("XML(\"{}\")", filename); + log::ctor("XML(istream)"); throw; } } -// istream -explicit XML(std::istream &is) +// From file +explicit XML(const std::string &filename) { try { - if (!read(is)) + if (!read(filename)) throw std::exception{}; } catch (...) { - log::ctor("XML(istream)"); + log::ctor("XML(\"{}\")", filename); throw; } } diff --git a/src/GNDStk/XML/src/read.hpp b/src/GNDStk/XML/src/read.hpp index a0dc154ec..e233ca919 100644 --- a/src/GNDStk/XML/src/read.hpp +++ b/src/GNDStk/XML/src/read.hpp @@ -17,11 +17,11 @@ std::istream &read(std::istream &is) is, pugi::parse_default | pugi::parse_declaration // preserve material - | pugi::parse_comments // preserve material + | pugi::parse_comments // preserve material ); // check for errors - // note: we've noticed that pugi doesn't (or, at least, doesn't + // note: we've noticed that pugixml doesn't (or, at least, doesn't // always) arrange for !is when pugi::xml_document.load() fails const bool pugierr = load.description() != std::string("No error"); if (pugierr || !is) { @@ -37,7 +37,7 @@ std::istream &read(std::istream &is) ); } else { // !is - // given the earlier comment about pugi and !is, it may + // given the earlier remark about pugixml and !is, it may // not be possible to get here, but we'll cover it... log::error( "pugi::xml_document.load(istream,...) returned with !istream" @@ -67,7 +67,7 @@ std::istream &read(std::istream &is) // ------------------------ -// read(file name) +// read(file) // ------------------------ bool read(const std::string &filename) diff --git a/src/GNDStk/XML/src/write.hpp b/src/GNDStk/XML/src/write.hpp index a9e76910b..8aff0457b 100644 --- a/src/GNDStk/XML/src/write.hpp +++ b/src/GNDStk/XML/src/write.hpp @@ -7,38 +7,54 @@ // write(ostream) // ------------------------ -std::ostream &write(std::ostream &os, const bool decl = true) const +std::ostream &write(std::ostream &os = std::cout, const bool decl = true) const { - // ...fixme Can we prevent pugixml from emitting a newline at the end? - // ...Concept: output functions shouldn't *assume* that someone who prints - // ...something wants a newline at the end. A user should explicitly provide - // ...the \n, std::endl, whatever, if they want that. One might think we'd - // ...always want the newline for a "large" or "compound" object (the - // ...printing of which might, in fact, even have internal newlines). - // ...However, automatically printing a newline makes the behavior - // ...different from what we expect with "simple" types - int, double, etc. - // ...Different makes it less predictable, and inconsistent. Print a vector - // ...of ints, for example, with an explicit newline after each, and we'll - // ...get one int per line. Print a vector of these XML objects in the same - // ...way, and we'll get blank lines, in between, if the XML printing takes - // ...it upon itself to print its own newline. The best behavior, in my - // ...opinion, is consistent behavior - it's easy to remember. So, then, - // ...no fluff, either before or after any object being written. + // Here, pugi::xml_document's save() capability does most of the work. - // call pugi::xml_document's write capability try { - // save + // Unfortunately, pugixml emits a newline at the end of its save(). + // In fact, a general output function shouldn't *assume* that someone + // who uses it actually wants the newline; it should let a user provide + // one if they want it. One might think we'd always want a newline for + // a "large" or "compound" object (the printing of which might, in fact, + // even have internal newlines). However, automatically printing a + // terminating newline makes the behavior different from what we expect + // with "simple" types - int, double, etc. "Different" makes behavior + // less predictable. Print a vector of ints, with a << std::endl after + // each int (the usual pattern), and we'll get one int per line. Print + // a vector of XML objects in the same manner, and we'll get blank lines + // between values if the XML printing already prints its own newline. + // Imagine a generic print(vector), where T could be int or XML or + // whatever else, and you can see the issue. So, we're actually going + // to circumvent pugixml's presumptuous \n by save()ing to a buffer, + // then shipping the buffer to the std::ostream, without the \n. This + // may seem goofy, and it may make the code less efficient (although + // I'm not seeing that in tests). The upside is, it makes XML objects + // behave predictably. Write one, and, as with int, double, or other + // well-mannered objects, you'll get a \n if AND ONLY IF you give it. + + // save to buffer + std::ostringstream buffer; doc.save( - os, + buffer, std::string(indent,' ').data(), decl ? pugi::format_default : pugi::format_default | pugi::format_no_declaration ); + // transfer buffer, chucking last character iff it's a newline + if (buffer) { + const std::size_t size = buffer.str().size(); + if (size) + os.write(buffer.str().data(), size-(buffer.str()[size-1] == '\n')); + } + // check for errors - if (!os) { - log::error("pugi::xml_document.save(ostream) returned with !ostream"); + if (!buffer || !os) { + log::error(!buffer + ? "pugi::xml_document.save(buffer) returned with !buffer" + : "ostream.write() returned with !ostream"); log::member("XML.write(ostream)"); } } catch (...) { @@ -53,7 +69,7 @@ std::ostream &write(std::ostream &os, const bool decl = true) const // ------------------------ -// write(file name) +// write(file) // ------------------------ bool write(const std::string &filename, const bool decl = true) const @@ -66,12 +82,10 @@ bool write(const std::string &filename, const bool decl = true) const return false; } - // write to ostream - if (!write(ofs,decl)) { - log::member("XML.write(\"{}\")", filename); - return false; - } + // write to the ofstream + if (write(ofs,decl) << std::endl) + return true; - // done - return true; + log::member("XML.write(\"{}\")", filename); + return false; } diff --git a/src/GNDStk/XML/test/XML.test.cpp b/src/GNDStk/XML/test/XML.test.cpp index a55cba0be..c630022ac 100644 --- a/src/GNDStk/XML/test/XML.test.cpp +++ b/src/GNDStk/XML/test/XML.test.cpp @@ -36,8 +36,7 @@ R"***( - -)***"; +)***"; // ----------------------------------------------------------------------------- @@ -65,7 +64,7 @@ SCENARIO("Testing GNDStk XML") { THEN("The Tree should have only an empty declaration node") { CHECK(t.children.size() == 1); CHECK(t.has_decl()); - CHECK(t.decl().name == "xml"); + CHECK(t.decl().name == special::xml); CHECK(t.decl().metadata.size() == 0); CHECK(t.decl().children.size() == 0); } @@ -133,7 +132,7 @@ SCENARIO("Testing GNDStk XML") { } } - // from file name + // from file // Note: Things like this are of course tested indirectly // all over the place. WHEN("We construct an XML from a file") { diff --git a/src/GNDStk/XML/test/resources/n-069_Tm_170-covar.json b/src/GNDStk/XML/test/resources/n-069_Tm_170-covar.json index d23640cb5..91cb7e1a0 100644 --- a/src/GNDStk/XML/test/resources/n-069_Tm_170-covar.json +++ b/src/GNDStk/XML/test/resources/n-069_Tm_170-covar.json @@ -1,6 +1,6 @@ { "covarianceSuite": { - "attributes": { + "#metadata": { "evaluation": "ENDF/B-8.0", "format": "1.9", "projectile": "n", @@ -8,7 +8,7 @@ }, "externalFiles": { "externalFile": { - "attributes": { + "#metadata": { "label": "reactions", "path": "n-069_Tm_170.xml" } @@ -16,30 +16,30 @@ }, "parameterCovariances": { "parameterCovariance": { - "attributes": { + "#metadata": { "label": "resolved resonances" }, "parameterCovarianceMatrix": { "array": { - "attributes": { + "#metadata": { "compression": "diagonal", "shape": "78,78" }, "values": { - "pcdata": { - "attributes": { - "text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" + "#data": { + "#metadata": { + "#text": "0.015 0 0 0 4.5e-5 0.015 3e-2 0 0 0 1.35e-4 0.015 2e-2 0 0 0 1.5e-3 0.012 5e-2 0 0 0 1.875e-3 6e-2 5e-2 0 0 0 1.05e-4 0.015 0.1 0 0 0 6e-4 0.012 0.1 0 0 0 2.25e-4 0.012 0.2 0 0 0 5.25e-3 0.012 0.2 0 0 0 3.45e-3 0.012 0.3 0 0 0 4.5e-4 0.012 0.3 0 0 0 3e-3 0.012 0.4 0 0 0 9e-3 0.012 0.4 0 0 0 1.425e-3 0.012" } } } }, - "attributes": { + "#metadata": { "label": "eval", "type": "absolute" }, "parameters": { "parameterLink": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']/resonanceParameters/table", "label": "resonanceParameters", "nParameters": "78" @@ -48,7 +48,7 @@ } }, "rowData": { - "attributes": { + "#metadata": { "href": "$reactions#/reactionSuite/resonances/resolved/BreitWigner[@label='eval']" } } @@ -56,21 +56,21 @@ }, "styles": { "evaluated": { - "attributes": { + "#metadata": { "date": "2011-10-01", "label": "eval", "library": "ENDF/B", "version": "8.0.1" }, "projectileEnergyDomain": { - "attributes": { + "#metadata": { "max": "30000000.0", "min": "1e-05", "unit": "eV" } }, "temperature": { - "attributes": { + "#metadata": { "unit": "K", "value": "0.0" } diff --git a/src/GNDStk/basic.hpp b/src/GNDStk/basic.hpp deleted file mode 100644 index bdd29f9e5..000000000 --- a/src/GNDStk/basic.hpp +++ /dev/null @@ -1,16 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Set of Meta and Child objects all of which use , meaning they'll -// retrieve metadata and child nodes in their original form in the GNDS tree. -// ----------------------------------------------------------------------------- - -namespace basic { - -#include "GNDStk/basic/src/meta.hpp" -#include "GNDStk/basic/src/child.hpp" - -using namespace meta; -using namespace child; -// using namespace common; - -} // namespace basic diff --git a/src/GNDStk/basic/src/child.hpp b/src/GNDStk/basic/src/child.hpp deleted file mode 100644 index 7241c6a2c..000000000 --- a/src/GNDStk/basic/src/child.hpp +++ /dev/null @@ -1,286 +0,0 @@ - -namespace child { - -// ----------------------------------------------------------------------------- -// Child -// -// The list below was auto-generated by a code we wrote that looked for all -// elements in every existing XML-format GNDS file that we had, and guessed, -// based on what it saw, if the element should be formulated as an Allow::one -// or an Allow::many. We then tweaked the auto-generated list just a bit; for -// example, to change "double" to "Double". At some point we'll probably want -// to tweak it more, based on a careful study of the GNDS specs. -// ----------------------------------------------------------------------------- - -// Note: a Child will retrieve an element in its original form -// in the GNDS tree: as (a const or non-const reference to) a Node. - - -// ----------------------------------------------------------------------------- -// Allowable top-level nodes, per LLNL-TR-774621-DRAFT -// ----------------------------------------------------------------------------- - -// Note: the ~ (tilde) makes them allowed as top-level nodes -inline const auto - PoPs = ~Child("PoPs"); -inline const auto - reactionSuite = ~Child("reactionSuite"); -inline const auto - covarianceSuite = ~Child("covarianceSuite"); -inline const auto - thermalScattering = ~Child("thermalScattering"); -inline const auto - fissionFragmentData = ~Child("fissionFragmentData"); - - - -// ----------------------------------------------------------------------------- -// General elements -// ----------------------------------------------------------------------------- - -// ------------------------ -// With Allow::one -// ------------------------ - -inline const Child - BreitWigner ("BreitWigner" ), - CoulombPlusNuclearElastic ("CoulombPlusNuclearElastic" ), - DebyeWaller ("DebyeWaller" ), - EFH ("EFH" ), - EFL ("EFL" ), - ENDFconversionFlags ("ENDFconversionFlags" ), - Js ("Js" ), - KalbachMann ("KalbachMann" ), - Ls ("Ls" ), - MadlandNix ("MadlandNix" ), - NBodyPhaseSpace ("NBodyPhaseSpace" ), - Q ("Q" ), - RMatrix ("RMatrix" ), - RutherfordScattering ("RutherfordScattering" ), - S_alpha_beta ("S_alpha_beta" ), - S_table ("S_table" ), - T_M ("T_M" ), - T_effective ("T_effective" ), - U ("U" ), - aliases ("aliases" ), - angular ("angular" ), - angularEnergy ("angularEnergy" ), - angularTwoBody ("angularTwoBody" ), - applicationData ("applicationData" ), - array ("array" ), - atomic ("atomic" ), - averageEnergies ("averageEnergies" ), - averageProductEnergy ("averageProductEnergy" ), - axes ("axes" ), - background ("background" ), - baryons ("baryons" ), - bindingEnergy ("bindingEnergy" ), - branching1d ("branching1d" ), - branching3d ("branching3d" ), - cdata ("cdata" ), - channels ("channels" ), - characteristicCrossSection ("characteristicCrossSection" ), - charge ("charge" ), - chemicalElements ("chemicalElements" ), - coherentElastic ("coherentElastic" ), - coherentPhotonScattering ("coherentPhotonScattering" ), - columnData ("columnData" ), - columnHeaders ("columnHeaders" ), - configurations ("configurations" ), - constant1d ("constant1d" ), - continuum ("continuum" ), - covarianceSections ("covarianceSections" ), - crossSection ("crossSection" ), - crossSections ("crossSections" ), - cutoffEnergy ("cutoffEnergy" ), - data ("data" ), - decayData ("decayData" ), - decayModes ("decayModes" ), - decayPath ("decayPath" ), - delayedBetaEnergy ("delayedBetaEnergy" ), - delayedGammaEnergy ("delayedGammaEnergy" ), - delayedNeutronKE ("delayedNeutronKE" ), - discreteGamma ("discreteGamma" ), - distribution ("distribution" ), - documentation ("documentation" ), - documentations ("documentations" ), - Double ("double" ), - doubleDifferentialCrossSection ("doubleDifferentialCrossSection" ), - durations ("durations" ), - e_critical ("e_critical" ), - e_max ("e_max" ), - energy ("energy" ), - energyAngular ("energyAngular" ), - evaporation ("evaporation" ), - externalFiles ("externalFiles" ), - f ("f" ), - fastRegion ("fastRegion" ), - fissionComponents ("fissionComponents" ), - fissionEnergyReleased ("fissionEnergyReleased" ), - freeAtomCrossSection ("freeAtomCrossSection" ), - g ("g" ), - gaugeBosons ("gaugeBosons" ), - generalEvaporation ("generalEvaporation" ), - gridded2d ("gridded2d" ), - gridded3d ("gridded3d" ), - halflife ("halflife" ), - hardSphereRadius ("hardSphereRadius" ), - imaginaryAnomalousFactor ("imaginaryAnomalousFactor" ), - imaginaryInterferenceTerm ("imaginaryInterferenceTerm" ), - incoherentElastic ("incoherentElastic" ), - incoherentInelastic ("incoherentInelastic" ), - incoherentPhotonScattering ("incoherentPhotonScattering" ), - incompleteReactions ("incompleteReactions" ), - institution ("institution" ), - intensity ("intensity" ), - internalConversionCoefficients ("internalConversionCoefficients" ), - internalPairFormationCoefficient("internalPairFormationCoefficient"), - isotopes ("isotopes" ), - isotropic2d ("isotropic2d" ), - leptons ("leptons" ), - levelSpacing ("levelSpacing" ), - link ("link" ), - listOfCovariances ("listOfCovariances" ), - mass ("mass" ), - mixed ("mixed" ), - multiplicities ("multiplicities" ), - multiplicity ("multiplicity" ), - neutrinoEnergy ("neutrinoEnergy" ), - nonNeutrinoEnergy ("nonNeutrinoEnergy" ), - nuclearAmplitudeExpansion ("nuclearAmplitudeExpansion" ), - nuclearPlusInterference ("nuclearPlusInterference" ), - nuclearTerm ("nuclearTerm" ), - nucleus ("nucleus" ), - nuclides ("nuclides" ), - orphanProducts ("orphanProducts" ), - outputChannel ("outputChannel" ), - parameterCovariances ("parameterCovariances" ), - parameters ("parameters" ), - parity ("parity" ), - pcdata ("pcdata" ), - photonEmissionProbabilities ("photonEmissionProbabilities" ), - pids ("pids" ), - polynomial1d ("polynomial1d" ), - positronEmissionIntensity ("positronEmissionIntensity" ), - primaryGamma ("primaryGamma" ), - probability ("probability" ), - productYields ("productYields" ), - productions ("productions" ), - products ("products" ), - projectileEnergyDomain ("projectileEnergyDomain" ), - promptGammaEnergy ("promptGammaEnergy" ), - promptNeutronKE ("promptNeutronKE" ), - promptProductKE ("promptProductKE" ), - r ("r" ), - reactions ("reactions" ), - realAnomalousFactor ("realAnomalousFactor" ), - realInterferenceTerm ("realInterferenceTerm" ), - recoil ("recoil" ), - reference ("reference" ), - regions2d ("regions2d" ), - resolved ("resolved" ), - resolvedRegion ("resolvedRegion" ), - resonanceParameters ("resonanceParameters" ), - resonanceReactions ("resonanceReactions" ), - resonances ("resonances" ), - resonancesWithBackground ("resonancesWithBackground" ), - rowData ("rowData" ), - scatteringAtoms ("scatteringAtoms" ), - scatteringFactor ("scatteringFactor" ), - scatteringRadius ("scatteringRadius" ), - simpleMaxwellianFission ("simpleMaxwellianFission" ), - spectra ("spectra" ), - spin ("spin" ), - spinGroups ("spinGroups" ), - standard ("standard" ), - string ("string" ), - styles ("styles" ), - summands ("summands" ), - sums ("sums" ), - table ("table" ), - tabulatedWidths ("tabulatedWidths" ), - temperature ("temperature" ), - theta ("theta" ), - time ("time" ), - totalEnergy ("totalEnergy" ), - uncertainty ("uncertainty" ), - uncorrelated ("uncorrelated" ), - unresolved ("unresolved" ), - unresolvedRegion ("unresolvedRegion" ), - unspecified ("unspecified" ), - weightedFunctionals ("weightedFunctionals" ), - widths ("widths" ), - xml ("xml" ), - yields ("yields" ); - -// ------------------------ -// With Allow::many -// ------------------------ - -inline const Child - J ("J" ), - L ("L" ), - Legendre ("Legendre" ), - XYs1d ("XYs1d" ), - XYs2d ("XYs2d" ), - XYs3d ("XYs3d" ), - add ("add" ), - averageEnergy ("averageEnergy" ), - averageParameterCovariance ("averageParameterCovariance" ), - axis ("axis" ), - baryon ("baryon" ), - channel ("channel" ), - chemicalElement ("chemicalElement" ), - column ("column" ), - comment ("comment" ), - configuration ("configuration" ), - conversion ("conversion" ), - covariance ("covariance" ), - covarianceMatrix ("covarianceMatrix" ), - crossSectionReconstructed ("crossSectionReconstructed" ), - crossSectionSum ("crossSectionSum" ), - decay ("decay" ), - decayMode ("decayMode" ), - discrete ("discrete" ), - duration ("duration" ), - evaluated ("evaluated" ), - externalFile ("externalFile" ), - fissionComponent ("fissionComponent" ), - fraction ("fraction" ), - gaugeBoson ("gaugeBoson" ), - grid ("grid" ), - integer ("integer" ), - isotope ("isotope" ), - lepton ("lepton" ), - metaStable ("metaStable" ), - multiplicitySum ("multiplicitySum" ), - nuclide ("nuclide" ), - parameterCovariance ("parameterCovariance" ), - parameterCovarianceMatrix ("parameterCovarianceMatrix" ), - parameterLink ("parameterLink" ), - product ("product" ), - production ("production" ), - productYield ("productYield" ), - reaction ("reaction" ), - regions1d ("regions1d" ), - resonanceReaction ("resonanceReaction" ), - scatteringAtom ("scatteringAtom" ), - section ("section" ), - shell ("shell" ), - shortRangeSelfScalingVariance ("shortRangeSelfScalingVariance" ), - spectrum ("spectrum" ), - spinGroup ("spinGroup" ), - sum ("sum" ), - summand ("summand" ), - values ("values" ), - weighted ("weighted" ), - width ("width" ); - -// fixme Probably redo this entire file based on Standard Interface experience -// fixme Same with misc:: namespace entries, assuming we keep misc:: -// Additional ones I've encountered while writing the Standard Interface -inline const Child interval("interval"); -inline const Child confidenceIntervals("confidenceIntervals"); -inline const Child logNormal("logNormal"); - -} // namespace child diff --git a/src/GNDStk/basic/src/meta.hpp b/src/GNDStk/basic/src/meta.hpp deleted file mode 100644 index 42e252f60..000000000 --- a/src/GNDStk/basic/src/meta.hpp +++ /dev/null @@ -1,118 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Meta -// For all metadata that we see in every existing XML-format GNDS file that -// we have. The list below was auto-generated by a code we wrote to look for -// all such metadata. -// ----------------------------------------------------------------------------- - -// A Meta will retrieve a metadatum in its original form in the GNDS -// tree: as (a const or non-const reference to) a std::string. - -namespace meta { - -inline const Meta - A ("A" ), - ENDF_MFMT ("ENDF_MFMT" ), - ENDF_MT ("ENDF_MT" ), - L ("L" ), - MAT ("MAT" ), - Z ("Z" ), - approximation ("approximation" ), - asymmetric ("asymmetric" ), - boundaryCondition ("boundaryCondition" ), - calculateChannelRadius ("calculateChannelRadius" ), - calculatePenetrability ("calculatePenetrability" ), - calculatedAtThermal ("calculatedAtThermal" ), - channelSpin ("channelSpin" ), - coefficient ("coefficient" ), - columnIndex ("columnIndex" ), - columns ("columns" ), - complete ("complete" ), - compression ("compression" ), - constant ("constant" ), - crossTerm ("crossTerm" ), - date ("date" ), - decayRate ("decayRate" ), - degreesOfFreedom ("degreesOfFreedom" ), - dependenceOnProcessedGroupWidth("dependenceOnProcessedGroupWidth"), - derivedFrom ("derivedFrom" ), - domainMax ("domainMax" ), - domainMin ("domainMin" ), - domainUnit ("domainUnit" ), - ejectile ("ejectile" ), - electronNumber ("electronNumber" ), - eliminated ("eliminated" ), - emissionMode ("emissionMode" ), - encoding ("encoding" ), - evaluation ("evaluation" ), - final ("final" ), - fissionGenre ("fissionGenre" ), - flags ("flags" ), - format ("format" ), - functionalForm ("functionalForm" ), - generation ("generation" ), - genre ("genre" ), - href ("href" ), - id ("id" ), - identicalParticles ("identicalParticles" ), - index ("index" ), - initial ("initial" ), - interpolation ("interpolation" ), - interpolationQualifier ("interpolationQualifier" ), - label ("label" ), - length ("length" ), - library ("library" ), - lowerIndex ("lowerIndex" ), - material ("material" ), - matrixStartIndex ("matrixStartIndex" ), - max ("max" ), - metaStableIndex ("metaStableIndex" ), - min ("min" ), - mode ("mode" ), - muCutoff ("muCutoff" ), - nParameters ("nParameters" ), - name ("name" ), - numberOfProducts ("numberOfProducts" ), - numberPerMolecule ("numberPerMolecule" ), - parity ("parity" ), - path ("path" ), - pid ("pid" ), - process ("process" ), - productFrame ("productFrame" ), - projectile ("projectile" ), - projectileFrame ("projectileFrame" ), - resonanceReaction ("resonanceReaction" ), - rows ("rows" ), - shape ("shape" ), - spin ("spin" ), - start ("start" ), - style ("style" ), - subshell ("subshell" ), - supportsAngularReconstruction ("supportsAngularReconstruction" ), - symbol ("symbol" ), - symmetry ("symmetry" ), - target ("target" ), - text ("text" ), - type ("type" ), - types ("types" ), - unit ("unit" ), - useForSelfShieldingOnly ("useForSelfShieldingOnly" ), - value ("value" ), - valueType ("valueType" ), - version ("version" ); - -// fixme Probably redo this entire file based on Standard Interface experience -// fixme Same with misc:: namespace entries, assuming we keep misc:: -// Additional ones I've encountered while writing the Standard Interface -inline const Meta - confidence ("confidence" ), - lower ("lower" ), - upper ("upper" ), - offset ("offset" ), - permutation ("permutation" ), - storageOrder("storageOrder"), - sep ("sep" ), - outerDomainValue("outerDomainValue"); - -} // namespace meta diff --git a/src/GNDStk/common.hpp b/src/GNDStk/common.hpp deleted file mode 100644 index e21dd49ec..000000000 --- a/src/GNDStk/common.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Set of Meta and Child objects that are useful enough as-is that we wish -// to include them in other sets of such objects, in other namespaces. -// ----------------------------------------------------------------------------- - -#include "GNDStk/common/src/detail.hpp" - -namespace common { - -// numeric -template -inline const Child< - // for general T, the following produces a vector; - // for T already a vector, it remains as-is - typename detail::numeric_type::type, - Allow::one, - detail::convert_pcdata_text_t -> numeric("pcdata"); - -// shortcuts for numeric; each gives a vector -inline const auto ints = numeric/"pcdata"; -inline const auto floats = numeric/"pcdata"; -inline const auto doubles = numeric/"pcdata"; -// fixme I'm not sure why the "pcdata" name doesn't come over automatically -// from numeric; it probably relates to order-of-initialization rules (or -// lack of rules?) for variable templates. We'll figure that out sometime. -// For now, the shortcuts are given the name directly, so it doesn't matter. - -} // namespace common diff --git a/src/GNDStk/common/src/detail.hpp b/src/GNDStk/common/src/detail.hpp deleted file mode 100644 index 2fbd6b089..000000000 --- a/src/GNDStk/common/src/detail.hpp +++ /dev/null @@ -1,90 +0,0 @@ - -namespace detail { - -// ----------------------------------------------------------------------------- -// convert_pcdata_text_t -// ----------------------------------------------------------------------------- - -class convert_pcdata_text_t { -public: - - // Node to container - template - void operator()(const Node &node, CONTAINER &container) const - { - try { - // Context: - // We're inside of a node that's inside of a node - // that looked something like this (in XML): - // 0.0 1.0 2.0 3.0 4.0 - // In GNDStk, the node has a metadatum with the key "text". - // The metadatum's string value is the content: "0.0 1.0 ..." in - // our example. Goal here: extract that content into the container. - container.clear(); - for (auto &m : node.metadata) - if (m.first == "text") { - convert(m.second, container); - return; - } - log::error( - "Unable to find metadatum key \"text\" in the current Node (\"{}\")", - node.name - ); - throw std::exception{}; - } catch (...) { - log::function("convert_pcdata_text_t(Node,container)"); - throw; - } - } - - // container to Node - template - void operator()(const CONTAINER &container, Node &node) const - { - try { - node.clear(); - node.name = "pcdata"; - std::string &destination = node.add("text","").second; - convert(container, destination); - } catch (...) { - log::function("convert_pcdata_text_t(container,Node)"); - throw; - } - } -}; - - -// ----------------------------------------------------------------------------- -// numeric_type -// ----------------------------------------------------------------------------- - -// default -// create vector -template -class numeric_type { -public: - using type = std::vector; -}; - -// keep deque -template -class numeric_type> { -public: - using type = std::deque; -}; - -// keep list -template -class numeric_type> { -public: - using type = std::list; -}; - -// keep vector -template -class numeric_type> { -public: - using type = std::vector; -}; - -} // namespace detail diff --git a/src/GNDStk/convert.hpp b/src/GNDStk/convert.hpp index 6ba39a5f4..3843061a1 100644 --- a/src/GNDStk/convert.hpp +++ b/src/GNDStk/convert.hpp @@ -2,6 +2,7 @@ #include "GNDStk/convert/src/detail.hpp" // convert to: -#include "GNDStk/convert/src/tree.hpp" +#include "GNDStk/convert/src/Node.hpp" #include "GNDStk/convert/src/XML.hpp" #include "GNDStk/convert/src/JSON.hpp" +#include "GNDStk/convert/src/HDF5.hpp" diff --git a/src/GNDStk/convert/src/HDF5.hpp b/src/GNDStk/convert/src/HDF5.hpp new file mode 100644 index 000000000..6fb9aadc6 --- /dev/null +++ b/src/GNDStk/convert/src/HDF5.hpp @@ -0,0 +1,141 @@ + +// ----------------------------------------------------------------------------- +// Node ==> HDF5 +// ----------------------------------------------------------------------------- + +inline bool convert(const Node &node, HDF5 &h, const std::string &name) +{ + static const std::string context = "convert(Node,HDF5)"; + + // clear + h.clear(); + + try { + // bookkeeping, re: HighFive employing basically a file descriptor + const std::string tmpfile = + name != "" ? name : h.temporaryName(h.fileDesc); + h.filePtr = new HighFive::File(tmpfile, HDF5::modeWrite); + + // ------------------------ + // Node + // ------------------------ + + if (node.name != "/") { + const bool ret = detail::node2hdf5(node,*h.filePtr); + h.filePtr->flush(); + return ret; + } + + // ------------------------ + // Tree + // ------------------------ + + detail::warn_node_top_metadata(node,context); + bool found_dec = false; + + for (auto &cptr : node.children) { + if (cptr->name == special::xml ) continue; + if (cptr->name == special::json) continue; + + if (cptr->name == special::hdf5 || cptr->name == special::decl) { + // looks like a declaration node + if (found_dec) // already seen + detail::info_node_multiple_dec(context); + // fixme Implement top-level metadata/attributes in HDF5 + found_dec = true; + } else { + // looks like a regular node + const bool ret = detail::node2hdf5(*cptr,*h.filePtr); + h.filePtr->flush(); + if (!ret) + return false; + } + } + + } catch (...) { + log::function(context); + throw; + } + + // done + return true; +} + + +// ----------------------------------------------------------------------------- +// HDF5 ==> HDF5 +// For completeness +// ----------------------------------------------------------------------------- + +inline bool convert(const HDF5 &from, HDF5 &to) +{ + // same object? + if (&to == &from) + return true; + + // clear + to.clear(); + + // empty? + if (from.empty()) + return true; + + // from ==> to + try { + std::ifstream ifs(from.filePtr->getName(), std::ios::binary); + if (!ifs) { + log::error("Could not open file \"{}\"", from.filePtr->getName()); + // The HDF5 class is different from the XML and JSON classes in that + // it essentially employs a "file descriptor" of sorts, through the + // underlying class HighFive::File. So, unlike convert(XML,XML) and + // convert(JSON,JSON), this function - convert(HDF5,HDF5) - needs + // to create a *file* for the destination object. It cannot simply + // duplicate an internal data structure, as the analogous XML and + // JSON convert() functions do. The above error message might thus + // surprise a user, who wouldn't necessarily realize that a file is + // being created as a result of this convert(). To help clarify the + // situation, we'll write an informational note. + log::info( + "We're attempting to open this in this context because it's\n" + "behind the source HDF5 object."); + throw std::exception{}; + } + if (!to.read(ifs)) + throw std::exception{}; + } catch (...) { + log::function("convert(HDF5,HDF5)"); + throw; + } + + // done + return true; +} + + +// ----------------------------------------------------------------------------- +// XML ==> HDF5 +// JSON ==> HDF5 +// As with our convert()s to XML, these go through temporaries. +// ----------------------------------------------------------------------------- + +inline bool convert(const XML &x, HDF5 &h) +{ + try { + Tree tmp; + return convert(x,tmp) && convert(tmp,h); + } catch (...) { + log::function("convert(XML,HDF5)"); + throw; + } +} + +inline bool convert(const JSON &j, HDF5 &h) +{ + try { + Tree tmp; + return convert(j,tmp) && convert(tmp,h); + } catch (...) { + log::function("convert(JSON,HDF5)"); + throw; + } +} diff --git a/src/GNDStk/convert/src/JSON.hpp b/src/GNDStk/convert/src/JSON.hpp index 20257eb03..1b6bf3e01 100644 --- a/src/GNDStk/convert/src/JSON.hpp +++ b/src/GNDStk/convert/src/JSON.hpp @@ -1,78 +1,49 @@ -// ----------------------------------------------------------------------------- -// convert(*,JSON) -// That is, convert to JSON objects -// ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- // Node ==> JSON // ----------------------------------------------------------------------------- inline bool convert(const Node &node, JSON &j) { + static const std::string context = "convert(Node,JSON)"; + // clear j.clear(); - // See comments for convert(Node,XML); smiilar ones apply here, except - // that JSON files don't have declaration nodes. - - static const std::string context = "convert(Node,JSON)"; try { + // ------------------------ + // Node + // ------------------------ - // Probably a regular Node - if (node.name != "") - return detail::node2json(node, j.doc); + if (node.name != "/") + return detail::node2json(node,j.doc); - // Probably a Tree... + // ------------------------ + // Tree + // ------------------------ - if (node.metadata.size() != 0) { - log::warning( - "Encountered Node with empty name \"\",\n" - "but the Node also contains metadata.\n" - "Not expected in this context. We'll ignore the metadata." - ); - log::function(context); - } + detail::warn_node_top_metadata(node,context); + bool found_dec = false; - bool found_decl = false; - bool found_top = false; + for (auto &cptr : node.children) { + if (cptr->name == special::xml ) continue; + if (cptr->name == special::hdf5) continue; - for (auto &c : node.children) { - if (c->name == "xml" || c->name == "json" || c->name == "hdf5") { + if (cptr->name == special::json || cptr->name == special::decl) { // looks like a declaration node - if (found_decl) { - // already seen - log::warning( - "Encountered Node with empty name \"\",\n" - "and > 1 child nodes that look like " - "declaration nodes.\n" - "Not expected in this context. " - "For JSON, we're ignoring declaration nodes anyway." - ); - log::function(context); - } - found_decl = true; + if (found_dec) // already seen + detail::info_node_multiple_dec(context); + // fixme Implement top-level metadata/attributes in JSON + found_dec = true; } else { // looks like a regular node - if (found_top) { - // already seen - log::warning( - "Encountered Node with empty name \"\",\n" - "and > 1 child nodes that look like " - "regular (non-declaration) nodes.\n" - "Not expected in this context. " - "We'll convert all the child nodes." - ); - log::function(context); - } - if (!detail::node2json(*c, j.doc)) + if (!detail::node2json(*cptr,j.doc)) return false; - found_top = true; } } } catch (...) { - log::function("convert(Tree,JSON)"); + log::function(context); throw; } @@ -81,68 +52,61 @@ inline bool convert(const Node &node, JSON &j) } - // ----------------------------------------------------------------------------- -// Tree ==> JSON +// JSON ==> JSON +// For completeness // ----------------------------------------------------------------------------- -inline bool convert(const Tree &tree, JSON &j) +inline bool convert(const JSON &from, JSON &to) { + // same object? + if (&to == &from) + return true; + + // clear + to.clear(); + + // empty? + if (from.empty()) + return true; + + // from ==> to try { - if (tree.has_top()) - detail::check_top(tree.top().name, "Tree", "convert(Tree,JSON)"); - return convert(*(const Node *)&tree, j); + to.doc = from.doc; // orderedJSON's assignment } catch (...) { - log::function("convert(Tree,JSON)"); + log::function("convert(JSON,JSON)"); throw; } -} + // done + return true; +} // ----------------------------------------------------------------------------- -// XML ==> JSON +// XML ==> JSON +// HDF5 ==> JSON +// As with our convert()s to XML, these go through temporaries. // ----------------------------------------------------------------------------- -// Goes through a tree. Could be made more efficient if written directly. -// We'll revisit this if it becomes more of an issue. inline bool convert(const XML &x, JSON &j) { - // temporary - Tree t; - - // convert try { - return convert(x,t) && convert(t,j); + Tree tmp; + return convert(x,tmp) && convert(tmp,j); } catch (...) { log::function("convert(XML,JSON)"); throw; } } - - -// ----------------------------------------------------------------------------- -// JSON ==> JSON -// For completeness -// ----------------------------------------------------------------------------- - -inline bool convert(const JSON &from, JSON &to) +inline bool convert(const HDF5 &h, JSON &j) { - if (&to == &from) - return true; - - // clear - to.clear(); - - // convert try { - to.doc = from.doc; // nlohmann::json's assignment + Tree tmp; + return convert(h,tmp) && convert(tmp,j); } catch (...) { - log::function("convert(JSON,JSON)"); + log::function("convert(HDF5,JSON)"); throw; } - - // done - return true; } diff --git a/src/GNDStk/convert/src/Node.hpp b/src/GNDStk/convert/src/Node.hpp new file mode 100644 index 000000000..46f21a9f1 --- /dev/null +++ b/src/GNDStk/convert/src/Node.hpp @@ -0,0 +1,205 @@ + +// ----------------------------------------------------------------------------- +// XML ==> Node +// ----------------------------------------------------------------------------- + +inline bool convert(const XML &x, Node &node, const bool &DECL) +{ + const bool decl = detail::getDecl(node,DECL); + + // ------------------------ + // bookkeeping + // ------------------------ + + // clear the receiving node + node.clear(); + + // optionally, make a boilerplate declaration node + if (decl) { + node.name = "/"; + node.add(special::xml); // "we built the object from an XML" + } + + // empty xml document? + if (x.empty()) + return true; + + try { + + // ------------------------ + // validate + // ------------------------ + + // Validation, itself, is independent of whether decl is true or false + + std::size_t size = 0; + std::string one, two; + for (const pugi::xml_node &xnode : x.doc) { + size++; + if (size == 1) + one = xnode.name(); + else if (size == 2) + two = xnode.name(); + else { + log::error( + "More than two main nodes in the XML\n", + "You can have up to " + "one declaration node and " + "one document node" + ); + throw std::exception{}; + } + } + + // possibly redundant with the earlier empty() test, but harmless + if (size == 0) + return true; + + // if two main nodes, they can't be of the same type + if (size == 2) { + if (one == "xml" && two == "xml") { + log::error("Two declaration nodes in the XML"); + throw std::exception{}; + } + if (one != "xml" && two != "xml") { + log::error("Two document nodes in the XML"); + throw std::exception{}; + } + } + + // ------------------------ + // convert the nodes + // ------------------------ + + for (const pugi::xml_node &xnode : x.doc) { + const std::string name = xnode.name(); + + if (name == "xml") { + // Declaration node + // Retrieve any XML attributes, e.g. version and encoding + if (decl) + for (const pugi::xml_attribute &xattr : xnode.attributes()) + node.one(special::xml).add(xattr.name(), xattr.value()); + } else { + // Document node + // Visit the node, and its children recursively + if (!detail::xml2node(xnode, decl ? node.add() : node)) + return false; + } + } + } catch (...) { + log::function("convert(XML,Node)"); + throw; + } + + // done + return true; +} + + + +// ----------------------------------------------------------------------------- +// JSON ==> Node +// ----------------------------------------------------------------------------- + +inline bool convert(const JSON &j, Node &node, const bool &DECL) +{ + const bool decl = detail::getDecl(node,DECL); + + // clear the receiving node + node.clear(); + + // optionally, make a boilerplate declaration node + if (decl) { + node.name = "/"; + node.add(special::json); // "we built the object from a JSON" + } + + // empty json document? + if (j.empty()) + return true; + + try { + // j.doc gives a JSON "object": {...}, i.e. a JSON brace construct, + // as opposed to a JSON key/value pair or specific JSON entity such + // as integer or boolean. Elsewhere, in recursive calls to the below + // function, we'd have already determined a node's name from a key. + // In this context, however, we don't have a key. The trailing "true" + // tells json2node to infer node.name from the contents of the {...}. + detail::json2node(j.doc, decl ? node.add() : node, true); + return true; + } catch (...) { + log::function("convert(JSON,Node)"); + throw; + } +} + + + +// ----------------------------------------------------------------------------- +// HDF5 ==> Node +// ----------------------------------------------------------------------------- + +/* +Remark + +HighFive::File references an entire HDF5 file. By extension, this applies to +GNDStk::HDF5 - our simple wrapper around HighFive::File that helps us to provide +uniform behavior between XML, JSON, and HDF5. Unlike XML and JSON, it apparently +can't reference just part of such a file, i.e. part of an HDF5 hierarchy. So, +convert(HDF5,Tree) may be more meaningful than convert(HDF5,Node), as Tree is +specifically for a full GNDS hierarchy, Node for possibly a partial hierarchy. +Consistent with how we handle conversions from XML and JSON, however, we define +the conversion in terms of Node (from which Tree is, of course, derived), and +then guess, based on the Node's name, whether it's a Tree, or a Node proper. We +may consider, at some point, having a convert(HighFive::Group,Node), i.e. with a +HighFive::Group rather than a HighFive::File, but such a function might or might +not prove to be useful. A HighFive::Group would come from a HighFive::File; it +wouldn't be a string on its own, like a "snippet" of XML or JSON. +*/ + +inline bool convert(const HDF5 &h, Node &node, const bool &DECL) +{ + const bool decl = detail::getDecl(node,DECL); + + // ------------------------ + // bookkeeping + // ------------------------ + + // clear the receiving node + node.clear(); + + // optionally, make a boilerplate declaration node + Node *declnode = nullptr; + if (decl) { + node.name = "/"; + declnode = &node.add(special::hdf5); // "we built the object from an HDF5" + } + + // empty HDF5 document? + if (h.empty()) + return true; + + // not empty in the earlier (h.filePtr == nullptr) sense, + // but with no real content in the HDF5 document? + const HighFive::Group &rootGroup = h.filePtr->getGroup("/"); + if (rootGroup.getNumberAttributes() == 0 && + rootGroup.getNumberObjects() == 0) + return true; + + try { + // if decl, then place any top-level attributes that exist, in the HDF5, + // into the Node's special::hdf5 child that would have been created above + + if (decl) + for (auto &attrName : rootGroup.listAttributeNames()) + if (!detail::attr2node(rootGroup.getAttribute(attrName),*declnode)) + return false; + + // visit the rest of the root HDF5 group + return detail::hdf52node(rootGroup, "/", node, decl); + } catch (...) { + log::function("convert(HDF5,Node)"); + throw; + } +} diff --git a/src/GNDStk/convert/src/XML.hpp b/src/GNDStk/convert/src/XML.hpp index cb3e90592..521dddb31 100644 --- a/src/GNDStk/convert/src/XML.hpp +++ b/src/GNDStk/convert/src/XML.hpp @@ -1,100 +1,77 @@ -// ----------------------------------------------------------------------------- -// convert(*,XML) -// That is, convert to XML objects -// ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- // Node ==> XML // ----------------------------------------------------------------------------- inline bool convert(const Node &node, XML &x) { + static const std::string context = "convert(Node,XML)"; + // clear x.clear(); - // We recognize here that the Node could in fact be the base of a Tree, + // We recognize below that the Node could in fact be the base of a Tree, // which might have a declaration node. If it does, then we'll preserve // the declaration node's information in the output XML object. // // The way we're storing things in Tree, a declaration node might contain, // for example, the following, if the Tree was built from an XML: // - // name: "xml" + // name: #xml // metadata: // "version", "1.0" // "encoding", "UTF-8" // children: - // N/A + // (none) // - // or this if the Tree was built from a JSON: - // - // name: "json" - // metadata: - // (nothing; empty vector) - // children: - // N/A - // - // or something else if the Tree was built in another manner. In an XML - // file, the declaration node is the thing like: . + // In an XML file, the declaration node is the construct that optionally + // can appear at the beginning, and looks like: . - static const std::string context = "convert(Node,XML)"; try { - - if (node.name != "") { - // A Tree should have name == "" at the root level, so we don't - // consider this to be a Tree. Just do a straight Node conversion. - return detail::node2xml(node, x.doc); + // ------------------------ + // Node + // ------------------------ + + if (node.name != "/") { + // A Tree should have name "/" at the root level, so this looks + // like it's garden-variety Node. Do a straight Node conversion. + return detail::node2xml(node,x.doc); } - // Henceforth it's presumably a Tree, unless someone gave the name "" - // to a regular node, which they really shouldn't have done... + // Henceforth it's presumably a Tree, unless someone gave the root Tree- + // node name to a regular node, which they really shouldn't have done. - if (node.metadata.size() != 0) { - log::warning( - "Encountered Node with empty name \"\",\n" - "but the Node also contains metadata.\n" - "Not expected in this context. We'll ignore the metadata." - ); - log::function(context); - } + // ------------------------ + // Tree + // ------------------------ + + detail::warn_node_top_metadata(node,context); + bool found_dec = false; + bool found_top = false; - pugi::xml_node xdecl; - bool found_decl = false; - bool found_top = false; + for (auto &cptr : node.children) { + if (cptr->name == special::json) continue; + if (cptr->name == special::hdf5) continue; - for (auto &c : node.children) { - if (c->name == "xml" || c->name == "json" || c->name == "hdf5") { + if (cptr->name == special::xml || cptr->name == special::decl) { // looks like a declaration node - if (found_decl) { - // already seen - log::warning( - "Encountered Node with empty name \"\",\n" - "and > 1 child nodes that look like " - "declaration nodes.\n" - "Not expected in this context. " - "We'll combine the metadata." - ); - log::function(context); - } else + pugi::xml_node xdecl; + if (found_dec) // already seen + detail::info_node_multiple_dec(context); + else xdecl = x.doc.append_child(pugi::node_declaration); - for (auto &meta : c->metadata) + for (auto &meta : cptr->metadata) xdecl.append_attribute(meta.first.data()) = meta.second.data(); - found_decl = true; + found_dec = true; } else { // looks like a regular node - if (found_top) { - // already seen - log::warning( - "Encountered Node with empty name \"\",\n" - "and > 1 child nodes that look like " - "regular (non-declaration) nodes.\n" - "Not expected in this context. " - "We'll convert all the child nodes." - ); + if (found_top) { // already seen + log::info( + "Node has name \"/\" and multiple \"document nodes\".\n" + "This is nonstandard in XML, but we'll write them all."); log::function(context); } - if (!detail::node2xml(*c, x.doc)) + if (!detail::node2xml(*cptr,x.doc)) return false; found_top = true; } @@ -110,25 +87,6 @@ inline bool convert(const Node &node, XML &x) } - -// ----------------------------------------------------------------------------- -// Tree ==> XML -// ----------------------------------------------------------------------------- - -inline bool convert(const Tree &tree, XML &x) -{ - try { - if (tree.has_top()) - detail::check_top(tree.top().name, "Tree", "convert(Tree,XML)"); - return convert(*(const Node *)&tree, x); - } catch (...) { - log::function("convert(Tree,XML)"); - throw; - } -} - - - // ----------------------------------------------------------------------------- // XML ==> XML // For completeness @@ -136,63 +94,72 @@ inline bool convert(const Tree &tree, XML &x) inline bool convert(const XML &from, XML &to) { + // same object? if (&to == &from) return true; // clear to.clear(); - // Unfortunately, we can't use pugi::xml_document's assignment, or for - // that matter its copy constructor, because, for whatever reason, the - // pugi library makes those private. (And, perhaps, those have shallow- - // copy semantics, too. I haven't checked into that, because we can't - // use those anyway.) + // empty? + if (from.empty()) + return true; - // For now, I'll write something simple that works, although not very - // efficiently: write "from" to a stringstream, then read "to" out of - // the stringstream. The GNDS files that I've seen so far aren't large - // enough to make this untenable. We can revisit this issue if and when - // it becomes necessary to be more efficient. + // It seems that pugi::xml_document's assignment operator, and for that + // matter its copy constructor, are private. So, we can't use either of + // those here. For now, then, we'll do something simple that works, but + // not very efficiently: write "from" to a stringstream, then read "to" + // from the stringstream. (Note that it's XML that's written and read.) + // The GNDS files that I've seen so far aren't large enough to make this + // problematic. We'll revisit this if and when more efficiency is needed. - // back up indentation + // back up indentation; is restored later const int indent = GNDStk::indent; - GNDStk::indent = 0; // saves memory in the stringstream + GNDStk::indent = 0; // to save memory in the intermediary stringstream - // from ==> stringstream ==> to + // from ==> temporary stringstream ==> to try { - std::stringstream ss; - from.write(ss); - to.read(ss); + std::stringstream tmp; + from.write(tmp,true); // true: include declaration node + if (!to.read(tmp)) + throw std::exception{}; } catch (...) { + GNDStk::indent = indent; log::function("convert(XML,XML)"); throw; } - // restore indentation - GNDStk::indent = indent; - // done + GNDStk::indent = indent; return true; } - // ----------------------------------------------------------------------------- // JSON ==> XML +// HDF5 ==> XML +// These go through temporaries, for compactness. They could likely be made +// more efficient if written directly. We'll revisit this issue if necessary. // ----------------------------------------------------------------------------- -// Goes through a tree. Could be made more efficient if written directly. -// We'll revisit this if it becomes more of an issue. inline bool convert(const JSON &j, XML &x) { - // temporary - Tree t; - - // convert try { - return convert(j,t) && convert(t,x); + Tree tmp; + return convert(j,tmp) && convert(tmp,x); } catch (...) { log::function("convert(JSON,XML)"); throw; } } + +inline bool convert(const HDF5 &h, XML &x) +{ + try { + Tree tmp; + return convert(h,tmp) && convert(tmp,x); + } catch (...) { + log::function("convert(HDF5,XML)"); + throw; + } +} diff --git a/src/GNDStk/convert/src/detail-hdf52node.hpp b/src/GNDStk/convert/src/detail-hdf52node.hpp new file mode 100644 index 000000000..c94c2ae76 --- /dev/null +++ b/src/GNDStk/convert/src/detail-hdf52node.hpp @@ -0,0 +1,346 @@ + +// Helper: hdf52node_error +inline void hdf52node_error(const std::string &message) +{ + log::error( + "Internal error in hdf52node():\n" + "Message: \"{}\".", message); + throw std::exception{}; +} + + +// ----------------------------------------------------------------------------- +// attr2node +// For HighFive::Attribute +// ----------------------------------------------------------------------------- + +// helper +template +bool attr2node(const HighFive::Attribute &attr, NODE &node) +{ + if (attr.getDataType() == HighFive::AtomicType{}) { + const std::string attrName = attr.getName(); + const std::size_t attrSize = attr.getSpace().getElementCount(); + + // Scalar case. Includes bool. + // fixme. ...or doesn't include bool. 2022-06-16, the current HighFive + // master appears to have broken HighFive's bool support, so I've + // if-constexpr'd it out here. We're not dealing with bool in the test + // suite at this time, so this is fine, at least for now. + if constexpr (!std::is_same_v) { + if (attrSize == 1) { + T scalar; + attr.read(scalar); + node.add(attrName,scalar); + return true; + } + } + + // Vector case. EXcludes bool, as HighFive (perhaps HDF5 in general?) + // doesn't appear to support it in this case. Indeed, the body of the + // if-constexpr doesn't *compile* with bool. (Hence our if-constexpr.) + if constexpr (!std::is_same_v) { + std::vector vector; + vector.reserve(attrSize); + attr.read(vector); + node.add(attrName,vector); + return true; + } + } + + return false; +} + +// attr2node +template +bool attr2node(const HighFive::Attribute &attr, NODE &node) +{ + // HighFive's documentation leaves much to be desired. I used what I found + // in HighFive/include/highfive/bits/H5DataType_misc.hpp to get an idea of + // what attribute *types* are allowed. That file also had some handling of + // C-style fixed-length strings, as with char[length], and std::complex as + // well. It didn't have long double, which I'd have liked, but that's fine. + // I won't bother with fixed-length strings or with std::complex right now, + // but will support the rest. + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + if (attr2node(attr,node)) return true; + + log::error( + "HDF5 Attribute \"{}\"'s DataType \"{}\" is not supported at this time.", + attr.getName(), attr.getDataType().string()); + log::function("attr2node()"); + + return false; +} + + +// ----------------------------------------------------------------------------- +// dset2node +// For HighFive::DataSet +// ----------------------------------------------------------------------------- + +// helper +template +bool dset2node(const HighFive::DataSet &dset, NODE &node) +{ + if (dset.getDataType() == HighFive::AtomicType{}) { + // Remarks as in the similar helper function attr2node() + const std::size_t dataSize = dset.getElementCount(); + + // See earlier fixme. bool support is removed for now, because it appears + // to be broken in the latest HighFive. + if constexpr (!std::is_same_v) { + if (dataSize == 1) { + T scalar; + dset.read(scalar); + node.name == special::data + ? node.add(special::text,scalar) + : node.add(special::data).add(special::text,scalar); + return true; + } + } + + if constexpr (!std::is_same_v) { + std::vector vector; + vector.reserve(dataSize); + dset.read(vector); + node.name == special::data + ? node.add(special::text,vector) + : node.add(special::data).add(special::text,vector); + return true; + } + } + + return false; +} + +// dset2node +template +bool dset2node( + const HighFive::DataSet &dset, const std::string &dsetName, + NODE &parent +) { + Node &node = parent.add( + beginsin(dsetName,special::data) ? special::data : dsetName); + + // the DataSet's attributes + for (const std::string &attrName : dset.listAttributeNames()) + if (attrName == special::nodename) + dset.getAttribute(attrName).read(node.name); + else if (!attr2node(dset.getAttribute(attrName), node)) + return false; + + // the DataSet's data + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + if (dset2node(dset,node)) return true; + + log::error( + "HDF5 DataSet \"{}\"'s DataType \"{}\" is not supported at this time.", + dsetName, dset.getDataType().string()); + log::function("dset2node()"); + + return false; +} + + +// ----------------------------------------------------------------------------- +// hdf52node +// ----------------------------------------------------------------------------- + +template +bool hdf52node( + const HighFive::Group &group, const std::string &groupName, + NODE &node, const bool decl +) { + const bool atRoot = groupName == "/"; + + // node name: from HDF5 group name + if (!decl) { + if (!atRoot) + node.name = groupName; + // strip digits from node name, if appropriate + if (node.name != "" && node.name[0] == special::prefix) + while (isdigit(node.name.back())) + node.name.pop_back(); + } + + // ------------------------ + // Group's attributes + // ==> metadata + // ------------------------ + + // Only if we're *not* at the root HDF5 group. If we are, then attributes + // would have already been handled, in a special way, by the caller. + if (!atRoot) { + for (const std::string &attrName : group.listAttributeNames()) { + if (attrName == special::nodename) { + // #nodename + // Handled not as a regular attribute, but as the present node's + // true name. The following line is basically a compressed version + // of attr2node (see early in this file). It assumes, + // in short, that this #nodename attribute is one (not a vector of) + // T == std::string. And that's precisely what it should be, given + // how GNDStk creates #nodename attributes in the first place. + group.getAttribute(attrName).read(node.name); + } else if (beginsin(attrName,special::cdata)) { + // #cdata, possibly with a numeric suffix + // Expand into a child node #cdata with a #text attribute. + std::string value; + group.getAttribute(attrName).read(value); + node.add(special::cdata).add(special::text,value); + } else if (beginsin(attrName,special::comment)) { + // #comment, possibly with a numeric suffix + // Expand into a child node #comment with a #text attribute. + std::string value; + group.getAttribute(attrName).read(value); + node.add(special::comment).add(special::text,value); + } else { + // Regular attribute + // Create a metadatum. Note that this gives the correct result + // for attributes with regular names, and also for attrName == + // special::text. + if (!attr2node(group.getAttribute(attrName), node)) + return false; + } // else if + } // for + } // if + + // ------------------------ + // Group's objects + // ==> children + // ------------------------ + + size_t count = 0; + for (const std::string &elemName : group.listObjectNames()) { + + const HighFive::ObjectType type = group.getObjectType(elemName); + if (type == HighFive::ObjectType::Group || + type == HighFive::ObjectType::Dataset + ) { + count++; + if (count > 1 && atRoot && !decl) { + log::error("More than one group and/or dataset at top HDF5 level"); + throw std::exception{}; + } + } + + switch (type) { + + // ------------------------ + // Group and DataSet are + // allowable and handled + // ------------------------ + + // Group + // ACTION: Call the present function recursively + case HighFive::ObjectType::Group : + try { + if (!hdf52node( + group.getGroup(elemName), elemName, + node.name == "" ? node : node.add(), + false + )) { + return false; + } + } catch (...) { + log::function("hdf52node()"); + throw; + } + break; + + // DataSet + // ACTION: Handle the DataSet's data + // Note: HighFive actually calls the following Dataset (lower-case s), + // not DataSet (upper-case S), but uses "DataSet" elsewhere. :-/ + case HighFive::ObjectType::Dataset : + try { + if (!dset2node( + group.getDataSet(elemName), elemName, + node + )) { + return false; + } + } catch (...) { + log::function("hdf52node()"); + throw; + } + break; + + // ------------------------ + // All other types are + // unexpected or unhandled + // ------------------------ + + // File + // NOT EXPECTED IN THIS CONTEXT + case HighFive::ObjectType::File : + hdf52node_error("ObjectType \"File\" is not expected here"); + break; + + // DataSpace (not to be confused with DataSet) + // NOT EXPECTED IN THIS CONTEXT + case HighFive::ObjectType::DataSpace : + hdf52node_error("ObjectType \"DataSpace\" is not expected here"); + break; + + // Attribute + // NOT EXPECTED IN THIS CONTEXT + case HighFive::ObjectType::Attribute : + // group.listObjectNames() (used in the for-loop we're in right + // now) apparently doesn't include attribute names - which is fine, + // because we already handled attributes earlier. So, here, we just + // produce an error if ObjectType::Attribute inexplicably made an + // appearance here, where we don't expect it. + hdf52node_error("ObjectType \"Attribute\" is not expected here"); + break; + + // UserDataType + // NOT HANDLED; These may or may not ever be needed + case HighFive::ObjectType::UserDataType : + hdf52node_error("ObjectType \"UserDataType\" is not supported"); + break; + + // Other + // NOT HANDLED; We're not sure when this would arise + case HighFive::ObjectType::Other : + hdf52node_error("ObjectType \"Other\" is not supported"); + break; + + // default + // NOT HANDLED; our switch() should have covered all bases + default: + hdf52node_error("ObjectType [unknown] is not supported"); + break; + + } // switch + } // for + + // done + return true; +} diff --git a/src/GNDStk/convert/src/detail-json2node.hpp b/src/GNDStk/convert/src/detail-json2node.hpp new file mode 100644 index 000000000..93428cffc --- /dev/null +++ b/src/GNDStk/convert/src/detail-json2node.hpp @@ -0,0 +1,170 @@ + +// Helper: json2node_error +inline void json2node_error(const std::string &message) +{ + log::error( + "Internal error in json2node():\n" + "Message: \"{}\".", message); + throw std::exception{}; +} + +// Forward declaration +template +void json2node(const orderedJSON &, NODE &, const bool inferNodeName = false); + + +// ----------------------------------------------------------------------------- +// json_array +// ----------------------------------------------------------------------------- + +inline std::string json_array(const orderedJSON &array) +{ + assert(array.is_array()); + + std::ostringstream oss; + int count = 0; + + for (const orderedJSON &element : array) { + // separator + oss << (count++ ? " " : ""); + // array element types we use + element.is_number_integer () ? (oss << element.get()) + : element.is_number_unsigned() ? (oss << element.get()) + : element.is_number_float () ? (oss << element.get()) + : element.is_string () ? (oss << element.get()) + : // unexpected + (json2node_error("JSON array element is of unexpected type"), oss); + } + + return oss.str(); +} + + +// ----------------------------------------------------------------------------- +// json_pair +// ----------------------------------------------------------------------------- + +template +void json_pair( + const std::string &key, const orderedJSON &val, + const orderedJSON &peers, NODE &node +) { + if (val.is_null()) { + // null; nothing to do + } else if (val.is_boolean()) { + // boolean + node.add(key, val.get() ? "true" : "false"); + } else if (val.is_number_integer()) { + // number: integer + node.add(key, val.get()); + } else if (val.is_number_unsigned()) { + // number: unsigned + node.add(key, val.get()); + } else if (val.is_number_float()) { + // number: double + node.add(key, val.get()); + } else if (val.is_string()) { + // string + node.add(key, val.get()); + } else if (val.is_array()) { + // array + if (peers.size() == 0) + node.add(key, json_array(val)); // context is such that it's metadata + else { + node.add(special::data).add(special::text, json_array(val)); + for (const auto &peer : peers.items()) { + if (peer.key() == key + special::nodename) + node.name = peer.value().get(); + if (peer.key() == key + special::metadata) { + for (const auto &m : peer.value().items()) + json_pair(m.key(), m.value(), orderedJSON{}, node); + } + } + } + } else if (val.is_object()) { + // object + try { + json2node(val,node); + } catch (...) { + log::function("json2node()"); + throw; + } + } else { + // unexpected + json2node_error("JSON key/value pair's value is of unexpected type"); + } +} + + +// ----------------------------------------------------------------------------- +// json2node +// ----------------------------------------------------------------------------- + +// NODE is GNDStk::Node, an incomplete type to the compiler here. +// Note: the object parameter is a JSON "object", i.e. {...}. +template +void json2node(const orderedJSON &object, NODE &node, bool inferNodeName) +{ + // The node sent here shouldn't already have metadata or children + if (node.metadata.size() != 0 || node.children.size() != 0) + json2node_error("Node should be empty, but has metadata and/or children"); + + // Special node names (special::prefix...) need trailing digits removed + if (node.name != "" && node.name[0] == special::prefix) + while (isdigit(node.name.back())) + node.name.pop_back(); + + // For each key/value pair + for (const auto &pair : object.items()) { + const std::string &key = pair.key(); + const orderedJSON &val = pair.value(); + + if (inferNodeName && key.find(special::prefix) == std::string::npos) { + // Infer the node name from this (non-special) key + node.name = key; + inferNodeName = false; + json_pair(key, val, object, node); + } else if (key == special::nodename) { + // Special key: nodename + node.name = val.get(); + inferNodeName = false; + } else if (key == special::metadata) { + // Special key: metadata + for (const auto &m : val.items()) + json_pair(m.key(), m.value(), orderedJSON{}, node); + } else if ( + beginsin(key,special::cdata) || + beginsin(key,special::comment) || + beginsin(key,special::data) + ) { + // Special key: cdata, comment, or data, with optional suffix + if (val.is_object()) { + try { + json2node(val, node.add(key)); + } catch (...) { + log::function("json2node()"); + throw; + } + } else { + beginsin(key,special::data) + ? node.add(special::data ) + .add(special::text, json_array(val)) + : beginsin(key,special::cdata) + ? node.add(special::cdata ) + .add(special::text, val.get()) + : node.add(special::comment) + .add(special::text, val.get()); + } + } else if (endsin(key,special::nodename) || + endsin(key,special::metadata)) { + // Special key: with nodename or metadata *suffix* + // Ignore, in this context. Note that key *equal* to either of those + // was handled earlier. The cases here are dealt with in json_pair(), + // called below. There, we process e.g. "foo", and scan object.items() + // to process "foo*" where * is either of the relevant suffixes. + } else { + // Normal key + json_pair(key, val, object, node.add(key)); + } + } // key/value pairs +} diff --git a/src/GNDStk/convert/src/detail-node2hdf5.hpp b/src/GNDStk/convert/src/detail-node2hdf5.hpp new file mode 100644 index 000000000..e9b7456bc --- /dev/null +++ b/src/GNDStk/convert/src/detail-node2hdf5.hpp @@ -0,0 +1,369 @@ + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +// ------------------------ +// scalar2Attr +// vector2Attr +// ------------------------ + +// scalar2Attr +template +void scalar2Attr( + const std::string &key, const std::string &value, + OBJECT &hdf5 +) { + T scalar; + convert(value,scalar); + hdf5.createAttribute(key,scalar); +} + +// vector2Attr +template +void vector2Attr( + const std::string &key, const std::string &value, + OBJECT &hdf5 +) { + std::vector vector; + convert(value,vector); + hdf5.createAttribute(key,vector); +} + + +// ------------------------ +// data2DataSet +// ------------------------ + +// helper +template +HighFive::DataSet data2DataSet( + const std::string &key, const std::string &value, + OBJECT &hdf5 +) { + // Similar to vector2Attr() above, but creates a DataSet, not an Attribute. + // Note that in the JSON-format analogs of the various helper functions in + // this section of code, an analog of *this* function doesn't exist. JSON + // doesn't have HDF5's distinction between "attributes" and "data sets". + // Therefore, writing a vector (as we do above, via createAttribute(), and + // here, via createDataSet()) is done, in JSON, in just one way: by creating + // a JSON key:value pair with the vector as the value. So, in the JSON code, + // we have an analog of the above vector2Attr() function, and that function + // is also used where this present function would otherwise have been used. + std::vector vector; + convert(value,vector); + return hdf5.createDataSet(key,vector); +} + +// w/ type string +template +HighFive::DataSet data2DataSet( + const std::string &key, const std::string &value, + OBJECT &hdf5 +) { + if (HDF5::typed) { + const std::string type = guessType(value); + + if (type == "int" || type == "ints" ) + return data2DataSet(key,value,hdf5); + if (type == "uint" || type == "uints" ) + return data2DataSet(key,value,hdf5); + if (type == "long" || type == "longs" ) + return data2DataSet(key,value,hdf5); + if (type == "ulong" || type == "ulongs" ) + return data2DataSet(key,value,hdf5); + if (type == "double" || type == "doubles") + return data2DataSet(key,value,hdf5); + } + return data2DataSet(key,value,hdf5); +} + + +// ----------------------------------------------------------------------------- +// meta2hdf5* +// See remarks in the JSON analogs of these functions. +// ----------------------------------------------------------------------------- + +// ------------------------ +// meta2hdf5_typed +// ------------------------ + +template +void meta2hdf5_typed(const NODE &node, OBJECT &hdf5) +{ + const std::string &parent = node.name; + + for (auto &meta : node.metadata) { + const std::string &key = meta.first; + const std::string &value = meta.second; + + // ------------------------ + // Special cases + // ------------------------ + + // *** #cdata/#text + // *** #comment/#text + if ((parent == special::cdata || + parent == special::comment) && key == special::text) { + hdf5.createAttribute(key,value); // just a simple string attribute + continue; + } + + // *** #data/#text + if (parent == special::data && key == special::text) { + const std::string type = guessType(value); + if (type == "int" || type == "ints") + vector2Attr(key,value,hdf5); + else if (type == "uint" || type == "uints") + vector2Attr(key,value,hdf5); + else if (type == "long" || type == "longs") + vector2Attr(key,value,hdf5); + else if (type == "ulong" || type == "ulongs") + vector2Attr(key,value,hdf5); + else if (type == "double" || type == "doubles") + vector2Attr(key,value,hdf5); + else + vector2Attr(key,value,hdf5); + continue; + } + + // *** key/#text not expected, except as already handled + if (key == special::text) { + log::warning("Metadatum \"{}\" not expected here; writing anyway", + special::text); + log::function("detail::meta2hdf5(Node named \"{}\", ...)", parent); + } + + // ------------------------ + // General case + // ------------------------ + + // *** key/value + const std::string type = guessType(value); + if (type == "int" ) scalar2Attr(key,value,hdf5); else + if (type == "ints" ) vector2Attr(key,value,hdf5); else + if (type == "uint" ) scalar2Attr(key,value,hdf5); else + if (type == "uints" ) vector2Attr(key,value,hdf5); else + if (type == "long" ) scalar2Attr(key,value,hdf5); else + if (type == "longs" ) vector2Attr(key,value,hdf5); else + if (type == "ulong" ) scalar2Attr(key,value,hdf5); else + if (type == "ulongs" ) vector2Attr(key,value,hdf5); else + if (type == "double" ) scalar2Attr(key,value,hdf5); else + if (type == "doubles") vector2Attr(key,value,hdf5); else + /* string OR strings*/ scalar2Attr(key,value,hdf5); + } +} // meta2hdf5_typed + + +// ------------------------ +// meta2hdf5_plain +// ------------------------ + +// Here, OBJECT hdf5 is either a HighFive::Group or a HighFive::DataSet +template +void meta2hdf5_plain(const NODE &node, OBJECT &hdf5) +{ + for (auto &meta : node.metadata) + hdf5.createAttribute(meta.first, meta.second); +} + + +// ------------------------ +// meta2hdf5 +// ------------------------ + +template +void meta2hdf5( + const NODE &node, OBJECT &hdf5, + const std::string &base, + const std::string &digits +) { + // Create #nodename iff necessary. See remarks in the analogous JSON code. + if (digits != "" && + !beginsin(base,std::string(1,special::prefix))) + hdf5.createAttribute(special::nodename, node.name); + + // Existing metadata + HDF5::typed + ? meta2hdf5_typed(node,hdf5) + : meta2hdf5_plain(node,hdf5); +} + + +// ----------------------------------------------------------------------------- +// hdf5_reduce_* +// ----------------------------------------------------------------------------- + +// ------------------------ +// hdf5_reduce_cdata_comment +// ------------------------ + +// Simplify certain #cdata and #comment cases. +template +bool hdf5_reduce_cdata_comment( + const NODE &node, OBJECT &hdf5, const std::string &suffix +) { + const std::string nameOriginal = node.name; + const std::string nameSuffixed = node.name + suffix; + + // #cdata or #comment + // #text the only metadatum + // no children + // Reduce to: string attribute, w/name == (#cdata or #comment) + suffix + // Sketch: + // +-----------------+ +-----------+ + // | #cdata/#comment | ==> | Attribute | name: #cdata/#comment + suffix + // | #text | | value | + // +-----------------+ +-----------+ + + if ( + (nameOriginal == special::cdata || nameOriginal == special::comment) && + node.children.size() == 0 && + node.metadata.size() == 1 && + node.metadata[0].first == special::text + ) { + // string attribute + hdf5.createAttribute(nameSuffixed,node.metadata[0].second); + return true; + } + + return false; +} + + +// ------------------------ +// hdf5_reduce_data +// ------------------------ + +// Simplify #data case. +template +bool hdf5_reduce_data( + const NODE &node, OBJECT &hdf5, const std::string &suffix +) { + const std::string nameOriginal = node.name; + const std::string nameSuffixed = node.name + suffix; + + // #data + // #text the only metadatum + // no children + // Reduce to: data set, w/name == #data + suffix + // Sketch: + // +----------+ +---------+ + // | #data | ==> | DataSet | name: #data + suffix + // | #text | | data | + // +----------+ +---------+ + + if (nameOriginal == special::data && + node.children.size() == 0 && + node.metadata.size() == 1 && + node.metadata[0].first == special::text + ) { + // See the remark in the analogous JSON function regarding the difference + // between this function and the one immediately below. + + // HDF5 data set + data2DataSet(nameSuffixed, node.metadata[0].second, hdf5); + return true; + } + + return false; +} + + +// ------------------------ +// hdf5_reduce_data_metadata +// ------------------------ + +// Simplify case of node with #data AND metadata +template +bool hdf5_reduce_data_metadata( + const NODE &node, OBJECT &hdf5, const std::string &suffix +) { + // name (think e.g. "values", as in XML ) + // any number of metadata (possibly 0) + // #data the only child + // #text the only metadatum + // no children + // Reduce to: data set, w/name == name + suffix + // Sketch: + // +---------------+ +----------------+ + // | name | ==> | DataSet | name: name + suffix + // | [metadata] | | [Attributes] | + // | #data | | data | + // | #text | +----------------+ + // | - | + // +---------------+ + + if (node.children.size() == 1 && + node.children[0]->name == special::data && + node.children[0]->metadata.size() == 1 && + node.children[0]->metadata[0].first == special::text && + node.children[0]->children.size() == 0 + ) { + // HDF5 data set + const std::string text = node.children[0]->metadata[0].second; + HighFive::DataSet dataset = data2DataSet(node.name+suffix, text, hdf5); + + // metadata + meta2hdf5(node, dataset, node.name, suffix); + return true; + } + + return false; +} + + +// ----------------------------------------------------------------------------- +// node2hdf5 +// ----------------------------------------------------------------------------- + +// NODE is just GNDStk::Node. The latter isn't used directly, because +// it's an "incomplete type", to the compiler, at this point. +// OBJECT is either HighFive::File or HighFive::Group. +template +bool node2hdf5(const NODE &node, OBJECT &h, const std::string &suffix = "") +{ + const std::string nameSuffixed = node.name + suffix; + + // ------------------------ + // Special cases + // ------------------------ + + if (HDF5::reduced && ( + hdf5_reduce_cdata_comment(node,h,suffix) || + hdf5_reduce_data (node,h,suffix) || + hdf5_reduce_data_metadata(node,h,suffix) + )) + return true; + + // ------------------------ + // General case + // ------------------------ + + // Create a new Group, in parameter h, for metadata and children + HighFive::Group group = h.createGroup(nameSuffixed); + + // metadata + meta2hdf5(node, group, node.name, suffix); + + // children - preprocess + // To understand this, see the remark in the JSON analog. + std::map childNames; + for (auto &c : node.children) { + auto iter = childNames.find(c->name); + if (iter == childNames.end()) + childNames.insert({c->name,0}); + else + iter->second = 1; + } + + // children + for (auto &c : node.children) { + const std::size_t counter = childNames.find(c->name)->second++; + if (!node2hdf5(*c, group, counter ? std::to_string(counter-1) : "")) + return false; + } + + // done + return true; +} diff --git a/src/GNDStk/convert/src/detail-node2json.hpp b/src/GNDStk/convert/src/detail-node2json.hpp new file mode 100644 index 000000000..21ff8bea4 --- /dev/null +++ b/src/GNDStk/convert/src/detail-node2json.hpp @@ -0,0 +1,465 @@ + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +// ------------------------ +// scalar2Value +// vector2Value +// ------------------------ + +// scalar2Value +template +void scalar2Value( + const std::string &key, const std::string &value, + orderedJSON &json +) { + // Parameter "value" is a string - for example "1", "2.34", or "foo". The + // caller will have guessed T == int, T == double, or T == std::string in + // those cases. In the present function, we wish to write std::string value + // AS-IS into the value part of a JSON key/value pair. However, when T is + // a number, like int or double, we wish to write it as a JSON number - so, + // without quotes. In constrast, only when T == std::string will we write + // it as a JSON string. Note that even when it's really a number, the value + // parameter arrives here as a std::string, because our (very customizable) + // handling of formatting and significant digits requires this. Here, right + // now, we can assume that a "number" inside std::string reflects the exact + // way that we want the number to be printed. + + if constexpr (std::is_same_v) { + // Write JSON string. + json[key] = value; + } else { + // Write JSON number (so unquoted, unlike in the string case above), + // but write the "number" exactly as it appears in parameter "value", + // which the caller guessed contains a number: "1", "2.34", etc. + // + // fixme Unfortunately, the nlohmann/json library does not, at the + // present time, allow us to write our string as a number - without + // quotes. It'll format the number as it wants to. Given that GNDStk + // allows fine control over the formatting of floating-point numbers, + // we'll need to deal with this at some point, to have our formatting + // be respected in JSON output. + T scalar; + convert(value,scalar); + json[key] = scalar; // For now. Later, write the value literally + } +} + +// vector2Value +template +void vector2Value( + const std::string &key, const std::string &value, + orderedJSON &json +) { + // Like the scalar case, but value is, for example, "1 2", "3.4 5.6 7.8", + // or "foo bar baz" - a vector of T == int, T = double, or T == std::string. + if constexpr (std::is_same_v) { + // Write JSON array of strings. + std::vector vector; + convert(value,vector); // single string ==> vector + json[key] = vector; + } else { + // Write JSON array of numbers. + // fixme Basically, the same fixme as above. For now, the "else" code + // here is the same as the "if" code, but that'll change. + std::vector vector; // For now. Later, std::vector... + convert(value,vector); + json[key] = vector; // For now. Later, write each string literally + } +} + + +// ------------------------ +// data2Value +// ------------------------ + +inline void data2Value( + const std::string &key, const std::string &value, + orderedJSON &json +) { + if (JSON::typed) { + const std::string type = guessType(value); + + if (type == "int" || type == "ints" ) + { vector2Value(key,value,json); return; } + if (type == "uint" || type == "uints" ) + { vector2Value(key,value,json); return; } + if (type == "long" || type == "longs" ) + { vector2Value(key,value,json); return; } + if (type == "ulong" || type == "ulongs" ) + { vector2Value(key,value,json); return; } + if (type == "double" || type == "doubles") + { vector2Value(key,value,json); return; } + } + vector2Value(key,value,json); +} + + +// ----------------------------------------------------------------------------- +// meta2json* +// ----------------------------------------------------------------------------- + +// ------------------------ +// meta2json_typed +// ------------------------ + +// Use our "guess what's in the string" code to try to infer what each +// metadatum's string value actually contains (a single int, say, or +// a vector of doubles). Use the inferred types in the JSON file. +template +void meta2json_typed(const NODE &node, orderedJSON &json) +{ + // Current node is the parent of its metadata + const std::string &parent = node.name; + + for (auto &meta : node.metadata) { + const std::string &key = meta.first; + const std::string &value = meta.second; + + // ------------------------ + // Special cases + // ------------------------ + + // *** #cdata/#text + // *** #comment/#text + // ACTION: Write these as-is. That is, do NOT apply our type-guessing code + // to a comment, or to the contents of a block like those + // that we see in existing XML-format GNDS files. The type guesser would + // see words, and think "vector of [whitespace-separated] strings," which + // would be wrong for what are clearly intended to be free-form strings. + if ((parent == special::cdata || + parent == special::comment) && key == special::text) { + json[key] = value; // just a simple string value + continue; + } + + // *** #data/#text + // ACTION: Apply our type-guessing code, but write *vectors* only, never + // scalars. So, 10 produces a vector with one element, + // NOT a scalar; while 10 20 30 produces a vector with + // three elements. What may look like scalars are made into vectors + // because we think this reflects what these data nodes are intended + // to represent. (If something was really just a scalar, then surely it + // would be placed into standard metadata (in <...>), not into data. + if (parent == special::data && key == special::text) { + const std::string type = guessType(value); + if (type == "int" || type == "ints") + vector2Value(key,value,json); + else if (type == "uint" || type == "uints") + vector2Value(key,value,json); + else if (type == "long" || type == "longs") + vector2Value(key,value,json); + else if (type == "ulong" || type == "ulongs") + vector2Value(key,value,json); + else if (type == "double" || type == "doubles") + vector2Value(key,value,json); + else + vector2Value(key,value,json); + continue; + } + + // *** key/#text not expected, except as already handled + if (key == special::text) { + log::warning("Metadatum \"{}\" not expected here; writing anyway", + special::text); + log::function("detail::meta2json(Node named \"{}\", ...)", parent); + } + + // ------------------------ + // General case + // ------------------------ + + // *** key/value + // ACTION: Apply our type-guessing code. + // Here we have normal metadata, as in . + // For numeric types we might produce vectors, if there appear to be + // multiple values. But for string types, we'll assume that the value + // is probably intended to be a free-form, human-readable descriptive + // string, which shouldn't be split into tokens and made into a vector. + const std::string type = guessType(value); + if (type == "int" ) scalar2Value(key,value,json); else + if (type == "ints" ) vector2Value(key,value,json); else + if (type == "uint" ) scalar2Value(key,value,json); else + if (type == "uints" ) vector2Value(key,value,json); else + if (type == "long" ) scalar2Value(key,value,json); else + if (type == "longs" ) vector2Value(key,value,json); else + if (type == "ulong" ) scalar2Value(key,value,json); else + if (type == "ulongs" ) vector2Value(key,value,json); else + if (type == "double" ) scalar2Value(key,value,json); else + if (type == "doubles") vector2Value(key,value,json); else + /* string OR strings*/ scalar2Value(key,value,json); + } +} // meta2json_typed + + +// ------------------------ +// meta2json_plain +// ------------------------ + +// Write simple JSON in which all metadata, as well as the contents +// of #cdata and #data nodes) end up being strings. Not even vectors +// of strings, as from H He Li ..., but single strings. +template +void meta2json_plain(const NODE &node, orderedJSON &json) +{ + for (auto &meta : node.metadata) + json[meta.first] = meta.second; +} + + +// ------------------------ +// meta2json +// ------------------------ + +template +void meta2json( + const NODE &node, orderedJSON &json, + const std::string &base, + const std::string &digits, + const std::string &prefix +) { + // Create #nodename iff necessary, to allow recovery of the node's original + // name. Note that #nodename isn't necessary for special nodes, in particular + // #cdata, #data, and #comment. For those, we can reliably reconstruct the + // original name by removing trailing digits. A regular node, in contrast, + // *might* have an actual name that has trailing digits (one user called a + // node "sigma0", for example); or, trailing digits might have been added - + // by us - solely for the purpose of disambiguating same-named child nodes + // (for example, "sigma") that appeared multiple times under the same XML + // parent (which is allowed), but which can't appear that way in JSON. (JSON + // doesn't allow duplicate keys in the same object). + if (digits != "" && // will have suffixed digits + !beginsin(base,std::string(1,special::prefix))) // isn't special + json[prefix + special::nodename] = node.name; + + // Existing metadata + // Remark: we could do without the "if (node.metadata.size())" conditional, + // except that the "json[...]" expressions have the side effect of creating + // JSON values (nulls to start with, until/unless something is added later). + // We don't want those to be created at all here if they won't end up having + // anything, in this case metadata, added to them. + if (node.metadata.size()) + JSON::typed + ? meta2json_typed(node, json[prefix + special::metadata]) + : meta2json_plain(node, json[prefix + special::metadata]); +} + + +// ----------------------------------------------------------------------------- +// json_reduce_* +// ----------------------------------------------------------------------------- + +// ------------------------ +// json_reduce_cdata_comment +// ------------------------ + +// Simplify certain #cdata and #comment cases. +template +bool json_reduce_cdata_comment( + const NODE &node, orderedJSON &json, const std::string &digits +) { + // Original node name, and suffixed name. The latter is for handling child + // nodes of the same name under the same parent node, and includes a numeric + // suffix (so, name0, name1, etc.) in that scenario. This is needed for JSON + // because JSON doesn't support same-named child nodes. In cases where the + // name was unique to begin with, nameOriginal == nameSuffixed. + const std::string nameOriginal = node.name; + const std::string nameSuffixed = node.name + digits; + + // #cdata or #comment + // #text the only metadatum + // no children + // Reduce to: string value, w/name == (#cdata or #comment) + digits + // Sketch: + // +-----------------+ +------------+ + // | #cdata/#comment | ==> | "name" : | name: #cdata/#comment + digits + // | #text | | "value" | + // +-----------------+ +------------+ + + if ( + (nameOriginal == special::cdata || nameOriginal == special::comment) && + node.children.size() == 0 && + node.metadata.size() == 1 && + node.metadata[0].first == special::text + ) { + // string value + json[nameSuffixed] = node.metadata[0].second; + return true; + } + + return false; +} + + +// ------------------------ +// json_reduce_data +// ------------------------ + +// Simplify #data case. +template +bool json_reduce_data( + const NODE &node, orderedJSON &json, const std::string &digits +) { + const std::string nameOriginal = node.name; + const std::string nameSuffixed = node.name + digits; + + // #data + // #text the only metadatum + // no children + // Reduce to: array, w/name == #data + digits + // Sketch: + // +----------+ +----------+ + // | #data | ==> | "name" : | name: #data + digits + // | #text | | [...] | + // +----------+ +----------+ + + if (nameOriginal == special::data && + node.children.size() == 0 && + node.metadata.size() == 1 && + node.metadata[0].first == special::text + ) { + // Remark. This case (basically, #data/#text) may look superficially + // like it would have been handled, in the case immediately below here, + // in the previous (next-up) recurse of the node2json() function. Often + // it would have, but not always. Later, name/#data/#text (three + // levels, so to speak) reduces to one level (name : [...]), but + // only if name has ONE child - the #data. That's true when we + // have (in XML) something like 1 2 3, as the data, + // i.e. the 1 2 3 part, is ' only child node. However, it's + // actually possible (though I don't see it in current GNDS files) to + // have something like: 1 2 3. There, the + // outer "name" node () has child foo and child #data, and + // thus can't be reduced in the manner that's done if only #data is + // there. In short, then, the present situation comes to pass if and + // when #data has sibling nodes. + + // JSON array + data2Value(nameSuffixed, node.metadata[0].second, json); + return true; + } + + return false; +} + + +// ------------------------ +// json_reduce_data_metadata +// ------------------------ + +// Simplify case of node with data AND metadata +template +bool json_reduce_data_metadata( + const NODE &node, orderedJSON &json, const std::string &digits +) { + const std::string nameSuffixed = node.name + digits; + + // name (think e.g. "values", as in XML ) + // any number of metadata (possibly 0) + // #data the only child + // #text the only metadatum + // no children + // Reduce to: array, w/name == name + digits; separately encoded metadata + // Sketch: + // +---------------+ +---------------------+ + // | name | ==> | "name" : | name: name + digits + // | [metadata] | | [...] | + // | #data | | "name#metadata" : { | + // | #text | | key/value pairs | + // | - | | } | + // +---------------+ +---------------------+ + // Remark. We're not super psyched about the "name#metadata" construction. + // It effectively splits the original node into two siblings in the JSON + // file; and, it differs from the present scenario's HDF5 handling, which + // places those metadata into HDF5 "attributes" within an HDF5 "data set". + // Here, the analog would be to place the metadata into the [...] part. + // That's doable, because JSON arrays are polymorphic, but we believe it + // would clutter the [...] with elements that would need to be interpreted, + // by whatever tool someone might use to process the JSON file, separately + // from how the rest of the [...] is interpreted. With HDF5 that probably + // isn't an issue, because a data set's *attributes*, while residing in the + // data set, would presumably be seen by HDF5 tools as logically distinct + // from its *data* proper. With JSON, we don't see how that would happen. + // Hence, our choice above. An important thing is that the above system + // is reversible - a file, thus written, can be read back in, recovering + // our original internal data structure unambiguously. Also, the two JSON + // constructs, "name" and "name#metadata", will appear next to each other, + // allowing someone who looks at the file to see what's going on. + + if (node.children.size() == 1 && + node.children[0]->name == special::data && + node.children[0]->metadata.size() == 1 && + node.children[0]->metadata[0].first == special::text && + node.children[0]->children.size() == 0 + ) { + // JSON array + const std::string text = node.children[0]->metadata[0].second; + data2Value(nameSuffixed, text, json); + + // metadata + meta2json(node, json, node.name, digits, nameSuffixed); + return true; + } + + return false; +} + + +// ----------------------------------------------------------------------------- +// node2json +// ----------------------------------------------------------------------------- + +// NODE is just GNDStk::Node. The latter isn't used directly, because +// it's an "incomplete type", to the compiler, at this point. +template +bool node2json(const NODE &node, orderedJSON &j, const std::string &digits = "") +{ + const std::string nameSuffixed = node.name + digits; + + // ------------------------ + // Special cases + // ------------------------ + + if (JSON::reduced && ( + json_reduce_cdata_comment(node,j,digits) || + json_reduce_data (node,j,digits) || + json_reduce_data_metadata(node,j,digits) + )) + return true; + + // ------------------------ + // General case + // ------------------------ + + // Create a new orderedJSON, in parameter j, for metadata and children + orderedJSON &json = j[nameSuffixed]; + + // metadata + meta2json(node, json, node.name, digits, ""); + + // children - preprocess + // First, account for what children appear in the current node. If any child + // name appears multiple times, we must deal with that. For each represented + // child name, the map gets 0 if the name appears once, 1 if it appears more + // than once. Later, this 0/1 is used initially to make a boolean choice; + // then it serves as a counter to generate a 0-indexed numeric suffix that + // makes the child names unique: name0, name1, etc. + std::map childNames; + for (auto &c : node.children) { + auto iter = childNames.find(c->name); + if (iter == childNames.end()) + childNames.insert({c->name,0}); // once (so far) + else + iter->second = 1; // more than once + } + + // children + for (auto &c : node.children) { + const std::size_t counter = childNames.find(c->name)->second++; + if (!node2json(*c, json, counter ? std::to_string(counter-1) : "")) + return false; + } + + // done + return true; +} diff --git a/src/GNDStk/convert/src/detail-node2xml.hpp b/src/GNDStk/convert/src/detail-node2xml.hpp new file mode 100644 index 000000000..209f134c5 --- /dev/null +++ b/src/GNDStk/convert/src/detail-node2xml.hpp @@ -0,0 +1,115 @@ + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +// check_special +template +bool check_special(const NODE &node, const std::string &label) +{ + if (node.children.size() != 0) { + log::error( + "Internal error in node2xml(Node, pugi::xml_node):\n" + "Ill-formed <" + label + "> node; " + "should have 0 children, but has {}.", + node.children.size() + ); + throw std::exception{}; + } + + if (node.metadata.size() != 1) { + log::error( + "Internal error in node2xml(Node, pugi::xml_node):\n" + "Ill-formed <" + label + "> node; " + "should have 1 metadatum, but has {}.", + node.metadata.size() + ); + throw std::exception{}; + } + + if (node.metadata.begin()->first != special::text) { + log::error( + "Internal error in node2xml(Node, pugi::xml_node):\n" + "Ill-formed <" + label + "> node; " + "should have metadatum key \"#text\", but has key \"{}\".", + node.metadata.begin()->first + ); + throw std::exception{}; + } + + return true; +} + +// write_cdata +template +bool write_cdata(const NODE &node, pugi::xml_node &xnode) +{ + if (!check_special(node,special::cdata)) + return false; + xnode.append_child(pugi::node_cdata) + .set_value(node.meta(special::text).data()); + return true; +} + +// write_data +template +bool write_data(const NODE &node, pugi::xml_node &xnode) +{ + if (!check_special(node,special::data)) + return false; + xnode.append_child(pugi::node_pcdata) + .set_value(node.meta(special::text).data()); + return true; +} + +// write_comment +template +bool write_comment(const NODE &node, pugi::xml_node &xnode) +{ + if (!check_special(node,special::comment)) + return false; + xnode.append_child(pugi::node_comment) + .set_value(node.meta(special::text).data()); + return true; +} + + +// ----------------------------------------------------------------------------- +// node2xml +// ----------------------------------------------------------------------------- + +template +bool node2xml(const NODE &node, pugi::xml_node &x) +{ + static const std::string context = "node2xml(Node, pugi::xml_node)"; + + // name + pugi::xml_node xnode = x.append_child(node.name.data()); + + // metadata + for (auto &meta : node.metadata) + xnode.append_attribute(meta.first.data()) = meta.second.data(); + + // children + for (auto &child : node.children) { + try { + // special element + if (child->name == special::cdata) + { if (write_cdata (*child,xnode)) continue; else return false; } + if (child->name == special::data) + { if (write_data (*child,xnode)) continue; else return false; } + if (child->name == special::comment) + { if (write_comment(*child,xnode)) continue; else return false; } + + // typical element + if (!node2xml(*child,xnode)) + return false; + } catch (...) { + log::function(context); + throw; + } + } + + // done + return true; +} diff --git a/src/GNDStk/convert/src/detail-xml2node.hpp b/src/GNDStk/convert/src/detail-xml2node.hpp new file mode 100644 index 000000000..a65e8f2f9 --- /dev/null +++ b/src/GNDStk/convert/src/detail-xml2node.hpp @@ -0,0 +1,137 @@ + +// ----------------------------------------------------------------------------- +// Helpers +// ----------------------------------------------------------------------------- + +// xml2node_error +inline void xml2node_error(const std::string &type) +{ + log::error( + "Internal error in xml2node():\n" + "Type pugi::{} found, but not handled, as sub-element.", type); + throw std::exception{}; +} + + +// ----------------------------------------------------------------------------- +// xml2node +// ----------------------------------------------------------------------------- + +/* +FYI, here's the pugixml code for pugi::xml_node_type: + +namespace pugi +{ + enum xml_node_type + { + node_null, // Empty (null) node handle + node_document, // A document tree's absolute root + node_element, // Element tag, i.e. '' + node_pcdata, // Plain character data, i.e. 'foo' + node_cdata, // Character data, i.e. '' + node_comment, // Comment tag, i.e. '' + node_pi, // Processing instruction, i.e. '' + node_declaration, // Document declaration, i.e. '' + node_doctype // Document type declaration, i.e. '' + }; +} +*/ + +// pugi::xml_node ==> Node +template +bool xml2node(const pugi::xml_node &xnode, NODE &node) +{ + // check destination node + if (!node.empty()) { + log::error( + "Internal error in xml2node():\n" + "Destination Node is supposed to arrive here empty, but didn't." + ); + throw std::exception{}; + } + + // name + node.name = xnode.name(); + + // metadata + for (const pugi::xml_attribute &xattr : xnode.attributes()) + node.add(xattr.name(), xattr.value()); + + // children (sub-nodes) + for (const pugi::xml_node &xsub : xnode) { + + // ------------------------ + // not handled right now + // ------------------------ + + // I don't think that the following should ever appear in this context + if (xsub.type() == pugi::node_document) + xml2node_error("node_document"); + if (xsub.type() == pugi::node_declaration) + xml2node_error("node_declaration"); + + // For now I won't handle these; let's ensure that we don't see them + if (xsub.type() == pugi::node_null) + xml2node_error("node_null"); + if (xsub.type() == pugi::node_pi) + xml2node_error("node_pi"); + if (xsub.type() == pugi::node_doctype) + xml2node_error("node_doctype"); + + // ------------------------ + // element (typical case) + // ------------------------ + + if (xsub.type() == pugi::node_element) { + try { + if (!xml2node(xsub,node.add())) + return false; + } catch (...) { + log::function("xml2node()"); + throw; + } + continue; + } + + // ------------------------ + // cdata, data, comment + // ------------------------ + + // We'll store these in a special manner as children of the current node, + // reflecting how they arrived through pugixml. Our manner of storing + // them will allow us to maintain their original ordering if, say, someone + // reads an XML, makes modest modifications or additions to data here and + // there, and then writes an XML back out. GNDS has no ordering, so doing + // this isn't necessary. It is, however, easy to handle, and users may + // appreciate that GNDStk doesn't remove comments, or change the ordering + // of cdata, data, or comment nodes, either individually or together. + + if (xsub.type() == pugi::node_cdata) { + node.add(special::cdata).add(special::text, xsub.value()); + continue; + } + + if (xsub.type() == pugi::node_pcdata) { + node.add(special::data).add(special::text, xsub.value()); + continue; + } + + if (xsub.type() == pugi::node_comment) { + node.add(special::comment).add(special::text, xsub.value()); + continue; + } + + // ------------------------ + // well we missed something + // ------------------------ + + log::error( + "Internal error in xml2node():\n" + "Encountered a pugi:: node type that we don't know about." + ); + throw std::exception{}; + } + + // done + return true; +} diff --git a/src/GNDStk/convert/src/detail.hpp b/src/GNDStk/convert/src/detail.hpp index 960b823f0..f109f375c 100644 --- a/src/GNDStk/convert/src/detail.hpp +++ b/src/GNDStk/convert/src/detail.hpp @@ -1,444 +1,36 @@ namespace detail { -// ----------------------------------------------------------------------------- -// Helpers for convert(*,JSON) -// ----------------------------------------------------------------------------- +// Node <==> XML +#include "detail-node2xml.hpp" +#include "detail-xml2node.hpp" -// node2json -template -bool node2json( - const NODE &node, nlohmann::json &j, - const std::string &suffix = "" -) { - // Original node name, and suffixed name. The latter is for handling child - // nodes of the same name under the same parent node, and includes a numeric - // suffix (so, name0, name1, etc.) in that scenario. This is needed for JSON - // because JSON doesn't support same-named child nodes. In cases where the - // name was unique to begin with, nameOriginal == nameSuffixed. - const std::string nameOriginal = node.name; - const std::string nameSuffixed = node.name + suffix; +// Node <==> JSON +#include "detail-node2json.hpp" +#include "detail-json2node.hpp" - // This also triggers node creation, in the event that the node exists but - // is null (so that nothing is entered later), e.g. in XML's . - auto &json = j[nameSuffixed]; - - // ------------------------ - // metadata ==> json - // ------------------------ - - if (suffix != "") - json["nodeName"] = nameOriginal; - - for (auto &meta : node.metadata) - json["attributes"][meta.first] = meta.second; - - // ------------------------ - // children ==> json - // ------------------------ - - // First, account for what children appear in the current node. If any child - // name appears multiple times, we must deal with that. For each represented - // child name, the map gets 0 if the name appears once, 1 if it appears more - // than once. Later, this 0/1 is used initially to make a boolean choice; - // then it serves as a counter to generate a 0-indexed numeric suffix that - // makes the child names unique: name0, name1, etc. - std::map childNames; - for (auto &c : node.children) { - auto iter = childNames.find(c->name); - if (iter == childNames.end()) - childNames.insert({c->name,0}); // once (so far) - else - iter->second = 1; // more than once - } - - // now revisit and process the child nodes - for (auto &c : node.children) { - const std::size_t counter = childNames.find(c->name)->second++; - if (!node2json(*c, json, counter ? std::to_string(counter-1) : "")) - return false; - } - - // done - return true; -} - - - -// ----------------------------------------------------------------------------- -// Helpers for convert(*,tree) -// ----------------------------------------------------------------------------- - -/* -FYI, here's the pugixml code for pugi::xml_node_type: - -namespace pugi -{ - // Tree node types - enum xml_node_type - { - node_null, // Empty (null) node handle - node_document, // A document tree's absolute root - node_element, // Element tag, i.e. '' - node_pcdata, // Plain character data, i.e. 'foo' - node_cdata, // Character data, i.e. '' - node_comment, // Comment tag, i.e. '' - node_pi, // Processing instruction, i.e. '' - node_declaration, // Document declaration, i.e. '' - node_doctype // Document type declaration, i.e. '' - }; -} -*/ - -// internal_error_xml2node -inline bool internal_error_xml2node(const std::string &str) -{ - log::error( - "Internal error in detail::xml2node(pugi::xml_node,Node):\n" - "type pugi::{} found, but not handled, as sub-element", - str - ); - throw std::exception{}; - return false; // in case we allow exceptions to be turned off -} - -// pugi::xml_node ==> Node -template -bool xml2node(const pugi::xml_node &xnode, NODE &node) -{ - // check destination node - if (!node.empty()) { - log::error( - "Internal error in detail::xml2node(pugi::xml_node,Node):\n" - "destination Node is supposed to arrive here empty, but didn't" - ); - throw std::exception{}; - return false; - } - - // name - node.name = xnode.name(); - - // metadata - for (const pugi::xml_attribute &xattr : xnode.attributes()) - node.add(xattr.name(), xattr.value()); - - // children (sub-nodes) - for (const pugi::xml_node &xsub : xnode) { - - // ------------------------ - // not handled right now - // ------------------------ - - // I don't think that the following should ever appear in this context - if (xsub.type() == pugi::node_document) - return internal_error_xml2node("node_document"); - if (xsub.type() == pugi::node_declaration) - return internal_error_xml2node("node_declaration"); - - // For now I won't handle these; let's ensure that we don't see them - if (xsub.type() == pugi::node_null) - return internal_error_xml2node("node_null"); - if (xsub.type() == pugi::node_pi) - return internal_error_xml2node("node_pi"); - if (xsub.type() == pugi::node_doctype) - return internal_error_xml2node("node_doctype"); - - // ------------------------ - // element (typical case) - // ------------------------ - - if (xsub.type() == pugi::node_element) { - try { - if (!xml2node(xsub,node.add())) - return false; - } catch (...) { - // recursive; no point printing error context, so just throw - throw; - } - continue; - } - - // ------------------------ - // cdata, pcdata, comment - // ------------------------ - - // We'll store these in a special manner as children of the current node, - // reflecting how they arrived through pugi xml. Our manner of storing - // them will allow us to maintain their original ordering if, say, someone - // reads an XML, makes modest modifications or additions to data here and - // there, and then writes an XML back out. GNDS has no ordering, so doing - // this isn't necessary. It is, however, easy to handle, and users may - // appreciate that GNDStk doesn't toss comments, or mess with the ordering - // of cdata, pcdata, or comment nodes, either individually or together. - // Of note, all bets are off if someone converts to JSON and back, because - // the nlohmann JSON library reorders everything lexicographically. - - if (xsub.type() == pugi::node_cdata) { - node.add("cdata").add("text", xsub.value()); - continue; - } - - if (xsub.type() == pugi::node_pcdata) { - node.add("pcdata").add("text", xsub.value()); - continue; - } - - if (xsub.type() == pugi::node_comment) { - node.add("comment").add("text", xsub.value()); - continue; - } - - // ------------------------ - // well we missed something - // ------------------------ - - log::error( - "Internal error in detail::xml2node(pugi::xml_node,Node):\n" - "we've encountered a pugi:: node type that we don't know about" - ); - throw std::exception{}; - return false; - } - - // done - return true; -} - - - -// nlohmann::json::const_iterator ==> Node -// Why the iterator rather than the json object? I found that there were some -// seemingly funny semantics in the json library. As we can see below, we have -// for example iter->is_object() (so, the -> operator, typical for iterators), -// but also iter.value() (the . operator - on an iterator). Similarly, also -// seen below, with the sub-elements. This is why we are, for now, writing -// our for-loops, here as well as in the functions that call this, in the older -// iterator form rather than the range-based-for form. Perhaps there's a way -// to reformulate all this in a shorter way, but this is what we have for now. +// Node <==> HDF5 +#include "detail-node2hdf5.hpp" +#include "detail-hdf52node.hpp" // Helper -inline bool internal_error_json2node(const std::string &str) -{ - log::error( - "Internal error in detail::json2node(nlohmann::json,Node):\n" - "message is \"{}\"; please let us know about this", - str - ); - throw std::exception{}; - return false; // in case we allow exceptions turned off -} - - -template -bool json2node(const nlohmann::json::const_iterator &iter, NODE &node) -{ - // the node sent here should be fresh, ready to receive entries... - if (!node.empty()) - return internal_error_json2node("!node.empty()"); - - // non-object cases were handled before a caller calls this function... - if (!iter->is_object()) - return internal_error_json2node("!iter->is_object()"); - - // any "attributes" key should have been handled in the caller... - if (iter.key() == "attributes") - return internal_error_json2node("iter.key() == \"attributes\""); - - // key,value ==> node name, json value to bring in - node.name = iter.key(); - const nlohmann::json &json = iter.value(); - - // elements - for (auto elem = json.begin(); elem != json.end(); ++elem) { - if (elem.key() == "nodeName") { - // nodeName? ...extract as current node's true name - node.name = elem->get(); - } else if (elem.key() == "attributes") { - // attributes? ...extract as current node's metadata - const auto &jsub = elem.value(); - for (auto attr = jsub.begin(); attr != jsub.end(); ++attr) - node.add(attr.key(), attr->get()); - } else if (elem->is_string()) { - // string? ...extract as metadata key/value pair - node.add(elem.key(), elem->get()); - } else if (elem->is_object()) { - // {} object? ...extract as normal child node - try { - if (!json2node(elem,node.add())) - return false; - } catch (...) { - // recursive; no point printing error context; just throw - throw; - } - } else if (elem->is_null()) { - // null node? ...extract as normal (albeit empty) child node - // In GNDS, e.g. XML's or - node.add().name = elem.key(); - } else { - // no other cases are handled right now - return internal_error_json2node("unhandled JSON value type"); - } - } - - // done - return true; -} - - - -// Node ==> Node -template -inline void node2Node(const NODE &from, NODE &to) +inline void warn_node_top_metadata(const Node &node, const std::string &context) { - // clear - to.clear(); - - // name - to.name = from.name; - - // metadata - for (auto &m : from.metadata) - to.add(m.first,m.second); - - // children - for (auto &c : from.children) - node2Node(*c, to.add()); -} - - - -// ----------------------------------------------------------------------------- -// Helpers for convert(*,XML) -// ----------------------------------------------------------------------------- - -// check_special -template -bool check_special(const NODE &node, const std::string &label) -{ - if (node.children.size() != 0) { - log::error( - "Internal error in detail::node2xml(Node,pugi::xml_node):\n" - "ill-formed <" + label + "> node; " - "should have 0 children, but has {}", - node.children.size() - ); - throw std::exception{}; - return false; - } - - if (node.metadata.size() != 1) { - log::error( - "Internal error in detail::node2xml(Node,pugi::xml_node):\n" - "ill-formed <" + label + "> node; " - "should have 1 metadatum, but has {}", - node.metadata.size() - ); - throw std::exception{}; - return false; - } - - if (node.metadata.begin()->first != "text") { - log::error( - "Internal error in detail::node2xml(Node,pugi::xml_node):\n" - "ill-formed <" + label + "> node; " - "should have metadatum key \"text\", but has key \"{}\"", - node.metadata.begin()->first - ); - throw std::exception{}; - return false; + if (node.metadata.size() != 0) { + log::warning( + "Node has name \"/\" but also contains metadata. This is\n" + "not expected in this context. We'll ignore the metadata."); + log::function(context); } - - return true; -} - - - -// write_cdata -template -bool write_cdata(const NODE &node, pugi::xml_node &xnode) -{ - if (!check_special(node,"cdata")) return false; - xnode.append_child(pugi::node_cdata).set_value(node.meta("text").data()); - return true; -} - -// write_pcdata -template -bool write_pcdata(const NODE &node, pugi::xml_node &xnode) -{ - if (!check_special(node,"pcdata")) return false; - xnode.append_child(pugi::node_pcdata).set_value(node.meta("text").data()); - return true; } -// write_comment -template -bool write_comment(const NODE &node, pugi::xml_node &xnode) -{ - if (!check_special(node,"comment")) return false; - xnode.append_child(pugi::node_comment).set_value(node.meta("text").data()); - return true; -} - - - -// node2xml -template -bool node2xml(const NODE &node, pugi::xml_node &x) +// Helper +inline void info_node_multiple_dec(const std::string &context) { - // name - pugi::xml_node xnode = x.append_child(node.name.data()); - - // metadata - for (auto &meta : node.metadata) - xnode.append_attribute(meta.first.data()) = meta.second.data(); - - // children - for (auto &child : node.children) { - try { - // special element - if (child->name == "cdata") - { if (write_cdata (*child,xnode)) continue; else return false; } - if (child->name == "pcdata") - { if (write_pcdata (*child,xnode)) continue; else return false; } - if (child->name == "comment") - { if (write_comment(*child,xnode)) continue; else return false; } - - // typical element - if (!node2xml(*child,xnode)) - return false; - } catch (...) { - // recursive; no point in printing error context; just throw - throw; - } - } - - // done - return true; -} - - - -// ----------------------------------------------------------------------------- -// check_top -// ----------------------------------------------------------------------------- - -inline void check_top( - const std::string &name, - const std::string &classname, - const std::string &context -) { - if (GNDStk::top && AllowedTop.find(name) == AllowedTop.end()) { - std::string message = - "Name \"{}\" in {} object's top-level node is not recognized\n" - "in our list of allowable names for top-level GNDS nodes:\n"; - for (const std::string &n : detail::AllowedTop) - message += " \"" + n + "\"\n"; - message += "Creating node \"{}\" anyway..."; - log::warning(message, name, classname, name); - log::function(context); - } + log::info( + "Node has name \"/\" but multiple \"declaration nodes\".\n" + "We'll combine the metadata from all such nodes."); + log::function(context); } } // namespace detail diff --git a/src/GNDStk/convert/src/tree.hpp b/src/GNDStk/convert/src/tree.hpp deleted file mode 100644 index c83be7d40..000000000 --- a/src/GNDStk/convert/src/tree.hpp +++ /dev/null @@ -1,234 +0,0 @@ - -// ----------------------------------------------------------------------------- -// convert(*,Tree) -// That is, convert to Tree objects -// -// Also: -// convert(*,Node) for * = XML/JSON -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// Tree ==> Tree -// ----------------------------------------------------------------------------- - -inline bool convert(const Tree &from, Tree &to) -{ - // same Tree? - if (&to == &from) - return true; - - // clear - to.clear(); - - // convert - try { - if (from.has_decl()) to.add() = from.decl(); - if (from.has_top ()) to.add() = from.top (); - } catch (...) { - log::function("convert(Tree,Tree)"); - throw; - } - - // done - return true; -} - - - -// ----------------------------------------------------------------------------- -// XML ==> Node -// XML ==> Tree -// ----------------------------------------------------------------------------- - -// XML ==> Node -inline bool convert(const XML &x, Node &node, const bool decl) -{ - // ------------------------ - // bookkeeping - // ------------------------ - - // clear the receiving object - node.clear(); - - // optionally, give it a boilerplate declaration node - if (decl) - node.add("xml"); // <== indicates that we built the object from an XML - - // empty xml document? - if (x.empty()) - return true; - - try { - - // ------------------------ - // validate - // ------------------------ - - // Validation, itself, is independent of whether decl is true or false - - std::size_t size = 0; - std::string one, two; - for (const pugi::xml_node &xnode : x.doc) { - size++; - if (size == 1) - one = xnode.name(); - else if (size == 2) - two = xnode.name(); - else { - log::error( - "More than two main nodes in the XML\n", - "You can have up to " - "one declaration node and " - "one document node" - ); - throw std::exception{}; - } - } - - // possibly redundant with the earlier empty() test, but harmless - if (size == 0) - return true; - - // if two main nodes, they can't be of the same type - if (size == 2) { - if (one == "xml" && two == "xml") { - log::error("Two declaration nodes in the XML"); - throw std::exception{}; - } - if (one != "xml" && two != "xml") { - log::error("Two document nodes in the XML"); - throw std::exception{}; - } - } - - // ------------------------ - // convert the nodes - // ------------------------ - - for (const pugi::xml_node &xnode : x.doc) { - const std::string name = xnode.name(); - - if (name == "xml") { - // Declaration node - // Retrieve any XML attributes, e.g. version and encoding - if (decl) - for (const pugi::xml_attribute &xattr : xnode.attributes()) - node.one("xml").add(xattr.name(), xattr.value()); - } else { - // Document node - // We'll assume that a check for this being a valid top-level - // GNDS node aligns with whether or not we're interested in any - // declaration node that might exist, as both of those concerns - // are associated with being at the top level of a GNDS tree - if (decl) - detail::check_top(name, "XML", "convert(XML,Node)"); - - // Visit the node, and its children recursively - if (!detail::xml2node(xnode, decl ? node.add() : node)) - return false; - } - } - } catch (...) { - log::function("convert(XML,Node)"); - throw; - } - - // done - return true; -} - - -// XML ==> Tree -inline bool convert(const XML &x, Tree &tree) -{ - try { - return convert(x, *(Node*)&tree, true); - } catch (...) { - log::function("convert(XML,Tree)"); - throw; - } -} - - - -// ----------------------------------------------------------------------------- -// JSON ==> Node -// JSON ==> Tree -// ----------------------------------------------------------------------------- - -// JSON ==> Node -inline bool convert(const JSON &j, Node &node, const bool decl) -{ - // ------------------------ - // bookkeeping - // ------------------------ - - // clear the receiving object - node.clear(); - - // optionally, give it a boilerplate declaration node - if (decl) - node.add("json"); // <== indicates that we built the object from a JSON - - // empty json document? - if (j.empty()) - return true; - - try { - - // ------------------------ - // validate - // ------------------------ - - const std::size_t size = j.doc.size(); - - // possibly redundant with the earlier empty() test, but harmless - if (size == 0) - return true; - - // a json document should have one main node - if (size != 1) { - // fixme Consider relaxing this, if doing so might ever make sense - log::error("More than one main node in the JSON"); - throw std::exception{}; - } - - // ------------------------ - // convert the nodes - // ------------------------ - - const std::string name = j.doc.begin().key(); - - // See comment above check_top() call in convert(XML,Node) above. - // JSON documents don't have "declaration nodes," as XML documents - // do, but here we interpret the bool decl parameter as essentially - // indicating whether we're reading a Node (decl == false) or full - // Tree (decl == true); and, the latter case suggests we're at the - // top level, and should thus validate it as a top-level GNDS node. - if (decl) - detail::check_top(name, "JSON", "convert(JSON,Node)"); - - // visit the node, and its children recursively - if (!detail::json2node(j.doc.begin(), decl ? node.add() : node)) - return false; - - } catch (...) { - log::function("convert(JSON,Node)"); - throw; - } - - // done - return true; -} - - -// JSON ==> Tree -inline bool convert(const JSON &j, Tree &tree) -{ - try { - return convert(j, *(Node*)&tree, true); - } catch (...) { - log::function("convert(JSON,Tree)"); - throw; - } -} diff --git a/src/GNDStk/convert_t.hpp b/src/GNDStk/convert_t.hpp deleted file mode 100644 index 34b24ec67..000000000 --- a/src/GNDStk/convert_t.hpp +++ /dev/null @@ -1,50 +0,0 @@ - -namespace detail { - -// ----------------------------------------------------------------------------- -// convert_t -// Serves as a default "function object" in places where a function object -// can be (optionally) user-provided for converting *from* something, *to* -// something else. -// ----------------------------------------------------------------------------- - -class convert_t { -public: - template - void operator()(const FROM &from, TO &to) const - { - if constexpr ( - std::is_constructible_v || - std::is_convertible_v - ) { - to = TO(from); - } else if constexpr (isVariant::value) { - std::visit([&to](auto &&alt) { convert_t{}(alt,to); }, from); - } else { - convert(from,to); - } - } -}; - - -// ----------------------------------------------------------------------------- -// default_converter -// Used for selecting the CONVERTER template argument of the Meta and Child -// classes. Usually gives convert_t, but gives void (which in turn won't, and -// shouldn't, be used) for Meta and Child, for which the concept -// of a converter is not applicable. -// ----------------------------------------------------------------------------- - -template -class default_converter { -public: - using type = convert_t; -}; - -template<> -class default_converter { -public: - using type = void; -}; - -} // namespace detail diff --git a/src/GNDStk/enums.hpp b/src/GNDStk/enums.hpp index 57e9f4071..c6f968733 100644 --- a/src/GNDStk/enums.hpp +++ b/src/GNDStk/enums.hpp @@ -1,12 +1,21 @@ #include "GNDStk/enums/enumeration.hpp" -// general -#include "GNDStk/enums/Encoding.hpp" +#include "GNDStk/enums/DateType.hpp" +#include "GNDStk/enums/ContributorType.hpp" +#include "GNDStk/enums/RelationType.hpp" +#include "GNDStk/enums/Parity.hpp" #include "GNDStk/enums/Frame.hpp" +#include "GNDStk/enums/Interpolation.hpp" +#include "GNDStk/enums/InterpolationQualifier.hpp" +#include "GNDStk/enums/HashAlgorithm.hpp" +#include "GNDStk/enums/DecayType.hpp" #include "GNDStk/enums/GridStyle.hpp" +#include "GNDStk/enums/BoundaryCondition.hpp" #include "GNDStk/enums/Interaction.hpp" -#include "GNDStk/enums/Interpolation.hpp" + +// general +#include "GNDStk/enums/Encoding.hpp" #include "GNDStk/enums/StorageOrder.hpp" // units-specific diff --git a/src/GNDStk/enums/BoundaryCondition.hpp b/src/GNDStk/enums/BoundaryCondition.hpp new file mode 100644 index 000000000..69e8679ed --- /dev/null +++ b/src/GNDStk/enums/BoundaryCondition.hpp @@ -0,0 +1,58 @@ +#ifndef NJOY_GNDSTK_BOUNDARYCONDITION +#define NJOY_GNDSTK_BOUNDARYCONDITION + +namespace enums { + + /** + * @class + * @brief Enumeration class for reference boundary condition values + */ + enum class BoundaryCondition { + + EliminateShiftFunction = 1, + NegativeOrbitalMomentum, + Brune, + Given + }; + + /** + * @brief Return whether or not a string is a valid boundary condition + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isBoundaryCondition( const std::string& string ) { + + return isSymbol< BoundaryCondition >( string ); + } + + /** + * @brief Template specialisation to convert BoundaryCondition to/from strings + */ + template <> + class Map< GNDStk::enums::BoundaryCondition > { + public: + + static inline const std::map< GNDStk::enums::BoundaryCondition, + const std::string > values{ + + { GNDStk::enums::BoundaryCondition::EliminateShiftFunction, "EliminateShiftFunction" }, + { GNDStk::enums::BoundaryCondition::NegativeOrbitalMomentum, "NegativeOrbitalMomentum" }, + { GNDStk::enums::BoundaryCondition::Brune, "Brune" }, + { GNDStk::enums::BoundaryCondition::Given, "Given" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::BoundaryCondition > symbols{ + + { "EliminateShiftFunction", GNDStk::enums::BoundaryCondition::EliminateShiftFunction }, + { "NegativeOrbitalMomentum", GNDStk::enums::BoundaryCondition::NegativeOrbitalMomentum }, + { "Brune", GNDStk::enums::BoundaryCondition::Brune }, + { "Given", GNDStk::enums::BoundaryCondition::Given } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/BoundaryCondition/test/BoundaryCondition.test.cpp b/src/GNDStk/enums/BoundaryCondition/test/BoundaryCondition.test.cpp new file mode 100644 index 000000000..bdc901621 --- /dev/null +++ b/src/GNDStk/enums/BoundaryCondition/test/BoundaryCondition.test.cpp @@ -0,0 +1,114 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using BoundaryCondition = enums::BoundaryCondition; + +SCENARIO( "BoundaryCondition" ) { + + GIVEN( "valid BoundaryCondition values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "EliminateShiftFunction" + == enums::toString( BoundaryCondition::EliminateShiftFunction ) ); + CHECK( "NegativeOrbitalMomentum" + == enums::toString( BoundaryCondition::NegativeOrbitalMomentum ) ); + CHECK( "Brune" == enums::toString( BoundaryCondition::Brune ) ); + CHECK( "Given" == enums::toString( BoundaryCondition::Given ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( BoundaryCondition::EliminateShiftFunction + == enums::fromString< BoundaryCondition >( "EliminateShiftFunction" ) ); + CHECK( BoundaryCondition::NegativeOrbitalMomentum + == enums::fromString< BoundaryCondition >( "NegativeOrbitalMomentum" ) ); + CHECK( BoundaryCondition::Brune == enums::fromString< BoundaryCondition >( "Brune" ) ); + CHECK( BoundaryCondition::Given == enums::fromString< BoundaryCondition >( "Given" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< BoundaryCondition >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << BoundaryCondition::EliminateShiftFunction << ' ' + << BoundaryCondition::NegativeOrbitalMomentum << ' ' + << BoundaryCondition::Brune << ' ' + << BoundaryCondition::Given; + + CHECK( "EliminateShiftFunction NegativeOrbitalMomentum Brune Given" == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + BoundaryCondition value; + std::istringstream in( "EliminateShiftFunction NegativeOrbitalMomentum Brune Given" ); + + in >> value; + CHECK( BoundaryCondition::EliminateShiftFunction == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( BoundaryCondition::NegativeOrbitalMomentum == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( BoundaryCondition::Brune == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( BoundaryCondition::Given == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + BoundaryCondition value = BoundaryCondition::EliminateShiftFunction; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( BoundaryCondition::EliminateShiftFunction == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isBoundaryCondition is used" ) { + + THEN( "registered BoundaryCondition values return true, " + "unregistered BoundaryCondition values return false" ) { + + CHECK( true == enums::isBoundaryCondition( "EliminateShiftFunction" ) ); + CHECK( true == enums::isBoundaryCondition( "NegativeOrbitalMomentum" ) ); + CHECK( true == enums::isBoundaryCondition( "Brune" ) ); + CHECK( true == enums::isBoundaryCondition( "Given" ) ); + CHECK( false == enums::isBoundaryCondition( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/BoundaryCondition/test/CMakeLists.txt b/src/GNDStk/enums/BoundaryCondition/test/CMakeLists.txt new file mode 100644 index 000000000..f2ba4b90b --- /dev/null +++ b/src/GNDStk/enums/BoundaryCondition/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.BoundaryCondition.test BoundaryCondition.test.cpp ) +target_compile_options( GNDStk.enums.BoundaryCondition.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.BoundaryCondition.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.BoundaryCondition COMMAND GNDStk.enums.BoundaryCondition.test ) diff --git a/src/GNDStk/enums/ContributorType.hpp b/src/GNDStk/enums/ContributorType.hpp new file mode 100644 index 000000000..397b2afee --- /dev/null +++ b/src/GNDStk/enums/ContributorType.hpp @@ -0,0 +1,109 @@ +#ifndef NJOY_GNDSTK_CONTRIBUTORTYPE +#define NJOY_GNDSTK_CONTRIBUTORTYPE + +namespace enums { + + /** + * @class + * @brief Enumeration class for contributor type values + */ + enum class ContributorType { + + ContactPerson = 1, + DataCollector, + DataCurator, + DataManager, + Distributor, + Editor, + HostingInstitution, + Producer, + ProjectLeader, + ProjectManager, + ProjectMember, + RegistrationAgency, + RegistrationAuthority, + RelatedPerson, + Researcher, + ResearchGroup, + RightsHolder, + Sponsor, + Supervisor, + WorkPackageLeader, + Other + }; + + /** + * @brief Return whether or not a string is a valid contributor type + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isContributorType( const std::string& string ) { + + return isSymbol< ContributorType >( string ); + } + + /** + * @brief Template specialisation to convert ContributorType to/from strings + */ + template <> + class Map< GNDStk::enums::ContributorType > { + public: + + static inline const std::map< GNDStk::enums::ContributorType, + const std::string > values{ + + { GNDStk::enums::ContributorType::ContactPerson, "ContactPerson" }, + { GNDStk::enums::ContributorType::DataCollector, "DataCollector" }, + { GNDStk::enums::ContributorType::DataCurator, "DataCurator" }, + { GNDStk::enums::ContributorType::DataManager, "DataManager" }, + { GNDStk::enums::ContributorType::Distributor, "Distributor" }, + { GNDStk::enums::ContributorType::Editor, "Editor" }, + { GNDStk::enums::ContributorType::HostingInstitution, "HostingInstitution" }, + { GNDStk::enums::ContributorType::Producer, "Producer" }, + { GNDStk::enums::ContributorType::ProjectLeader, "ProjectLeader" }, + { GNDStk::enums::ContributorType::ProjectManager, "ProjectManager" }, + { GNDStk::enums::ContributorType::ProjectMember, "ProjectMember" }, + { GNDStk::enums::ContributorType::RegistrationAgency, "RegistrationAgency" }, + { GNDStk::enums::ContributorType::RegistrationAuthority, "RegistrationAuthority" }, + { GNDStk::enums::ContributorType::RelatedPerson, "RelatedPerson" }, + { GNDStk::enums::ContributorType::Researcher, "Researcher" }, + { GNDStk::enums::ContributorType::ResearchGroup, "ResearchGroup" }, + { GNDStk::enums::ContributorType::RightsHolder, "RightsHolder" }, + { GNDStk::enums::ContributorType::Sponsor, "Sponsor" }, + { GNDStk::enums::ContributorType::Supervisor, "Supervisor" }, + { GNDStk::enums::ContributorType::WorkPackageLeader, "WorkPackageLeader" }, + { GNDStk::enums::ContributorType::Other, "Other" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::ContributorType > symbols{ + + { "ContactPerson", GNDStk::enums::ContributorType::ContactPerson }, + { "DataCollector", GNDStk::enums::ContributorType::DataCollector }, + { "DataCurator", GNDStk::enums::ContributorType::DataCurator }, + { "DataManager", GNDStk::enums::ContributorType::DataManager }, + { "Distributor", GNDStk::enums::ContributorType::Distributor }, + { "Editor", GNDStk::enums::ContributorType::Editor }, + { "HostingInstitution", GNDStk::enums::ContributorType::HostingInstitution }, + { "Producer", GNDStk::enums::ContributorType::Producer }, + { "ProjectLeader", GNDStk::enums::ContributorType::ProjectLeader }, + { "ProjectManager", GNDStk::enums::ContributorType::ProjectManager }, + { "ProjectMember", GNDStk::enums::ContributorType::ProjectMember }, + { "RegistrationAgency", GNDStk::enums::ContributorType::RegistrationAgency }, + { "RegistrationAuthority", GNDStk::enums::ContributorType::RegistrationAuthority }, + { "RelatedPerson", GNDStk::enums::ContributorType::RelatedPerson }, + { "Researcher", GNDStk::enums::ContributorType::Researcher }, + { "ResearchGroup", GNDStk::enums::ContributorType::ResearchGroup }, + { "RightsHolder", GNDStk::enums::ContributorType::RightsHolder }, + { "Sponsor", GNDStk::enums::ContributorType::Sponsor }, + { "Supervisor", GNDStk::enums::ContributorType::Supervisor }, + { "WorkPackageLeader", GNDStk::enums::ContributorType::WorkPackageLeader }, + { "Other", GNDStk::enums::ContributorType::Other } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/ContributorType/test/CMakeLists.txt b/src/GNDStk/enums/ContributorType/test/CMakeLists.txt new file mode 100644 index 000000000..ce1835c6b --- /dev/null +++ b/src/GNDStk/enums/ContributorType/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.ContributorType.test ContributorType.test.cpp ) +target_compile_options( GNDStk.enums.ContributorType.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.ContributorType.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.ContributorType COMMAND GNDStk.enums.ContributorType.test ) diff --git a/src/GNDStk/enums/ContributorType/test/ContributorType.test.cpp b/src/GNDStk/enums/ContributorType/test/ContributorType.test.cpp new file mode 100644 index 000000000..0586bad6e --- /dev/null +++ b/src/GNDStk/enums/ContributorType/test/ContributorType.test.cpp @@ -0,0 +1,293 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using ContributorType = enums::ContributorType; + +SCENARIO( "ContributorType" ) { + + GIVEN( "valid encoding values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "ContactPerson" == enums::toString( ContributorType::ContactPerson ) ); + CHECK( "DataCollector" == enums::toString( ContributorType::DataCollector ) ); + CHECK( "DataCurator" == enums::toString( ContributorType::DataCurator ) ); + CHECK( "DataManager" == enums::toString( ContributorType::DataManager ) ); + CHECK( "Distributor" == enums::toString( ContributorType::Distributor ) ); + CHECK( "Editor" == enums::toString( ContributorType::Editor ) ); + CHECK( "HostingInstitution" == enums::toString( ContributorType::HostingInstitution ) ); + CHECK( "Producer" == enums::toString( ContributorType::Producer ) ); + CHECK( "ProjectLeader" == enums::toString( ContributorType::ProjectLeader ) ); + CHECK( "ProjectManager" == enums::toString( ContributorType::ProjectManager ) ); + CHECK( "ProjectMember" == enums::toString( ContributorType::ProjectMember ) ); + CHECK( "RegistrationAgency" == enums::toString( ContributorType::RegistrationAgency ) ); + CHECK( "RegistrationAuthority" == enums::toString( ContributorType::RegistrationAuthority ) ); + CHECK( "RelatedPerson" == enums::toString( ContributorType::RelatedPerson ) ); + CHECK( "Researcher" == enums::toString( ContributorType::Researcher ) ); + CHECK( "ResearchGroup" == enums::toString( ContributorType::ResearchGroup ) ); + CHECK( "RightsHolder" == enums::toString( ContributorType::RightsHolder ) ); + CHECK( "Sponsor" == enums::toString( ContributorType::Sponsor ) ); + CHECK( "Supervisor" == enums::toString( ContributorType::Supervisor ) ); + CHECK( "WorkPackageLeader" == enums::toString( ContributorType::WorkPackageLeader ) ); + CHECK( "Other" == enums::toString( ContributorType::Other ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( ContributorType::ContactPerson + == enums::fromString< ContributorType >( "ContactPerson" ) ); + CHECK( ContributorType::DataCollector + == enums::fromString< ContributorType >( "DataCollector" ) ); + CHECK( ContributorType::DataCurator + == enums::fromString< ContributorType >( "DataCurator" ) ); + CHECK( ContributorType::DataManager + == enums::fromString< ContributorType >( "DataManager" ) ); + CHECK( ContributorType::Distributor + == enums::fromString< ContributorType >( "Distributor" ) ); + CHECK( ContributorType::Editor + == enums::fromString< ContributorType >( "Editor" ) ); + CHECK( ContributorType::HostingInstitution + == enums::fromString< ContributorType >( "HostingInstitution" ) ); + CHECK( ContributorType::Producer + == enums::fromString< ContributorType >( "Producer" ) ); + CHECK( ContributorType::ProjectLeader + == enums::fromString< ContributorType >( "ProjectLeader" ) ); + CHECK( ContributorType::ProjectManager + == enums::fromString< ContributorType >( "ProjectManager" ) ); + CHECK( ContributorType::ProjectMember + == enums::fromString< ContributorType >( "ProjectMember" ) ); + CHECK( ContributorType::RegistrationAgency + == enums::fromString< ContributorType >( "RegistrationAgency" ) ); + CHECK( ContributorType::RegistrationAuthority + == enums::fromString< ContributorType >( "RegistrationAuthority" ) ); + CHECK( ContributorType::RelatedPerson + == enums::fromString< ContributorType >( "RelatedPerson" ) ); + CHECK( ContributorType::Researcher + == enums::fromString< ContributorType >( "Researcher" ) ); + CHECK( ContributorType::ResearchGroup + == enums::fromString< ContributorType >( "ResearchGroup" ) ); + CHECK( ContributorType::RightsHolder + == enums::fromString< ContributorType >( "RightsHolder" ) ); + CHECK( ContributorType::Sponsor + == enums::fromString< ContributorType >( "Sponsor" ) ); + CHECK( ContributorType::Supervisor + == enums::fromString< ContributorType >( "Supervisor" ) ); + CHECK( ContributorType::WorkPackageLeader + == enums::fromString< ContributorType >( "WorkPackageLeader" ) ); + CHECK( ContributorType::Other + == enums::fromString< ContributorType >( "Other" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< ContributorType >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << ContributorType::ContactPerson << ' ' + << ContributorType::DataCollector << ' ' + << ContributorType::DataCurator << ' ' + << ContributorType::DataManager << ' ' + << ContributorType::Distributor << ' ' + << ContributorType::Editor << ' ' + << ContributorType::HostingInstitution << ' ' + << ContributorType::Producer << ' ' + << ContributorType::ProjectLeader << ' ' + << ContributorType::ProjectManager << ' ' + << ContributorType::ProjectMember << ' ' + << ContributorType::RegistrationAgency << ' ' + << ContributorType::RegistrationAuthority << ' ' + << ContributorType::RelatedPerson << ' ' + << ContributorType::Researcher << ' ' + << ContributorType::ResearchGroup << ' ' + << ContributorType::RightsHolder << ' ' + << ContributorType::Sponsor << ' ' + << ContributorType::Supervisor << ' ' + << ContributorType::WorkPackageLeader << ' ' + << ContributorType::Other; + + CHECK( "ContactPerson DataCollector DataCurator DataManager " + "Distributor Editor HostingInstitution Producer " + "ProjectLeader ProjectManager ProjectMember RegistrationAgency " + "RegistrationAuthority RelatedPerson Researcher ResearchGroup " + "RightsHolder Sponsor Supervisor WorkPackageLeader Other" + == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + ContributorType value; + std::istringstream in( "ContactPerson DataCollector DataCurator DataManager " + "Distributor Editor HostingInstitution Producer " + "ProjectLeader ProjectManager ProjectMember RegistrationAgency " + "RegistrationAuthority RelatedPerson Researcher ResearchGroup " + "RightsHolder Sponsor Supervisor WorkPackageLeader Other" ); + + in >> value; + CHECK( ContributorType::ContactPerson == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::DataCollector == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::DataCurator == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::DataManager == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Distributor == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Editor == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::HostingInstitution == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Producer == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::ProjectLeader == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::ProjectManager == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::ProjectMember == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::RegistrationAgency == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::RegistrationAuthority == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::RelatedPerson == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Researcher == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::ResearchGroup == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::RightsHolder == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Sponsor == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Supervisor == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::WorkPackageLeader == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( ContributorType::Other == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + ContributorType value = ContributorType::ContactPerson; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( ContributorType::ContactPerson == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isContributorType is used" ) { + + THEN( "registered date types return true, " + "unregistered date types return false" ) { + + CHECK( true == enums::isContributorType( "ContactPerson" ) ); + CHECK( true == enums::isContributorType( "DataCollector" ) ); + CHECK( true == enums::isContributorType( "DataCurator" ) ); + CHECK( true == enums::isContributorType( "DataManager" ) ); + CHECK( true == enums::isContributorType( "Distributor" ) ); + CHECK( true == enums::isContributorType( "Editor" ) ); + CHECK( true == enums::isContributorType( "HostingInstitution" ) ); + CHECK( true == enums::isContributorType( "Producer" ) ); + CHECK( true == enums::isContributorType( "ProjectLeader" ) ); + CHECK( true == enums::isContributorType( "ProjectManager" ) ); + CHECK( true == enums::isContributorType( "ProjectMember" ) ); + CHECK( true == enums::isContributorType( "RegistrationAgency" ) ); + CHECK( true == enums::isContributorType( "RegistrationAuthority" ) ); + CHECK( true == enums::isContributorType( "RelatedPerson" ) ); + CHECK( true == enums::isContributorType( "Researcher" ) ); + CHECK( true == enums::isContributorType( "ResearchGroup" ) ); + CHECK( true == enums::isContributorType( "RightsHolder" ) ); + CHECK( true == enums::isContributorType( "Sponsor" ) ); + CHECK( true == enums::isContributorType( "Supervisor" ) ); + CHECK( true == enums::isContributorType( "WorkPackageLeader" ) ); + CHECK( true == enums::isContributorType( "Other" ) ); + CHECK( false == enums::isContributorType( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/DateType.hpp b/src/GNDStk/enums/DateType.hpp new file mode 100644 index 000000000..3148a3a7b --- /dev/null +++ b/src/GNDStk/enums/DateType.hpp @@ -0,0 +1,76 @@ +#ifndef NJOY_GNDSTK_DATETYPE +#define NJOY_GNDSTK_DATETYPE + +namespace enums { + + /** + * @class + * @brief Enumeration class for date type values + */ + enum class DateType { + + accepted = 1, + available, + copyrighted, + collected, + created, + issued, + submitted, + updated, + valid, + withdrawn + }; + + /** + * @brief Return whether or not a string is a valid date type + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isDateType( const std::string& string ) { + + return isSymbol< DateType >( string ); + } + + /** + * @brief Template specialisation to convert DateType to/from strings + */ + template <> + class Map< GNDStk::enums::DateType > { + public: + + static inline const std::map< GNDStk::enums::DateType, + const std::string > values{ + + { GNDStk::enums::DateType::accepted, "accepted" }, + { GNDStk::enums::DateType::available, "available" }, + { GNDStk::enums::DateType::copyrighted, "copyrighted" }, + { GNDStk::enums::DateType::collected, "collected" }, + { GNDStk::enums::DateType::created, "created" }, + { GNDStk::enums::DateType::issued, "issued" }, + { GNDStk::enums::DateType::submitted, "submitted" }, + { GNDStk::enums::DateType::updated, "updated" }, + { GNDStk::enums::DateType::valid, "valid" }, + { GNDStk::enums::DateType::withdrawn, "withdrawn" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::DateType > symbols{ + + { "accepted", GNDStk::enums::DateType::accepted }, + { "available", GNDStk::enums::DateType::available }, + { "copyrighted", GNDStk::enums::DateType::copyrighted }, + { "collected", GNDStk::enums::DateType::collected }, + { "created", GNDStk::enums::DateType::created }, + { "issued", GNDStk::enums::DateType::issued }, + { "submitted", GNDStk::enums::DateType::submitted }, + { "updated", GNDStk::enums::DateType::updated }, + { "valid", GNDStk::enums::DateType::valid }, + { "withdrawn", GNDStk::enums::DateType::withdrawn } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/DateType/test/CMakeLists.txt b/src/GNDStk/enums/DateType/test/CMakeLists.txt new file mode 100644 index 000000000..aee211fcd --- /dev/null +++ b/src/GNDStk/enums/DateType/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.DateType.test DateType.test.cpp ) +target_compile_options( GNDStk.enums.DateType.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.DateType.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.DateType COMMAND GNDStk.enums.DateType.test ) diff --git a/src/GNDStk/enums/DateType/test/DateType.test.cpp b/src/GNDStk/enums/DateType/test/DateType.test.cpp new file mode 100644 index 000000000..3e05a1f21 --- /dev/null +++ b/src/GNDStk/enums/DateType/test/DateType.test.cpp @@ -0,0 +1,160 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using DateType = enums::DateType; + +SCENARIO( "DateType" ) { + + GIVEN( "valid encoding values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "accepted" == enums::toString( DateType::accepted ) ); + CHECK( "available" == enums::toString( DateType::available ) ); + CHECK( "copyrighted" == enums::toString( DateType::copyrighted ) ); + CHECK( "collected" == enums::toString( DateType::collected ) ); + CHECK( "created" == enums::toString( DateType::created ) ); + CHECK( "issued" == enums::toString( DateType::issued ) ); + CHECK( "submitted" == enums::toString( DateType::submitted ) ); + CHECK( "updated" == enums::toString( DateType::updated ) ); + CHECK( "valid" == enums::toString( DateType::valid ) ); + CHECK( "withdrawn" == enums::toString( DateType::withdrawn ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( DateType::accepted == enums::fromString< DateType >( "accepted" ) ); + CHECK( DateType::available == enums::fromString< DateType >( "available" ) ); + CHECK( DateType::copyrighted == enums::fromString< DateType >( "copyrighted" ) ); + CHECK( DateType::collected == enums::fromString< DateType >( "collected" ) ); + CHECK( DateType::created == enums::fromString< DateType >( "created" ) ); + CHECK( DateType::issued == enums::fromString< DateType >( "issued" ) ); + CHECK( DateType::submitted == enums::fromString< DateType >( "submitted" ) ); + CHECK( DateType::updated == enums::fromString< DateType >( "updated" ) ); + CHECK( DateType::valid == enums::fromString< DateType >( "valid" ) ); + CHECK( DateType::withdrawn == enums::fromString< DateType >( "withdrawn" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< DateType >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << DateType::accepted << ' ' << DateType::available << ' ' + << DateType::copyrighted << ' ' << DateType::collected << ' ' + << DateType::created << ' ' << DateType::issued << ' ' + << DateType::submitted << ' ' << DateType::updated << ' ' + << DateType::valid << ' ' << DateType::withdrawn; + + CHECK( "accepted available copyrighted collected " + "created issued submitted updated valid withdrawn" == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + DateType value; + std::istringstream in( "accepted available copyrighted collected created issued submitted updated valid withdrawn" ); + + in >> value; + CHECK( DateType::accepted == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::available == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::copyrighted == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::collected == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::created == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::issued == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::submitted == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::updated == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::valid == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DateType::withdrawn == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + DateType value = DateType::accepted; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( DateType::accepted == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isDateType is used" ) { + + THEN( "registered date types return true, " + "unregistered date types return false" ) { + + CHECK( true == enums::isDateType( "accepted" ) ); + CHECK( true == enums::isDateType( "available" ) ); + CHECK( true == enums::isDateType( "copyrighted" ) ); + CHECK( true == enums::isDateType( "collected" ) ); + CHECK( true == enums::isDateType( "created" ) ); + CHECK( true == enums::isDateType( "issued" ) ); + CHECK( true == enums::isDateType( "submitted" ) ); + CHECK( true == enums::isDateType( "updated" ) ); + CHECK( true == enums::isDateType( "valid" ) ); + CHECK( true == enums::isDateType( "withdrawn" ) ); + CHECK( false == enums::isDateType( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/DecayType.hpp b/src/GNDStk/enums/DecayType.hpp new file mode 100644 index 000000000..5d24e7f67 --- /dev/null +++ b/src/GNDStk/enums/DecayType.hpp @@ -0,0 +1,82 @@ +#ifndef NJOY_GNDSTK_DECAYTYPE +#define NJOY_GNDSTK_DECAYTYPE + +namespace enums { + + /** + * @class + * @brief Enumeration class for interpolation decay type values + */ + enum class DecayType { + + SpontaneousFission = 1, + BetaMinus, + BetaPlus, + ElectronCapture, + ElectroMagnetic, + IsomericTransition, + Neutron, + Proton, + Deuteron, + Triton, + Alpha, + AtomicRelaxation + }; + + /** + * @brief Return whether or not a string is a valid relation type + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isDecayType( const std::string& string ) { + + return isSymbol< DecayType >( string ); + } + + /** + * @brief Template specialisation to convert DecayType to/from strings + */ + template <> + class Map< GNDStk::enums::DecayType > { + public: + + static inline const std::map< GNDStk::enums::DecayType, + const std::string > values{ + + { GNDStk::enums::DecayType::SpontaneousFission, "SF" }, + { GNDStk::enums::DecayType::BetaMinus, "beta-" }, + { GNDStk::enums::DecayType::BetaPlus, "beta+" }, + { GNDStk::enums::DecayType::ElectronCapture, "EC" }, + { GNDStk::enums::DecayType::ElectroMagnetic, "electroMagnetic" }, + { GNDStk::enums::DecayType::IsomericTransition, "IT" }, + { GNDStk::enums::DecayType::Neutron, "n" }, + { GNDStk::enums::DecayType::Proton, "p" }, + { GNDStk::enums::DecayType::Deuteron, "d" }, + { GNDStk::enums::DecayType::Triton, "t" }, + { GNDStk::enums::DecayType::Alpha, "alpha" }, + { GNDStk::enums::DecayType::AtomicRelaxation, "atomicRelaxation" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::DecayType > symbols{ + + { "SF", GNDStk::enums::DecayType::SpontaneousFission }, + { "beta-", GNDStk::enums::DecayType::BetaMinus }, + { "beta+", GNDStk::enums::DecayType::BetaPlus }, + { "EC", GNDStk::enums::DecayType::ElectronCapture }, + { "electroMagnetic", GNDStk::enums::DecayType::ElectroMagnetic }, + { "IT", GNDStk::enums::DecayType::IsomericTransition }, + { "n", GNDStk::enums::DecayType::Neutron }, + { "p", GNDStk::enums::DecayType::Proton }, + { "d", GNDStk::enums::DecayType::Deuteron }, + { "t", GNDStk::enums::DecayType::Triton }, + { "alpha", GNDStk::enums::DecayType::Alpha }, + { "atomicRelaxation", GNDStk::enums::DecayType::AtomicRelaxation } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/DecayType/test/CMakeLists.txt b/src/GNDStk/enums/DecayType/test/CMakeLists.txt new file mode 100644 index 000000000..de111b825 --- /dev/null +++ b/src/GNDStk/enums/DecayType/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.DecayType.test DecayType.test.cpp ) +target_compile_options( GNDStk.enums.DecayType.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.DecayType.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.DecayType COMMAND GNDStk.enums.DecayType.test ) diff --git a/src/GNDStk/enums/DecayType/test/DecayType.test.cpp b/src/GNDStk/enums/DecayType/test/DecayType.test.cpp new file mode 100644 index 000000000..5f2b96a26 --- /dev/null +++ b/src/GNDStk/enums/DecayType/test/DecayType.test.cpp @@ -0,0 +1,182 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using DecayType = enums::DecayType; + +SCENARIO( "DecayType" ) { + + GIVEN( "valid DecayType values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "SF" == enums::toString( DecayType::SpontaneousFission ) ); + CHECK( "beta-" == enums::toString( DecayType::BetaMinus ) ); + CHECK( "beta+" == enums::toString( DecayType::BetaPlus ) ); + CHECK( "EC" == enums::toString( DecayType::ElectronCapture ) ); + CHECK( "electroMagnetic" == enums::toString( DecayType::ElectroMagnetic ) ); + CHECK( "IT" == enums::toString( DecayType::IsomericTransition ) ); + CHECK( "n" == enums::toString( DecayType::Neutron ) ); + CHECK( "p" == enums::toString( DecayType::Proton ) ); + CHECK( "d" == enums::toString( DecayType::Deuteron ) ); + CHECK( "t" == enums::toString( DecayType::Triton ) ); + CHECK( "alpha" == enums::toString( DecayType::Alpha ) ); + CHECK( "atomicRelaxation" == enums::toString( DecayType::AtomicRelaxation ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( DecayType::SpontaneousFission == enums::fromString< DecayType >( "SF" ) ); + CHECK( DecayType::BetaMinus == enums::fromString< DecayType >( "beta-" ) ); + CHECK( DecayType::BetaPlus == enums::fromString< DecayType >( "beta+" ) ); + CHECK( DecayType::ElectronCapture == enums::fromString< DecayType >( "EC" ) ); + CHECK( DecayType::ElectroMagnetic == enums::fromString< DecayType >( "electroMagnetic" ) ); + CHECK( DecayType::IsomericTransition == enums::fromString< DecayType >( "IT" ) ); + CHECK( DecayType::Neutron == enums::fromString< DecayType >( "n" ) ); + CHECK( DecayType::Proton == enums::fromString< DecayType >( "p" ) ); + CHECK( DecayType::Deuteron == enums::fromString< DecayType >( "d" ) ); + CHECK( DecayType::Triton == enums::fromString< DecayType >( "t" ) ); + CHECK( DecayType::Alpha == enums::fromString< DecayType >( "alpha" ) ); + CHECK( DecayType::AtomicRelaxation == enums::fromString< DecayType >( "atomicRelaxation" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< DecayType >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << DecayType::SpontaneousFission << ' ' + << DecayType::BetaMinus << ' ' + << DecayType::BetaPlus << ' ' + << DecayType::ElectronCapture << ' ' + << DecayType::ElectroMagnetic << ' ' + << DecayType::IsomericTransition << ' ' + << DecayType::Neutron << ' ' + << DecayType::Proton << ' ' + << DecayType::Deuteron << ' ' + << DecayType::Triton << ' ' + << DecayType::Alpha << ' ' + << DecayType::AtomicRelaxation; + + CHECK( "SF beta- beta+ EC electroMagnetic IT n p d t alpha atomicRelaxation" == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + DecayType value; + std::istringstream in( "SF beta- beta+ EC electroMagnetic IT n p d t alpha atomicRelaxation" ); + + in >> value; + CHECK( DecayType::SpontaneousFission == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::BetaMinus == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::BetaPlus == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::ElectronCapture == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::ElectroMagnetic == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::IsomericTransition == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::Neutron == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::Proton == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::Deuteron == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::Triton == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::Alpha == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( DecayType::AtomicRelaxation == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + DecayType value = DecayType::SpontaneousFission; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( DecayType::SpontaneousFission == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isDecayType is used" ) { + + THEN( "registered DecayType values return true, " + "unregistered DecayType values return false" ) { + + CHECK( true == enums::isDecayType( "SF" ) ); + CHECK( true == enums::isDecayType( "beta-" ) ); + CHECK( true == enums::isDecayType( "beta+" ) ); + CHECK( true == enums::isDecayType( "EC" ) ); + CHECK( true == enums::isDecayType( "electroMagnetic" ) ); + CHECK( true == enums::isDecayType( "IT" ) ); + CHECK( true == enums::isDecayType( "n" ) ); + CHECK( true == enums::isDecayType( "p" ) ); + CHECK( true == enums::isDecayType( "d" ) ); + CHECK( true == enums::isDecayType( "t" ) ); + CHECK( true == enums::isDecayType( "alpha" ) ); + CHECK( true == enums::isDecayType( "atomicRelaxation" ) ); + CHECK( false == enums::isDecayType( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/Encoding/test/Encoding.test.cpp b/src/GNDStk/enums/Encoding/test/Encoding.test.cpp index 3230b1b38..08ce7f8df 100644 --- a/src/GNDStk/enums/Encoding/test/Encoding.test.cpp +++ b/src/GNDStk/enums/Encoding/test/Encoding.test.cpp @@ -79,7 +79,8 @@ SCENARIO( "Encoding" ) { WHEN( "isEncoding is used" ) { - THEN( "registered encoding values return true, unregistered encoding values return false" ) { + THEN( "registered encoding values return true, " + "unregistered encoding values return false" ) { CHECK( true == enums::isEncoding( "ascii" ) ); CHECK( true == enums::isEncoding( "utf8" ) ); diff --git a/src/GNDStk/enums/Frame.hpp b/src/GNDStk/enums/Frame.hpp index 5b598e67f..7555c5523 100644 --- a/src/GNDStk/enums/Frame.hpp +++ b/src/GNDStk/enums/Frame.hpp @@ -6,9 +6,7 @@ namespace enums { /** * @class - * @brief Enumeration class giving acceptable frame values - * - * See GNDS v1.9 specifications section 3.5.3 + * @brief Enumeration class for reference frame values */ enum class Frame { diff --git a/src/GNDStk/enums/Frame/test/Frame.test.cpp b/src/GNDStk/enums/Frame/test/Frame.test.cpp index 2448994ff..56ce003c9 100644 --- a/src/GNDStk/enums/Frame/test/Frame.test.cpp +++ b/src/GNDStk/enums/Frame/test/Frame.test.cpp @@ -26,8 +26,10 @@ SCENARIO( "Frame" ) { THEN( "no exception is thrown when the symbol is registered" ) { - CHECK( Frame::lab == enums::fromString< Frame >( "lab" ) ); - CHECK( Frame::centerOfMass == enums::fromString< Frame >( "centerOfMass" ) ); + CHECK( Frame::lab == + enums::fromString< Frame >( "lab" ) ); + CHECK( Frame::centerOfMass == + enums::fromString< Frame >( "centerOfMass" ) ); } // THEN THEN( "an exception is thrown when the symbol is not registered" ) { @@ -79,7 +81,8 @@ SCENARIO( "Frame" ) { WHEN( "isFrame is used" ) { - THEN( "registered frame values return true, unregistered frame values return false" ) { + THEN( "registered frame values return true, " + "unregistered frame values return false" ) { CHECK( true == enums::isFrame( "lab" ) ); CHECK( true == enums::isFrame( "centerOfMass" ) ); diff --git a/src/GNDStk/enums/GridStyle.hpp b/src/GNDStk/enums/GridStyle.hpp index 06759c324..403a5dd44 100644 --- a/src/GNDStk/enums/GridStyle.hpp +++ b/src/GNDStk/enums/GridStyle.hpp @@ -1,4 +1,3 @@ - #ifndef NJOY_GNDSTK_GRIDSTYLE #define NJOY_GNDSTK_GRIDSTYLE @@ -7,8 +6,6 @@ namespace enums { /** * @class * @brief Enumeration class giving acceptable grid style values - * - * See GNDS v1.9 specifications section 5.1.3 */ enum class GridStyle { @@ -51,8 +48,8 @@ namespace enums { static inline const std::map< const std::string, GNDStk::enums::GridStyle > symbols{ - { "none", GNDStk::enums::GridStyle::none }, - { "link", GNDStk::enums::GridStyle::link }, + { "none", GNDStk::enums::GridStyle::none }, + { "link", GNDStk::enums::GridStyle::link }, { "points", GNDStk::enums::GridStyle::points }, { "boundaries", GNDStk::enums::GridStyle::boundaries }, { "parameters", GNDStk::enums::GridStyle::parameters } diff --git a/src/GNDStk/enums/GridStyle/test/GridStyle.test.cpp b/src/GNDStk/enums/GridStyle/test/GridStyle.test.cpp index d6aa8797d..8f6d5f24a 100644 --- a/src/GNDStk/enums/GridStyle/test/GridStyle.test.cpp +++ b/src/GNDStk/enums/GridStyle/test/GridStyle.test.cpp @@ -29,11 +29,16 @@ SCENARIO( "GridStyle" ) { THEN( "no exception is thrown when the symbol is registered" ) { - CHECK( GridStyle::none == enums::fromString< GridStyle >( "none" ) ); - CHECK( GridStyle::link == enums::fromString< GridStyle >( "link" ) ); - CHECK( GridStyle::points == enums::fromString< GridStyle >( "points" ) ); - CHECK( GridStyle::boundaries == enums::fromString< GridStyle >( "boundaries" ) ); - CHECK( GridStyle::parameters == enums::fromString< GridStyle >( "parameters" ) ); + CHECK( GridStyle::none == + enums::fromString< GridStyle >( "none" ) ); + CHECK( GridStyle::link == + enums::fromString< GridStyle >( "link" ) ); + CHECK( GridStyle::points == + enums::fromString< GridStyle >( "points" ) ); + CHECK( GridStyle::boundaries == + enums::fromString< GridStyle >( "boundaries" ) ); + CHECK( GridStyle::parameters == + enums::fromString< GridStyle >( "parameters" ) ); } // THEN THEN( "an exception is thrown when the symbol is not registered" ) { diff --git a/src/GNDStk/enums/HashAlgorithm.hpp b/src/GNDStk/enums/HashAlgorithm.hpp new file mode 100644 index 000000000..98a4ec245 --- /dev/null +++ b/src/GNDStk/enums/HashAlgorithm.hpp @@ -0,0 +1,52 @@ +#ifndef NJOY_GNDSTK_HASHALGORITHM +#define NJOY_GNDSTK_HASHALGORITHM + +namespace enums { + + /** + * @class + * @brief Enumeration class for hash algorithm values + */ + enum class HashAlgorithm { + + md5 = 1, + sha1 = 2 + }; + + /** + * @brief Return whether or not a string is a valid hash algorithm value + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isHashAlgorithm( const std::string& string ) { + + return isSymbol< HashAlgorithm >( string ); + } + + /** + * @brief Template specialisation to convert HashAlgorithm to/from strings + */ + template <> + class Map< GNDStk::enums::HashAlgorithm > { + public: + + static inline const std::map< GNDStk::enums::HashAlgorithm, + const std::string > values{ + + { GNDStk::enums::HashAlgorithm::md5, "md5" }, + { GNDStk::enums::HashAlgorithm::sha1, "sha1" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::HashAlgorithm > symbols{ + + { "md5", GNDStk::enums::HashAlgorithm::md5 }, + { "sha1", GNDStk::enums::HashAlgorithm::sha1 } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/HashAlgorithm/test/CMakeLists.txt b/src/GNDStk/enums/HashAlgorithm/test/CMakeLists.txt new file mode 100644 index 000000000..d04273dc2 --- /dev/null +++ b/src/GNDStk/enums/HashAlgorithm/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.HashAlgorithm.test HashAlgorithm.test.cpp ) +target_compile_options( GNDStk.enums.HashAlgorithm.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.HashAlgorithm.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.HashAlgorithm COMMAND GNDStk.enums.HashAlgorithm.test ) diff --git a/src/GNDStk/enums/HashAlgorithm/test/HashAlgorithm.test.cpp b/src/GNDStk/enums/HashAlgorithm/test/HashAlgorithm.test.cpp new file mode 100644 index 000000000..4c1a3ef13 --- /dev/null +++ b/src/GNDStk/enums/HashAlgorithm/test/HashAlgorithm.test.cpp @@ -0,0 +1,91 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using HashAlgorithm = enums::HashAlgorithm; + +SCENARIO( "HashAlgorithm" ) { + + GIVEN( "valid frame values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "md5" == enums::toString( HashAlgorithm::md5 ) ); + CHECK( "sha1" == enums::toString( HashAlgorithm::sha1 ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( HashAlgorithm::md5 == enums::fromString< HashAlgorithm >( "md5" ) ); + CHECK( HashAlgorithm::sha1 == enums::fromString< HashAlgorithm >( "sha1" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< HashAlgorithm >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << HashAlgorithm::md5 << ' ' << HashAlgorithm::sha1; + + CHECK( "md5 sha1" == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + HashAlgorithm value; + std::istringstream in( "md5 sha1" ); + + in >> value; + CHECK( HashAlgorithm::md5 == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( HashAlgorithm::sha1 == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + HashAlgorithm value = HashAlgorithm::sha1; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( HashAlgorithm::sha1 == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isHashAlgorithm is used" ) { + + THEN( "registered frame values return true, " + "unregistered frame values return false" ) { + + CHECK( true == enums::isHashAlgorithm( "md5" ) ); + CHECK( true == enums::isHashAlgorithm( "sha1" ) ); + CHECK( false == enums::isHashAlgorithm( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/Interaction.hpp b/src/GNDStk/enums/Interaction.hpp index 2aa344368..106b0fcc2 100644 --- a/src/GNDStk/enums/Interaction.hpp +++ b/src/GNDStk/enums/Interaction.hpp @@ -1,4 +1,3 @@ - #ifndef NJOY_GNDSTK_INTERACTION #define NJOY_GNDSTK_INTERACTION @@ -39,17 +38,23 @@ namespace enums { static inline const std::map< GNDStk::enums::Interaction, const std::string > values{ - { GNDStk::enums::Interaction::nuclear, "nuclear" }, - { GNDStk::enums::Interaction::atomic, "atomic" }, - { GNDStk::enums::Interaction::thermalNeutronScatteringLaw, "thermalNeutronScatteringLaw" } + { GNDStk::enums::Interaction::nuclear, + "nuclear" }, + { GNDStk::enums::Interaction::atomic, + "atomic" }, + { GNDStk::enums::Interaction::thermalNeutronScatteringLaw, + "thermalNeutronScatteringLaw" } }; static inline const std::map< const std::string, GNDStk::enums::Interaction > symbols{ - { "nuclear", GNDStk::enums::Interaction::nuclear }, - { "atomic", GNDStk::enums::Interaction::atomic }, - { "thermalNeutronScatteringLaw", GNDStk::enums::Interaction::thermalNeutronScatteringLaw } + { "nuclear", + GNDStk::enums::Interaction::nuclear }, + { "atomic", + GNDStk::enums::Interaction::atomic }, + { "thermalNeutronScatteringLaw", + GNDStk::enums::Interaction::thermalNeutronScatteringLaw } }; }; diff --git a/src/GNDStk/enums/Interaction/test/Interaction.test.cpp b/src/GNDStk/enums/Interaction/test/Interaction.test.cpp index 669926ee6..bfbf14aec 100644 --- a/src/GNDStk/enums/Interaction/test/Interaction.test.cpp +++ b/src/GNDStk/enums/Interaction/test/Interaction.test.cpp @@ -17,9 +17,12 @@ SCENARIO( "Interaction" ) { THEN( "no exception is thrown and the correct string is returned" ) { - CHECK( "nuclear" == enums::toString( Interaction::nuclear ) ); - CHECK( "atomic" == enums::toString( Interaction::atomic ) ); - CHECK( "thermalNeutronScatteringLaw" == enums::toString( Interaction::thermalNeutronScatteringLaw ) ); + CHECK( "nuclear" == + enums::toString( Interaction::nuclear ) ); + CHECK( "atomic" == + enums::toString( Interaction::atomic ) ); + CHECK( "thermalNeutronScatteringLaw" == + enums::toString( Interaction::thermalNeutronScatteringLaw ) ); } // THEN } // WHEN @@ -27,9 +30,12 @@ SCENARIO( "Interaction" ) { THEN( "no exception is thrown when the symbol is registered" ) { - CHECK( Interaction::nuclear == enums::fromString< Interaction >( "nuclear" ) ); - CHECK( Interaction::atomic == enums::fromString< Interaction >( "atomic" ) ); - CHECK( Interaction::thermalNeutronScatteringLaw == enums::fromString< Interaction >( "thermalNeutronScatteringLaw" ) ); + CHECK( Interaction::nuclear == + enums::fromString("nuclear")); + CHECK( Interaction::atomic == + enums::fromString("atomic")); + CHECK( Interaction::thermalNeutronScatteringLaw == + enums::fromString("thermalNeutronScatteringLaw")); } // THEN THEN( "an exception is thrown when the symbol is not registered" ) { @@ -87,7 +93,8 @@ SCENARIO( "Interaction" ) { WHEN( "isInteraction is used" ) { - THEN( "registered interaction values return true, unregistered interaction values return false" ) { + THEN( "registered interaction values return true, " + "unregistered interaction values return false" ) { CHECK( true == enums::isInteraction( "nuclear" ) ); CHECK( true == enums::isInteraction( "atomic" ) ); diff --git a/src/GNDStk/enums/Interpolation.hpp b/src/GNDStk/enums/Interpolation.hpp index 94281587e..762c95164 100644 --- a/src/GNDStk/enums/Interpolation.hpp +++ b/src/GNDStk/enums/Interpolation.hpp @@ -1,4 +1,3 @@ - #ifndef NJOY_GNDSTK_INTERPOLATION #define NJOY_GNDSTK_INTERPOLATION @@ -6,9 +5,7 @@ namespace enums { /** * @class - * @brief Enumeration class giving acceptable interpolation values - * - * See GNDS v1.9 specifications section 3.5.3 + * @brief Enumeration class for interpolation values */ enum class Interpolation { @@ -21,7 +18,7 @@ namespace enums { }; /** - * @brief Return whether or not a string is a valid interpolation + * @brief Return whether or not a string is a valid interpolation value * * @param[in] string the string to be verified * diff --git a/src/GNDStk/enums/Interpolation/test/Interpolation.test.cpp b/src/GNDStk/enums/Interpolation/test/Interpolation.test.cpp index 64a19e6ee..e34e39605 100644 --- a/src/GNDStk/enums/Interpolation/test/Interpolation.test.cpp +++ b/src/GNDStk/enums/Interpolation/test/Interpolation.test.cpp @@ -22,7 +22,8 @@ SCENARIO( "Interpolation" ) { CHECK( "lin-log" == enums::toString( Interpolation::linlog ) ); CHECK( "log-lin" == enums::toString( Interpolation::loglin ) ); CHECK( "log-log" == enums::toString( Interpolation::loglog ) ); - CHECK( "charged-particle" == enums::toString( Interpolation::chargedparticle ) ); + CHECK( "charged-particle" == + enums::toString( Interpolation::chargedparticle ) ); } // THEN } // WHEN @@ -30,12 +31,18 @@ SCENARIO( "Interpolation" ) { THEN( "no exception is thrown when the symbol is registered" ) { - CHECK( Interpolation::flat == enums::fromString< Interpolation >( "flat" ) ); - CHECK( Interpolation::linlin == enums::fromString< Interpolation >( "lin-lin" ) ); - CHECK( Interpolation::linlog == enums::fromString< Interpolation >( "lin-log" ) ); - CHECK( Interpolation::loglin == enums::fromString< Interpolation >( "log-lin" ) ); - CHECK( Interpolation::loglog == enums::fromString< Interpolation >( "log-log" ) ); - CHECK( Interpolation::chargedparticle == enums::fromString< Interpolation >( "charged-particle" ) ); + CHECK( Interpolation::flat == + enums::fromString< Interpolation >( "flat" ) ); + CHECK( Interpolation::linlin == + enums::fromString< Interpolation >( "lin-lin" ) ); + CHECK( Interpolation::linlog == + enums::fromString< Interpolation >( "lin-log" ) ); + CHECK( Interpolation::loglin == + enums::fromString< Interpolation >( "log-lin" ) ); + CHECK( Interpolation::loglog == + enums::fromString< Interpolation >( "log-log" ) ); + CHECK( Interpolation::chargedparticle == + enums::fromString< Interpolation >( "charged-particle" ) ); } // THEN THEN( "an exception is thrown when the symbol is not registered" ) { @@ -53,7 +60,8 @@ SCENARIO( "Interpolation" ) { << Interpolation::linlog << ' ' << Interpolation::loglin << ' ' << Interpolation::loglog << ' ' << Interpolation::chargedparticle; - CHECK( "flat lin-lin lin-log log-lin log-log charged-particle" == out.str() ); + CHECK( "flat lin-lin lin-log log-lin log-log charged-particle" == + out.str() ); } // THEN } // WHEN @@ -110,7 +118,8 @@ SCENARIO( "Interpolation" ) { WHEN( "isInterpolation is used" ) { - THEN( "registered interpolation values return true, unregistered interpolation values return false" ) { + THEN( "registered interpolation values return true, " + "unregistered interpolation values return false" ) { CHECK( true == enums::isInterpolation( "flat" ) ); CHECK( true == enums::isInterpolation( "lin-lin" ) ); diff --git a/src/GNDStk/enums/InterpolationQualifier.hpp b/src/GNDStk/enums/InterpolationQualifier.hpp new file mode 100644 index 000000000..e7c3e0f2a --- /dev/null +++ b/src/GNDStk/enums/InterpolationQualifier.hpp @@ -0,0 +1,59 @@ +#ifndef NJOY_GNDSTK_INTERPOLATIONQUALIFIER +#define NJOY_GNDSTK_INTERPOLATIONQUALIFIER + +namespace enums { + + /** + * @class + * @brief Enumeration class for interpolation qualifier values + */ + enum class InterpolationQualifier { + + direct = 1, + unitBase, + correspondingEnergies, + correspondingPoints + }; + + /** + * @brief Return whether or not a string is a valid interpolation qualifier + * value + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isInterpolationQualifier( const std::string& string ) { + + return isSymbol< InterpolationQualifier >( string ); + } + + /** + * @brief Template specialisation to convert InterpolationQualifier to/from strings + */ + template <> + class Map< GNDStk::enums::InterpolationQualifier > { + public: + + static inline const std::map< GNDStk::enums::InterpolationQualifier, + const std::string > values{ + + { GNDStk::enums::InterpolationQualifier::direct, "direct" }, + { GNDStk::enums::InterpolationQualifier::unitBase, "unitBase" }, + { GNDStk::enums::InterpolationQualifier::correspondingEnergies, "correspondingEnergies" }, + { GNDStk::enums::InterpolationQualifier::correspondingPoints, "correspondingPoints" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::InterpolationQualifier > symbols{ + + { "direct", GNDStk::enums::InterpolationQualifier::direct }, + { "unitBase", GNDStk::enums::InterpolationQualifier::unitBase }, + { "correspondingEnergies", GNDStk::enums::InterpolationQualifier::correspondingEnergies }, + { "correspondingPoints", GNDStk::enums::InterpolationQualifier::correspondingPoints } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/InterpolationQualifier/test/CMakeLists.txt b/src/GNDStk/enums/InterpolationQualifier/test/CMakeLists.txt new file mode 100644 index 000000000..6f280bddc --- /dev/null +++ b/src/GNDStk/enums/InterpolationQualifier/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.InterpolationQualifier.test InterpolationQualifier.test.cpp ) +target_compile_options( GNDStk.enums.InterpolationQualifier.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.InterpolationQualifier.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.InterpolationQualifier COMMAND GNDStk.enums.InterpolationQualifier.test ) diff --git a/src/GNDStk/enums/InterpolationQualifier/test/InterpolationQualifier.test.cpp b/src/GNDStk/enums/InterpolationQualifier/test/InterpolationQualifier.test.cpp new file mode 100644 index 000000000..2f681667c --- /dev/null +++ b/src/GNDStk/enums/InterpolationQualifier/test/InterpolationQualifier.test.cpp @@ -0,0 +1,118 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using InterpolationQualifier = enums::InterpolationQualifier; + +SCENARIO( "InterpolationQualifier" ) { + + GIVEN( "valid interpolation values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "direct" == enums::toString( InterpolationQualifier::direct ) ); + CHECK( "unitBase" == enums::toString( InterpolationQualifier::unitBase ) ); + CHECK( "correspondingEnergies" + == enums::toString( InterpolationQualifier::correspondingEnergies ) ); + CHECK( "correspondingPoints" + == enums::toString( InterpolationQualifier::correspondingPoints ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( InterpolationQualifier::direct + == enums::fromString< InterpolationQualifier >( "direct" ) ); + CHECK( InterpolationQualifier::unitBase + == enums::fromString< InterpolationQualifier >( "unitBase" ) ); + CHECK( InterpolationQualifier::correspondingEnergies + == enums::fromString< InterpolationQualifier >( "correspondingEnergies" ) ); + CHECK( InterpolationQualifier::correspondingPoints + == enums::fromString< InterpolationQualifier >( "correspondingPoints" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< InterpolationQualifier >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << InterpolationQualifier::direct << ' ' + << InterpolationQualifier::unitBase << ' ' + << InterpolationQualifier::correspondingEnergies << ' ' + << InterpolationQualifier::correspondingPoints; + + CHECK( "direct unitBase correspondingEnergies correspondingPoints" + == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + InterpolationQualifier value; + std::istringstream in( "direct unitBase correspondingEnergies " + "correspondingPoints" ); + + in >> value; + CHECK( InterpolationQualifier::direct == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( InterpolationQualifier::unitBase == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( InterpolationQualifier::correspondingEnergies == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( InterpolationQualifier::correspondingPoints == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + InterpolationQualifier value = InterpolationQualifier::unitBase; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( InterpolationQualifier::unitBase == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isInterpolationQualifier is used" ) { + + THEN( "registered interpolation qualifier values return true, " + "unregistered interpolation values return false" ) { + + CHECK( true == enums::isInterpolationQualifier( "direct" ) ); + CHECK( true == enums::isInterpolationQualifier( "unitBase" ) ); + CHECK( true == enums::isInterpolationQualifier( "correspondingEnergies" ) ); + CHECK( true == enums::isInterpolationQualifier( "correspondingPoints" ) ); + CHECK( false == enums::isInterpolationQualifier( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/Parity.hpp b/src/GNDStk/enums/Parity.hpp new file mode 100644 index 000000000..4c8e2485c --- /dev/null +++ b/src/GNDStk/enums/Parity.hpp @@ -0,0 +1,52 @@ +#ifndef NJOY_GNDSTK_PARITY +#define NJOY_GNDSTK_PARITY + +namespace enums { + + /** + * @class + * @brief Enumeration class for particle parity values + */ + enum class Parity { + + minus = -1, + plus = +1 + }; + + /** + * @brief Return whether or not a string is a valid parity + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isParity( const std::string& string ) { + + return isSymbol< Parity >( string ); + } + + /** + * @brief Template specialisation to convert Parity to/from strings + */ + template <> + class Map< GNDStk::enums::Parity > { + public: + + static inline const std::map< GNDStk::enums::Parity, + const std::string > values{ + + { GNDStk::enums::Parity::minus, "-1" }, + { GNDStk::enums::Parity::plus, "+1" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::Parity > symbols{ + + { "-1", GNDStk::enums::Parity::minus }, + { "+1", GNDStk::enums::Parity::plus } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/Parity/test/CMakeLists.txt b/src/GNDStk/enums/Parity/test/CMakeLists.txt new file mode 100644 index 000000000..2f659f4f0 --- /dev/null +++ b/src/GNDStk/enums/Parity/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.Parity.test Parity.test.cpp ) +target_compile_options( GNDStk.enums.Parity.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.Parity.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.Parity COMMAND GNDStk.enums.Parity.test ) diff --git a/src/GNDStk/enums/Parity/test/Parity.test.cpp b/src/GNDStk/enums/Parity/test/Parity.test.cpp new file mode 100644 index 000000000..b12d9ae2b --- /dev/null +++ b/src/GNDStk/enums/Parity/test/Parity.test.cpp @@ -0,0 +1,91 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using Parity = enums::Parity; + +SCENARIO( "Parity" ) { + + GIVEN( "valid frame values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "-1" == enums::toString( Parity::minus ) ); + CHECK( "+1" == enums::toString( Parity::plus ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( Parity::minus == enums::fromString< Parity >( "-1" ) ); + CHECK( Parity::plus == enums::fromString< Parity >( "+1" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< Parity >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << Parity::minus << ' ' << Parity::plus; + + CHECK( "-1 +1" == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + Parity value; + std::istringstream in( "-1 +1" ); + + in >> value; + CHECK( Parity::minus == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( Parity::plus == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + Parity value = Parity::plus; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( Parity::plus == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isParity is used" ) { + + THEN( "registered parity values return true, " + "unregistered parity values return false" ) { + + CHECK( true == enums::isParity( "-1" ) ); + CHECK( true == enums::isParity( "+1" ) ); + CHECK( false == enums::isParity( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/RelationType.hpp b/src/GNDStk/enums/RelationType.hpp new file mode 100644 index 000000000..7b896e5cc --- /dev/null +++ b/src/GNDStk/enums/RelationType.hpp @@ -0,0 +1,148 @@ +#ifndef NJOY_GNDSTK_RELATIONTYPE +#define NJOY_GNDSTK_RELATIONTYPE + +namespace enums { + + /** + * @class + * @brief Enumeration class for interpolation qualifier values + */ + enum class RelationType { + + IsCitedBy = 1, + Cites, + IsSupplementTo, + IsSupplementedBy, + IsContinuedBy, + Continues, + Describes, + IsDescribedBy, + HasMetadata, + IsMetadataFor, + HasVersion, + IsVersionOf, + IsNewVersionOf, + IsPreviousVersionOf, + IsPartOf, + HasPart, + IsPublishedIn, + IsReferencedBy, + References, + IsDocumentedBy, + Documents, + IsCompiledBy, + Compiles, + IsVariantFormOf, + IsOriginalFormOf, + IsIdenticalTo, + IsReviewedBy, + Reviews, + IsDerivedFrom, + IsSourceOf, + IsRequiredBy, + Requires, + Obsoletes, + IsObsoletedBy + }; + + /** + * @brief Return whether or not a string is a valid relation type + * + * @param[in] string the string to be verified + * + * @return true/false + */ + inline bool isRelationType( const std::string& string ) { + + return isSymbol< RelationType >( string ); + } + + /** + * @brief Template specialisation to convert RelationType to/from strings + */ + template <> + class Map< GNDStk::enums::RelationType > { + public: + + static inline const std::map< GNDStk::enums::RelationType, + const std::string > values{ + + { GNDStk::enums::RelationType::IsCitedBy, "IsCitedBy" }, + { GNDStk::enums::RelationType::Cites, "Cites" }, + { GNDStk::enums::RelationType::IsSupplementTo, "IsSupplementTo" }, + { GNDStk::enums::RelationType::IsSupplementedBy, "IsSupplementedBy" }, + { GNDStk::enums::RelationType::IsContinuedBy, "IsContinuedBy" }, + { GNDStk::enums::RelationType::Continues, "Continues" }, + { GNDStk::enums::RelationType::Describes, "Describes" }, + { GNDStk::enums::RelationType::IsDescribedBy, "IsDescribedBy" }, + { GNDStk::enums::RelationType::HasMetadata, "HasMetadata" }, + { GNDStk::enums::RelationType::IsMetadataFor, "IsMetadataFor" }, + { GNDStk::enums::RelationType::HasVersion, "HasVersion" }, + { GNDStk::enums::RelationType::IsVersionOf, "IsVersionOf" }, + { GNDStk::enums::RelationType::IsNewVersionOf, "IsNewVersionOf" }, + { GNDStk::enums::RelationType::IsPreviousVersionOf, "IsPreviousVersionOf" }, + { GNDStk::enums::RelationType::IsPartOf, "IsPartOf" }, + { GNDStk::enums::RelationType::HasPart, "HasPart" }, + { GNDStk::enums::RelationType::IsPublishedIn, "IsPublishedIn" }, + { GNDStk::enums::RelationType::IsReferencedBy, "IsReferencedBy" }, + { GNDStk::enums::RelationType::References, "References" }, + { GNDStk::enums::RelationType::IsDocumentedBy, "IsDocumentedBy" }, + { GNDStk::enums::RelationType::Documents, "Documents" }, + { GNDStk::enums::RelationType::IsCompiledBy, "IsCompiledBy" }, + { GNDStk::enums::RelationType::Compiles, "Compiles" }, + { GNDStk::enums::RelationType::IsVariantFormOf, "IsVariantFormOf" }, + { GNDStk::enums::RelationType::IsOriginalFormOf, "IsOriginalFormOf" }, + { GNDStk::enums::RelationType::IsIdenticalTo, "IsIdenticalTo" }, + { GNDStk::enums::RelationType::IsReviewedBy, "IsReviewedBy" }, + { GNDStk::enums::RelationType::Reviews, "Reviews" }, + { GNDStk::enums::RelationType::IsDerivedFrom, "IsDerivedFrom" }, + { GNDStk::enums::RelationType::IsSourceOf, "IsSourceOf" }, + { GNDStk::enums::RelationType::IsRequiredBy, "IsRequiredBy" }, + { GNDStk::enums::RelationType::Requires, "Requires" }, + { GNDStk::enums::RelationType::Obsoletes, "Obsoletes" }, + { GNDStk::enums::RelationType::IsObsoletedBy, "IsObsoletedBy" } + }; + + static inline const std::map< const std::string, + GNDStk::enums::RelationType > symbols{ + + { "IsCitedBy", GNDStk::enums::RelationType::IsCitedBy }, + { "Cites", GNDStk::enums::RelationType::Cites }, + { "IsSupplementTo", GNDStk::enums::RelationType::IsSupplementTo }, + { "IsSupplementedBy", GNDStk::enums::RelationType::IsSupplementedBy }, + { "IsContinuedBy", GNDStk::enums::RelationType::IsContinuedBy }, + { "Continues", GNDStk::enums::RelationType::Continues }, + { "Describes", GNDStk::enums::RelationType::Describes }, + { "IsDescribedBy", GNDStk::enums::RelationType::IsDescribedBy }, + { "HasMetadata", GNDStk::enums::RelationType::HasMetadata }, + { "IsMetadataFor", GNDStk::enums::RelationType::IsMetadataFor }, + { "HasVersion", GNDStk::enums::RelationType::HasVersion }, + { "IsVersionOf", GNDStk::enums::RelationType::IsVersionOf }, + { "IsNewVersionOf", GNDStk::enums::RelationType::IsNewVersionOf }, + { "IsPreviousVersionOf", GNDStk::enums::RelationType::IsPreviousVersionOf }, + { "IsPartOf", GNDStk::enums::RelationType::IsPartOf }, + { "HasPart", GNDStk::enums::RelationType::HasPart }, + { "IsPublishedIn", GNDStk::enums::RelationType::IsPublishedIn }, + { "IsReferencedBy", GNDStk::enums::RelationType::IsReferencedBy }, + { "References", GNDStk::enums::RelationType::References }, + { "IsDocumentedBy", GNDStk::enums::RelationType::IsDocumentedBy }, + { "Documents", GNDStk::enums::RelationType::Documents }, + { "IsCompiledBy", GNDStk::enums::RelationType::IsCompiledBy }, + { "Compiles", GNDStk::enums::RelationType::Compiles }, + { "IsVariantFormOf", GNDStk::enums::RelationType::IsVariantFormOf }, + { "IsOriginalFormOf", GNDStk::enums::RelationType::IsOriginalFormOf }, + { "IsIdenticalTo", GNDStk::enums::RelationType::IsIdenticalTo }, + { "IsReviewedBy", GNDStk::enums::RelationType::IsReviewedBy }, + { "Reviews", GNDStk::enums::RelationType::Reviews }, + { "IsDerivedFrom", GNDStk::enums::RelationType::IsDerivedFrom }, + { "IsSourceOf", GNDStk::enums::RelationType::IsSourceOf }, + { "IsRequiredBy", GNDStk::enums::RelationType::IsRequiredBy }, + { "Requires", GNDStk::enums::RelationType::Requires }, + { "Obsoletes", GNDStk::enums::RelationType::Obsoletes }, + { "IsObsoletedBy", GNDStk::enums::RelationType::IsObsoletedBy } + }; + }; + +} // namespace enums + +#endif diff --git a/src/GNDStk/enums/RelationType/test/CMakeLists.txt b/src/GNDStk/enums/RelationType/test/CMakeLists.txt new file mode 100644 index 000000000..afd7cf2ff --- /dev/null +++ b/src/GNDStk/enums/RelationType/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_executable( GNDStk.enums.RelationType.test RelationType.test.cpp ) +target_compile_options( GNDStk.enums.RelationType.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${GNDStk_appended_flags} ) +target_link_libraries( GNDStk.enums.RelationType.test PUBLIC GNDStk ) +file( GLOB resources "resources/*" ) +foreach( resource ${resources}) + file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) +endforeach() +add_test( NAME GNDStk.enums.RelationType COMMAND GNDStk.enums.RelationType.test ) diff --git a/src/GNDStk/enums/RelationType/test/RelationType.test.cpp b/src/GNDStk/enums/RelationType/test/RelationType.test.cpp new file mode 100644 index 000000000..cc8ef56b6 --- /dev/null +++ b/src/GNDStk/enums/RelationType/test/RelationType.test.cpp @@ -0,0 +1,393 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "GNDStk.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::GNDStk; +using RelationType = enums::RelationType; + +SCENARIO( "RelationType" ) { + + GIVEN( "valid encoding values and symbols" ) { + + WHEN( "toString is used" ) { + + THEN( "no exception is thrown and the correct string is returned" ) { + + CHECK( "IsCitedBy" == enums::toString( RelationType::IsCitedBy ) ); + CHECK( "Cites" == enums::toString( RelationType::Cites ) ); + CHECK( "IsSupplementTo" == enums::toString( RelationType::IsSupplementTo ) ); + CHECK( "IsSupplementedBy" == enums::toString( RelationType::IsSupplementedBy ) ); + CHECK( "IsContinuedBy" == enums::toString( RelationType::IsContinuedBy ) ); + CHECK( "Continues" == enums::toString( RelationType::Continues ) ); + CHECK( "Describes" == enums::toString( RelationType::Describes ) ); + CHECK( "IsDescribedBy" == enums::toString( RelationType::IsDescribedBy ) ); + CHECK( "HasMetadata" == enums::toString( RelationType::HasMetadata ) ); + CHECK( "IsMetadataFor" == enums::toString( RelationType::IsMetadataFor ) ); + CHECK( "HasVersion" == enums::toString( RelationType::HasVersion ) ); + CHECK( "IsVersionOf" == enums::toString( RelationType::IsVersionOf ) ); + CHECK( "IsNewVersionOf" == enums::toString( RelationType::IsNewVersionOf ) ); + CHECK( "IsPreviousVersionOf" == enums::toString( RelationType::IsPreviousVersionOf ) ); + CHECK( "IsPartOf" == enums::toString( RelationType::IsPartOf ) ); + CHECK( "HasPart" == enums::toString( RelationType::HasPart ) ); + CHECK( "IsPublishedIn" == enums::toString( RelationType::IsPublishedIn ) ); + CHECK( "IsReferencedBy" == enums::toString( RelationType::IsReferencedBy ) ); + CHECK( "References" == enums::toString( RelationType::References ) ); + CHECK( "IsDocumentedBy" == enums::toString( RelationType::IsDocumentedBy ) ); + CHECK( "Documents" == enums::toString( RelationType::Documents ) ); + CHECK( "IsCompiledBy" == enums::toString( RelationType::IsCompiledBy ) ); + CHECK( "Compiles" == enums::toString( RelationType::Compiles ) ); + CHECK( "IsVariantFormOf" == enums::toString( RelationType::IsVariantFormOf ) ); + CHECK( "IsOriginalFormOf" == enums::toString( RelationType::IsOriginalFormOf ) ); + CHECK( "IsIdenticalTo" == enums::toString( RelationType::IsIdenticalTo ) ); + CHECK( "IsReviewedBy" == enums::toString( RelationType::IsReviewedBy ) ); + CHECK( "Reviews" == enums::toString( RelationType::Reviews ) ); + CHECK( "IsDerivedFrom" == enums::toString( RelationType::IsDerivedFrom ) ); + CHECK( "IsSourceOf" == enums::toString( RelationType::IsSourceOf ) ); + CHECK( "IsRequiredBy" == enums::toString( RelationType::IsRequiredBy ) ); + CHECK( "Requires" == enums::toString( RelationType::Requires ) ); + CHECK( "Obsoletes" == enums::toString( RelationType::Obsoletes ) ); + CHECK( "IsObsoletedBy" == enums::toString( RelationType::IsObsoletedBy ) ); + } // THEN + } // WHEN + + WHEN( "fromString is used" ) { + + THEN( "no exception is thrown when the symbol is registered" ) { + + CHECK( RelationType::IsCitedBy == enums::fromString< RelationType >( "IsCitedBy" ) ); + CHECK( RelationType::Cites == enums::fromString< RelationType >( "Cites" ) ); + CHECK( RelationType::IsSupplementTo == enums::fromString< RelationType >( "IsSupplementTo" ) ); + CHECK( RelationType::IsSupplementedBy == enums::fromString< RelationType >( "IsSupplementedBy" ) ); + CHECK( RelationType::IsContinuedBy == enums::fromString< RelationType >( "IsContinuedBy" ) ); + CHECK( RelationType::Continues == enums::fromString< RelationType >( "Continues" ) ); + CHECK( RelationType::Describes == enums::fromString< RelationType >( "Describes" ) ); + CHECK( RelationType::IsDescribedBy == enums::fromString< RelationType >( "IsDescribedBy" ) ); + CHECK( RelationType::HasMetadata == enums::fromString< RelationType >( "HasMetadata" ) ); + CHECK( RelationType::IsMetadataFor == enums::fromString< RelationType >( "IsMetadataFor" ) ); + CHECK( RelationType::HasVersion == enums::fromString< RelationType >( "HasVersion" ) ); + CHECK( RelationType::IsVersionOf == enums::fromString< RelationType >( "IsVersionOf" ) ); + CHECK( RelationType::IsNewVersionOf == enums::fromString< RelationType >( "IsNewVersionOf" ) ); + CHECK( RelationType::IsPreviousVersionOf == enums::fromString< RelationType >( "IsPreviousVersionOf" ) ); + CHECK( RelationType::IsPartOf == enums::fromString< RelationType >( "IsPartOf" ) ); + CHECK( RelationType::HasPart == enums::fromString< RelationType >( "HasPart" ) ); + CHECK( RelationType::IsPublishedIn == enums::fromString< RelationType >( "IsPublishedIn" ) ); + CHECK( RelationType::IsReferencedBy == enums::fromString< RelationType >( "IsReferencedBy" ) ); + CHECK( RelationType::References == enums::fromString< RelationType >( "References" ) ); + CHECK( RelationType::IsDocumentedBy == enums::fromString< RelationType >( "IsDocumentedBy" ) ); + CHECK( RelationType::Documents == enums::fromString< RelationType >( "Documents" ) ); + CHECK( RelationType::IsCompiledBy == enums::fromString< RelationType >( "IsCompiledBy" ) ); + CHECK( RelationType::Compiles == enums::fromString< RelationType >( "Compiles" ) ); + CHECK( RelationType::IsVariantFormOf == enums::fromString< RelationType >( "IsVariantFormOf" ) ); + CHECK( RelationType::IsOriginalFormOf == enums::fromString< RelationType >( "IsOriginalFormOf" ) ); + CHECK( RelationType::IsIdenticalTo == enums::fromString< RelationType >( "IsIdenticalTo" ) ); + CHECK( RelationType::IsReviewedBy == enums::fromString< RelationType >( "IsReviewedBy" ) ); + CHECK( RelationType::Reviews == enums::fromString< RelationType >( "Reviews" ) ); + CHECK( RelationType::IsDerivedFrom == enums::fromString< RelationType >( "IsDerivedFrom" ) ); + CHECK( RelationType::IsSourceOf == enums::fromString< RelationType >( "IsSourceOf" ) ); + CHECK( RelationType::IsRequiredBy == enums::fromString< RelationType >( "IsRequiredBy" ) ); + CHECK( RelationType::Requires == enums::fromString< RelationType >( "Requires" ) ); + CHECK( RelationType::Obsoletes == enums::fromString< RelationType >( "Obsoletes" ) ); + CHECK( RelationType::IsObsoletedBy == enums::fromString< RelationType >( "IsObsoletedBy" ) ); + } // THEN + + THEN( "an exception is thrown when the symbol is not registered" ) { + + CHECK_THROWS( enums::fromString< RelationType >( "unregistered" ) ); + } // THEN + } // WHEN + + WHEN( "operator<< is used" ) { + + THEN( "no exception is thrown and the symbol is written to the stream" ) { + + std::ostringstream out; + out << RelationType::IsCitedBy << ' ' + << RelationType::Cites << ' ' + << RelationType::IsSupplementTo << ' ' + << RelationType::IsSupplementedBy << ' ' + << RelationType::IsContinuedBy << ' ' + << RelationType::Continues << ' ' + << RelationType::Describes << ' ' + << RelationType::IsDescribedBy << ' ' + << RelationType::HasMetadata << ' ' + << RelationType::IsMetadataFor << ' ' + << RelationType::HasVersion << ' ' + << RelationType::IsVersionOf << ' ' + << RelationType::IsNewVersionOf << ' ' + << RelationType::IsPreviousVersionOf << ' ' + << RelationType::IsPartOf << ' ' + << RelationType::HasPart << ' ' + << RelationType::IsPublishedIn << ' ' + << RelationType::IsReferencedBy << ' ' + << RelationType::References << ' ' + << RelationType::IsDocumentedBy << ' ' + << RelationType::Documents << ' ' + << RelationType::IsCompiledBy << ' ' + << RelationType::Compiles << ' ' + << RelationType::IsVariantFormOf << ' ' + << RelationType::IsOriginalFormOf << ' ' + << RelationType::IsIdenticalTo << ' ' + << RelationType::IsReviewedBy << ' ' + << RelationType::Reviews << ' ' + << RelationType::IsDerivedFrom << ' ' + << RelationType::IsSourceOf << ' ' + << RelationType::IsRequiredBy << ' ' + << RelationType::Requires << ' ' + << RelationType::Obsoletes << ' ' + << RelationType::IsObsoletedBy; + + CHECK( "IsCitedBy Cites IsSupplementTo IsSupplementedBy IsContinuedBy " + "Continues Describes IsDescribedBy HasMetadata IsMetadataFor " + "HasVersion IsVersionOf IsNewVersionOf IsPreviousVersionOf " + "IsPartOf HasPart IsPublishedIn IsReferencedBy References " + "IsDocumentedBy Documents IsCompiledBy Compiles IsVariantFormOf " + "IsOriginalFormOf IsIdenticalTo IsReviewedBy Reviews IsDerivedFrom " + "IsSourceOf IsRequiredBy Requires Obsoletes IsObsoletedBy" + == out.str() ); + } // THEN + } // WHEN + + WHEN( "operator>> is used" ) { + + THEN( "the stream is not in fail() when the symbol is registered" ) { + + RelationType value; + std::istringstream in( "IsCitedBy Cites IsSupplementTo IsSupplementedBy IsContinuedBy " + "Continues Describes IsDescribedBy HasMetadata IsMetadataFor " + "HasVersion IsVersionOf IsNewVersionOf IsPreviousVersionOf " + "IsPartOf HasPart IsPublishedIn IsReferencedBy References " + "IsDocumentedBy Documents IsCompiledBy Compiles IsVariantFormOf " + "IsOriginalFormOf IsIdenticalTo IsReviewedBy Reviews IsDerivedFrom " + "IsSourceOf IsRequiredBy Requires Obsoletes IsObsoletedBy" ); + + in >> value; + CHECK( RelationType::IsCitedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Cites == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsSupplementTo == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsSupplementedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsContinuedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Continues == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Describes == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsDescribedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::HasMetadata == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsMetadataFor == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::HasVersion == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsVersionOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsNewVersionOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsPreviousVersionOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsPartOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::HasPart == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsPublishedIn == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsReferencedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::References == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsDocumentedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Documents == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsCompiledBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Compiles == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsVariantFormOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsOriginalFormOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsIdenticalTo == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsReviewedBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Reviews == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsDerivedFrom == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsSourceOf == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsRequiredBy == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Requires == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::Obsoletes == value ); + CHECK( false == in.fail() ); + CHECK( false == in.eof() ); + + in >> value; + CHECK( RelationType::IsObsoletedBy == value ); + CHECK( false == in.fail() ); + CHECK( true == in.eof() ); + } // THEN + + THEN( "the stream is in fail() and the position has not changed when " + "the symbol is not registered" ) { + + RelationType value = RelationType::IsCitedBy; + std::istringstream in( "unregistered" ); + in >> value; + + CHECK( RelationType::IsCitedBy == value ); + CHECK( true == in.fail() ); + } // THEN + } // WHEN + + WHEN( "isRelationType is used" ) { + + THEN( "registered date types return true, " + "unregistered date types return false" ) { + + CHECK( true == enums::isRelationType( "IsCitedBy" ) ); + CHECK( true == enums::isRelationType( "Cites" ) ); + CHECK( true == enums::isRelationType( "IsSupplementTo" ) ); + CHECK( true == enums::isRelationType( "IsSupplementedBy" ) ); + CHECK( true == enums::isRelationType( "IsContinuedBy" ) ); + CHECK( true == enums::isRelationType( "Continues" ) ); + CHECK( true == enums::isRelationType( "Describes" ) ); + CHECK( true == enums::isRelationType( "IsDescribedBy" ) ); + CHECK( true == enums::isRelationType( "HasMetadata" ) ); + CHECK( true == enums::isRelationType( "IsMetadataFor" ) ); + CHECK( true == enums::isRelationType( "HasVersion" ) ); + CHECK( true == enums::isRelationType( "IsVersionOf" ) ); + CHECK( true == enums::isRelationType( "IsNewVersionOf" ) ); + CHECK( true == enums::isRelationType( "IsPreviousVersionOf" ) ); + CHECK( true == enums::isRelationType( "IsPartOf" ) ); + CHECK( true == enums::isRelationType( "HasPart" ) ); + CHECK( true == enums::isRelationType( "IsPublishedIn" ) ); + CHECK( true == enums::isRelationType( "IsReferencedBy" ) ); + CHECK( true == enums::isRelationType( "References" ) ); + CHECK( true == enums::isRelationType( "IsDocumentedBy" ) ); + CHECK( true == enums::isRelationType( "Documents" ) ); + CHECK( true == enums::isRelationType( "IsCompiledBy" ) ); + CHECK( true == enums::isRelationType( "Compiles" ) ); + CHECK( true == enums::isRelationType( "IsVariantFormOf" ) ); + CHECK( true == enums::isRelationType( "IsOriginalFormOf" ) ); + CHECK( true == enums::isRelationType( "IsIdenticalTo" ) ); + CHECK( true == enums::isRelationType( "IsReviewedBy" ) ); + CHECK( true == enums::isRelationType( "Reviews" ) ); + CHECK( true == enums::isRelationType( "IsDerivedFrom" ) ); + CHECK( true == enums::isRelationType( "IsSourceOf" ) ); + CHECK( true == enums::isRelationType( "IsRequiredBy" ) ); + CHECK( true == enums::isRelationType( "Requires" ) ); + CHECK( true == enums::isRelationType( "Obsoletes" ) ); + CHECK( true == enums::isRelationType( "IsObsoletedBy" ) ); + CHECK( false == enums::isRelationType( "unregistered" ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO diff --git a/src/GNDStk/enums/StorageOrder/test/StorageOrder.test.cpp b/src/GNDStk/enums/StorageOrder/test/StorageOrder.test.cpp index cea39c96e..be7770dbb 100644 --- a/src/GNDStk/enums/StorageOrder/test/StorageOrder.test.cpp +++ b/src/GNDStk/enums/StorageOrder/test/StorageOrder.test.cpp @@ -26,8 +26,10 @@ SCENARIO( "StorageOrder" ) { THEN( "no exception is thrown when the symbol is registered" ) { - CHECK( StorageOrder::rowMajor == enums::fromString< StorageOrder >( "rowMajor" ) ); - CHECK( StorageOrder::columnMajor == enums::fromString< StorageOrder >( "columnMajor" ) ); + CHECK( StorageOrder::rowMajor == + enums::fromString< StorageOrder >( "rowMajor" ) ); + CHECK( StorageOrder::columnMajor == + enums::fromString< StorageOrder >( "columnMajor" ) ); } // THEN THEN( "an exception is thrown when the symbol is not registered" ) { @@ -79,7 +81,8 @@ SCENARIO( "StorageOrder" ) { WHEN( "isStorageOrder is used" ) { - THEN( "registered storage order values return true, unregistered storage order values return false" ) { + THEN( "registered storage order values return true, " + "unregistered storage order values return false" ) { CHECK( true == enums::isStorageOrder( "rowMajor" ) ); CHECK( true == enums::isStorageOrder( "columnMajor" ) ); diff --git a/src/GNDStk/keyword.hpp b/src/GNDStk/keyword.hpp deleted file mode 100644 index b6f929996..000000000 --- a/src/GNDStk/keyword.hpp +++ /dev/null @@ -1,17 +0,0 @@ - -// ----------------------------------------------------------------------------- -// This file defines constructs that are intended to help us, and users, -// create Meta and Child objects. -// ----------------------------------------------------------------------------- - -// keyword_t -class keyword_t { -public: - #include "GNDStk/keyword/src/meta.hpp" - #include "GNDStk/keyword/src/child.hpp" -}; - -// keyword -// An object of the keyword_t type. -// Useful for creating Meta and Child objects. -inline const keyword_t keyword; diff --git a/src/GNDStk/keyword/src/child.hpp b/src/GNDStk/keyword/src/child.hpp deleted file mode 100644 index 5b37e5b68..000000000 --- a/src/GNDStk/keyword/src/child.hpp +++ /dev/null @@ -1,48 +0,0 @@ - -// ----------------------------------------------------------------------------- -// keyword_t.child() -// ----------------------------------------------------------------------------- - -// child(name,converter,filter,top) -// To make a Child -template< - class TYPE, - Allow ALLOW = Allow::one, - class CONVERTER = typename detail::default_converter::type, - class FILTER = detail::noFilter -> -static Child< - typename detail::isNotVoid::type, // ensure TYPE != void - ALLOW, - CONVERTER, - FILTER -> child( - const std::string &name, - const TYPE &object = TYPE{}, - const CONVERTER &converter = CONVERTER{}, - const FILTER &filter = FILTER{}, - const bool top = false -) { - return Child(name,object,converter,filter,top); -} - - -// child(name,filter,top) -// To make a Child -template< - class TYPE = void, - Allow ALLOW = Allow::one, - class FILTER = detail::noFilter -> -static Child< - typename detail::is_void::type, // ensure TYPE == void - ALLOW, - void, - FILTER -> child( - const std::string &name, - const FILTER &filter = FILTER{}, - const bool top = false -) { - return Child(name,filter,top); -} diff --git a/src/GNDStk/keyword/src/meta.hpp b/src/GNDStk/keyword/src/meta.hpp deleted file mode 100644 index d0ebaa934..000000000 --- a/src/GNDStk/keyword/src/meta.hpp +++ /dev/null @@ -1,35 +0,0 @@ - -// ----------------------------------------------------------------------------- -// keyword_t.meta() -// ----------------------------------------------------------------------------- - -// meta(name,converter) -// To make a Meta -template< - class TYPE, - class CONVERTER = typename detail::default_converter::type -> -static Meta< - typename detail::isNotVoid::type, // ensure TYPE != void - CONVERTER -> meta( - const std::string &name, - const TYPE &object = TYPE{}, - const CONVERTER &converter = CONVERTER{} -) { - return Meta{name,object,converter}; -} - - -// meta(name) -// To make a Meta -template< - class TYPE = void -> -static Meta< - typename detail::is_void::type // ensure TYPE == void -> meta( - const std::string &name -) { - return Meta(name); -} diff --git a/src/GNDStk/keyword/test/CMakeLists.txt b/src/GNDStk/keyword/test/CMakeLists.txt deleted file mode 100644 index a39ef1a71..000000000 --- a/src/GNDStk/keyword/test/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ - -add_executable( GNDStk.keyword.test keyword.test.cpp ) -target_compile_options( GNDStk.keyword.test PRIVATE ${${PREFIX}_common_flags} -$<$:${${PREFIX}_strict_flags}>$<$: -${${PREFIX}_DEBUG_flags} -$<$:${${PREFIX}_coverage_flags}>> -$<$: -${${PREFIX}_RELEASE_flags} -$<$:${${PREFIX}_link_time_optimization_flags}> -$<$:${${PREFIX}_nonportable_optimization_flags}>> - -${CXX_appended_flags} ${GNDStk_appended_flags} ) -target_link_libraries( GNDStk.keyword.test PUBLIC GNDStk ) -file( GLOB resources "resources/*" ) -foreach( resource ${resources}) - file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" ) -endforeach() -add_test( NAME GNDStk.keyword COMMAND GNDStk.keyword.test ) \ No newline at end of file diff --git a/src/GNDStk/keyword/test/keyword.test.cpp b/src/GNDStk/keyword/test/keyword.test.cpp deleted file mode 100644 index 72ec2fb06..000000000 --- a/src/GNDStk/keyword/test/keyword.test.cpp +++ /dev/null @@ -1,404 +0,0 @@ - -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" -#include "GNDStk.hpp" - -using namespace njoy::GNDStk; -using std::string; - - - -// ----------------------------------------------------------------------------- -// Custom types -// ----------------------------------------------------------------------------- - -// ------------------------ -// version_t -// ------------------------ - -// class -struct version_t { - int major = -1; - int minor = -1; - int patch = -1; -}; - -// operator>> -std::istream &operator>>(std::istream &s, version_t &obj) -{ - char ch; // '.' - return s >> obj.major >> ch >> obj.minor >> ch >> obj.patch; -} - -// ------------------------ -// date_t -// ------------------------ - -// class -struct date_t { - int year = -1; - int month = -1; - int day = -1; -}; - -// operator>> -std::istream &operator>>(std::istream &s, date_t &obj) -{ - char ch; // '-' - return s >> obj.year >> ch >> obj.month >> ch >> obj.day; -} - -// ------------------------ -// shape_t -// ------------------------ - -// class -struct shape_t { - // or maybe it should cols, rows; not important for this example - int rows = -1; - int cols = -1; -}; - -// operator>> -std::istream &operator>>(std::istream &s, shape_t &obj) -{ - char ch; // ',' - return s >> obj.rows >> ch >> obj.cols; -} - -// ------------------------ -// values_t -// ------------------------ - -// class -using values_t = std::vector; - -// ------------------------ -// manifest_t -// ------------------------ - -// class -struct manifest_t { - string information; -}; - -// convert -template -void convert(const NODE &node, manifest_t &man) -{ - std::ostringstream oss; - - // name - oss << "node: \"" << node.name << '"' << std::endl; - - // metadata - oss << " metadata:" << std::endl; - for (auto &m : node.metadata) - oss << " \"" << m.first << '"' << std::endl; - - // children - oss << " children:" << std::endl; - for (auto &c : node.children) - oss << " \"" << c->name << '"' << std::endl; - - man.information = oss.str(); -} - - - -// ----------------------------------------------------------------------------- -// Some literal strings representing correct values -// ----------------------------------------------------------------------------- - -static const std::string manifest_tree = -R"***(node: "" - metadata: - children: - "xml" - "covarianceSuite" -)***"; - -static const std::string manifest_covarianceSuite = -R"***(node: "covarianceSuite" - metadata: - "projectile" - "target" - "evaluation" - "format" - children: - "styles" - "externalFiles" - "parameterCovariances" -)***"; - -static const std::string manifest_parameterCovariances = -R"***(node: "parameterCovariance" - metadata: - "label" - children: - "rowData" - "parameterCovarianceMatrix" -)***"; - - - -// ----------------------------------------------------------------------------- -// Scenario -// ----------------------------------------------------------------------------- - -SCENARIO("Testing GNDStk keyword") { - - using namespace misc; - - // tree - const njoy::GNDStk::Tree tree("n-069_Tm_170-covar.xml"); - - // ------------------------ - // exercise some built-ins - // ------------------------ - - WHEN("We access a tree using some built-in Child and Meta objects") { - CHECK(tree(xml).metadata.size() == 2); - CHECK(tree(xml).children.size() == 0); - CHECK(tree(xml,version) == "1.0"); - CHECK(tree(xml,encoding) == "UTF-8"); - CHECK(tree(covarianceSuite).metadata.size() == 4); - CHECK(tree(covarianceSuite).children.size() == 3); - CHECK(tree(covarianceSuite,projectile) == "n"); - CHECK(tree(covarianceSuite,target) == "Tm170"); - CHECK(tree(covarianceSuite,evaluation) == "ENDF/B-8.0"); - CHECK(tree(covarianceSuite,format) == 1.9); - CHECK(tree(covarianceSuite,styles).metadata.size() == 0); - CHECK(tree(covarianceSuite,styles).children.size() == 1); - CHECK(tree(covarianceSuite,styles,--evaluated).metadata.size() == 4); - CHECK(tree(covarianceSuite,styles,--evaluated).children.size() == 2); - CHECK(tree(covarianceSuite,styles,--evaluated,misc::meta::label) == "eval"); - } // WHEN - - - // ------------------------ - // make our own - // ------------------------ - - // for metadata - auto myversion = keyword.meta("version"); - auto mydate = keyword.meta("date"); - auto myshape = keyword.meta("shape",shape_t{},detail::convert_t{}); - - // for children - // The following is just like GNDStk::common::numeric, - // or equivalently, GNDStk::[basic or core]::numeric. - auto mynumbers = keyword.child - ("pcdata",values_t{},detail::convert_pcdata_text_t{}); - - // In the following, a name of "" means to stay at the current node - auto mymanifest = keyword.child(""); - - auto vers = tree(xml,myversion); - - - // ------------------------ - // use them - // ------------------------ - - WHEN("We build our own Child and Meta objects, using keyword_t") { - - THEN("Try extracting xml version") { - // Extract version into *our* version type - // Specifically: myversion keyword ==> version_t - CHECK(vers.major == 1); - CHECK(vers.minor == 0); - } - - THEN("Try extracting covarianceSuite/styles/evaluated/version") { - // Now extract version - vers = tree(covarianceSuite,styles,--evaluated,myversion); - CHECK(vers.major == 8); - CHECK(vers.minor == 0); - CHECK(vers.patch == 1); - } - - // For brevity, let's make a shortcut to - auto &eval = tree(covarianceSuite,styles,--evaluated); - - THEN("Try extracting covarianceSuite/styles/evaluated/date") { - // Extract date in , via the shortcut - // Specifically: mydate keyword ==> date_t - auto date = eval(mydate); - CHECK(date.year == 2011); - CHECK(date.month == 10); - CHECK(date.day == 1); - } - - // Pull out , to make some upcoming queries shorter - auto &arr = tree( - covarianceSuite, parameterCovariances, --parameterCovariance, - --parameterCovarianceMatrix, array); - - THEN("Try extracting .../array/shape") { - // Extract shape into our shape type - // Specifically: myshape keyword ==> shape_t - auto shape = arr(myshape); - CHECK(shape.rows == 78); - CHECK(shape.cols == 78); - } - - THEN("Try extracting .../array/values") { - // Extract values into our values_t type, - // which is vector. - // Specifically: myshape keyword ==> shape_t - auto val = arr(--child::values,mynumbers); - CHECK(val[0] == 0.015); - CHECK(val[1] == 0); - CHECK(val[2] == 0); - CHECK(val[3] == 0); - CHECK(val[4] == 4.5e-5); - } - - } // WHEN - - - // ------------------------ - // Special keyword - // with lookup "" - // ------------------------ - - // Special keyword: mymanifest, a child keyword with lookup key "". - // Meaning: for the currently active Node, print its name, the names - // of its metadata, and the names of its children. This demonstrates - // how we could build various "x-ray" or "dictionary" type tools. - // See how manifest_t is set up, earlier in this file. - - // Examine the tree itself - WHEN("We use a special \"\"-named keyword to examine tree") { - auto man = tree(mymanifest); - CHECK(man.information == manifest_tree); - } - - // Let's look at what's in the top-level GNDS node. Note that top() - // gets us the top-level node here, from which we call (manifest); - // we do *not* write tree.top(manifest), which wouldn't make sense. - WHEN("We use a special \"\"-named keyword to examine tree.top()") { - auto man = tree.top()(mymanifest); - CHECK(man.information == manifest_covarianceSuite); - } - - // Of course we can do this as well, knowing that covarianceSuite - // is the top-level node - WHEN("We use a special \"\"-named keyword to examine ") { - auto man = tree(covarianceSuite, mymanifest); - CHECK(man.information == manifest_covarianceSuite); - } - - // And let's dig further: - WHEN("We use a special \"\"-named keyword to examine " - ".../") { - auto man = tree( - covarianceSuite, parameterCovariances, - --parameterCovariance, mymanifest - ); - CHECK(man.information == manifest_parameterCovariances); - } - - - // ------------------------ - // Exercise keyword - // builder... - // ------------------------ - - // To properly test this, we should really have something like the Boost - // demangle library, to print a representation of the *type* that's being - // created. For now, let's just make sure that the expressions are valid. - - // ------------------------ - // ...metadata, type - // ------------------------ - - { - { auto m = keyword.meta ("m" ); } - { auto m = keyword.meta ("m", 0 ); } - { auto m = keyword.meta ("m", 0, detail::convert_t{}); } - { auto m = keyword.meta< > ("m" ); } - { auto m = keyword.meta< > ("m", 0 ); } - { auto m = keyword.meta< > ("m", 0, detail::convert_t{}); } - { auto m = keyword.meta ("m" ); } - { auto m = keyword.meta ("m", 0 ); } - { auto m = keyword.meta ("m", 0, detail::convert_t{}); } - { auto m = keyword.meta ("m" ); } - { auto m = keyword.meta ("m", 0 ); } - { auto m = keyword.meta ("m", 0, detail::convert_t{}); } - } - - // ------------------------ - // ...metadata, void - // ------------------------ - - { - { auto m = keyword.meta ("m"); } - { auto m = keyword.meta< > ("m"); } - { auto m = keyword.meta ("m"); } - } - - // ------------------------ - // ...children, type - // ------------------------ - - // The commented-out cases are ambiguous: - // TYPE for , or FILTER for ? - { - { auto c = keyword.child ("c" ); } - // { auto c = keyword.child ("c", 0 ); } - { auto c = keyword.child ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - { auto c = keyword.child< > ("c" ); } - // { auto c = keyword.child< > ("c", 0 ); } - { auto c = keyword.child< > ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child< > ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child< > ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", 0 ); } - { auto c = keyword.child ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", 0 ); } - { auto c = keyword.child ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", 0 ); } - { auto c = keyword.child ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", 0 ); } - { auto c = keyword.child ("c", 0, detail::convert_t{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{} ); } - { auto c = keyword.child ("c", 0, detail::convert_t{}, detail::noFilter{}, false); } - } - - // ------------------------ - // ...children, void - // ------------------------ - - // The commented-out cases are ambiguous, as above. - { - { auto c = keyword.child ("c" ); } - // { auto c = keyword.child ("c", detail::noFilter{} ); } - { auto c = keyword.child ("c", detail::noFilter{}, false); } - { auto c = keyword.child< > ("c" ); } - // { auto c = keyword.child< > ("c", detail::noFilter{} ); } - { auto c = keyword.child< > ("c", detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", detail::noFilter{} ); } - { auto c = keyword.child ("c", detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", detail::noFilter{} ); } - { auto c = keyword.child ("c", detail::noFilter{}, false); } - { auto c = keyword.child ("c" ); } - { auto c = keyword.child ("c", detail::noFilter{} ); } - { auto c = keyword.child ("c", detail::noFilter{}, false); } - } -} diff --git a/src/GNDStk/misc.hpp b/src/GNDStk/misc.hpp deleted file mode 100644 index 68204de95..000000000 --- a/src/GNDStk/misc.hpp +++ /dev/null @@ -1,22 +0,0 @@ - -// ----------------------------------------------------------------------------- -// Set of miscellaneous Meta and Child objects. These are "miscellaneous" -// in the sense that some use , meaning they'll retrieve metadata and -// child nodes in their original form in the GNDS tree, while others stipulate -// specific types. We've split these out from other sets of Meta and Child -// objects because we may phase them out over time, to be replaced with ones -// that use various custom types, as GNDStk continues to develop. -// ----------------------------------------------------------------------------- - -#include "GNDStk/misc/src/detail.hpp" - -namespace misc { - -#include "GNDStk/misc/src/meta.hpp" -#include "GNDStk/misc/src/child.hpp" - -using namespace meta; -using namespace child; -// using namespace common; - -} // namespace misc diff --git a/src/GNDStk/misc/src/child.hpp b/src/GNDStk/misc/src/child.hpp deleted file mode 100644 index 60b31ea1c..000000000 --- a/src/GNDStk/misc/src/child.hpp +++ /dev/null @@ -1,338 +0,0 @@ - -namespace child { - -// ----------------------------------------------------------------------------- -// Allowable top-level nodes, per LLNL-TR-774621-DRAFT -// ----------------------------------------------------------------------------- - -// Note: the ~ (tilde) makes them allowed as top-level nodes -inline const auto - PoPs = ~Child("PoPs"); -inline const auto - reactionSuite = ~Child("reactionSuite"); -inline const auto - covarianceSuite = ~Child("covarianceSuite"); -inline const auto - thermalScattering = ~Child("thermalScattering"); -inline const auto - fissionFragmentData = ~Child("fissionFragmentData"); - - - -// ----------------------------------------------------------------------------- -// Child Objects -// ----------------------------------------------------------------------------- - -// ------------------------ -// one + many pair -// constructs -// ------------------------ - -GNDSTK_MAKE_CHILD(void, averageEnergies, one); -GNDSTK_MAKE_CHILD(void, averageEnergy, many); - -GNDSTK_MAKE_CHILD(void, axes, one); -GNDSTK_MAKE_CHILD(void, axis, many); - -GNDSTK_MAKE_CHILD(void, baryons, one); -GNDSTK_MAKE_CHILD(void, baryon, many); - -GNDSTK_MAKE_CHILD(void, channels, one); -GNDSTK_MAKE_CHILD(void, channel, many); - -GNDSTK_MAKE_CHILD(void, chemicalElements, one); -GNDSTK_MAKE_CHILD(void, chemicalElement, many); - -GNDSTK_MAKE_CHILD(void, configurations, one); -GNDSTK_MAKE_CHILD(void, configuration, many); - -GNDSTK_MAKE_CHILD(void, decayModes, one); -GNDSTK_MAKE_CHILD(void, decayMode, many); - -GNDSTK_MAKE_CHILD(void, durations, one); -GNDSTK_MAKE_CHILD(void, duration, many); - -GNDSTK_MAKE_CHILD(void, externalFiles, one); -GNDSTK_MAKE_CHILD(void, externalFile, many); - -GNDSTK_MAKE_CHILD(void, fissionComponents, one); -GNDSTK_MAKE_CHILD(void, fissionComponent, many); - -GNDSTK_MAKE_CHILD(void, gaugeBosons, one); -GNDSTK_MAKE_CHILD(void, gaugeBoson, many); - -GNDSTK_MAKE_CHILD(void, isotopes, one); -GNDSTK_MAKE_CHILD(void, isotope, many); - -GNDSTK_MAKE_CHILD(void, Js, one); -GNDSTK_MAKE_CHILD(void, J, many); - -GNDSTK_MAKE_CHILD(void, leptons, one); -GNDSTK_MAKE_CHILD(void, lepton, many); - -GNDSTK_MAKE_CHILD(void, nuclides, one); -GNDSTK_MAKE_CHILD(void, nuclide, many); - -GNDSTK_MAKE_CHILD(void, productions, one); -// The GNDS manual says: -// production: [optional, must appear one time] -// but we think that that's wrong. It actually does appear more than once -// in some parent nodes in some GNDS files. We think the manual makes the -// same mistake at least two more times - with and . -// Both sometimes appear multiple times under a single parent in some GNDS -// files, but the manual says "must appear one time" for both. (The manual -// says "must appear at least one time" elsewhere, for things that can -// appear multiple times under a single parent.) -GNDSTK_MAKE_CHILD(void, production, many); - -GNDSTK_MAKE_CHILD(void, products, one); -GNDSTK_MAKE_CHILD(void, product, many); - -GNDSTK_MAKE_CHILD(void, productYields, one); -GNDSTK_MAKE_CHILD(void, productYield, many); - -GNDSTK_MAKE_CHILD(void, reactions, one); -GNDSTK_MAKE_CHILD(void, reaction, many); - -GNDSTK_MAKE_CHILD(void, resonanceReactions, one); -GNDSTK_MAKE_CHILD(void, resonanceReaction, many); - -GNDSTK_MAKE_CHILD(void, scatteringAtoms, one); -GNDSTK_MAKE_CHILD(void, scatteringAtom, many); - -GNDSTK_MAKE_CHILD(void, spectra, one); -GNDSTK_MAKE_CHILD(void, spectrum, many); - -GNDSTK_MAKE_CHILD(void, spinGroups, one); -GNDSTK_MAKE_CHILD(void, spinGroup, many); - -GNDSTK_MAKE_CHILD(void, widths, one); -GNDSTK_MAKE_CHILD(void, width, many); - -GNDSTK_MAKE_CHILD(void, sums, one); -GNDSTK_MAKE_CHILD(void, sum, many); - -GNDSTK_MAKE_CHILD(void, Ls, one); -GNDSTK_MAKE_CHILD(void, L, many); - -GNDSTK_MAKE_CHILD(void, summands, one); -GNDSTK_MAKE_CHILD(void, summand, many); - - -// ------------------------ -// Others, not paired -// as above -// ------------------------ - -// fixme -// Do more sorting/categorization -// Some may actually be singular/plural pairs - -// Allow::one cases -GNDSTK_MAKE_CHILD(void, aliases, one); -GNDSTK_MAKE_CHILD(void, angular, one); -GNDSTK_MAKE_CHILD(void, angularEnergy, one); -GNDSTK_MAKE_CHILD(void, angularTwoBody, one); -GNDSTK_MAKE_CHILD(void, applicationData, one); -GNDSTK_MAKE_CHILD(void, array, one); -GNDSTK_MAKE_CHILD(void, atomic, one); -GNDSTK_MAKE_CHILD(void, averageProductEnergy, one); -GNDSTK_MAKE_CHILD(void, background, one); -GNDSTK_MAKE_CHILD(void, bindingEnergy, one); -GNDSTK_MAKE_CHILD(void, branching1d, one); -GNDSTK_MAKE_CHILD(void, branching3d, one); -GNDSTK_MAKE_CHILD(void, BreitWigner, one); -GNDSTK_MAKE_CHILD(void, characteristicCrossSection, one); -GNDSTK_MAKE_CHILD(void, charge, one); -GNDSTK_MAKE_CHILD(void, coherentElastic, one); -GNDSTK_MAKE_CHILD(void, coherentPhotonScattering, one); -GNDSTK_MAKE_CHILD(void, columnData, one); -GNDSTK_MAKE_CHILD(void, columnHeaders, one); -GNDSTK_MAKE_CHILD(void, constant1d, one); -GNDSTK_MAKE_CHILD(void, continuum, one); -GNDSTK_MAKE_CHILD(void, CoulombPlusNuclearElastic, one); -GNDSTK_MAKE_CHILD(void, covarianceSections, one); -GNDSTK_MAKE_CHILD(void, crossSection, one); -GNDSTK_MAKE_CHILD(void, crossSections, one); -GNDSTK_MAKE_CHILD(void, cutoffEnergy, one); -GNDSTK_MAKE_CHILD(void, data, one); -GNDSTK_MAKE_CHILD(void, DebyeWaller, one); -GNDSTK_MAKE_CHILD(void, decayData, one); -GNDSTK_MAKE_CHILD(void, decayPath, one); -GNDSTK_MAKE_CHILD(void, delayedBetaEnergy, one); -GNDSTK_MAKE_CHILD(void, delayedGammaEnergy, one); -GNDSTK_MAKE_CHILD(void, delayedNeutronKE, one); -GNDSTK_MAKE_CHILD(void, discreteGamma, one); -GNDSTK_MAKE_CHILD(void, distribution, one); -GNDSTK_MAKE_CHILD(void, documentation, one); -GNDSTK_MAKE_CHILD(void, documentations, one); -GNDSTK_MAKE_CHILD(void, doubleDifferentialCrossSection, one); -GNDSTK_MAKE_CHILD(void, e_critical, one); -GNDSTK_MAKE_CHILD(void, EFH, one); -GNDSTK_MAKE_CHILD(void, EFL, one); -GNDSTK_MAKE_CHILD(void, e_max, one); -GNDSTK_MAKE_CHILD(void, ENDFconversionFlags, one); -GNDSTK_MAKE_CHILD(void, energy, one); -GNDSTK_MAKE_CHILD(void, energyAngular, one); -GNDSTK_MAKE_CHILD(void, evaporation, one); -GNDSTK_MAKE_CHILD(void, f, one); -GNDSTK_MAKE_CHILD(void, fastRegion, one); -GNDSTK_MAKE_CHILD(void, fissionEnergyReleased, one); -GNDSTK_MAKE_CHILD(void, freeAtomCrossSection, one); -GNDSTK_MAKE_CHILD(void, g, one); -GNDSTK_MAKE_CHILD(void, generalEvaporation, one); -GNDSTK_MAKE_CHILD(void, gridded2d, one); -GNDSTK_MAKE_CHILD(void, gridded3d, one); -GNDSTK_MAKE_CHILD(void, halflife, one); -GNDSTK_MAKE_CHILD(void, hardSphereRadius, one); -GNDSTK_MAKE_CHILD(void, imaginaryAnomalousFactor, one); -GNDSTK_MAKE_CHILD(void, imaginaryInterferenceTerm, one); -GNDSTK_MAKE_CHILD(void, incoherentElastic, one); -GNDSTK_MAKE_CHILD(void, incoherentInelastic, one); -GNDSTK_MAKE_CHILD(void, incoherentPhotonScattering, one); -GNDSTK_MAKE_CHILD(void, incompleteReactions, one); -GNDSTK_MAKE_CHILD(void, institution, one); -GNDSTK_MAKE_CHILD(void, intensity, one); -GNDSTK_MAKE_CHILD(void, internalConversionCoefficients, one); -GNDSTK_MAKE_CHILD(void, internalPairFormationCoefficient, one); -GNDSTK_MAKE_CHILD(void, isotropic2d, one); -GNDSTK_MAKE_CHILD(void, KalbachMann, one); -GNDSTK_MAKE_CHILD(void, levelSpacing, one); -GNDSTK_MAKE_CHILD(void, link, one); -GNDSTK_MAKE_CHILD(void, listOfCovariances, one); -GNDSTK_MAKE_CHILD(void, MadlandNix, one); -GNDSTK_MAKE_CHILD(void, mass, one); -GNDSTK_MAKE_CHILD(void, mixed, one); -GNDSTK_MAKE_CHILD(void, multiplicities, one); -GNDSTK_MAKE_CHILD(void, multiplicity, one); -GNDSTK_MAKE_CHILD(void, NBodyPhaseSpace, one); -GNDSTK_MAKE_CHILD(void, neutrinoEnergy, one); -GNDSTK_MAKE_CHILD(void, nonNeutrinoEnergy, one); -GNDSTK_MAKE_CHILD(void, nuclearAmplitudeExpansion, one); -GNDSTK_MAKE_CHILD(void, nuclearPlusInterference, one); -GNDSTK_MAKE_CHILD(void, nuclearTerm, one); -GNDSTK_MAKE_CHILD(void, nucleus, one); -GNDSTK_MAKE_CHILD(void, orphanProducts, one); -GNDSTK_MAKE_CHILD(void, outputChannel, one); -GNDSTK_MAKE_CHILD(void, parameterCovariances, one); -GNDSTK_MAKE_CHILD(void, parameters, one); -GNDSTK_MAKE_CHILD(void, parity, one); -GNDSTK_MAKE_CHILD(void, photonEmissionProbabilities, one); -GNDSTK_MAKE_CHILD(void, pids, one); -GNDSTK_MAKE_CHILD(void, polynomial1d, one); -GNDSTK_MAKE_CHILD(void, positronEmissionIntensity, one); -GNDSTK_MAKE_CHILD(void, primaryGamma, one); -GNDSTK_MAKE_CHILD(void, probability, one); -GNDSTK_MAKE_CHILD(void, projectileEnergyDomain, one); -GNDSTK_MAKE_CHILD(void, promptGammaEnergy, one); -GNDSTK_MAKE_CHILD(void, promptNeutronKE, one); -GNDSTK_MAKE_CHILD(void, promptProductKE, one); -GNDSTK_MAKE_CHILD(void, Q, one); -GNDSTK_MAKE_CHILD(void, r, one); -GNDSTK_MAKE_CHILD(void, realAnomalousFactor, one); -GNDSTK_MAKE_CHILD(void, realInterferenceTerm, one); -GNDSTK_MAKE_CHILD(void, recoil, one); -GNDSTK_MAKE_CHILD(void, reference, one); -GNDSTK_MAKE_CHILD(void, regions2d, one); -GNDSTK_MAKE_CHILD(void, resolved, one); -GNDSTK_MAKE_CHILD(void, resolvedRegion, one); -GNDSTK_MAKE_CHILD(void, resonanceParameters, one); -GNDSTK_MAKE_CHILD(void, resonances, one); -GNDSTK_MAKE_CHILD(void, resonancesWithBackground, one); -GNDSTK_MAKE_CHILD(void, RMatrix, one); -GNDSTK_MAKE_CHILD(void, rowData, one); -GNDSTK_MAKE_CHILD(void, RutherfordScattering, one); -GNDSTK_MAKE_CHILD(void, S_alpha_beta, one); -GNDSTK_MAKE_CHILD(void, scatteringFactor, one); -GNDSTK_MAKE_CHILD(void, scatteringRadius, one); -GNDSTK_MAKE_CHILD(void, simpleMaxwellianFission, one); -GNDSTK_MAKE_CHILD(void, spin, one); -GNDSTK_MAKE_CHILD(void, S_table, one); -GNDSTK_MAKE_CHILD(void, standard, one); -GNDSTK_MAKE_CHILD(void, string, one); -GNDSTK_MAKE_CHILD(void, styles, one); -GNDSTK_MAKE_CHILD(void, table, one); -GNDSTK_MAKE_CHILD(void, tabulatedWidths, one); -GNDSTK_MAKE_CHILD(void, T_effective, one); -GNDSTK_MAKE_CHILD(void, temperature, one); -GNDSTK_MAKE_CHILD(void, theta, one); -GNDSTK_MAKE_CHILD(void, time, one); -GNDSTK_MAKE_CHILD(void, T_M, one); -GNDSTK_MAKE_CHILD(void, totalEnergy, one); -GNDSTK_MAKE_CHILD(void, U, one); -GNDSTK_MAKE_CHILD(void, uncertainty, one); -GNDSTK_MAKE_CHILD(void, uncorrelated, one); -GNDSTK_MAKE_CHILD(void, unresolved, one); -GNDSTK_MAKE_CHILD(void, unresolvedRegion, one); -GNDSTK_MAKE_CHILD(void, unspecified, one); -GNDSTK_MAKE_CHILD(void, weightedFunctionals, one); -GNDSTK_MAKE_CHILD(void, xml, one); -GNDSTK_MAKE_CHILD(void, yields, one); - -// Allow::many cases -GNDSTK_MAKE_CHILD(void, add, many); -GNDSTK_MAKE_CHILD(void, averageParameterCovariance, many); -GNDSTK_MAKE_CHILD(void, column, many); -GNDSTK_MAKE_CHILD(void, conversion, many); -GNDSTK_MAKE_CHILD(void, covariance, many); -GNDSTK_MAKE_CHILD(void, covarianceMatrix, many); -GNDSTK_MAKE_CHILD(void, crossSectionReconstructed, many); -GNDSTK_MAKE_CHILD(void, crossSectionSum, many); -GNDSTK_MAKE_CHILD(void, decay, many); -GNDSTK_MAKE_CHILD(void, discrete, many); -GNDSTK_MAKE_CHILD(void, evaluated, many); -GNDSTK_MAKE_CHILD(void, fraction, many); -GNDSTK_MAKE_CHILD(void, grid, many); -GNDSTK_MAKE_CHILD(void, integer, many); -GNDSTK_MAKE_CHILD(void, Legendre, many); -GNDSTK_MAKE_CHILD(void, metaStable, many); -GNDSTK_MAKE_CHILD(void, multiplicitySum, many); -GNDSTK_MAKE_CHILD(void, parameterCovariance, many); -GNDSTK_MAKE_CHILD(void, parameterCovarianceMatrix, many); -GNDSTK_MAKE_CHILD(void, parameterLink, many); -GNDSTK_MAKE_CHILD(void, regions1d, many); -GNDSTK_MAKE_CHILD(void, section, many); -GNDSTK_MAKE_CHILD(void, shell, many); -GNDSTK_MAKE_CHILD(void, shortRangeSelfScalingVariance, many); -GNDSTK_MAKE_CHILD(void, values, many); -GNDSTK_MAKE_CHILD(void, weighted, many); -GNDSTK_MAKE_CHILD(void, XYs1d, many); -GNDSTK_MAKE_CHILD(void, XYs2d, many); -GNDSTK_MAKE_CHILD(void, XYs3d, many); - - - -// ----------------------------------------------------------------------------- -// Some special cases -// ----------------------------------------------------------------------------- - -// Double -// Not called double, for obvious reasons. -inline const Child Double("double"); - -// cdata, comment -// These are where XML or (comment) material -// resides. It's reasonable to extract such content into std::strings. We -// then store these as nodes of those respective names, each with one metadatum -// having a key of "text" and a value containing the original content. -inline const Child - cdata("cdata"); -inline const Child - comment("comment"); - -// pcdata -// These are where data appearing in constructs like this: -// 1.2 3.4 5.6 7.8 9.0 -// reside. In that case, our internal tree structure would have a node named -// "values", which would have a child node named "pcdata", which would have a -// metadatum with a key of "text" and a value containing the original content: -// the "1.2 ..." in the above example. Our examination of many GNDS files shows -// that some pcdata nodes contain integers, while others contain doubles. We -// therefore define pcdata as a Child with , so that we can access it -// in its original form and thus dig further down to its "text" metadatum, at -// which point we can decide elsewhere what's appropriate for that. (Read into -// a vector of ints? A vector of doubles? Something else?) -inline const Child - pcdata("pcdata"); - -} // namespace child diff --git a/src/GNDStk/misc/src/detail.hpp b/src/GNDStk/misc/src/detail.hpp deleted file mode 100644 index 44c5e34e0..000000000 --- a/src/GNDStk/misc/src/detail.hpp +++ /dev/null @@ -1,15 +0,0 @@ - -namespace detail { - -// text_metadatum_to_string -// Helper for cdata and comment -class text_metadatum_to_string { -public: - template - void operator()(const NODE &node, std::string &to) const - { - to = node.meta("text"); - } -}; - -} // namespace detail diff --git a/src/GNDStk/misc/src/meta.hpp b/src/GNDStk/misc/src/meta.hpp deleted file mode 100644 index 99004b9cc..000000000 --- a/src/GNDStk/misc/src/meta.hpp +++ /dev/null @@ -1,142 +0,0 @@ - -namespace meta { - -// ----------------------------------------------------------------------------- -// Meta Objects -// ----------------------------------------------------------------------------- - -// bool -GNDSTK_MAKE_META(bool, calculateChannelRadius); -GNDSTK_MAKE_META(bool, calculatedAtThermal); -GNDSTK_MAKE_META(bool, calculatePenetrability); -GNDSTK_MAKE_META(bool, identicalParticles); -GNDSTK_MAKE_META(bool, supportsAngularReconstruction); -GNDSTK_MAKE_META(bool, useForSelfShieldingOnly); -GNDSTK_MAKE_META(bool, complete); - -// int -GNDSTK_MAKE_META(int, A); -GNDSTK_MAKE_META(int, columnIndex); -GNDSTK_MAKE_META(int, columns); -GNDSTK_MAKE_META(int, ENDF_MT); -GNDSTK_MAKE_META(int, index); -GNDSTK_MAKE_META(int, L); -GNDSTK_MAKE_META(int, lowerIndex); -GNDSTK_MAKE_META(int, MAT); -GNDSTK_MAKE_META(int, matrixStartIndex); -GNDSTK_MAKE_META(int, metaStableIndex); -GNDSTK_MAKE_META(int, nParameters); -GNDSTK_MAKE_META(int, numberOfProducts); -GNDSTK_MAKE_META(int, numberPerMolecule); -GNDSTK_MAKE_META(int, parity); -GNDSTK_MAKE_META(int, rows); -GNDSTK_MAKE_META(int, Z); - -// double -GNDSTK_MAKE_META(double, coefficient); -GNDSTK_MAKE_META(double, domainMax); -GNDSTK_MAKE_META(double, domainMin); -GNDSTK_MAKE_META(double, electronNumber); -GNDSTK_MAKE_META(double, format); -GNDSTK_MAKE_META(double, max); -GNDSTK_MAKE_META(double, min); -GNDSTK_MAKE_META(double, muCutoff); - -// string -GNDSTK_MAKE_META(std::string, approximation); -GNDSTK_MAKE_META(std::string, asymmetric); -GNDSTK_MAKE_META(std::string, boundaryCondition); -GNDSTK_MAKE_META(std::string, compression); -GNDSTK_MAKE_META(std::string, crossTerm); -GNDSTK_MAKE_META(std::string, dependenceOnProcessedGroupWidth); -GNDSTK_MAKE_META(std::string, derivedFrom); -GNDSTK_MAKE_META(std::string, domainUnit); -GNDSTK_MAKE_META(std::string, ejectile); -GNDSTK_MAKE_META(std::string, eliminated); -GNDSTK_MAKE_META(std::string, emissionMode); -GNDSTK_MAKE_META(std::string, encoding); -GNDSTK_MAKE_META(std::string, ENDF_MFMT); -GNDSTK_MAKE_META(std::string, evaluation); -GNDSTK_MAKE_META(std::string, final); // is a C++ *contextual* keyword; so OK -GNDSTK_MAKE_META(std::string, fissionGenre); -GNDSTK_MAKE_META(std::string, flags); -GNDSTK_MAKE_META(std::string, functionalForm); -GNDSTK_MAKE_META(std::string, generation); -GNDSTK_MAKE_META(std::string, genre); -GNDSTK_MAKE_META(std::string, href); -GNDSTK_MAKE_META(std::string, id); -GNDSTK_MAKE_META(std::string, initial); -GNDSTK_MAKE_META(std::string, interpolation); -GNDSTK_MAKE_META(std::string, interpolationQualifier); -GNDSTK_MAKE_META(std::string, label); -GNDSTK_MAKE_META(std::string, library); -GNDSTK_MAKE_META(std::string, material); -GNDSTK_MAKE_META(std::string, mode); -GNDSTK_MAKE_META(std::string, name); -GNDSTK_MAKE_META(std::string, path); -GNDSTK_MAKE_META(std::string, pid); -GNDSTK_MAKE_META(std::string, process); -GNDSTK_MAKE_META(std::string, productFrame); -GNDSTK_MAKE_META(std::string, projectile); -GNDSTK_MAKE_META(std::string, projectileFrame); -GNDSTK_MAKE_META(std::string, resonanceReaction); -GNDSTK_MAKE_META(std::string, shape); -GNDSTK_MAKE_META(std::string, style); -GNDSTK_MAKE_META(std::string, subshell); -GNDSTK_MAKE_META(std::string, symbol); -GNDSTK_MAKE_META(std::string, symmetry); -GNDSTK_MAKE_META(std::string, target); -GNDSTK_MAKE_META(std::string, type); -GNDSTK_MAKE_META(std::string, unit); -GNDSTK_MAKE_META(std::string, version); -GNDSTK_MAKE_META(std::string, valueType); -GNDSTK_MAKE_META(std::string, date); -GNDSTK_MAKE_META(std::string, decayRate); // always has double and "1/s"? - - - -// ----------------------------------------------------------------------------- -// Meta Objects -// Special cases -// ----------------------------------------------------------------------------- - -// ------------------------ -// Variant cases; comma in -// variant<,> prevents use -// of the macro -// ------------------------ - -// constant -inline const Meta> -constant("constant"); - -// degreesOfFreedom -// I'd have expected an int for this, always, but some of the GNDS files have -// a non-integral double. Perhaps we could arrange to always read as a double. -inline const Meta> -degreesOfFreedom("degreesOfFreedom"); - -// value -inline const Meta> -value("value"); - -// [ids]value -// Shorthands for specific cases. -// Prefixes {i,d,s} mean {int,double,string}. -inline const Meta ivalue("value"); -inline const Meta dvalue("value"); -inline const Meta svalue("value"); - -// channelSpin -// This actually looks to me like it's always either an int, or some kind -// of fraction, so figure out something clever in place of variant. Perhaps -// a rational-number class? -inline const Meta> -channelSpin("channelSpin"); - -// spin -// Same remark as for channelSpin. -inline const Meta> -spin("spin"); - -} // namespace meta diff --git a/src/GNDStk/node2type.hpp b/src/GNDStk/node2type.hpp index 7ad32a1e5..d076caae2 100644 --- a/src/GNDStk/node2type.hpp +++ b/src/GNDStk/node2type.hpp @@ -22,10 +22,11 @@ to an istream prior to operator>>. // convert(Node,Node) // ----------------------------------------------------------------------------- -inline void convert(const Node &from, Node &to) +inline bool convert(const Node &from, Node &to) { try { to = from; + return true; } catch (...) { log::function("convert(Node,Node)"); throw; diff --git a/src/GNDStk/node2type/test/node2type.test.cpp b/src/GNDStk/node2type/test/node2type.test.cpp index 34f53e512..4d402d96d 100644 --- a/src/GNDStk/node2type/test/node2type.test.cpp +++ b/src/GNDStk/node2type/test/node2type.test.cpp @@ -3,6 +3,7 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; @@ -39,19 +40,20 @@ SCENARIO("Testing GNDStk convert(Node,type)") { WHEN("We make a Node foo with particular content") { Node foo("foo"); - // If a Node has a "text" metadatum, then the convert(Node,container) + // If a Node has a special::text metadatum, then the + // convert(Node,container) // function, where container is e.g. vector, will attempt to fill - // the container with the contents of the "text" metadatum's value. - foo.add("text","12 34 56 78 90"); + // the container with the contents of the special::text metadatum's value. + foo.add(special::text,"12 34 56 78 90"); // Update, 2020-10-19. The relevant convert() functionality has been - // reformulated into the detail::convert_pcdata_text_t callable object, + // reformulated into the detail::convert_data_text_t callable object, // so we'll reformulate with that. Ultimately, due to the location of // the new code, we should probably put this test material elsewhere. THEN("convert(foo,deque) extracts the content correctly") { std::deque container; - detail::convert_pcdata_text_t{}(foo,container); + detail::convert_data_text_t{}(foo,container); CHECK(container.size() == 5); CHECK(container[0] == 12); CHECK(container[1] == 34); @@ -62,7 +64,7 @@ SCENARIO("Testing GNDStk convert(Node,type)") { THEN("convert(foo,list) extracts the content correctly") { std::list container; - detail::convert_pcdata_text_t{}(foo,container); + detail::convert_data_text_t{}(foo,container); CHECK(container.size() == 5); auto iter = container.begin(); CHECK(*iter++ == 12); @@ -74,7 +76,7 @@ SCENARIO("Testing GNDStk convert(Node,type)") { THEN("convert(foo,vector) extracts the content correctly") { std::vector container; - detail::convert_pcdata_text_t{}(foo,container); + detail::convert_data_text_t{}(foo,container); CHECK(container.size() == 5); CHECK(container[0] == 12); CHECK(container[1] == 34); diff --git a/src/GNDStk/or.hpp b/src/GNDStk/or.hpp index abe2a4e51..1e24b511b 100644 --- a/src/GNDStk/or.hpp +++ b/src/GNDStk/or.hpp @@ -1,326 +1,147 @@ -// ----------------------------------------------------------------------------- -// fixme -// Material here should be rearranged at some point, to be consistent with the -// general NJOY21 source structure. For now, we're making it available quickly. -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// Helper classes: -// IsMeta -// IsChild -// IsMetaOrChild -// IsStringOrRegex -// for SFINAE. -// ----------------------------------------------------------------------------- - -namespace detail { - -// ------------------------ -// IsMeta -// ------------------------ - -// default -template -class IsMeta { -public: - static constexpr bool value = false; -}; - -// Meta -template -class IsMeta> { -public: - static constexpr bool value = true; -}; - - -// ------------------------ -// IsChild -// ------------------------ - -// default -template -class IsChild { -public: - static constexpr bool value = false; -}; - -// Child -template -class IsChild> { -public: - static constexpr bool value = true; -}; - - -// ------------------------ -// IsMetaOrChild -// ------------------------ - -template -class IsMetaOrChild { -public: - static constexpr bool value = IsMeta::value || IsChild::value; -}; - - -// ------------------------ -// IsStringOrRegex -// ------------------------ - -// default -template -class IsStringOrRegex { -public: - static constexpr bool value = false; -}; - -// string -template<> -class IsStringOrRegex { -public: - static constexpr bool value = true; - using type = std::string; -}; - -// char * -template<> -class IsStringOrRegex { -public: - static constexpr bool value = true; - using type = std::string; -}; - -// const char * -template<> -class IsStringOrRegex { -public: - static constexpr bool value = true; - using type = std::string; -}; - -// char[N] -template -class IsStringOrRegex { -public: - static constexpr bool value = true; - using type = std::string; -}; - -// regex -template<> -class IsStringOrRegex { -public: - static constexpr bool value = true; - using type = std::regex; -}; - - -// ------------------------ -// IsPairChildStringOrRegex -// ------------------------ - -// default -template -class IsPairChildStringOrRegex { -public: - static constexpr bool value = false; -}; - -// pair -template -class IsPairChildStringOrRegex> { -public: - static constexpr bool value = - IsChild::value && IsStringOrRegex::value; -}; - -} // namespace detail - - - -// ----------------------------------------------------------------------------- -// Helper functionality for std::tuple -// ----------------------------------------------------------------------------- - -namespace detail { - -// ------------------------ -// tupleAllButLast -// ------------------------ - -// These are adapted from: https://stackoverflow.com/questions/51810702 - -template -constexpr auto tupleAllButLastHelper( - const std::tuple &tup, - std::index_sequence -) { - return std::tuple(std::get(tup)...); -} - -template< - class... Args, - class = std::enable_if_t<(0 < sizeof...(Args))> -> -constexpr auto tupleAllButLast(const std::tuple &tup) -{ - return tupleAllButLastHelper( - tup, - std::make_index_sequence{} - ); -} - - -// ------------------------ -// tupleReplaceLast -// ------------------------ - -// Given a tuple with at least one element, make a new tuple that's mostly the -// same, except for a different last element, which can be of a different type. - -template< - class... Args, class RHS, - class = std::enable_if_t<(0 < sizeof...(Args))> -> -constexpr auto tupleReplaceLast(const std::tuple &tup, const RHS &rhs) -{ - return std::tuple_cat(tupleAllButLast(tup), std::tuple(rhs)); -} - -} // namespace detail +#include "GNDStk/or/src/detail.hpp" +/* +Discussion. + +KeyTuple is based mostly on std::tuple, but is specifically designed to help +GNDStk's multi-query system work smoothly. + +makeKeyTuple() can be understood in terms of the KEYS() function in a class +that derives from GNDStk::Component. Typically, a KEYS() function returns some +number of Meta and/or Child objects, |'d together with one of the operator| +overloads that we provide at the end of this file. However, a KEYS() function +can in fact return any of: + + - A KeyTuple (via operator| as described above). + - A single Meta object. + - A single Child object. + - A std::tuple<>. + +The first use is probably the most common, but all are allowed. The purpose of +makeKeyTuple() (which could be considered analogous to std::make_pair in C++) +is to take any of the above, and return an appropriately templated version of +KeyTuple, representing what KEYS() is asking for. Other functions can then be +defined uniformly in terms of KeyTuple only - not KeyTuple, Meta, etc. +*/ // ----------------------------------------------------------------------------- -// KeywordTup +// KeyTuple // ----------------------------------------------------------------------------- // default template -class KeywordTup { +class KeyTuple { public: std::tuple tup; + // last_t using last_t = - // Sans std::decay, const &ness can break detail::IsSomething<> traits. - // Note: sizeof...(Ks) >= 1 here, because we'll specialize the <> case + // Without std::decay, const &ness can break detail::IsSomething<> traits. + // Note: sizeof...(Ks) >= 1 here; we've specialized the KeyTuple<> case. std::decay_t(tup))>; - // KeywordTup(KeywordTup, RHS) + // KeyTuple(KeyTuple, RHS) template< class... LHS, class RHS, - // ensure Ks... == LHS... RHS + // require Ks... == LHS... RHS class = std::enable_if_t< - std::is_same_v< - std::tuple, - std::tuple - > + std::is_same_v, std::tuple> >, - // ensure RHS \in {Meta, Child, pair, string, regex} + // require RHS \in {Meta, Child, pair} class = std::enable_if_t< - detail::IsMetaOrChild::value || - detail::IsPairChildStringOrRegex::value + detail::IsMetaOrChild_v || + detail::IsPairChildStringOrRegex_v > > - KeywordTup(const KeywordTup &lhs, const RHS &rhs) : + KeyTuple(const KeyTuple &lhs, const RHS &rhs) : tup(std::tuple_cat(lhs.tup, std::tuple(rhs))) { } - // KeywordTup(tuple) - KeywordTup(const std::tuple &tup) : - tup(tup) - { } + // KeyTuple(tuple) + KeyTuple(const std::tuple &tup) : tup(tup) { } }; - // <> -// intentionally non-constructible template<> -class KeywordTup<> +class KeyTuple<> { - KeywordTup() = delete; - KeywordTup(const KeywordTup &) = delete; - KeywordTup(KeywordTup &&) = delete; +public: + std::tuple<> tup; + KeyTuple(const std::tuple<> &tup) : tup(tup) { } }; - -// just Meta +// for Meta template -class KeywordTup> { +class KeyTuple> { using M = Meta; public: std::tuple tup; - explicit KeywordTup(const M &m) : tup(m) { } + explicit KeyTuple(const M &m) : tup(m) { } }; - -// just Child +// for Child template -class KeywordTup> { +class KeyTuple> { using C = Child; public: std::tuple tup; - explicit KeywordTup(const C &c) : tup(c) { } + explicit KeyTuple(const C &c) : tup(c) { } }; - -// std::pair +// for std::pair template -class KeywordTup,std::string>> { +class KeyTuple,std::string>> { using CPAIR = std::pair,std::string>; public: using last_t = CPAIR; std::tuple tup; - explicit KeywordTup(const CPAIR &cpair) : tup(cpair) { } + explicit KeyTuple(const CPAIR &cpair) : tup(cpair) { } }; - -// std::pair +// for std::pair template -class KeywordTup,std::regex>> { +class KeyTuple,std::regex>> { using CPAIR = std::pair,std::regex>; public: using last_t = CPAIR; std::tuple tup; - explicit KeywordTup(const CPAIR &cpair) : tup(cpair) { } + explicit KeyTuple(const CPAIR &cpair) : tup(cpair) { } }; - // ----------------------------------------------------------------------------- -// toKeywordTup +// makeKeyTuple // ----------------------------------------------------------------------------- -// for std::tuple +// for KeyTuple template -constexpr auto toKeywordTup(const std::tuple &tup) +constexpr auto makeKeyTuple(const KeyTuple &keytup) { - return KeywordTup(tup); -} - -// for KeywordTup -template -constexpr auto toKeywordTup(const KeywordTup &kwds) -{ - return kwds; + return keytup; } // for Meta, Child, and pair -// Returns a 1-element KeywordTup made from the object +// Returns a 1-element KeyTuple made from the object template< class T, class = std::enable_if_t< - detail::IsMetaOrChild::value || - detail::IsPairChildStringOrRegex::value + detail::IsMetaOrChild_v || + detail::IsPairChildStringOrRegex_v > > -constexpr auto toKeywordTup(const T &obj) +constexpr auto makeKeyTuple(const T &obj) { - return KeywordTup(obj); + return KeyTuple(obj); } +// for std::tuple +template +constexpr auto makeKeyTuple(const std::tuple &tup) +{ + return KeyTuple(tup); +} // ----------------------------------------------------------------------------- @@ -332,56 +153,55 @@ constexpr auto toKeywordTup(const T &obj) CASES ------------------------ -Below, KeywordTup<...> doesn't include <>; at least one element must exist. - ------------------------------------------+------------------------------------ - CASE | RESULT ------------------------------------------+------------------------------------ -1. Meta/Child | Meta/Child | - a. Meta | Meta | KeywordTup - b. Meta | Child | KeywordTup - c. Child | Meta | KeywordTup - d. Child | Child | KeywordTup ------------------------------------------+------------------------------------ -2. Child | string/regex | - a. Child | string | KeywordTup> - b. Child | char * | KeywordTup> - c. Child | regex | KeywordTup> ------------------------------------------+------------------------------------ -3. KeywordTup<...> | Meta/Child | - a. KeywordTup<...> | Meta | KeywordTup<...,Meta> - b. KeywordTup<...> | Child | KeywordTup<...,Child> ------------------------------------------+------------------------------------ -4. KeywordTup<...,Child> | string/regex | - a. KeywordTup<...,Child> | string | KeywordTup<...,pair> - b. KeywordTup<...,Child> | char * | KeywordTup<...,pair> - c. KeywordTup<...,Child> | regex | KeywordTup<...,pair> ------------------------------------------+------------------------------------ +Below, KeyTuple<...> doesn't include <>; at least one element must exist. + +---------------------------------------+------------------------------------ + CASE | RESULT +---------------------------------------+------------------------------------ +1. Meta/Child | Meta/Child | + a. Meta | Meta | KeyTuple + b. Meta | Child | KeyTuple + c. Child | Meta | KeyTuple + d. Child | Child | KeyTuple +---------------------------------------+------------------------------------ +2. Child | string/regex | + a. Child | string | KeyTuple> + b. Child | char * | KeyTuple> + c. Child | regex | KeyTuple> +---------------------------------------+------------------------------------ +3. KeyTuple<...> | Meta/Child | + a. KeyTuple<...> | Meta | KeyTuple<...,Meta> + b. KeyTuple<...> | Child | KeyTuple<...,Child> +---------------------------------------+------------------------------------ +4. KeyTuple<...,Child> | string/regex | + a. KeyTuple<...,Child> | string | KeyTuple<...,pair> + b. KeyTuple<...,Child> | char * | KeyTuple<...,pair> + c. KeyTuple<...,Child> | regex | KeyTuple<...,pair> +---------------------------------------+------------------------------------ */ // ------------------------ -// Bootstrap KeywordTup<...> +// Bootstrap KeyTuple<...> // ------------------------ // 1. Meta/Child | Meta/Child -// ==> KeywordTup +// ==> KeyTuple template< class LHS, class RHS, - class = std::enable_if_t::value>, - class = std::enable_if_t::value> + class = std::enable_if_t>, + class = std::enable_if_t> > auto operator|( const LHS &lhs, // via SFINAE: Meta or Child const RHS &rhs // via SFINAE: Meta or Child ) { - log::debug("or #1: Meta/Child | Meta/Child"); - return KeywordTup(KeywordTup(lhs),rhs); + return KeyTuple(KeyTuple(lhs),rhs); } // 2. Child | string/regex -// ==> KeywordTup> +// ==> KeyTuple> template< class TYPE, Allow ALLOW, class CONVERTER, class FILTER, class RHS, class StringOrRegex = typename detail::IsStringOrRegex::type @@ -390,54 +210,50 @@ auto operator|( const Child &lhs, const RHS &rhs // via SFINAE: string (or char * etc.) or regex ) { - log::debug("or #2: Child | string/regex"); using LHS = Child; - return KeywordTup>( + return KeyTuple>( std::pair(lhs,StringOrRegex(rhs)) ); } - // ------------------------ -// Append to KeywordTup<...> +// Append to KeyTuple<...> // ------------------------ -// 3. KeywordTup<...> | Meta/Child -// ==> KeywordTup<..., Meta/Child> +// 3. KeyTuple<...> | Meta/Child +// ==> KeyTuple<..., Meta/Child> template< class... LHS, class RHS, - class = std::enable_if_t::value> + class = std::enable_if_t> > auto operator|( - const KeywordTup &lhs, + const KeyTuple &lhs, const RHS &rhs // via SFINAE: Meta or Child ) { - log::debug("or #3: KeywordTup<...> | Meta/Child"); - return KeywordTup(lhs,rhs); + return KeyTuple(lhs,rhs); } -// 4. KeywordTup<...,Child> | string/regex -// ==> KeywordTup<..., pair> +// 4. KeyTuple<...,Child> | string/regex +// ==> KeyTuple<..., pair> template< class... LHS, class RHS, class = std::enable_if_t< - detail::IsChild::last_t>::value + detail::IsChild::last_t>::value >, class StringOrRegex = typename detail::IsStringOrRegex::type > auto operator|( - const KeywordTup &lhs, - const RHS &rhs // via SFINAE: string (or char * etc.) or regex + const KeyTuple &lhs, + const RHS &rhs // via SFINAE: string or char array, or regex ) { - log::debug("or #4: KeywordTup<...,Child> | string/regex"); - return toKeywordTup( + return makeKeyTuple( detail::tupleReplaceLast( lhs.tup, std::make_pair( std::get(lhs.tup), - StringOrRegex(rhs) + StringOrRegex(rhs) // cast ensures char array ==> std::string ) ) ); diff --git a/src/GNDStk/or/src/detail.hpp b/src/GNDStk/or/src/detail.hpp new file mode 100644 index 000000000..1086ce250 --- /dev/null +++ b/src/GNDStk/or/src/detail.hpp @@ -0,0 +1,172 @@ + +namespace detail { + +// ----------------------------------------------------------------------------- +// Helper classes for SFINAE +// ----------------------------------------------------------------------------- + +// ------------------------ +// IsMeta +// ------------------------ + +// default +template +struct IsMeta { + static constexpr bool value = false; +}; + +// Meta +template +struct IsMeta> { + static constexpr bool value = true; +}; + + +// ------------------------ +// IsChild +// ------------------------ + +// default +template +struct IsChild { + static constexpr bool value = false; +}; + +// Child +template +struct IsChild> { + static constexpr bool value = true; +}; + + +// ------------------------ +// IsMetaOrChild +// ------------------------ + +template +struct IsMetaOrChild { + static constexpr bool value = IsMeta::value || IsChild::value; +}; + +// IsMetaOrChild_v +template +inline constexpr bool IsMetaOrChild_v = IsMetaOrChild::value; + + +// ------------------------ +// IsStringOrRegex +// ------------------------ + +// default +template +struct IsStringOrRegex { + static constexpr bool value = false; +}; + +// string +template<> +struct IsStringOrRegex { + static constexpr bool value = true; + using type = std::string; +}; + +// char * +template<> +struct IsStringOrRegex { + static constexpr bool value = true; + using type = std::string; +}; + +// const char * +template<> +struct IsStringOrRegex { + static constexpr bool value = true; + using type = std::string; +}; + +// char[N] +template +struct IsStringOrRegex { + static constexpr bool value = true; + using type = std::string; +}; + +// regex +template<> +struct IsStringOrRegex { + static constexpr bool value = true; + using type = std::regex; +}; + + +// ------------------------ +// IsPairChildStringOrRegex +// ------------------------ + +// default +template +struct IsPairChildStringOrRegex { + static constexpr bool value = false; +}; + +// pair +template +struct IsPairChildStringOrRegex> { + static constexpr bool value = + IsChild::value && IsStringOrRegex::value; +}; + +// IsPairChildStringOrRegex_v +template +inline constexpr bool IsPairChildStringOrRegex_v = + IsPairChildStringOrRegex::value; + + +// ----------------------------------------------------------------------------- +// Helper functionality for std::tuple +// ----------------------------------------------------------------------------- + +// ------------------------ +// tupleAllButLast +// ------------------------ + +// Adapted from: https://stackoverflow.com/questions/51810702 + +template +constexpr auto tupleAllButLastHelper( + const std::tuple &tup, + std::index_sequence +) { + return std::tuple(std::get(tup)...); +} + +template< + class... Args, + class = std::enable_if_t<(0 < sizeof...(Args))> +> +constexpr auto tupleAllButLast(const std::tuple &tup) +{ + return tupleAllButLastHelper( + tup, + std::make_index_sequence{} + ); +} + + +// ------------------------ +// tupleReplaceLast +// ------------------------ + +// Given a tuple with at least one element, make a new tuple that's mostly the +// same, except for a different last element, which can be of a different type. + +template< + class... Args, class RHS, + class = std::enable_if_t<(0 < sizeof...(Args))> +> +constexpr auto tupleReplaceLast(const std::tuple &tup, const RHS &rhs) +{ + return std::tuple_cat(tupleAllButLast(tup), std::tuple(rhs)); +} + +} // namespace detail diff --git a/src/GNDStk/precision.hpp b/src/GNDStk/precision.hpp index 72600a092..9dca03f2c 100644 --- a/src/GNDStk/precision.hpp +++ b/src/GNDStk/precision.hpp @@ -19,7 +19,7 @@ // reals: all of the above // in each of: // GNDStk::metadata:: -// GNDStk::data:: (in body text, i.e. XML "plain character data") +// GNDStk::data:: (in block data, i.e. XML "plain character data") // GNDStk:: // the last meaning for both metadata:: and data::. diff --git a/src/GNDStk/precision/src/detail.hpp b/src/GNDStk/precision/src/detail.hpp index e54a3148d..514cdec0e 100644 --- a/src/GNDStk/precision/src/detail.hpp +++ b/src/GNDStk/precision/src/detail.hpp @@ -8,26 +8,32 @@ namespace detail { // PrecisionContext enum class PrecisionContext { metadata, // for GNDStk metadata values - data, // for "body text", a.k.a. XML "plain character data" - general // for both of the above together + data, // for block data, a.k.a. XML "plain character data" + general // for both of the above }; // PrecisionType enum class PrecisionType { - // use formatting that's available through C++ input and output streams + // Use formatting that's available through C++ input and output streams. stream, - // use GNDStk's ability to use to_chars()/from_chars() if SFINAE detects - // that they're available in std:: with the C++ distro that's being used + + // For input, prefer using strtof(), strtod(), and strtold() (for float, + // double, and long double, respectively) over using an input stream. Our + // experience suggests that these are faster for reading big data vectors. + strto, + + // Use GNDStk's ability to use to_chars()/from_chars(), if conditional + // compilation and SFINAE indicate that they're available in std:: with + // the C++ distro that's being used. fixed, scientific, shortest }; - // ----------------------------------------------------------------------------- // Classes behind GNDStk's own floating-point manipulators. -// These match with our three custom PrecisionType values. +// These match with our to/from_chars()-related PrecisionType values. // ----------------------------------------------------------------------------- class Fixed { }; @@ -35,7 +41,6 @@ class Scientific { }; class Shortest { }; - // ----------------------------------------------------------------------------- // Precision class // ----------------------------------------------------------------------------- @@ -52,12 +57,12 @@ to produce a decimal representation of that number. What we plan to *do* with the decimal representation isn't relevant here. Perhaps we'll write it to std::cout, or to some other output stream. Perhaps we don't wish to do anything with it stream-wise, but instead plan to place -it into a GNDStk Tree. Here, now, we're concerned only with the process of -producing a decimal representation of the number. +it into a GNDStk Node in some form. Here, now, we're concerned only with the +process of producing a decimal representation of the number. Naturally, for the decimal representation, we'll use a std::string. -So: given a floating-point number, we want to produce a string. We already +So: given a floating-point number, we wish to produce a string. We already know that C++ provides more than one way to do this. A basic and reasonably flexible way is to begin with an output string stream (a std::ostringstream), use its operator<< to write the floating-point number, and then call the @@ -67,11 +72,11 @@ I/O manipulators. For example, oss << std::setprecision(10) << thenumber, where oss is the std::ostringstream. GNDStk provides that methodology. To do so, objects of the below Precision -class contain a std::ostringstream, the properties of which can be set in -the usual way: by calling << on the Precision object. Precision's operator<< -will pass on its arguments to the std::ostringstream, where those arguments -will be "stored," so to speak, for use whenever the std::ostringstream is -used for the output of a floating-point number. +class contain a std::ostringstream, the properties of which can be set by +calling << on the Precision object. Precision's operator<< passes on its +arguments to the std::ostringstream, where those arguments are "stored," so +to speak, in the std::ostringstream, to be used when the std::ostringstream +is used for writing a floating-point number. However, for the fun and profit of our users, we wish to provide something extra. Sufficiently recent C++-17 enabled compilers provide the to_chars() @@ -81,21 +86,20 @@ such representation. The round-trip guarantee essentially means that if we start with, say, a double-precision number (at the time of this writing, probably 64 bits in memory), use to_chars() to make a string, and then read the string with from_chars(), then we're guaranteed to recover exactly the -same 64 bits in memory - that is, precisely the same double we began with. +same 64 bits in memory - precisely the same double we began with. -Aside: the guarantee requires that from_chars(), not necessarily any old -string-to-floating-point process, be used to read back a string that was +Aside: the guarantee requires that from_chars(), not necessarily any string- +to-floating-point process, be used to read from a string that was earlier produced by to_chars(). Also, obviously, such a guarantee simply cannot be honored if different compilers, computing platforms, or floating-point sizes are used for to_chars() versus from_chars(). Under those circumstances, no -algorithm in the universe could make the guarantee. +algorithm in the universe could make the "round-trip" guarantee. The above discussion speaks in terms of output: operator<<, std::ostringstream, -etc. Our Precision class, below, handles *input* just as fully. +etc. Our Precision class, below, handles *input* in the analogous manner. */ - // ----------------------------------------------------------------------------- // Precision // Set properties for: in the given context, the given floating-point type. @@ -106,13 +110,14 @@ class Precision { // The following hold properties that can be set by using operator<< and // operator>>. The properties might or might not be used when writing or - // reading floating-point numbers, depending on the *type flags below. + // reading floating-point numbers; that depends on the *type flags below. static std::ostringstream oss; static std::istringstream iss; // The value of the following determines whether the above *stringstreams // will be used when writing or reading floating-point numbers, or whether - // to_chars() and from_chars() will be used instead. + // to_chars() and from_chars() will be used instead, or perhaps (for input) + // whether the strto*() family of functions are used. static PrecisionType otype; static PrecisionType itype; @@ -133,8 +138,9 @@ class Precision { // so that the token [chars_format] (which is used in both the SFINAE and // in the function body itself) doesn't even make sense to the compiler. // Perhaps we can find a way around this. For now, given that we don't want - // to_chars() and from_chars() to be GNDStk's default at this time, we'll - // use an #ifdef to remove this code altogether unless someone wants it. + // to_chars() and from_chars() to be GNDStk's default at this time (they're + // slower, and they require a later-model compiler than our users may have), + // we'll use an #ifdef to remove this code unless someone asks for it. template< class T, @@ -149,30 +155,36 @@ class Precision { std::to_chars_result >> > - bool write(const T &value, std::string &str, int) + bool write(const T &value, std::string &str, int) const { - // todo: Use a T-dependent sufficient size + // todo: compute a T-dependent sufficient size std::string chars(100,'\0'); // todo: check to_chars' return value - if (otype == PrecisionType::fixed) + if (otype == PrecisionType::fixed) { + // fixed std::to_chars(chars.data(), chars.data() + chars.size(), value, std::chars_format::fixed); - else if (otype == PrecisionType::scientific) + } else if (otype == PrecisionType::scientific) { + // scientific std::to_chars(chars.data(), chars.data() + chars.size(), value, std::chars_format::scientific); - else + } else { + // shortest std::to_chars(chars.data(), chars.data() + chars.size(), value); + } - str = chars.data(); // ensure output std::string stops at \0 + str = chars.data(); // ensure output std::string stops at the first \0 return true; } #endif template - bool write(const T &, std::string &, double) + bool write(const T &, std::string &, double) const { - // tell the caller that floating-point to_chars() isn't available + // Tell the caller that floating-point to_chars() isn't available. + // In this case the "write to string" didn't happen here, and MUST + // instead be done by the caller. return false; } @@ -184,11 +196,11 @@ class Precision { // SFINAE test call. Using T{}, as we did in write(), but here for the (NON- // const &) from_chars() parameter, would in normal circumstances be a C++ // error (rvalue passed to non-const lvalue reference). Here, the attempt to - // do so would make the SFINAE fail always, defeating its purpose. + // do so would instead make the SFINAE fail always, defeating its purpose. #ifdef GNDSTK_PRECISION template - auto read(const std::string &str, T &value, int) -> + auto read(const std::string &str, T &value, int) const -> std::enable_if_t< std::is_same_v< decltype(std::from_chars((char*)0, (char*)0, value)), @@ -198,7 +210,8 @@ class Precision { > { // Provide a clean slate for from_chars(), which skips white space - // but doesn't like '+'. So we'll skip the white space, AND any '+'. + // but doesn't like '+'. So we'll skip the white space ourselves, + // and then skip any '+' as well. const char *first = str.data(); while (isspace(*first)) first++; @@ -211,57 +224,264 @@ class Precision { #endif template - bool read(const std::string &, T &, double) + bool read(const std::string &, T &, double) const { - // tell the caller that floating-point from_chars() isn't available + // Tell the caller that floating-point from_chars() isn't available. + // In this case the "read from string" didn't happen here, and MUST + // instead be done by the caller. return false; } public: // ------------------------ - // write + // write single value // ------------------------ - std::string write(const REAL &value) + // The value's std::string representation is returned + std::string write(const REAL &value) const { - if (otype != PrecisionType::stream) { - // Use std::to_chars() for REAL, if it exists; - // else fall through and use the ostringstream + // N.B.: the two code blocks below can't be reordered, + // because of the potential fall-through. + + // CASE: fixed, scientific, shortest + if ( + otype == PrecisionType::fixed || + otype == PrecisionType::scientific || + otype == PrecisionType::shortest + ) { + // Use std::to_chars(), if it exists for REAL; + // otherwise, FALL THROUGH and use the ostringstream. std::string str; if (write(value,str,0)) return str; } - // Use the ostringstream - oss.str(""); - oss.clear(); - oss << value; + // CASE: strto, stream + // Use the ostringstream. Note that here, in write(), the PrecisionType:: + // strto case arrives here - in the PrecisionType::stream case - because + // strto does something special only for *input*. See the read()s, below. + oss.clear(); // <== clear any existing error flags + oss.str(""); // <== clear any previously printed value + oss << value; // with whatever properties oss happens to have right now return oss.str(); } // ------------------------ - // read + // read single value // ------------------------ - REAL read(const std::string &str) + // The value (as obtained from the std::string) is returned + REAL read(const std::string &str) const { - REAL value = REAL(0); + // CASE: strto + // One would probably use the strto*() functions for speed, relative + // to the other options. In that spirit, check for this case first. + if (itype == PrecisionType::strto) { + if constexpr (std::is_same_v) + return strtof (str.data(), nullptr); + if constexpr (std::is_same_v) + return strtod (str.data(), nullptr); + if constexpr (std::is_same_v) + return strtold(str.data(), nullptr); + } + + REAL value; - if (itype != PrecisionType::stream) { - // Use std::from_chars() for REAL, if it exists; - // else fall through and use the istringstream + // CASE: fixed, scientific, shortest + if ( + itype == PrecisionType::fixed || + itype == PrecisionType::scientific || + itype == PrecisionType::shortest + ) { + // Use std::from_chars(), if it exists for REAL; + // otherwise, FALL THROUGH and use the istringstream. if (read(str,value,0)) return value; } + // CASE: stream // Use the istringstream - iss.str(str); - iss.clear(); - iss >> value; + iss.clear(); // <== clear any existing error flags + iss.str(str); // <== set str as the brand-new input string + iss >> value; // with whatever properties iss happens to have right now return value; } + // ------------------------ + // read vector of values: + // private OpenMP version + // ------------------------ + +private: + +#ifdef _OPENMP + bool readOpenMP(const std::string &str, std::vector &vec) const + { + // Number of threads. + // If there's just *one* thread, then we certainly won't bother with the + // overhead of using OpenMP. Instead, we'll return to the serial read(). + const int nthreads = detail::get_nthreads(); + if (nthreads == 1) + return false; + + // String size. + const std::size_t size = str.size(); + + // Assume, as a approximation that probably isn't too terrible, that the + // printed floating-point numbers in the input string average around some + // number nchars of characters in length, including separating whitespace. + // Compute a rough estimate of how many floating-points are in the string. + // If that value is less than some minimum threshold, then don't deal with + // OpenMP's overhead, and instead return to the serial read(). + // todo: It might be worth factoring float vs. double vs. long double into + // this computation. It also might be worth considering the actual number + // of threads, as computed above - and possibly, in borderline situations, + // reducing the number of threads but still using more than just one. + static const std::size_t NCHARS = 10, MINFLOATS = 200; + if (size/NCHARS < MINFLOATS) + return false; + + // Compute an approximate splitting of the input string into substrings, + // each to be handled by a different thread. + std::vector loc; + loc.reserve(nthreads+1); + for (int t = 0; t < nthreads; ++t) + loc.push_back(&str[t*(size/nthreads)]); + loc.push_back(&str[size]); // <== simplifies some logic below + + // Refine the approximate splitting so that borders occur at whitespace; + // specifically, at the beginnings of runs of whitespace. + for (int t = 1; t < nthreads; ++t) { + while (loc[t-1] < loc[t] && !isspace(*(loc[t] ))) loc[t]--; + while (loc[t-1] < loc[t] && isspace(*(loc[t]-1))) loc[t]--; + } + + // Set number of threads + detail::set_nthreads(nthreads); + std::vector> subvec(nthreads); + + // CASE: strto + if (itype == PrecisionType::strto) { + if constexpr (std::is_floating_point_v) { + #pragma omp parallel + { + const int t = detail::this_thread(); + char *end = (char *)loc[t]; + REAL element; + + for (const char *begin = end; end < loc[t+1]; begin = end+1) { + if constexpr (std::is_same_v) + if (element = strtof (begin,&end), end <= begin) break; + if constexpr (std::is_same_v) + if (element = strtod (begin,&end), end <= begin) break; + if constexpr (std::is_same_v) + if (element = strtold(begin,&end), end <= begin) break; + subvec[t].push_back(element); + } + } + + // Splice the per-thread vectors; then we're done. Note that we + // begin with total[size] = vec.size(), not 0, below, to compute + // the necessary reserve. The caller may or may not have been told, + // by *its* caller, to clear the vector. Either cleared, or not + // cleared, is perfectly allowable. + std::size_t total = vec.size(); + for (int t = 0; t < nthreads; ++t) + total += subvec[t].size(); + vec.reserve(total); + for (int t = 0; t < nthreads; ++t) + vec.insert(vec.end(), subvec[t].begin(), subvec[t].end()); + return true; + } + // Fall through... + } + + // todo Implement parallel support for other than PrecisionType::strto + return false; + } +#endif // #ifdef _OPENMP + +public: + + // ------------------------ + // read vector of values + // ------------------------ + + // Values obtained from the std::string parameter + // are read into the std::vector parameter + void read( + const std::string &str, + std::vector &vec, const bool clear = true + ) const { + // Clear the vector, unless the caller has indicated otherwise. + if (clear) + vec.clear(); + + // If the string is empty, there's nothing more to do. + if (str.size() == 0) + return; + + // If OpenMP is available, AND circumstances are such that the + // readOpenMP() function actually does the reading, then we're + // done in this function. Else, continue and do the read below. + #ifdef _OPENMP + if (readOpenMP(str,vec)) + return; + #endif + + REAL element; + + // CASE: strto + if (itype == PrecisionType::strto) { + // Otherwise, we'll need to fall through to other cases, and in fact + // we wouldn't want to enter the below do-loop... + if constexpr (std::is_floating_point_v) { + const char *begin = str.data(); + char *end; + + do { + if constexpr (std::is_same_v) + element = strtof (begin,&end); + if constexpr (std::is_same_v) + element = strtod (begin,&end); + if constexpr (std::is_same_v) + element = strtold(begin,&end); + if (end == begin) break; + vec.push_back(element); + begin = end+1; + } while (*end); + return; // done + } + // Fall through... + } + + // CASE: fixed, scientific, shortest + if ( + itype == PrecisionType::fixed || + itype == PrecisionType::scientific || + itype == PrecisionType::shortest + ) { + // The following amounts to a test of whether std::from_chars() + // exists for REAL. We proceed here if and only if it does; and + // otherwise fall through to the stream case. + if (read("1",element,0)) { + std::istringstream i(str); + std::string tmpstr; + while (i >> tmpstr) + vec.push_back(read(tmpstr,element,0)); + } + // Fall through... + } + + // CASE: stream + // Use the istringstream + iss.clear(); // <== clear any existing error flags + iss.str(str); // <== set str as the brand-new input string + while (iss >> element) + vec.push_back(element); + } + // ------------------------ // For C++ I/O stream // manipulators @@ -295,7 +515,7 @@ class Precision { // ------------------------ // For special GNDStk - // manipulators... + // manipulators // ------------------------ // When you use the below specializations of operator<< and operator>>, i.e. @@ -304,9 +524,9 @@ class Precision { // for input should automatically use it for output; and vice versa. Our // special manipulators cause std::to_chars() and std::from_chars() to be // used, if they're available. std::to_chars() and std::from_chars() are - // designed to be ideal when uses with each other (although they don't need - // to be used together); so, it makes sense that we'd want to "tie" their - // use together, at least by default. + // designed to be ideal when used with each other (although they don't NEED + // to be used together). Therefore, it makes sense that we'd want to "tie" + // their use together, at least by default. bool tie = true; // ------------------------ @@ -361,9 +581,8 @@ class Precision { }; - // ----------------------------------------------------------------------------- -// static initialization +// Static initialization // ----------------------------------------------------------------------------- template @@ -384,8 +603,7 @@ template PrecisionType Precision::otype = PrecisionType::stream; template -PrecisionType Precision::itype = PrecisionType::stream; - +PrecisionType Precision::itype = PrecisionType::strto; // ----------------------------------------------------------------------------- @@ -418,7 +636,6 @@ class Precision { }; - // ----------------------------------------------------------------------------- // Precision // Set properties for: in metadata and data, the given floating-point type. @@ -447,7 +664,6 @@ class Precision { }; - // ----------------------------------------------------------------------------- // Precision // Set properties for: in metadata and data, float, double, and long double. diff --git a/src/GNDStk/precision/test/detail.test.cpp b/src/GNDStk/precision/test/detail.test.cpp index 11a0b7f44..bcd705b2a 100644 --- a/src/GNDStk/precision/test/detail.test.cpp +++ b/src/GNDStk/precision/test/detail.test.cpp @@ -2,7 +2,7 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; // helper template @@ -117,7 +117,7 @@ SCENARIO("Testing precision detail:: functionality") { { detail::Precision p; }; */ - // Use for the test... + // Use Precision for the test... detail::Precision v; detail::Precision f; detail::Precision d; diff --git a/src/GNDStk/precision/test/precision-test-classes.json b/src/GNDStk/precision/test/precision-test-classes.json index 61c0fb333..84c22938a 100644 --- a/src/GNDStk/precision/test/precision-test-classes.json +++ b/src/GNDStk/precision/test/precision-test-classes.json @@ -18,7 +18,7 @@ "required": false } }, - "data": "float", + "vector": "float", "childNodes": {} }, @@ -39,7 +39,7 @@ "required": false } }, - "data": "double", + "vector": "double", "childNodes": {} }, @@ -60,7 +60,7 @@ "required": false } }, - "data": "long double", + "vector": "long double", "childNodes": {} }, @@ -120,19 +120,19 @@ }, "childNodes": { "floats": { - "occurrence": "1", + "times": "1", "required": false }, "doubles": { - "occurrence": "1", + "times": "1", "required": false }, "quads": { - "occurrence": "1", + "times": "1", "required": false }, "reals": { - "occurrence": "1", + "times": "1", "required": false } } diff --git a/src/GNDStk/precision/test/precision.test.cpp b/src/GNDStk/precision/test/precision.test.cpp index f851a9334..f0f5be648 100644 --- a/src/GNDStk/precision/test/precision.test.cpp +++ b/src/GNDStk/precision/test/precision.test.cpp @@ -3,7 +3,7 @@ #include "catch.hpp" #include "GNDStk.hpp" -using namespace njoy::GNDStk::core; +using namespace njoy::GNDStk; #include "precision.test.hpp" // ----------------------------------------------------------------------------- @@ -65,23 +65,19 @@ R"***( const std::string xml_metadata_individual = R"***( - -)***"; +)***"; const std::string xml_metadata_real = R"***( - -)***"; +)***"; const std::string xml_gndstk_individual = R"***( - -)***"; +)***"; const std::string xml_gndstk_real = R"***( - -)***"; +)***"; // ------------------------ @@ -149,7 +145,7 @@ SCENARIO("Precision code in the convert()s between stream and real, " // SCENARIO // ----------------------------------------------------------------------------- -SCENARIO("Precision code in BodyText::get(), " +SCENARIO("Precision code in BlockData::get(), " "for reworking a data vector to have a different data type") { // Context/action: @@ -240,28 +236,28 @@ SCENARIO("Precision code in BodyText::get(), " num.reals() = fvec; data::floats << std::setprecision(4); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "1.414 1.732 2.236"); + CHECK((Node(num))(reals).data() == "1.414 1.732 2.236"); } THEN("data::reals precision has the intended effect") { num.reals() = fvec; data::reals << std::setprecision(5); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "1.4142 1.7321 2.2361"); + CHECK((Node(num))(reals).data() == "1.4142 1.7321 2.2361"); } THEN("GNDStk::floats precision has the intended effect") { num.reals() = fvec; njoy::GNDStk::floats << std::setprecision(6); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "1.41421 1.73205 2.23607"); + CHECK((Node(num))(reals).data() == "1.41421 1.73205 2.23607"); } THEN("GNDStk::reals precision has the intended effect") { num.reals() = fvec; njoy::GNDStk::reals << std::setprecision(7); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "1.414214 1.732051 2.236068"); + CHECK((Node(num))(reals).data() == "1.414214 1.732051 2.236068"); } } // WHEN @@ -282,28 +278,28 @@ SCENARIO("Precision code in BodyText::get(), " num.reals() = dvec; data::doubles << std::setprecision(4); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "2.646 3.317 3.606"); + CHECK((Node(num))(reals).data() == "2.646 3.317 3.606"); } THEN("data::reals precision has the intended effect") { num.reals() = dvec; data::reals << std::setprecision(5); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "2.6458 3.3166 3.6056"); + CHECK((Node(num))(reals).data() == "2.6458 3.3166 3.6056"); } THEN("GNDStk::doubles precision has the intended effect") { num.reals() = dvec; njoy::GNDStk::doubles << std::setprecision(6); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "2.64575 3.31662 3.60555"); + CHECK((Node(num))(reals).data() == "2.64575 3.31662 3.60555"); } THEN("GNDStk::reals precision has the intended effect") { num.reals() = dvec; njoy::GNDStk::reals << std::setprecision(7); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "2.645751 3.316625 3.605551"); + CHECK((Node(num))(reals).data() == "2.645751 3.316625 3.605551"); } } // WHEN @@ -324,28 +320,28 @@ SCENARIO("Precision code in BodyText::get(), " num.reals() = qvec; data::longdoubles << std::setprecision(4); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "4.123 4.359 4.796"); + CHECK((Node(num))(reals).data() == "4.123 4.359 4.796"); } THEN("data::reals precision has the intended effect") { num.reals() = qvec; data::reals << std::setprecision(5); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "4.1231 4.3589 4.7958"); + CHECK((Node(num))(reals).data() == "4.1231 4.3589 4.7958"); } THEN("GNDStk::longdoubles precision has the intended effect") { num.reals() = qvec; njoy::GNDStk::longdoubles << std::setprecision(6); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "4.12311 4.3589 4.79583"); + CHECK((Node(num))(reals).data() == "4.12311 4.3589 4.79583"); } THEN("GNDStk::reals precision has the intended effect") { num.reals() = qvec; njoy::GNDStk::reals << std::setprecision(7); num.reals()->get>(); - CHECK((Node(num))(reals).pcdata() == "4.123106 4.358899 4.795832"); + CHECK((Node(num))(reals).data() == "4.123106 4.358899 4.795832"); } } // WHEN } // SCENARIO @@ -356,7 +352,7 @@ SCENARIO("Precision code in BodyText::get(), " // SCENARIO // ----------------------------------------------------------------------------- -SCENARIO("Precision code in BodyText::get(), " +SCENARIO("Precision code in BlockData::get(), " "for converting from a raw string to a vector of data") { // Context/action: @@ -373,7 +369,7 @@ SCENARIO("Precision code in BodyText::get(), " // raw string to floats // ------------------------ - WHEN("We convert a raw \"body text\" string to a vector") { + WHEN("We convert a raw \"block data\" string to a vector") { // Initialize the raw string r = string; @@ -392,7 +388,7 @@ SCENARIO("Precision code in BodyText::get(), " // raw string to doubles // ------------------------ - WHEN("We convert a raw \"body text\" string to a vector") { + WHEN("We convert a raw \"block data\" string to a vector") { r = string; THEN("We get the expected result") { r.get>(); @@ -406,7 +402,7 @@ SCENARIO("Precision code in BodyText::get(), " // raw string to long doubles // ------------------------ - WHEN("We convert a raw \"body text\" string to a vector") { + WHEN("We convert a raw \"block data\" string to a vector") { r = string; THEN("We get the expected result") { r.get>(); @@ -423,7 +419,7 @@ SCENARIO("Precision code in BodyText::get(), " // SCENARIO // ----------------------------------------------------------------------------- -SCENARIO("Precision code in BodyText::toNode(), " +SCENARIO("Precision code in BlockData::toNode(), " "for writing... VALUES THAT ARE TO GO HERE") { // Context/action: @@ -454,25 +450,25 @@ SCENARIO("Precision code in BodyText::toNode(), " THEN("data::floats precision has the intended effect") { r = fvec; data::floats << std::setprecision(4); - CHECK((Node(r)).pcdata() == "1.414 1.732 2.236"); + CHECK((Node(r)).data() == "1.414 1.732 2.236"); } THEN("data::reals precision has the intended effect") { r = fvec; data::reals << std::setprecision(5); - CHECK((Node(r)).pcdata() == "1.4142 1.7321 2.2361"); + CHECK((Node(r)).data() == "1.4142 1.7321 2.2361"); } THEN("GNDStk::floats precision has the intended effect") { r = fvec; njoy::GNDStk::floats << std::setprecision(6); - CHECK((Node(r)).pcdata() == "1.41421 1.73205 2.23607"); + CHECK((Node(r)).data() == "1.41421 1.73205 2.23607"); } THEN("GNDStk::reals precision has the intended effect") { r = fvec; njoy::GNDStk::reals << std::setprecision(7); - CHECK((Node(r)).pcdata() == "1.414214 1.732051 2.236068"); + CHECK((Node(r)).data() == "1.414214 1.732051 2.236068"); } } // WHEN @@ -490,25 +486,25 @@ SCENARIO("Precision code in BodyText::toNode(), " THEN("data::doubles precision has the intended effect") { r = dvec; data::doubles << std::setprecision(4); - CHECK((Node(r)).pcdata() == "2.646 3.317 3.606"); + CHECK((Node(r)).data() == "2.646 3.317 3.606"); } THEN("data::reals precision has the intended effect") { r = dvec; data::reals << std::setprecision(5); - CHECK((Node(r)).pcdata() == "2.6458 3.3166 3.6056"); + CHECK((Node(r)).data() == "2.6458 3.3166 3.6056"); } THEN("GNDStk::doubles precision has the intended effect") { r = dvec; njoy::GNDStk::doubles << std::setprecision(6); - CHECK((Node(r)).pcdata() == "2.64575 3.31662 3.60555"); + CHECK((Node(r)).data() == "2.64575 3.31662 3.60555"); } THEN("GNDStk::reals precision has the intended effect") { r = dvec; njoy::GNDStk::reals << std::setprecision(7); - CHECK((Node(r)).pcdata() == "2.645751 3.316625 3.605551"); + CHECK((Node(r)).data() == "2.645751 3.316625 3.605551"); } } // WHEN @@ -526,25 +522,25 @@ SCENARIO("Precision code in BodyText::toNode(), " THEN("data::longdoubles precision has the intended effect") { r = qvec; data::longdoubles << std::setprecision(4); - CHECK((Node(r)).pcdata() == "4.123 4.359 4.796"); + CHECK((Node(r)).data() == "4.123 4.359 4.796"); } THEN("data::reals precision has the intended effect") { r = qvec; data::reals << std::setprecision(5); - CHECK((Node(r)).pcdata() == "4.1231 4.3589 4.7958"); + CHECK((Node(r)).data() == "4.1231 4.3589 4.7958"); } THEN("GNDStk::longdoubles precision has the intended effect") { r = qvec; njoy::GNDStk::longdoubles << std::setprecision(6); - CHECK((Node(r)).pcdata() == "4.12311 4.3589 4.79583"); + CHECK((Node(r)).data() == "4.12311 4.3589 4.79583"); } THEN("GNDStk::reals precision has the intended effect") { r = qvec; njoy::GNDStk::reals << std::setprecision(7); - CHECK((Node(r)).pcdata() == "4.123106 4.358899 4.795832"); + CHECK((Node(r)).data() == "4.123106 4.358899 4.795832"); } } // WHEN } // SCENARIO @@ -560,63 +556,47 @@ SCENARIO("Precision code in BodyText::toNode(), " // ------------------------ const std::string printed_metadata_individual = -R"***(precision::Numbers { // GNDS: numbers - adouble : 1.414214 - afloat : 1.7321 - aquad : 2.23606798 - bdouble : 2.44949 - bfloat : 2.6458 - bquad : 2.82842712 - doubles : // optional; has no value - floats : // optional; has no value - quads : // optional; has no value - reals : // optional; has no value -} // precision::Numbers +R"***({ + adouble : 1.414214 // its default + afloat : 1.7321 // its default + aquad : 2.23606798 // its default + bdouble : 2.44949 // its default + bfloat : 2.6458 // its default + bquad : 2.82842712 // its default +} )***"; const std::string printed_metadata_real = -R"***(precision::Numbers { // GNDS: numbers - adouble : 1.41 - afloat : 1.73 - aquad : 2.24 - bdouble : 2.45 - bfloat : 2.65 - bquad : 2.83 - doubles : // optional; has no value - floats : // optional; has no value - quads : // optional; has no value - reals : // optional; has no value -} // precision::Numbers +R"***({ + adouble : 1.41 // its default + afloat : 1.73 // its default + aquad : 2.24 // its default + bdouble : 2.45 // its default + bfloat : 2.65 // its default + bquad : 2.83 // its default +} )***"; const std::string printed_gndstk_individual = -R"***(precision::Numbers { // GNDS: numbers - adouble : 1.4142136 - afloat : 1.73205 - aquad : 2.236067977 - bdouble : 2.4494897 - bfloat : 2.64575 - bquad : 2.828427125 - doubles : // optional; has no value - floats : // optional; has no value - quads : // optional; has no value - reals : // optional; has no value -} // precision::Numbers +R"***({ + adouble : 1.4142136 // its default + afloat : 1.73205 // its default + aquad : 2.236067977 // its default + bdouble : 2.4494897 // its default + bfloat : 2.64575 // its default + bquad : 2.828427125 // its default +} )***"; const std::string printed_gndstk_real = -R"***(precision::Numbers { // GNDS: numbers - adouble : 1.414 - afloat : 1.732 - aquad : 2.236 - bdouble : 2.449 - bfloat : 2.646 - bquad : 2.828 - doubles : // optional; has no value - floats : // optional; has no value - quads : // optional; has no value - reals : // optional; has no value -} // precision::Numbers +R"***({ + adouble : 1.414 // its default + afloat : 1.732 // its default + aquad : 2.236 // its default + bdouble : 2.449 // its default + bfloat : 2.646 // its default + bquad : 2.828 // its default +} )***"; @@ -630,6 +610,9 @@ SCENARIO("Precision code in Component::write(), " // Context/action: // metadata, write + njoy::GNDStk::colors = false; + njoy::GNDStk::shades = false; + Node node; node << input_numbers_metadata; @@ -725,135 +708,107 @@ R"***( // ------------------------ const std::string block_data_individual = -R"***(precision::Numbers { // GNDS: numbers - adouble : // defaulted; is its default (1.414) - afloat : // defaulted; is its default (1.732) - aquad : // defaulted; is its default (2.236) - bdouble : // defaulted; is its default (2.449) - bfloat : // defaulted; is its default (2.646) - bquad : // defaulted; is its default (2.828) - precision::Doubles { // GNDS: doubles - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value +R"***({ + adouble : 1.414 // its default + afloat : 1.732 // its default + aquad : 2.236 // its default + bdouble : 2.449 // its default + bfloat : 2.646 // its default + bquad : 2.828 // its default + doubles { + start : 0 // its default 3.352228 7.682296 2.777747 5.5397 4.773971 6.288709 - } // precision::Doubles - precision::Floats { // GNDS: floats - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // doubles + floats { + start : 0 // its default 8.4019 3.9438 7.831 7.9844 9.1165 1.9755 - } // precision::Floats - precision::Quads { // GNDS: quads - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // floats + quads { + start : 0 // its default 3.64784473 5.1340091 9.52229725 9.16195068 6.35711728 7.17296929 - } // precision::Quads - reals : // optional; has no value -} // precision::Numbers + } // quads +} )***"; const std::string block_data_real = -R"***(precision::Numbers { // GNDS: numbers - adouble : // defaulted; is its default (1.414) - afloat : // defaulted; is its default (1.732) - aquad : // defaulted; is its default (2.236) - bdouble : // defaulted; is its default (2.449) - bfloat : // defaulted; is its default (2.646) - bquad : // defaulted; is its default (2.828) - precision::Doubles { // GNDS: doubles - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value +R"***({ + adouble : 1.414 // its default + afloat : 1.732 // its default + aquad : 2.236 // its default + bdouble : 2.449 // its default + bfloat : 2.646 // its default + bquad : 2.828 // its default + doubles { + start : 0 // its default 3.35 7.68 2.78 5.54 4.77 6.29 - } // precision::Doubles - precision::Floats { // GNDS: floats - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // doubles + floats { + start : 0 // its default 8.4 3.94 7.83 7.98 9.12 1.98 - } // precision::Floats - precision::Quads { // GNDS: quads - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // floats + quads { + start : 0 // its default 3.65 5.13 9.52 9.16 6.36 7.17 - } // precision::Quads - reals : // optional; has no value -} // precision::Numbers + } // quads +} )***"; const std::string block_gndstk_individual = -R"***(precision::Numbers { // GNDS: numbers - adouble : // defaulted; is its default (1.4142136) - afloat : // defaulted; is its default (1.73205) - aquad : // defaulted; is its default (2.236067977) - bdouble : // defaulted; is its default (2.4494897) - bfloat : // defaulted; is its default (2.64575) - bquad : // defaulted; is its default (2.828427125) - precision::Doubles { // GNDS: doubles - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value +R"***({ + adouble : 1.4142136 // its default + afloat : 1.73205 // its default + aquad : 2.236067977 // its default + bdouble : 2.4494897 // its default + bfloat : 2.64575 // its default + bquad : 2.828427125 // its default + doubles { + start : 0 // its default 3.3522276 7.6822959 2.7777471 5.5396996 4.7739705 6.2887092 - } // precision::Doubles - precision::Floats { // GNDS: floats - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // doubles + floats { + start : 0 // its default 8.40188 3.94383 7.83099 7.9844 9.11647 1.97551 - } // precision::Floats - precision::Quads { // GNDS: quads - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // floats + quads { + start : 0 // its default 3.647844728 5.134009102 9.522297252 9.16195068 6.35711728 7.172969294 - } // precision::Quads - reals : // optional; has no value -} // precision::Numbers + } // quads +} )***"; const std::string block_gndstk_real = -R"***(precision::Numbers { // GNDS: numbers - adouble : // defaulted; is its default (1.414) - afloat : // defaulted; is its default (1.732) - aquad : // defaulted; is its default (2.236) - bdouble : // defaulted; is its default (2.449) - bfloat : // defaulted; is its default (2.646) - bquad : // defaulted; is its default (2.828) - precision::Doubles { // GNDS: doubles - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value +R"***({ + adouble : 1.414 // its default + afloat : 1.732 // its default + aquad : 2.236 // its default + bdouble : 2.449 // its default + bfloat : 2.646 // its default + bquad : 2.828 // its default + doubles { + start : 0 // its default 3.352 7.682 2.778 5.54 4.774 6.289 - } // precision::Doubles - precision::Floats { // GNDS: floats - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // doubles + floats { + start : 0 // its default 8.402 3.944 7.831 7.984 9.116 1.976 - } // precision::Floats - precision::Quads { // GNDS: quads - length : // optional; has no value - start : // defaulted; is its default (0) - valueType : // optional; has no value + } // floats + quads { + start : 0 // its default 3.648 5.134 9.522 9.162 6.357 7.173 - } // precision::Quads - reals : // optional; has no value -} // precision::Numbers + } // quads +} )***"; @@ -861,12 +816,12 @@ R"***(precision::Numbers { // GNDS: numbers // SCENARIO // ------------------------ -SCENARIO("Precision code in BodyText::write(), " +SCENARIO("Precision code in BlockData::write(), " "for writing data blocks with Component::write()'s prettyprinter") { // Context/action: // data, write - // This actually happens in detail::writeComponentPart() + // This actually happens in detail::printComponentPart() Node node; node << input_numbers_full; diff --git a/src/GNDStk/precision/test/precision.test.hpp b/src/GNDStk/precision/test/precision.test.hpp index 531e64571..0e8f1c5bc 100644 --- a/src/GNDStk/precision/test/precision.test.hpp +++ b/src/GNDStk/precision/test/precision.test.hpp @@ -15,12 +15,12 @@ class Floats : public Component { friend class Component; // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "precision"; } - static auto className() { return "Floats"; } - static auto GNDSName() { return "floats"; } + static auto NAMESPACE() { return "precision"; } + static auto CLASS() { return "Floats"; } + static auto NODENAME() { return "floats"; } // Core Interface object to extract metadata and child nodes - static auto keys() + static auto KEYS() { return // metadata @@ -33,10 +33,30 @@ class Floats : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "length", + "start", + "valueType" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "length", + "start", + "value_type" + }; + return names; + } + public: using Component::construct; - using BodyText::operator=; + using BlockData::operator=; // ------------------------ // Relevant defaults @@ -56,7 +76,7 @@ class Floats : public Component { mutable std::optional length; mutable Defaulted start{0}; mutable std::optional valueType; - } content; + } Content; // ------------------------ // Getters @@ -65,21 +85,21 @@ class Floats : public Component { // length const std::optional &length() const - { return content.length; } + { return Content.length; } std::optional &length() - { return content.length; } + { return Content.length; } // start const Defaulted &start() const - { return content.start; } + { return Content.start; } Defaulted &start() - { return content.start; } + { return Content.start; } // valueType const std::optional &valueType() const - { return content.valueType; } + { return Content.valueType; } std::optional &valueType() - { return content.valueType; } + { return Content.valueType; } // ------------------------ // Setters @@ -89,17 +109,17 @@ class Floats : public Component { // length(value) Floats &length(const std::optional &obj) - { BodyText::length(length() = obj); return *this; } + { BlockData::length(length() = obj); return *this; } // start(value) Floats &start(const Defaulted &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } Floats &start(const std::optional &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } // valueType(value) Floats &valueType(const std::optional &obj) - { BodyText::valueType(valueType() = obj); return *this; } + { BlockData::valueType(valueType() = obj); return *this; } // ------------------------ // Construction @@ -108,10 +128,10 @@ class Floats : public Component { // default Floats() : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(); @@ -121,11 +141,11 @@ class Floats : public Component { Floats(const Floats &other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{other.content} + Content{other.Content} { Component::finish(other); } @@ -134,11 +154,11 @@ class Floats : public Component { Floats(Floats &&other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{std::move(other.content)} + Content{std::move(other.Content)} { Component::finish(other); } @@ -146,10 +166,10 @@ class Floats : public Component { // from node Floats(const Node &node) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(node); @@ -163,12 +183,12 @@ class Floats : public Component { const std::optional &valueType ) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() }, - content{ + Content{ length, Defaulted(defaults.start,start), valueType @@ -178,13 +198,13 @@ class Floats : public Component { } // from vector - template>> + template>> Floats(const std::vector &vector) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(vector); @@ -221,12 +241,12 @@ class Doubles : public Component { friend class Component; // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "precision"; } - static auto className() { return "Doubles"; } - static auto GNDSName() { return "doubles"; } + static auto NAMESPACE() { return "precision"; } + static auto CLASS() { return "Doubles"; } + static auto NODENAME() { return "doubles"; } // Core Interface object to extract metadata and child nodes - static auto keys() + static auto KEYS() { return // metadata @@ -239,10 +259,30 @@ class Doubles : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "length", + "start", + "valueType" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "length", + "start", + "value_type" + }; + return names; + } + public: using Component::construct; - using BodyText::operator=; + using BlockData::operator=; // ------------------------ // Relevant defaults @@ -262,7 +302,7 @@ class Doubles : public Component { mutable std::optional length; mutable Defaulted start{0}; mutable std::optional valueType; - } content; + } Content; // ------------------------ // Getters @@ -271,21 +311,21 @@ class Doubles : public Component { // length const std::optional &length() const - { return content.length; } + { return Content.length; } std::optional &length() - { return content.length; } + { return Content.length; } // start const Defaulted &start() const - { return content.start; } + { return Content.start; } Defaulted &start() - { return content.start; } + { return Content.start; } // valueType const std::optional &valueType() const - { return content.valueType; } + { return Content.valueType; } std::optional &valueType() - { return content.valueType; } + { return Content.valueType; } // ------------------------ // Setters @@ -295,17 +335,17 @@ class Doubles : public Component { // length(value) Doubles &length(const std::optional &obj) - { BodyText::length(length() = obj); return *this; } + { BlockData::length(length() = obj); return *this; } // start(value) Doubles &start(const Defaulted &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } Doubles &start(const std::optional &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } // valueType(value) Doubles &valueType(const std::optional &obj) - { BodyText::valueType(valueType() = obj); return *this; } + { BlockData::valueType(valueType() = obj); return *this; } // ------------------------ // Construction @@ -314,10 +354,10 @@ class Doubles : public Component { // default Doubles() : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(); @@ -327,11 +367,11 @@ class Doubles : public Component { Doubles(const Doubles &other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{other.content} + Content{other.Content} { Component::finish(other); } @@ -340,11 +380,11 @@ class Doubles : public Component { Doubles(Doubles &&other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{std::move(other.content)} + Content{std::move(other.Content)} { Component::finish(other); } @@ -352,10 +392,10 @@ class Doubles : public Component { // from node Doubles(const Node &node) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(node); @@ -369,12 +409,12 @@ class Doubles : public Component { const std::optional &valueType ) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() }, - content{ + Content{ length, Defaulted(defaults.start,start), valueType @@ -384,13 +424,13 @@ class Doubles : public Component { } // from vector - template>> + template>> Doubles(const std::vector &vector) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(vector); @@ -427,12 +467,12 @@ class Quads : public Component { friend class Component; // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "precision"; } - static auto className() { return "Quads"; } - static auto GNDSName() { return "quads"; } + static auto NAMESPACE() { return "precision"; } + static auto CLASS() { return "Quads"; } + static auto NODENAME() { return "quads"; } // Core Interface object to extract metadata and child nodes - static auto keys() + static auto KEYS() { return // metadata @@ -445,10 +485,30 @@ class Quads : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "length", + "start", + "valueType" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "length", + "start", + "value_type" + }; + return names; + } + public: using Component::construct; - using BodyText::operator=; + using BlockData::operator=; // ------------------------ // Relevant defaults @@ -468,7 +528,7 @@ class Quads : public Component { mutable std::optional length; mutable Defaulted start{0}; mutable std::optional valueType; - } content; + } Content; // ------------------------ // Getters @@ -477,21 +537,21 @@ class Quads : public Component { // length const std::optional &length() const - { return content.length; } + { return Content.length; } std::optional &length() - { return content.length; } + { return Content.length; } // start const Defaulted &start() const - { return content.start; } + { return Content.start; } Defaulted &start() - { return content.start; } + { return Content.start; } // valueType const std::optional &valueType() const - { return content.valueType; } + { return Content.valueType; } std::optional &valueType() - { return content.valueType; } + { return Content.valueType; } // ------------------------ // Setters @@ -501,17 +561,17 @@ class Quads : public Component { // length(value) Quads &length(const std::optional &obj) - { BodyText::length(length() = obj); return *this; } + { BlockData::length(length() = obj); return *this; } // start(value) Quads &start(const Defaulted &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } Quads &start(const std::optional &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } // valueType(value) Quads &valueType(const std::optional &obj) - { BodyText::valueType(valueType() = obj); return *this; } + { BlockData::valueType(valueType() = obj); return *this; } // ------------------------ // Construction @@ -520,10 +580,10 @@ class Quads : public Component { // default Quads() : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(); @@ -533,11 +593,11 @@ class Quads : public Component { Quads(const Quads &other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{other.content} + Content{other.Content} { Component::finish(other); } @@ -546,11 +606,11 @@ class Quads : public Component { Quads(Quads &&other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{std::move(other.content)} + Content{std::move(other.Content)} { Component::finish(other); } @@ -558,10 +618,10 @@ class Quads : public Component { // from node Quads(const Node &node) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(node); @@ -575,12 +635,12 @@ class Quads : public Component { const std::optional &valueType ) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() }, - content{ + Content{ length, Defaulted(defaults.start,start), valueType @@ -590,13 +650,13 @@ class Quads : public Component { } // from vector - template>> + template>> Quads(const std::vector &vector) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(vector); @@ -633,12 +693,12 @@ class Reals : public Component { friend class Component; // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "precision"; } - static auto className() { return "Reals"; } - static auto GNDSName() { return "reals"; } + static auto NAMESPACE() { return "precision"; } + static auto CLASS() { return "Reals"; } + static auto NODENAME() { return "reals"; } // Core Interface object to extract metadata and child nodes - static auto keys() + static auto KEYS() { return // metadata @@ -651,10 +711,30 @@ class Reals : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "length", + "start", + "valueType" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "length", + "start", + "value_type" + }; + return names; + } + public: using Component::construct; - using BodyText::operator=; + using BlockData::operator=; // ------------------------ // Relevant defaults @@ -674,7 +754,7 @@ class Reals : public Component { mutable std::optional length; mutable Defaulted start{0}; mutable std::optional valueType; - } content; + } Content; // ------------------------ // Getters @@ -683,21 +763,21 @@ class Reals : public Component { // length const std::optional &length() const - { return content.length; } + { return Content.length; } std::optional &length() - { return content.length; } + { return Content.length; } // start const Defaulted &start() const - { return content.start; } + { return Content.start; } Defaulted &start() - { return content.start; } + { return Content.start; } // valueType const std::optional &valueType() const - { return content.valueType; } + { return Content.valueType; } std::optional &valueType() - { return content.valueType; } + { return Content.valueType; } // ------------------------ // Setters @@ -707,17 +787,17 @@ class Reals : public Component { // length(value) Reals &length(const std::optional &obj) - { BodyText::length(length() = obj); return *this; } + { BlockData::length(length() = obj); return *this; } // start(value) Reals &start(const Defaulted &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } Reals &start(const std::optional &obj) - { BodyText::start(content.start = obj); return *this; } + { BlockData::start(start() = obj); return *this; } // valueType(value) Reals &valueType(const std::optional &obj) - { BodyText::valueType(valueType() = obj); return *this; } + { BlockData::valueType(valueType() = obj); return *this; } // ------------------------ // Construction @@ -726,10 +806,10 @@ class Reals : public Component { // default Reals() : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(); @@ -739,11 +819,11 @@ class Reals : public Component { Reals(const Reals &other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{other.content} + Content{other.Content} { Component::finish(other); } @@ -752,11 +832,11 @@ class Reals : public Component { Reals(Reals &&other) : Component{ other, - content.length, - content.start, - content.valueType + this->length(), + this->start(), + this->valueType() }, - content{std::move(other.content)} + Content{std::move(other.Content)} { Component::finish(other); } @@ -764,10 +844,10 @@ class Reals : public Component { // from node Reals(const Node &node) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(node); @@ -781,12 +861,12 @@ class Reals : public Component { const std::optional &valueType ) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() }, - content{ + Content{ length, Defaulted(defaults.start,start), valueType @@ -796,13 +876,13 @@ class Reals : public Component { } // from vector - template>> + template>> Reals(const std::vector &vector) : Component{ - BodyText{}, - content.length, - content.start, - content.valueType + BlockData{}, + this->length(), + this->start(), + this->valueType() } { Component::finish(vector); @@ -839,26 +919,32 @@ class Numbers : public Component { friend class Component; // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "precision"; } - static auto className() { return "Numbers"; } - static auto GNDSName() { return "numbers"; } + static auto NAMESPACE() { return "precision"; } + static auto CLASS() { return "Numbers"; } + static auto NODENAME() { return "numbers"; } // Core Interface object to extract metadata and child nodes - static auto keys() + static auto KEYS() { return // metadata - Defaulted{1.414213562373095048801688724209698078569671875377} + Defaulted + {1.414213562373095048801688724209698078569671875377} / Meta<>("adouble") | - Defaulted{1.732050807568877293527446341505872366942805253810} + Defaulted + {1.732050807568877293527446341505872366942805253810} / Meta<>("afloat") | - Defaulted{2.236067977499789696409173668731276235440618359612} + Defaulted + {2.236067977499789696409173668731276235440618359612} / Meta<>("aquad") | - Defaulted{2.449489742783178098197284074705891391965947480657} + Defaulted + {2.449489742783178098197284074705891391965947480657} / Meta<>("bdouble") | - Defaulted{2.645751311064590590501615753639260425710259183082} + Defaulted + {2.645751311064590590501615753639260425710259183082} / Meta<>("bfloat") | - Defaulted{2.828427124746190097603377448419396157139343750754} + Defaulted + {2.828427124746190097603377448419396157139343750754} / Meta<>("bquad") | // children std::optional{} @@ -872,6 +958,40 @@ class Numbers : public Component { ; } + static const auto &FIELDNAMES() + { + static const std::vector names = { + "adouble", + "afloat", + "aquad", + "bdouble", + "bfloat", + "bquad", + "doubles", + "floats", + "quads", + "reals" + }; + return names; + } + + static const auto &PYTHONNAMES() + { + static const std::vector names = { + "adouble", + "afloat", + "aquad", + "bdouble", + "bfloat", + "bquad", + "doubles", + "floats", + "quads", + "reals" + }; + return names; + } + public: using Component::construct; @@ -882,12 +1002,18 @@ class Numbers : public Component { // ------------------------ static inline const struct Defaults { - static inline const double adouble = 1.414213562373095048801688724209698078569671875377; - static inline const float afloat = 1.732050807568877293527446341505872366942805253810; - static inline const long double aquad = 2.236067977499789696409173668731276235440618359612; - static inline const double bdouble = 2.449489742783178098197284074705891391965947480657; - static inline const float bfloat = 2.645751311064590590501615753639260425710259183082; - static inline const long double bquad = 2.828427124746190097603377448419396157139343750754; + static inline const double adouble = + 1.414213562373095048801688724209698078569671875377; + static inline const float afloat = + 1.732050807568877293527446341505872366942805253810; + static inline const long double aquad = + 2.236067977499789696409173668731276235440618359612; + static inline const double bdouble = + 2.449489742783178098197284074705891391965947480657; + static inline const float bfloat = + 2.645751311064590590501615753639260425710259183082; + static inline const long double bquad = + 2.828427124746190097603377448419396157139343750754; } defaults; // ------------------------ @@ -896,19 +1022,25 @@ class Numbers : public Component { struct { // metadata - Defaulted adouble{1.414213562373095048801688724209698078569671875377}; - Defaulted afloat{1.732050807568877293527446341505872366942805253810}; - Defaulted aquad{2.236067977499789696409173668731276235440618359612}; - Defaulted bdouble{2.449489742783178098197284074705891391965947480657}; - Defaulted bfloat{2.645751311064590590501615753639260425710259183082}; - Defaulted bquad{2.828427124746190097603377448419396157139343750754}; + Defaulted adouble + { 1.414213562373095048801688724209698078569671875377 }; + Defaulted afloat + { 1.732050807568877293527446341505872366942805253810 }; + Defaulted aquad + { 2.236067977499789696409173668731276235440618359612 }; + Defaulted bdouble + { 2.449489742783178098197284074705891391965947480657 }; + Defaulted bfloat + { 2.645751311064590590501615753639260425710259183082 }; + Defaulted bquad + { 2.828427124746190097603377448419396157139343750754 }; // children std::optional doubles; std::optional floats; std::optional quads; std::optional reals; - } content; + } Content; // ------------------------ // Getters @@ -917,63 +1049,63 @@ class Numbers : public Component { // adouble const Defaulted &adouble() const - { return content.adouble; } + { return Content.adouble; } Defaulted &adouble() - { return content.adouble; } + { return Content.adouble; } // afloat const Defaulted &afloat() const - { return content.afloat; } + { return Content.afloat; } Defaulted &afloat() - { return content.afloat; } + { return Content.afloat; } // aquad const Defaulted &aquad() const - { return content.aquad; } + { return Content.aquad; } Defaulted &aquad() - { return content.aquad; } + { return Content.aquad; } // bdouble const Defaulted &bdouble() const - { return content.bdouble; } + { return Content.bdouble; } Defaulted &bdouble() - { return content.bdouble; } + { return Content.bdouble; } // bfloat const Defaulted &bfloat() const - { return content.bfloat; } + { return Content.bfloat; } Defaulted &bfloat() - { return content.bfloat; } + { return Content.bfloat; } // bquad const Defaulted &bquad() const - { return content.bquad; } + { return Content.bquad; } Defaulted &bquad() - { return content.bquad; } + { return Content.bquad; } // doubles const std::optional &doubles() const - { return content.doubles; } + { return Content.doubles; } std::optional &doubles() - { return content.doubles; } + { return Content.doubles; } // floats const std::optional &floats() const - { return content.floats; } + { return Content.floats; } std::optional &floats() - { return content.floats; } + { return Content.floats; } // quads const std::optional &quads() const - { return content.quads; } + { return Content.quads; } std::optional &quads() - { return content.quads; } + { return Content.quads; } // reals const std::optional &reals() const - { return content.reals; } + { return Content.reals; } std::optional &reals() - { return content.reals; } + { return Content.reals; } // ------------------------ // Setters @@ -983,39 +1115,39 @@ class Numbers : public Component { // adouble(value) Numbers &adouble(const Defaulted &obj) - { content.adouble = obj; return *this; } + { adouble() = obj; return *this; } Numbers &adouble(const std::optional &obj) - { content.adouble = obj; return *this; } + { adouble() = obj; return *this; } // afloat(value) Numbers &afloat(const Defaulted &obj) - { content.afloat = obj; return *this; } + { afloat() = obj; return *this; } Numbers &afloat(const std::optional &obj) - { content.afloat = obj; return *this; } + { afloat() = obj; return *this; } // aquad(value) Numbers &aquad(const Defaulted &obj) - { content.aquad = obj; return *this; } + { aquad() = obj; return *this; } Numbers &aquad(const std::optional &obj) - { content.aquad = obj; return *this; } + { aquad() = obj; return *this; } // bdouble(value) Numbers &bdouble(const Defaulted &obj) - { content.bdouble = obj; return *this; } + { bdouble() = obj; return *this; } Numbers &bdouble(const std::optional &obj) - { content.bdouble = obj; return *this; } + { bdouble() = obj; return *this; } // bfloat(value) Numbers &bfloat(const Defaulted &obj) - { content.bfloat = obj; return *this; } + { bfloat() = obj; return *this; } Numbers &bfloat(const std::optional &obj) - { content.bfloat = obj; return *this; } + { bfloat() = obj; return *this; } // bquad(value) Numbers &bquad(const Defaulted &obj) - { content.bquad = obj; return *this; } + { bquad() = obj; return *this; } Numbers &bquad(const std::optional &obj) - { content.bquad = obj; return *this; } + { bquad() = obj; return *this; } // doubles(value) Numbers &doubles(const std::optional &obj) @@ -1040,17 +1172,17 @@ class Numbers : public Component { // default Numbers() : Component{ - BodyText{}, - content.adouble, - content.afloat, - content.aquad, - content.bdouble, - content.bfloat, - content.bquad, - content.doubles, - content.floats, - content.quads, - content.reals + BlockData{}, + this->adouble(), + this->afloat(), + this->aquad(), + this->bdouble(), + this->bfloat(), + this->bquad(), + this->doubles(), + this->floats(), + this->quads(), + this->reals() } { Component::finish(); @@ -1060,18 +1192,18 @@ class Numbers : public Component { Numbers(const Numbers &other) : Component{ other, - content.adouble, - content.afloat, - content.aquad, - content.bdouble, - content.bfloat, - content.bquad, - content.doubles, - content.floats, - content.quads, - content.reals + this->adouble(), + this->afloat(), + this->aquad(), + this->bdouble(), + this->bfloat(), + this->bquad(), + this->doubles(), + this->floats(), + this->quads(), + this->reals() }, - content{other.content} + Content{other.Content} { Component::finish(other); } @@ -1080,18 +1212,18 @@ class Numbers : public Component { Numbers(Numbers &&other) : Component{ other, - content.adouble, - content.afloat, - content.aquad, - content.bdouble, - content.bfloat, - content.bquad, - content.doubles, - content.floats, - content.quads, - content.reals + this->adouble(), + this->afloat(), + this->aquad(), + this->bdouble(), + this->bfloat(), + this->bquad(), + this->doubles(), + this->floats(), + this->quads(), + this->reals() }, - content{std::move(other.content)} + Content{std::move(other.Content)} { Component::finish(other); } @@ -1099,17 +1231,17 @@ class Numbers : public Component { // from node Numbers(const Node &node) : Component{ - BodyText{}, - content.adouble, - content.afloat, - content.aquad, - content.bdouble, - content.bfloat, - content.bquad, - content.doubles, - content.floats, - content.quads, - content.reals + BlockData{}, + this->adouble(), + this->afloat(), + this->aquad(), + this->bdouble(), + this->bfloat(), + this->bquad(), + this->doubles(), + this->floats(), + this->quads(), + this->reals() } { Component::finish(node); @@ -1130,19 +1262,19 @@ class Numbers : public Component { const std::optional &reals ) : Component{ - BodyText{}, - content.adouble, - content.afloat, - content.aquad, - content.bdouble, - content.bfloat, - content.bquad, - content.doubles, - content.floats, - content.quads, - content.reals + BlockData{}, + this->adouble(), + this->afloat(), + this->aquad(), + this->bdouble(), + this->bfloat(), + this->bquad(), + this->doubles(), + this->floats(), + this->quads(), + this->reals() }, - content{ + Content{ Defaulted(defaults.adouble,adouble), Defaulted(defaults.afloat,afloat), Defaulted(defaults.aquad,aquad), diff --git a/src/GNDStk/string2type.hpp b/src/GNDStk/string2type.hpp index edbd7f838..4e9d9e9d9 100644 --- a/src/GNDStk/string2type.hpp +++ b/src/GNDStk/string2type.hpp @@ -55,6 +55,12 @@ inline void convert(std::istream &is, T &value) } } +// string +inline void convert(std::istream &is, std::string &value) +{ + is >> value; +} + // pair template inline void convert(std::istream &is, std::pair &p) diff --git a/src/GNDStk/string2type/test/string2type.test.cpp b/src/GNDStk/string2type/test/string2type.test.cpp index 6302388f5..d036e9a84 100644 --- a/src/GNDStk/string2type/test/string2type.test.cpp +++ b/src/GNDStk/string2type/test/string2type.test.cpp @@ -84,7 +84,7 @@ SCENARIO("Testing GNDStk convert(istream/string,type)") { CHECK(*iter++ == 300); } - THEN("It works for T == vector") { + THEN("It works for T == vector") { std::istringstream iss("1000 2000 3000"); std::vector container; convert(iss,container); @@ -93,6 +93,17 @@ SCENARIO("Testing GNDStk convert(istream/string,type)") { CHECK(container[1] == 2000); CHECK(container[2] == 3000); } + + THEN("It works for T == vector") { + std::istringstream iss("a bc def ghij"); + std::vector container; + convert(iss,container); + CHECK(container.size() == 4); + CHECK(container[0] == "a"); + CHECK(container[1] == "bc"); + CHECK(container[2] == "def"); + CHECK(container[3] == "ghij"); + } } // ------------------------ @@ -193,6 +204,27 @@ SCENARIO("Testing GNDStk convert(istream/string,type)") { convert(str,val); CHECK(val == 7.89L); } + + THEN("It works correctly for vector") { + const std::string str("1000 2000 3000"); + std::vector container; + convert(str,container); + CHECK(container.size() == 3); + CHECK(container[0] == 1000); + CHECK(container[1] == 2000); + CHECK(container[2] == 3000); + } + + THEN("It works correctly for vector") { + const std::string str("a bc def ghij"); + std::vector container; + convert(str,container); + CHECK(container.size() == 4); + CHECK(container[0] == "a"); + CHECK(container[1] == "bc"); + CHECK(container[2] == "def"); + CHECK(container[3] == "ghij"); + } } // WHEN } // SCENARIO diff --git a/src/GNDStk/test/CMakeLists.txt b/src/GNDStk/test/CMakeLists.txt deleted file mode 100644 index cad85f9e3..000000000 --- a/src/GNDStk/test/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ - -add_executable( GNDStk.test GNDStk.test.cpp ) -target_compile_options( GNDStk.test PRIVATE ${${PREFIX}_common_flags} -$<$:${${PREFIX}_strict_flags}>$<$: -${${PREFIX}_DEBUG_flags} -$<$:${${PREFIX}_coverage_flags}>> -$<$: -${${PREFIX}_RELEASE_flags} -$<$:${${PREFIX}_link_time_optimization_flags}> -$<$:${${PREFIX}_nonportable_optimization_flags}>> - -${CXX_appended_flags} ${GNDStk_appended_flags} ) -target_link_libraries( GNDStk.test PUBLIC GNDStk ) -add_test( NAME GNDStk COMMAND GNDStk.test ) \ No newline at end of file diff --git a/src/GNDStk/test/GNDStk.test.cpp b/src/GNDStk/test/GNDStk.test.cpp deleted file mode 100644 index 81c033903..000000000 --- a/src/GNDStk/test/GNDStk.test.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" diff --git a/src/GNDStk/test/keys.hpp b/src/GNDStk/test/keys.hpp new file mode 100644 index 000000000..d6d2a8ff8 --- /dev/null +++ b/src/GNDStk/test/keys.hpp @@ -0,0 +1,324 @@ + +// ----------------------------------------------------------------------------- +// basic:: +// Some Meta and Child objects that use , meaning that they'll retrieve +// metadata and child nodes in their original form in the GNDS tree. These are +// used in various test codes. +// ----------------------------------------------------------------------------- + +namespace basic { + +// ------------------------ +// Meta<> +// ------------------------ + +namespace meta { + inline const njoy::GNDStk::Meta + ENDF_MT ("ENDF_MT" ), + index ("index" ), + label ("label" ), + projectile("projectile"), + symbol ("symbol" ), + TEXT (njoy::GNDStk::special::text), + unit ("unit" ), + value ("value" ), + version ("version" ); +} // namespace meta + +// ------------------------ +// Child<> +// ------------------------ + +namespace child { + + // Some top-level nodes, per LLNL-TR-774621-DRAFT + inline const njoy::GNDStk::Child + PoPs("PoPs"), + reactionSuite("reactionSuite"); + + // With Allow::one + inline const njoy::GNDStk::Child + RMatrix ("RMatrix" ), + angularTwoBody ("angularTwoBody" ), + axes ("axes" ), + CDATA (njoy::GNDStk::special::cdata), + chemicalElements ("chemicalElements" ), + crossSection ("crossSection" ), + data ("data" ), + distribution ("distribution" ), + documentation ("documentation" ), + documentations ("documentations" ), + Double ("double" ), + gaugeBosons ("gaugeBosons" ), + mass ("mass" ), + outputChannel ("outputChannel" ), + DATA (njoy::GNDStk::special::data), + products ("products" ), + reactions ("reactions" ), + regions2d ("regions2d" ), + resolved ("resolved" ), + resonanceParameters("resonanceParameters"), + resonances ("resonances" ), + spin ("spin" ), + spinGroups ("spinGroups" ), + styles ("styles" ), + table ("table" ), + temperature ("temperature" ); + + // With Allow::many + inline const njoy::GNDStk::Child + XYs1d ("XYs1d" ), + axis ("axis" ), + chemicalElement("chemicalElement"), + evaluated ("evaluated" ), + fraction ("fraction" ), + gaugeBoson ("gaugeBoson" ), + product ("product" ), + reaction ("reaction" ), + spinGroup ("spinGroup" ), + values ("values" ); +} // namespace child + +using namespace meta; +using namespace child; + +} // namespace basic + + + +// ----------------------------------------------------------------------------- +// misc:: +// Some miscellaneous Meta and Child objects for use in various test codes. +// These are "miscellaneous" in the sense that some use , meaning that +// they'll retrieve metadata and child nodes in their original form in the +// GNDS tree, while others stipulate specific types. +// ----------------------------------------------------------------------------- + +// Helper for the CDATA Child object below +namespace njoy { +namespace GNDStk { +namespace detail { + // text_metadatum_to_string + class text_metadatum_to_string { + public: + template + void operator()(const NODE &node, std::string &to) const + { + to = node.meta(special::text); + } + }; +} // namespace detail +} // namespace GNDStk +} // namespace njoy + +namespace misc { + +// ------------------------ +// Meta<> +// ------------------------ + +namespace meta { + // int + GNDSTK_MAKE_META(int, A); + GNDSTK_MAKE_META(int, ENDF_MT); + + // double + GNDSTK_MAKE_META(double, format); + + // string + GNDSTK_MAKE_META(std::string, encoding); + GNDSTK_MAKE_META(std::string, evaluation); + GNDSTK_MAKE_META(std::string, id); + GNDSTK_MAKE_META(std::string, label); + GNDSTK_MAKE_META(std::string, projectile); + GNDSTK_MAKE_META(std::string, projectileFrame); + GNDSTK_MAKE_META(std::string, symbol); + GNDSTK_MAKE_META(std::string, target); + GNDSTK_MAKE_META(std::string, unit); + GNDSTK_MAKE_META(std::string, version); + + // value, as double + inline const njoy::GNDStk::Meta dvalue("value"); +} // namespace meta + +// ------------------------ +// Child<> +// ------------------------ + +namespace child { + // Some top-level nodes, per LLNL-TR-774621-DRAFT + inline const njoy::GNDStk::Child + PoPs ("PoPs"), + reactionSuite ("reactionSuite"), + covarianceSuite ("covarianceSuite"), + thermalScattering("thermalScattering"); + + // Misc. Child Objects + GNDSTK_MAKE_CHILD(void, axes, one); + GNDSTK_MAKE_CHILD(void, axis, many); + GNDSTK_MAKE_CHILD(void, chemicalElements, one); + GNDSTK_MAKE_CHILD(void, chemicalElement, many); + GNDSTK_MAKE_CHILD(void, isotopes, one); + GNDSTK_MAKE_CHILD(void, isotope, many); + GNDSTK_MAKE_CHILD(void, nuclides, one); + GNDSTK_MAKE_CHILD(void, reactions, one); + GNDSTK_MAKE_CHILD(void, reaction, many); + GNDSTK_MAKE_CHILD(void, crossSection, one); + GNDSTK_MAKE_CHILD(void, styles, one); + GNDSTK_MAKE_CHILD(void, temperature, one); + inline const njoy::GNDStk::Child + xml(njoy::GNDStk::special::xml); + GNDSTK_MAKE_CHILD(void, evaluated, many); + GNDSTK_MAKE_CHILD(void, XYs1d, many); + + // CDATA + inline const njoy::GNDStk::Child< + std::string, + njoy::GNDStk::Allow::one, + njoy::GNDStk::detail::text_metadatum_to_string + > + CDATA(njoy::GNDStk::special::cdata); +} // namespace child + +using namespace meta; +using namespace child; + +} // namespace misc + + + +// ----------------------------------------------------------------------------- +// Some Child objects that are useful enough as-is that we wish to include them +// in other sets of such objects, in other namespaces. +// ----------------------------------------------------------------------------- + +namespace njoy { +namespace GNDStk { +namespace detail { + +// ------------------------ +// convert_data_text_t +// ------------------------ + +class convert_data_text_t { +public: + + // Node to container + template + void operator()(const njoy::GNDStk::Node &node, CONTAINER &container) const + { + using namespace njoy::GNDStk; + try { + // Context: + // We're inside of a data node that's inside of a node that + // looked something like this (in XML): + // 0.0 1.0 2.0 3.0 4.0 + // In GNDStk, the data node has a metadatum with the key special::text. + // The metadatum's string value is the content: "0.0 1.0 ..." in our + // example. Goal here: extract that content into the container. + container.clear(); + for (auto &m : node.metadata) + if (m.first == special::text) { + convert(m.second, container); + return; + } + log::error( + "Could not find metadatum key \"#text\" " + "in the current Node (\"{}\")", + node.name + ); + throw std::exception{}; + } catch (...) { + log::function("convert_data_text_t(Node,container)"); + throw; + } + } + + // container to Node + template + void operator()(const CONTAINER &container, njoy::GNDStk::Node &node) const + { + using namespace njoy::GNDStk; + try { + node.clear(); + node.name = special::data; + std::string &destination = node.add(special::text,"").second; + convert(container, destination); + } catch (...) { + log::function("convert_data_text_t(container,Node)"); + throw; + } + } +}; + +// ------------------------ +// numeric_type +// ------------------------ + +// default +// create vector +template +class numeric_type { +public: + using type = std::vector; +}; + +// keep deque +template +class numeric_type> { +public: + using type = std::deque; +}; + +// keep list +template +class numeric_type> { +public: + using type = std::list; +}; + +// keep vector +template +class numeric_type> { +public: + using type = std::vector; +}; + +} // namespace detail +} // namespace GNDStk +} // namespace njoy + +// ------------------------ +// Child<> +// ------------------------ + +namespace common { + +// Helper: getNumeric +// Doing numeric (below) strictly as a variable template would lead +// to initialization-order issues with the specializations. +template +const auto &getNumeric() +{ + static const njoy::GNDStk::Child< + // for general T, the following produces a vector; + // for T already a vector, it remains as-is + typename njoy::GNDStk::detail::numeric_type::type, + njoy::GNDStk::Allow::one, + njoy::GNDStk::detail::convert_data_text_t + > ret(njoy::GNDStk::special::data); + return ret; +} + +// numeric +template +inline const auto numeric = getNumeric(); + +// specializations, for float and double +inline const auto floats = getNumeric(); +inline const auto doubles = getNumeric(); + +} // namespace common + +namespace basic { using namespace common; } +namespace misc { using namespace common; } diff --git a/src/GNDStk/type2node.hpp b/src/GNDStk/type2node.hpp index 4fe0bedef..cca58db71 100644 --- a/src/GNDStk/type2node.hpp +++ b/src/GNDStk/type2node.hpp @@ -10,7 +10,7 @@ The description of those, seen in reverse, applies here. In short, these functions are for taking various types, perhaps user-defined, and converting them into a Node that's destined to be added as a child node. -At the moment, this file is empty except for comments. We're intentionally +At the moment, this file is empty except for remarks. We're intentionally leaving it here, as a placeholder, in case we decide that we *should* have some default type-to-Node convert() functions. */ diff --git a/src/GNDStk/type2node/test/type2node.test.cpp b/src/GNDStk/type2node/test/type2node.test.cpp index 6df6ba386..08869528d 100644 --- a/src/GNDStk/type2node/test/type2node.test.cpp +++ b/src/GNDStk/type2node/test/type2node.test.cpp @@ -3,12 +3,13 @@ #include "catch.hpp" #include "GNDStk.hpp" +#include "GNDStk/test/keys.hpp" using namespace njoy::GNDStk; static const std::string correct_node = -R"***(pcdata: - text: 1 2.3 4.56)***"; +R"***(#data: + #text: 1 2.3 4.56)***"; SCENARIO("Testing GNDStk convert(type,Node)") { @@ -18,20 +19,20 @@ SCENARIO("Testing GNDStk convert(type,Node)") { // convert(type,Node) function. // Update, 2020-10-19. The relevant convert() functionality has been - // reformulated into the detail::convert_pcdata_text_t callable object, + // reformulated into the detail::convert_data_text_t callable object, // so we'll reformulate with that. Ultimately, due to the location of // the new code, we should probably put this test material elsewhere. WHEN("type is vector") { std::vector container = { 1, 2.3, 4.56 }; Node n("old name"); - detail::convert_pcdata_text_t{}(container,n); + detail::convert_data_text_t{}(container,n); // one way to check the Node - CHECK(n.name == "pcdata"); + CHECK(n.name == special::data); CHECK(n.metadata.size() == 1); CHECK(n.children.size() == 0); - CHECK(n.metadata[0].first == "text"); + CHECK(n.metadata[0].first == special::text); CHECK(n.metadata[0].second == "1 2.3 4.56"); // a shorter way @@ -42,7 +43,7 @@ SCENARIO("Testing GNDStk convert(type,Node)") { WHEN("type is deque") { std::deque container = { 1, 2.3, 4.56 }; Node n("old name"); - detail::convert_pcdata_text_t{}(container,n); + detail::convert_data_text_t{}(container,n); std::ostringstream oss; oss << n; CHECK(oss.str() == correct_node); } @@ -50,7 +51,7 @@ SCENARIO("Testing GNDStk convert(type,Node)") { WHEN("type is list") { std::list container = { 1, 2.3, 4.56 }; Node n("old name"); - detail::convert_pcdata_text_t{}(container,n); + detail::convert_data_text_t{}(container,n); std::ostringstream oss; oss << n; CHECK(oss.str() == correct_node); } diff --git a/src/GNDStk/type2string.hpp b/src/GNDStk/type2string.hpp index 1ae8f0c38..53db6d2a4 100644 --- a/src/GNDStk/type2string.hpp +++ b/src/GNDStk/type2string.hpp @@ -13,7 +13,7 @@ key/value pair. */ // User-settable flag -inline bool comma = false; +inline bool commas = false; // ----------------------------------------------------------------------------- @@ -34,11 +34,17 @@ inline void convert(const T &value, std::ostream &os) } } +// string +inline void convert(const std::string &value, std::ostream &os) +{ + os << value; +} + // pair template inline void convert(const std::pair &p, std::ostream &os) { - if ((convert(p.first,os),os) && os << (GNDStk::comma ? ',' : ' ')) + if ((convert(p.first,os),os) && os << (GNDStk::commas ? ',' : ' ')) convert(p.second,os); } @@ -49,7 +55,7 @@ inline void convert(const std::pair &p, std::ostream &os) const std::container &value, \ std::ostream &os \ ) { \ - const std::string sep = GNDStk::comma ? "," : " "; \ + const std::string sep = GNDStk::commas ? "," : " "; \ std::size_t count = 0; \ for (const T &val : value) \ if (!(os << (count++ ? sep : "") && (convert(val,os),os))) \ diff --git a/src/GNDStk/type2string/test/type2string.test.cpp b/src/GNDStk/type2string/test/type2string.test.cpp index cf403cfa0..23d9f3c35 100644 --- a/src/GNDStk/type2string/test/type2string.test.cpp +++ b/src/GNDStk/type2string/test/type2string.test.cpp @@ -212,8 +212,8 @@ SCENARIO("Testing some GNDStk::convert(pair,ostream) functionality") { // ------------------------ WHEN("We call convert(pair,ostream)") { - THEN("It works correctly when GNDStk::comma == false") { - njoy::GNDStk::comma = false; // we don't want a comma in the output... + THEN("It works correctly when GNDStk::commas == false") { + njoy::GNDStk::commas = false; // we don't want a comma in the output... const std::pair p(12,34); std::ostringstream oss; njoy::GNDStk::convert(p,oss); @@ -221,8 +221,8 @@ SCENARIO("Testing some GNDStk::convert(pair,ostream) functionality") { CHECK(str == "12 34"); // ...so, no comma } - THEN("It works correctly when GNDStk::comma == true") { - njoy::GNDStk::comma = true; // we do want a comma in the output... + THEN("It works correctly when GNDStk::commas == true") { + njoy::GNDStk::commas = true; // we want a comma in the output... const std::pair p(56,78); std::ostringstream oss; njoy::GNDStk::convert(p,oss); diff --git a/src/GNDStk/utility.hpp b/src/GNDStk/utility.hpp index 1c0979664..499be38e2 100644 --- a/src/GNDStk/utility.hpp +++ b/src/GNDStk/utility.hpp @@ -3,6 +3,8 @@ // Miscellaneous variables, enums, etc. // ----------------------------------------------------------------------------- +using orderedJSON = nlohmann::ordered_json; + // indent // Number of spaces of indentation you want, in the output of certain types inline int indent = 3; @@ -16,17 +18,12 @@ inline std::string indentTo(const int level) // Should Node's debugging output print addresses and parent-node addresses? inline bool parents = false; -// top -// When reading, check whether the document node is in our list of allowable -// GNDS top-level nodes -inline bool top = false; - // file type / format enum class FileType { - // default, automagick, etc. - null, - // our plain text format (for writing only) - text, + // default: guess from file magic number (input) or extension (output) + guess, + // our plain-text "debug format"; for writing only (not reading) + debug, // give users easy-to-type lowercase as well as acronym-style uppercase... xml, XML = xml, json, JSON = json, @@ -39,6 +36,25 @@ enum class Allow { many }; +namespace special { + inline const char prefix = '#'; + + inline const std::string + any = prefix + std::string(""), + decl = prefix + std::string(""), + nodename = prefix + std::string("nodename"), + metadata = prefix + std::string("metadata"), + cdata = prefix + std::string("cdata"), + data = prefix + std::string("data"), + self = prefix + std::string("self"), + anydata = cdata + "|" + data, // either + comment = prefix + std::string("comment"), + text = prefix + std::string("text"), + xml = prefix + std::string("xml"), + json = prefix + std::string("json"), + hdf5 = prefix + std::string("hdf5"); +} + namespace detail { // default_* @@ -59,19 +75,6 @@ inline bool sent(const std::string &string) return &string != &default_string; } -// allowable declaration nodes -inline std::set AllowedDecl = { - "xml", - "json", - "hdf5", -}; - -// allowable top-level GNDS nodes -inline std::set AllowedTop = { - // added as they're identified - // in our Child class -}; - // noFilter class noFilter { public: @@ -92,37 +95,14 @@ inline void failback(std::istream &is, const std::streampos pos) // ----------------------------------------------------------------------------- -// Helper constructs for some simple Log-enhancing pretty-printing +// Helper constructs for some simple Log-enhancing prettyprinting // ----------------------------------------------------------------------------- -// align, color +// align, colors // Users can set these in their own codes. // Remember that they're scoped in njoy::GNDStk, like other things. -inline bool align = true; // extra spaces, to line stuff up for easy reading -inline bool color = false; // default: impose no ANSI escape-sequence clutter - -// fixme A possible concern here is that the alignment, as controlled by the -// align bool, is only applied to the message string that's sent as the first -// parameter to our log:: functions - not to the entire message that might be -// constructed and printed. -// -// Imagine that you wrote: -// -// log::error("Some information: {}", someStringParameterWithNewlines); -// -// Our log:: functions ultimately forward their own parameters to the external -// Log library for final handling. Before doing so, they process the message -// string ("Some information: {}", in our example above). If align == true, -// they create a *modified* message string - with spacing for alignment after -// any newlines. However, content that arrives through the "{}"s, from other -// parameters, and that has newlines, doesn't get alignment spacing. Someone -// might then see the diagnostic, and believe that our alignment flag is broken. -// -// We should consider solutions to this - ones that don't require replicating -// too much content from the external Log library, and that allow us to still -// take advantage of its convenient "{}" notation for writing parameters. For -// now, a few particular "long" diagnostic messages in GNDStk are formatted -// and printed completely into the format string, so that we avoid this issue. +inline bool align = true; // extra spaces, to line stuff up for easy reading +inline bool colors = true; // default: yes, colors. Switch off if not wanted. namespace detail { @@ -132,21 +112,37 @@ inline std::string diagnostic( const std::string &message, const std::string &prefix = "" ) { + // Remark. Below, if align == true, we place spaces after any newlines that + // appear in the message, so that output that would otherwise: + // [error] look something + // like this + // will instead: + // [error] look something + // like this + // Later, in functions like our error() and warning(), strings returned from + // this present (diagnostic()) function are sent to one of the Log:: library + // functions. Those replace instances of "{}" with the values of parameters, + // similarly to how the old C language printf() replaces "%". The code below + // just does the alignment business for the message string, not for any of + // those additional parameters. In the event that one of those is a string, + // and has newlines, alignment may not be as one might initially expect. So, + // this is just something to be aware of. + static std::map codes = { - { "info", "\033[36;21m" }, // cyan - { "warning", "\033[33;1m" }, // yellow - { "error", "\033[31;21m" }, // red - { "debug", "\033[37;21m" } // white + { "info", "\033[32;1m" }, // green + { "warning", "\033[33;1m" }, // yellow + { "error", "\033[31;1m" }, // red + { "debug", "\033[37;1m" } // white }; static const std::string under = "\033[4m"; // underline on static const std::string unoff = "\033[24m"; // underline off - static const std::string reset = "\033[0m"; // all color/decorations off + static const std::string reset = "\033[0m"; // all colors/decorations off static const std::size_t warn = 7; // length of "warning", the longest label // full text, including the (possibly underlined) prefix if one was provided const std::string text = prefix == "" ? message - : (color ? under : "") + prefix + (color ? unoff : "") + ": " + message; + : (colors ? under : "") + prefix + (colors ? unoff : "") + ": " + message; // full text, possibly spaced for alignment std::string spaced, indent = std::string(warn+3,' '); // 3 for '[', ']', ' ' @@ -157,8 +153,14 @@ inline std::string diagnostic( } else spaced = text; - // final message, possibly colorized - return color ? codes[label] + spaced + reset : spaced; + // final message, possibly colored + return colors ? codes[label] + spaced + reset : spaced; +} + +// context +inline std::string context(const std::string &type, const std::string &name) +{ + return diagnostic("info", type + " " + name, "Context"); } } // namespace detail @@ -166,26 +168,34 @@ inline std::string diagnostic( // ----------------------------------------------------------------------------- -// Miscellaneous output/printing related flags +// Miscellaneous flags // ----------------------------------------------------------------------------- // ------------------------ // re: Component class // ------------------------ -// Should Component's generic write() function print comments? +// Should vectors in Component-derived classes be sorted automatically? +inline bool sort = false; + +// Should Component's generic print() function print comments? inline bool comments = true; // For printing. -// When writing a Component with its generic write() function (or its stream -// output, which uses write()), AND the Component is based on a BodyText with -// hasBodyText == true, values will be printed with GNDStk::columns across. -// "columns" is aliased to "across" for convenience, because, at the time of -// this writing, GNDStk has a Meta<> object, named "columns", which would also -// be in scope if the core namespace is used. So, a user might prefer to use -// the name "across". -inline std::size_t columns = 4; -inline std::size_t &across = columns; +// +// Applicable when writing a Component with its "prettyprinting" generic write() +// function - or with its stream output, which uses its generic write(). +// +// If the Component is based on a BlockData with hasBlockData == true, then data +// are printed using GNDStk::columns columns. If columns <= 0, it means to print +// all data on one line. +// +// If the data array's size is large, a user may wish to limit the total number +// of printed values. This can be done with the "elements" variable. A value of +// less than 0 means unlimited. All other values, including 0, mean to print no +// more than that number of values. +inline long columns = 4; +inline long elements = -1; @@ -193,16 +203,15 @@ inline std::size_t &across = columns; // Flags for fine-tuning diagnostic output // ----------------------------------------------------------------------------- -// Names of these flags align with those in our log:: functions (see below), -// for consistency and predictability. These are in namespace GNDStk while -// those are in namespace GNDStk::log, so the names don't conflict. +// Names of these flags reflect names in our log:: functions (see below), for +// consistency and predictability. These flags are in namespace GNDStk, while +// those are in namespace GNDStk::log; so, the names don't conflict. // Print info messages? (with log::info()) -inline bool info = true; +inline bool notes = true; // Print warnings? (with log::warning()) -inline bool warning = true; -inline bool &warnings = warning; // alias; plural may "read" better +inline bool warnings = true; // Print debug messages? (with log::debug()) inline bool debug = false; @@ -211,6 +220,7 @@ inline bool debug = false; // log::function() // log::member() // log::ctor() +// log::dtor() // log::assign() inline bool context = true; @@ -230,9 +240,9 @@ namespace log { // info template -inline void info(const std::string &str, Args &&...args) +void info(const std::string &str, Args &&...args) { - if (GNDStk::info) { + if (GNDStk::notes) { const std::string msg = detail::diagnostic("info",str); Log::info(msg.data(), std::forward(args)...); } @@ -240,9 +250,9 @@ inline void info(const std::string &str, Args &&...args) // warning template -inline void warning(const std::string &str, Args &&...args) +void warning(const std::string &str, Args &&...args) { - if (GNDStk::warning) { + if (GNDStk::warnings) { const std::string msg = detail::diagnostic("warning",str); Log::warning(msg.data(), std::forward(args)...); } @@ -250,7 +260,7 @@ inline void warning(const std::string &str, Args &&...args) // error template -inline void error(const std::string &str, Args &&...args) +void error(const std::string &str, Args &&...args) { const std::string msg = detail::diagnostic("error",str); Log::error(msg.data(), std::forward(args)...); @@ -258,7 +268,7 @@ inline void error(const std::string &str, Args &&...args) // debug template -inline void debug(const std::string &str, Args &&...args) +void debug(const std::string &str, Args &&...args) { if (GNDStk::debug) { const std::string msg = detail::diagnostic("debug",str); @@ -272,48 +282,59 @@ inline void debug(const std::string &str, Args &&...args) // some context information // ------------------------ -// context is a regular function +// context (general) template -inline void function(const std::string &str, Args &&...args) +void context(const std::string &str, Args &&...args) { if (GNDStk::context) { - const std::string msg = - detail::diagnostic("info", "function " + str, "Context"); + const std::string msg = detail::diagnostic("info",str); Log::info(msg.data(), std::forward(args)...); } } +// context is a regular function +template +void function(const std::string &str, Args &&...args) +{ + if (GNDStk::context) + Log::info(detail::context("function", str).data(), + std::forward(args)...); +} + // context is a member function template -inline void member(const std::string &str, Args &&...args) +void member(const std::string &str, Args &&...args) { - if (GNDStk::context) { - const std::string msg = - detail::diagnostic("info", "member function " + str, "Context"); - Log::info(msg.data(), std::forward(args)...); - } + if (GNDStk::context) + Log::info(detail::context("member function", str).data(), + std::forward(args)...); } // context is a constructor template -inline void ctor(const std::string &str, Args &&...args) +void ctor(const std::string &str, Args &&...args) { - if (GNDStk::context) { - const std::string msg = - detail::diagnostic("info", "constructor " + str, "Context"); - Log::info(msg.data(), std::forward(args)...); - } + if (GNDStk::context) + Log::info(detail::context("constructor", str).data(), + std::forward(args)...); +} + +// context is a destructor +template +void dtor(const std::string &str, Args &&...args) +{ + if (GNDStk::context) + Log::info(detail::context("destructor", str).data(), + std::forward(args)...); } // context is an assignment operator template -inline void assign(const std::string &str, Args &&...args) +void assign(const std::string &str, Args &&...args) { - if (GNDStk::context) { - const std::string msg = - detail::diagnostic("info", "assignment " + str, "Context"); - Log::info(msg.data(), std::forward(args)...); - } + if (GNDStk::context) + Log::info(detail::context("assignment", str).data(), + std::forward(args)...); } } // namespace log @@ -323,44 +344,42 @@ inline void assign(const std::string &str, Args &&...args) // ----------------------------------------------------------------------------- // Forward declarations: some classes; convert // We're not fans of having lots of forward declarations, but these are here -// because (1) the relevant classes (Tree, XML, JSON) use these functions in, -// e.g., their constructors, which are defined in-class; and (2) the convert() -// functions in turn work with the classes and thus need the class definitions -// to be available. The alternative would be to mostly define the classes, but -// only declare their constructors; then define the convert()s; then finally -// define the constructors. We think the forward declarations are clearer. +// because (1) relevant classes use these functions in, for example, their +// constructors, which are defined in-class; and (2) our convert() functions +// in turn work with the classes and thus need the class definitions to be +// available. The alternative would be to mostly define the classes, but only +// declare their constructors; then define the convert()s; then finally define +// the constructors. We think the forward declarations are clearer. // ----------------------------------------------------------------------------- -// Node class Node; - -// Tree -class Tree; - -// XML, JSON class XML; class JSON; +class HDF5; -// Node to {XML,JSON} -bool convert(const Node &, XML &x); -bool convert(const Node &, JSON &j); - -// Tree to {Tree,XML,JSON} -bool convert(const Tree &, Tree &); -bool convert(const Tree &, XML &); -bool convert(const Tree &, JSON &); +// Node ==> {Node,XML,JSON,HDF5} +bool convert(const Node &, Node &); +bool convert(const Node &, XML &); +bool convert(const Node &, JSON &); +bool convert(const Node &, HDF5 &, const std::string & = ""); -// XML to {Node,Tree,XML,JSON} -bool convert(const XML &, Node &, const bool); -bool convert(const XML &, Tree &); +// XML ==> {Node,XML,JSON,HDF5} +bool convert(const XML &, Node &, const bool & = detail::default_bool); bool convert(const XML &, XML &); bool convert(const XML &, JSON &); +bool convert(const XML &, HDF5 &); -// JSON to {Node,Tree,XML,JSON} -bool convert(const JSON &, Node &, const bool); -bool convert(const JSON &, Tree &); +// JSON ==> {Node,XML,JSON,HDF5} +bool convert(const JSON &, Node &, const bool & = detail::default_bool); bool convert(const JSON &, XML &); bool convert(const JSON &, JSON &); +bool convert(const JSON &, HDF5 &); + +// HDF5 ==> {Node,XML,JSON,HDF5} +bool convert(const HDF5 &, Node &, const bool & = detail::default_bool); +bool convert(const HDF5 &, XML &); +bool convert(const HDF5 &, JSON &); +bool convert(const HDF5 &, HDF5 &); @@ -368,7 +387,7 @@ bool convert(const JSON &, JSON &); // Utility constructs // The functions here could possibly go into the detail namespace, but could // arguably be useful, in their own right, to users. So, I'll leave them out -// in the overall project namespace (which enclosed the #include of this file). +// in the overall project namespace. // ----------------------------------------------------------------------------- // endsin @@ -378,9 +397,15 @@ inline bool endsin(const std::string &str, const std::string &end) return str.size() >= end.size() && &str[str.size()-end.size()] == end; } +// beginsin +inline bool beginsin(const std::string &str, const std::string &begin) +{ + return strncmp(&str[0], &begin[0], begin.size()) == 0; +} + // nocasecmp // Case-insensitive string comparison. -// The old C-language strcasecmp() is nonstandard. A modern, true caseless +// The old C language strcasecmp() is nonstandard. A modern, true caseless // string comparison is actually a tougher nut to crack than meets the eye, // but the following will suffice for our English-language purposes. inline bool nocasecmp(const std::string &one, const std::string &two) @@ -424,36 +449,44 @@ inline bool endsin_json(const std::string &str) inline bool endsin_hdf5(const std::string &str) { return - endsin(str,".hdf" ) - || endsin(str,".HDF" ) - || endsin(str,".h5" ) + endsin(str,".h5" ) || endsin(str,".H5" ) || endsin(str,".hdf5") || endsin(str,".HDF5") || endsin(str,".he5" ) - || endsin(str,".HE5" ); + || endsin(str,".HE5" ) + || endsin(str,".hdf" ) + || endsin(str,".HDF" ); + // The last two aren't official HDF5 extensions, but we'll allow them. This + // was motivated by the experience of one of our users, who wrote a file with + // the .hdf extension. At the time, we didn't recognize .hdf as an allowable + // HDF5 extention, and so our "file type guesser" fell back on its default: + // our internal debug-dump format. The user saw the debug dump, and wondered + // if it was HDF5. (It wasn't.) So, now, we'll write HDF5 when someone calls + // their file something.hdf or something.HDF. But if that happens, then we'll + // also print a message about that extension not officially being for HDF5. } // ----------------------------------------------------------------------------- // Re: file format indicators -// These are used in places where we're allowing a user to give a string, +// These are used in places where we're allowing a user to provide a string, // e.g. "xml", in place of a file format specifier ala enum class file. // ----------------------------------------------------------------------------- -// null -inline bool eq_null(const std::string &str) +// guess +inline bool eq_guess(const std::string &str) { return - nocasecmp(str,"null") || str == ""; + nocasecmp(str,"guess") || str == ""; } // tree -inline bool eq_text(const std::string &str) +inline bool eq_debug(const std::string &str) { return - nocasecmp(str,"text"); + nocasecmp(str,"debug"); } // xml @@ -474,10 +507,23 @@ inline bool eq_json(const std::string &str) inline bool eq_hdf5(const std::string &str) { return - nocasecmp(str,"hdf" ) - || nocasecmp(str,"h5" ) + nocasecmp(str,"h5" ) || nocasecmp(str,"hdf5") - || nocasecmp(str,"he5" ); + || nocasecmp(str,"he5" ) + || nocasecmp(str,"hdf" ); // not official, but we'll allow +} + +inline FileType string2filetype(const std::string &str, bool &matched) +{ + matched = true; + if (eq_guess(str)) return FileType::guess; + if (eq_debug(str)) return FileType::debug; + if (eq_xml (str)) return FileType::xml; + if (eq_json (str)) return FileType::json; + if (eq_hdf5 (str)) return FileType::hdf5; + + matched = false; + return FileType::guess; } @@ -493,17 +539,21 @@ namespace detail { // ------------------------ template -class isVariant { -public: +struct isVariant { static constexpr bool value = false; }; template -class isVariant> { -public: +struct isVariant> { static constexpr bool value = true; }; +template +inline constexpr bool isVariant_v = isVariant::value; + +template +using isVariant_t = std::enable_if_t>; + // ------------------------ // isAlternative // ------------------------ @@ -512,15 +562,13 @@ class isVariant> { // no (general case) template -class is_alternative { -public: +struct is_alternative { static constexpr bool value = false; }; // yes template -class is_alternative> { -public: +struct is_alternative> { static constexpr bool value = (std::is_same_v || ...); }; @@ -528,54 +576,19 @@ template inline constexpr bool isAlternative = is_alternative::value; -// ------------------------ -// isAlternativeOrTheVariant -// ------------------------ - -// Is T one of the alternatives in variant, OR is T == variant -// itself? (Not any variant, but precisely that one.) -// -// Consider the functionality (Node::meta() and Node::child(), at the time of -// this writing) that use this. Invoked with a particular type from the variant, -// a call - say, to meta() - might look like node.template meta(M), where -// M is a Meta<> object with the variant type. In contrast, one could merely -// write node.meta(M) for the full variant, i.e. with no specific alternative -// type stipulated. By making this SFINAE work for the full variant, not just -// for each of its constituent types (as with isAlternative), we allow the -// node.template meta(M) form also to work for the full variant. While -// the short (and no doubt preferred) form would be available even without the -// following, we choose to support consistency by allowing the .template form -// to be used too. This might prove to be useful if, for instance, a user embeds -// the call in question into a single function template that invokes the long -// form, while intending to support calls of either the full variant or any of -// its types. - -template -class is_alternativeOrTheVariant { -public: - static constexpr bool value = - isAlternative || std::is_same_v; -}; - -template -inline constexpr bool isAlternativeOrTheVariant = - is_alternativeOrTheVariant::value; - // ------------------------ // is_void // ------------------------ // general template -class is_void { -public: +struct is_void { static constexpr bool value = false; }; // void template<> -class is_void { -public: +struct is_void { static constexpr bool value = true; using type = void; }; @@ -590,16 +603,14 @@ inline constexpr bool isVoid = is_void::value; // general template -class isNotVoid { -public: +struct isNotVoid { static constexpr bool value = true; using type = T; }; // void template<> -class isNotVoid { -public: +struct isNotVoid { static constexpr bool value = false; }; @@ -608,25 +619,24 @@ class isNotVoid { // isIterable // ------------------------ -// fixme -// At some point, we really need a reliable "is_container" traits class. -// For now, I'll use this. +// The intention of this traits class is to decide if an object of the given +// type is suitable for use as the range-expression in a range-based for-loop. +// For now, we're just checking that it has a begin() and an end(). This is +// probably sufficient for our needs, and could be relaxed later if necessary. template -class isIterable { -public: +struct isIterable { static constexpr bool value = false; }; template -class isIterable< +struct isIterable< T, std::void_t< decltype(std::declval().begin()), decltype(std::declval().end()) > > { -public: static constexpr bool value = true; }; @@ -635,21 +645,90 @@ class isIterable< // ----------------------------------------------------------------------------- -// print_format +// printFormat // ----------------------------------------------------------------------------- namespace detail { -inline std::string print_format(const FileType f, const bool brief = false) +inline std::string printFormat(const FileType f) { - return std::string(brief ? "" : "FileType::") + ( - f == FileType::null ? "null" - : f == FileType::text ? "text" - : f == FileType::xml ? "XML" - : f == FileType::json ? "JSON" - : f == FileType::hdf5 ? "HDF5" + return std::string("FileType::") + ( + f == FileType::guess ? "guess" + : f == FileType::debug ? "debug" + : f == FileType::xml ? "XML" + : f == FileType::json ? "JSON" + : f == FileType::hdf5 ? "HDF5" : "unknown" ); } } // namespace detail + + + +// ----------------------------------------------------------------------------- +// Re: OpenMP +// Completely optional - and turned off by default - to use in GNDStk. +// A user must compile with -fopenmp (g++/clang++) to get OpenMP at all. +// At the moment, what we do with threading is very limited. +// ----------------------------------------------------------------------------- + +// Number of threads +// Users can set this in their own codes +inline int threads = 1; + +namespace detail { + +#ifdef _OPENMP + // get_nthreads() + inline int get_nthreads() + { + const int want = njoy::GNDStk::threads; + const int have = omp_get_num_procs(); + + if (want <= 0) + return std::max(1,want+have); + if (want >= have) + return have; + return want; + } + + // set_nthreads() + inline void set_nthreads(const int nthreads) + { + omp_set_num_threads(nthreads); + } + + // this_thread() + inline int this_thread() + { + return omp_get_thread_num(); + } +#else + inline int get_nthreads() { return 1; } + inline void set_nthreads(const int) { /* nothing */ } + inline int this_thread () { return 0; } +#endif + +} // namespace detail + + +// ----------------------------------------------------------------------------- +// DataNode +// ----------------------------------------------------------------------------- + +template +struct DataNode : public T +{ + using T::operator=; + bool cdata = preferCDATA; + + // constructors + explicit DataNode(const T &from = T{}) : T(from) { } + DataNode(const DataNode &from) = default; + DataNode(DataNode &&from) = default; + + // assignment + DataNode &operator=(const DataNode &from) = default; + DataNode &operator=(DataNode &&from) = default; +}; diff --git a/src/GNDStk/v1.9.hpp b/src/GNDStk/v1.9.hpp deleted file mode 100644 index a38502179..000000000 --- a/src/GNDStk/v1.9.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9 -#define NJOY_GNDSTK_V1_9 - -#include "GNDStk/v1.9/containers/Axes.hpp" -#include "GNDStk/v1.9/containers/Axis.hpp" -#include "GNDStk/v1.9/containers/Grid.hpp" -#include "GNDStk/v1.9/containers/Link.hpp" -#include "GNDStk/v1.9/containers/Regions1d.hpp" -#include "GNDStk/v1.9/containers/Values.hpp" -#include "GNDStk/v1.9/containers/XYs1d.hpp" - -#include "GNDStk/v1.9/transport/CrossSection.hpp" -#include "GNDStk/v1.9/transport/Reaction.hpp" -#include "GNDStk/v1.9/transport/ReactionSuite.hpp" -#include "GNDStk/v1.9/transport/Reactions.hpp" - -#include "GNDStk/v1.9/key.hpp" - -#endif diff --git a/src/GNDStk/v1.9/containers/Axes.hpp b/src/GNDStk/v1.9/containers/Axes.hpp deleted file mode 100644 index cee1b9753..000000000 --- a/src/GNDStk/v1.9/containers/Axes.hpp +++ /dev/null @@ -1,294 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_AXES -#define NJOY_GNDSTK_V1_9_CONTAINERS_AXES - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/containers/Axis.hpp" -#include "GNDStk/v1.9/containers/Grid.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Axes -// ----------------------------------------------------------------------------- - -namespace containers { - -class Axes : public Component { - - using axis_grid_t = std::variant< - containers::Axis, - containers::Grid - >; - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Axes"; } - static auto GNDSName() { return "axes"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("href") | - // children - axis_grid_t{} - / ++(Child<>("axis") || Child<>("grid")) - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::optional href; - // children - variant - std::vector axis_grid; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // href - const std::optional &href() const - { return content.href; } - std::optional &href() - { return content.href; } - - // axis_grid - const std::vector &axis_grid() const - { return content.axis_grid; } - std::vector &axis_grid() - { return content.axis_grid; } - - // axis_grid(index) - const axis_grid_t &axis_grid(const std::size_t index) const - { return getter(axis_grid(), index, "axis_grid"); } - axis_grid_t &axis_grid(const std::size_t index) - { return getter(axis_grid(), index, "axis_grid"); } - - // axis_grid(label) - const axis_grid_t &axis_grid(const std::string &label) const - { return getter(axis_grid(), label, "axis_grid"); } - axis_grid_t &axis_grid(const std::string &label) - { return getter(axis_grid(), label, "axis_grid"); } - - // axis(index) - const containers::Axis *axis(const std::size_t index) const - { return getter(axis_grid(), index, "axis"); } - containers::Axis *axis(const std::size_t index) - { return getter(axis_grid(), index, "axis"); } - - // axis(label) - const containers::Axis *axis(const std::string &label) const - { return getter(axis_grid(), label, "axis"); } - containers::Axis *axis(const std::string &label) - { return getter(axis_grid(), label, "axis"); } - - // grid(index) - const containers::Grid *grid(const std::size_t index) const - { return getter(axis_grid(), index, "grid"); } - containers::Grid *grid(const std::size_t index) - { return getter(axis_grid(), index, "grid"); } - - // grid(label) - const containers::Grid *grid(const std::string &label) const - { return getter(axis_grid(), label, "grid"); } - containers::Grid *grid(const std::string &label) - { return getter(axis_grid(), label, "grid"); } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // href(value) - Axes &href(const std::optional &obj) - { href() = obj; return *this; } - - // axis_grid(value) - Axes &axis_grid(const std::vector &obj) - { axis_grid() = obj; return *this; } - - // axis_grid(index,value) - Axes &axis_grid( - const std::size_t index, - const axis_grid_t &obj - ) { - axis_grid(index) = obj; return *this; - } - - // axis_grid(label,value) - Axes &axis_grid( - const std::string &label, - const axis_grid_t &obj - ) { - axis_grid(label) = obj; return *this; - } - - // axis(index,value) - Axes &axis( - const std::size_t index, - const std::optional &obj - ) { - if (obj) axis_grid(index,obj.value()); - return *this; - } - - // axis(label,value) - Axes &axis( - const std::string &label, - const std::optional &obj - ) { - if (obj) axis_grid(label,obj.value()); - return *this; - } - - // grid(index,value) - Axes &grid( - const std::size_t index, - const std::optional &obj - ) { - if (obj) axis_grid(index,obj.value()); - return *this; - } - - // grid(label,value) - Axes &grid( - const std::string &label, - const std::optional &obj - ) { - if (obj) axis_grid(label,obj.value()); - return *this; - } - - // ------------------------ - // Construction - // ------------------------ - - // default - Axes() : - Component{ - BodyText{}, - content.href, - content.axis_grid - } - { - Component::finish(); - } - - // copy - Axes(const Axes &other) : - Component{ - other, - content.href, - content.axis_grid - }, - content{other.content} - { - Component::finish(other); - } - - // move - Axes(Axes &&other) : - Component{ - other, - content.href, - content.axis_grid - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Axes(const Node &node) : - Component{ - BodyText{}, - content.href, - content.axis_grid - } - { - Component::finish(node); - } - - // from fields - explicit Axes( - const std::optional &href, - const std::vector &axis_grid - ) : - Component{ - BodyText{}, - content.href, - content.axis_grid - }, - content{ - href, - axis_grid - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Axes &operator=(const Axes &) = default; - - // move - Axes &operator=(Axes &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Axes/src/custom.hpp" - -}; // class Axes - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Axes/test/Axes.test.cpp b/src/GNDStk/v1.9/containers/Axes/test/Axes.test.cpp deleted file mode 100644 index 38e513bd2..000000000 --- a/src/GNDStk/v1.9/containers/Axes/test/Axes.test.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" -#include "GNDStk/v1.9/containers/Axes.hpp" - -// other includes - -// convenience typedefs -using namespace njoy::GNDStk; -using Axes = v1_9::containers::Axes; -using Axis = v1_9::containers::Axis; -using Grid = v1_9::containers::Grid; -using Values = v1_9::containers::Values; -using Link = v1_9::containers::Link; - -std::string chunk(); -void verifyChunk( const Axes& ); -std::string invalidName(); - -SCENARIO( "Axes" ) { - - GIVEN( "valid data for the component" ) { - - std::string string = chunk(); - - WHEN( "autogenerated constructor: the data is given explicitly" ) { - - std::vector< std::variant< Axis, Grid > > axis = { - - Axis( 1, "energy_in", "eV" ), - Axis( 0, "radius", "fm" ) - }; - - Axes chunk( std::nullopt, axis ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - - WHEN( "the data is constructed from a node" ) { - - Node node; - node << chunk(); - Axes chunk( node ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - } // GIVEN - - GIVEN( "a valid component instance" ) { - - WHEN( "the component is copied" ) { - - Node node; - node << chunk(); - Axes chunk( node ); - - // copy constructor - Axes copy( chunk ); - - // copy assignment - Axes assign; - assign = chunk; - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( copy ); - verifyChunk( assign ); - } // THEN - } // WHEN - - WHEN( "the data is moved" ) { - - Node node; - node << chunk(); - Axes chunk( node ); - Axes chunk2( node ); - - // move constructor - Axes move( std::move( chunk ) ); - - // move assignment - Axes assign; - assign = std::move( chunk2 ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( move ); - verifyChunk( assign ); - } // THEN - } // WHEN - } // GIVEN - - GIVEN( "invalid data" ) { - - WHEN( "when the wrong node is used" ) { - - Node node; - node << invalidName(); - - THEN( "an exception is thrown" ) { - - CHECK_THROWS( Axes( node ) ); - } // THEN - } // WHEN - } // GIVEN -} // SCENARIO - -std::string chunk() { - - return -R"***( - - - -)***"; -} - -void verifyChunk( const Axes& component ) { - - CHECK( std::nullopt == component.href() ); - - CHECK( 2 == component.axis_grid().size() ); - CHECK( 2 == component.size() ); - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // indexing into the vector and accessing the variant directly - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - decltype(auto) axis_i0 = std::get< Axis >( component.axis_grid()[0] ); - - CHECK( std::nullopt != axis_i0.index() ); - CHECK( std::nullopt != axis_i0.label() ); - CHECK( std::nullopt != axis_i0.unit() ); - - CHECK( 0 == axis_i0.index().value() ); - CHECK( "radius" == axis_i0.label().value() ); - CHECK( "fm" == axis_i0.unit().value() ); - - decltype(auto) axis_i1 = std::get< Axis >( component.axis_grid()[1] ); - - CHECK( std::nullopt != axis_i1.index() ); - CHECK( std::nullopt != axis_i1.label() ); - CHECK( std::nullopt != axis_i1.unit() ); - - CHECK( 1 == axis_i1.index().value() ); - CHECK( "energy_in" == axis_i1.label().value() ); - CHECK( "eV" == axis_i1.unit().value() ); - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // using the index based axis_grid getter and accessing the variant directly - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//! @todo a compilation issue exists, where a pointer is returned instead of a reference? - - decltype(auto) axis_ii0 = std::get< Axis >( component.axis_grid( 0 ) ); - - CHECK( std::nullopt != axis_ii0.index() ); - CHECK( std::nullopt != axis_ii0.label() ); - CHECK( std::nullopt != axis_ii0.unit() ); - - CHECK( 0 == axis_ii0.index().value() ); - CHECK( "radius" == axis_ii0.label().value() ); - CHECK( "fm" == axis_ii0.unit().value() ); - - decltype(auto) axis_ii1 = std::get< Axis >( component.axis_grid( 1 ) ); - - CHECK( std::nullopt != axis_ii1.index() ); - CHECK( std::nullopt != axis_ii1.label() ); - CHECK( std::nullopt != axis_ii1.unit() ); - - CHECK( 1 == axis_ii1.index().value() ); - CHECK( "energy_in" == axis_ii1.label().value() ); - CHECK( "eV" == axis_ii1.unit().value() ); - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // using the label based axis_grid getter and accessing the variant directly - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - decltype(auto) axis_iii0 = std::get< Axis >( component.axis_grid( "radius" ) ); - - CHECK( std::nullopt != axis_iii0.index() ); - CHECK( std::nullopt != axis_iii0.label() ); - CHECK( std::nullopt != axis_iii0.unit() ); - - CHECK( 0 == axis_iii0.index().value() ); - CHECK( "radius" == axis_iii0.label().value() ); - CHECK( "fm" == axis_iii0.unit().value() ); - - decltype(auto) axis_iii1 = std::get< Axis >( component.axis_grid( "energy_in" ) ); - - CHECK( std::nullopt != axis_iii1.index() ); - CHECK( std::nullopt != axis_iii1.label() ); - CHECK( std::nullopt != axis_iii1.unit() ); - - CHECK( 1 == axis_iii1.index().value() ); - CHECK( "energy_in" == axis_iii1.label().value() ); - CHECK( "eV" == axis_iii1.unit().value() ); - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // using the index based axis getter - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - decltype(auto) axis_iv0 = *component.axis( 0 ); - - CHECK( std::nullopt != axis_iv0.index() ); - CHECK( std::nullopt != axis_iv0.label() ); - CHECK( std::nullopt != axis_iv0.unit() ); - - CHECK( 0 == axis_iv0.index().value() ); - CHECK( "radius" == axis_iv0.label().value() ); - CHECK( "fm" == axis_iv0.unit().value() ); - - decltype(auto) axis_iv1 = *component.axis( 1 ); - - CHECK( std::nullopt != axis_iv1.index() ); - CHECK( std::nullopt != axis_iv1.label() ); - CHECK( std::nullopt != axis_iv1.unit() ); - - CHECK( 1 == axis_iv1.index().value() ); - CHECK( "energy_in" == axis_iv1.label().value() ); - CHECK( "eV" == axis_iv1.unit().value() ); - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // using the label based axis getter - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - decltype(auto) axis_v0 = *component.axis( "radius" ); - - CHECK( std::nullopt != axis_v0.index() ); - CHECK( std::nullopt != axis_v0.label() ); - CHECK( std::nullopt != axis_v0.unit() ); - - CHECK( 0 == axis_v0.index().value() ); - CHECK( "radius" == axis_v0.label().value() ); - CHECK( "fm" == axis_v0.unit().value() ); - - decltype(auto) axis_v1 = *component.axis( "energy_in" ); - - CHECK( std::nullopt != axis_v1.index() ); - CHECK( std::nullopt != axis_v1.label() ); - CHECK( std::nullopt != axis_v1.unit() ); - - CHECK( 1 == axis_v1.index().value() ); - CHECK( "energy_in" == axis_v1.label().value() ); - CHECK( "eV" == axis_v1.unit().value() ); -} - -std::string invalidName() { - - // wrong name for the node - return -R"***( - - -)***"; -} diff --git a/src/GNDStk/v1.9/containers/Axis.hpp b/src/GNDStk/v1.9/containers/Axis.hpp deleted file mode 100644 index 2fb9d900f..000000000 --- a/src/GNDStk/v1.9/containers/Axis.hpp +++ /dev/null @@ -1,216 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_AXIS -#define NJOY_GNDSTK_V1_9_CONTAINERS_AXIS - -// core interface -#include "GNDStk.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Axis -// ----------------------------------------------------------------------------- - -namespace containers { - -class Axis : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Axis"; } - static auto GNDSName() { return "axis"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("index") | - std::optional{} - / Meta<>("label") | - std::optional{} - / Meta<>("unit") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::optional index; - std::optional label; - std::optional unit; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // index - const std::optional &index() const - { return content.index; } - std::optional &index() - { return content.index; } - - // label - const std::optional &label() const - { return content.label; } - std::optional &label() - { return content.label; } - - // unit - const std::optional &unit() const - { return content.unit; } - std::optional &unit() - { return content.unit; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // index(value) - Axis &index(const std::optional &obj) - { index() = obj; return *this; } - - // label(value) - Axis &label(const std::optional &obj) - { label() = obj; return *this; } - - // unit(value) - Axis &unit(const std::optional &obj) - { unit() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Axis() : - Component{ - BodyText{}, - content.index, - content.label, - content.unit - } - { - Component::finish(); - } - - // copy - Axis(const Axis &other) : - Component{ - other, - content.index, - content.label, - content.unit - }, - content{other.content} - { - Component::finish(other); - } - - // move - Axis(Axis &&other) : - Component{ - other, - content.index, - content.label, - content.unit - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Axis(const Node &node) : - Component{ - BodyText{}, - content.index, - content.label, - content.unit - } - { - Component::finish(node); - } - - // from fields - explicit Axis( - const std::optional &index, - const std::optional &label, - const std::optional &unit - ) : - Component{ - BodyText{}, - content.index, - content.label, - content.unit - }, - content{ - index, - label, - unit - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Axis &operator=(const Axis &) = default; - - // move - Axis &operator=(Axis &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Axis/src/custom.hpp" - -}; // class Axis - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Axis/src/custom.hpp b/src/GNDStk/v1.9/containers/Axis/src/custom.hpp deleted file mode 100644 index 0dd9bcbf2..000000000 --- a/src/GNDStk/v1.9/containers/Axis/src/custom.hpp +++ /dev/null @@ -1,18 +0,0 @@ -private: - - static inline helpMap help = { - - { "", "A GNDS 1.9 basic container component: an axis with an index, label and\n" - "optional unit\n\n" - "This component in used in the axes node, which in turn is used in most\n" - "functional containers." }, - { "constructor", "Initialise the axis component\n\n" - "Arguments:\n" - " self the axis component\n" - " index the index of the axis component\n" - " label the label of the axis component\n" - " unit the unit of the axis component\n" }, - { "index", "The index of the axis component" }, - { "label", "The label of the axis component" }, - { "unit", "The unit of the axis component" } - }; diff --git a/src/GNDStk/v1.9/containers/Grid.hpp b/src/GNDStk/v1.9/containers/Grid.hpp deleted file mode 100644 index bf20dbf93..000000000 --- a/src/GNDStk/v1.9/containers/Grid.hpp +++ /dev/null @@ -1,310 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_GRID -#define NJOY_GNDSTK_V1_9_CONTAINERS_GRID - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/containers/Link.hpp" -#include "GNDStk/v1.9/containers/Values.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Grid -// ----------------------------------------------------------------------------- - -namespace containers { - -class Grid : public Component { - - using link_values_t = std::variant< - containers::Link, - containers::Values - >; - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Grid"; } - static auto GNDSName() { return "grid"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("index") | - Defaulted{enums::Interpolation::linlin} - / Meta<>("interpolation") | - std::optional{} - / Meta<>("label") | - std::optional{} - / Meta<>("style") | - std::optional{} - / Meta<>("unit") | - // children - link_values_t{} - / --(Child<>("link") || Child<>("values")) - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - static inline const enums::Interpolation interpolation = enums::Interpolation::linlin; - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::optional index; - Defaulted interpolation{enums::Interpolation::linlin}; - std::optional label; - std::optional style; - std::optional unit; - // children - variant - link_values_t link_values; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // index - const std::optional &index() const - { return content.index; } - std::optional &index() - { return content.index; } - - // interpolation - const Defaulted &interpolation() const - { return content.interpolation; } - Defaulted &interpolation() - { return content.interpolation; } - - // label - const std::optional &label() const - { return content.label; } - std::optional &label() - { return content.label; } - - // style - const std::optional &style() const - { return content.style; } - std::optional &style() - { return content.style; } - - // unit - const std::optional &unit() const - { return content.unit; } - std::optional &unit() - { return content.unit; } - - // link_values - const link_values_t &link_values() const - { return content.link_values; } - link_values_t &link_values() - { return content.link_values; } - - // link - const containers::Link *link() const - { return getter(link_values(), "link"); } - containers::Link *link() - { return getter(link_values(), "link"); } - - // values - const containers::Values *values() const - { return getter(link_values(), "values"); } - containers::Values *values() - { return getter(link_values(), "values"); } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // index(value) - Grid &index(const std::optional &obj) - { index() = obj; return *this; } - - // interpolation(value) - Grid &interpolation(const Defaulted &obj) - { content.interpolation = obj; return *this; } - Grid &interpolation(const std::optional &obj) - { content.interpolation = obj; return *this; } - - // label(value) - Grid &label(const std::optional &obj) - { label() = obj; return *this; } - - // style(value) - Grid &style(const std::optional &obj) - { style() = obj; return *this; } - - // unit(value) - Grid &unit(const std::optional &obj) - { unit() = obj; return *this; } - - // link_values(value) - Grid &link_values(const link_values_t &obj) - { link_values() = obj; return *this; } - - // link(value) - Grid &link(const std::optional &obj) - { if (obj) link_values(obj.value()); return *this; } - - // values(value) - Grid &values(const std::optional &obj) - { if (obj) link_values(obj.value()); return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Grid() : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.style, - content.unit, - content.link_values - } - { - Component::finish(); - } - - // copy - Grid(const Grid &other) : - Component{ - other, - content.index, - content.interpolation, - content.label, - content.style, - content.unit, - content.link_values - }, - content{other.content} - { - Component::finish(other); - } - - // move - Grid(Grid &&other) : - Component{ - other, - content.index, - content.interpolation, - content.label, - content.style, - content.unit, - content.link_values - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Grid(const Node &node) : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.style, - content.unit, - content.link_values - } - { - Component::finish(node); - } - - // from fields - // std::optional replaces Defaulted; this class knows the default(s) - explicit Grid( - const std::optional &index, - const std::optional &interpolation, - const std::optional &label, - const std::optional &style, - const std::optional &unit, - const link_values_t &link_values - ) : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.style, - content.unit, - content.link_values - }, - content{ - index, - Defaulted(defaults.interpolation,interpolation), - label, - style, - unit, - link_values - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Grid &operator=(const Grid &) = default; - - // move - Grid &operator=(Grid &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Grid/src/custom.hpp" - -}; // class Grid - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Grid/test/Grid.test.cpp b/src/GNDStk/v1.9/containers/Grid/test/Grid.test.cpp deleted file mode 100644 index 078ac9417..000000000 --- a/src/GNDStk/v1.9/containers/Grid/test/Grid.test.cpp +++ /dev/null @@ -1,256 +0,0 @@ -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" -#include "GNDStk/v1.9/containers/Grid.hpp" - -// other includes - -// convenience typedefs -using namespace njoy::GNDStk; -using Values = v1_9::containers::Values; -using Link = v1_9::containers::Link; -using Grid = v1_9::containers::Grid; - -std::string chunk(); -void verifyChunk( const Grid& ); -std::string chunkWithLink(); -void verifyChunkWithLink( const Grid& ); -std::string invalidName(); - -SCENARIO( "Grid" ) { - - GIVEN( "valid data for the component with a Values component" ) { - - std::string string = chunk(); - - WHEN( "autogenerated constructor: the data is given explicitly" ) { - - unsigned int index = 2; - std::string label = "row_energy_bounds"; - std::string unit = "eV"; - enums::GridStyle style = enums::GridStyle::boundaries; - std::vector< double > values = { 1e-5, 2e7 }; - - Grid chunk( index, std::nullopt, label, style, unit, Values( values ) ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - - WHEN( "the data is constructed from a node" ) { - - Node node; - node << chunk(); - Grid chunk( node ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - } // GIVEN - - GIVEN( "valid data for the component with a Link component" ) { - - std::string string = chunkWithLink(); - - WHEN( "autogenerated constructor: the data is given explicitly" ) { - - unsigned int index = 1; - std::string label = "column_energy_bounds"; - std::string unit = "eV"; - enums::GridStyle style = enums::GridStyle::link; - std::string href = "../../grid[@index='2']/values"; - - Grid chunk( index, std::nullopt, label, style, unit, - Link( href ) ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunkWithLink( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - - WHEN( "the data is constructed from a node" ) { - - Node node; - node << chunkWithLink(); - Grid chunk( node ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunkWithLink( chunk ); - } // THEN - - THEN( "it can be written in XML" ) { - - std::ostringstream out; - XML( Node( chunk ) ).write( out, false ); - - CHECK( out.str() == string ); - } // THEN - } // WHEN - } // GIVEN - - GIVEN( "a valid component instance" ) { - - WHEN( "the component is copied" ) { - - Node node; - node << chunk(); - Grid chunk( node ); - - // copy constructor - Grid copy( chunk ); - - // copy assignment - Grid assign; - assign = chunk; - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( copy ); - verifyChunk( assign ); - } // THEN - } // WHEN - - WHEN( "the data is moved" ) { - - Node node; - node << chunk(); - Grid chunk( node ); - Grid chunk2( node ); - - // move constructor - Grid move( std::move( chunk ) ); - - // move assignment - Grid assign; - assign = std::move( chunk2 ); - - THEN( "the component can be constructed and members can be tested" ) { - - verifyChunk( move ); - verifyChunk( assign ); - } // THEN - } // WHEN - } // GIVEN - - GIVEN( "invalid data" ) { - - WHEN( "when the wrong node is used" ) { - - Node node; - node << invalidName(); - - THEN( "an exception is thrown" ) { - - CHECK_THROWS( Grid( node ) ); - } // THEN - } // WHEN - } // GIVEN -} // SCENARIO - -std::string chunk() { - - return -R"***( - 1e-05 2e+07 - -)***"; -} - -void verifyChunk( const Grid& component ) { - - CHECK( std::nullopt != component.index() ); - CHECK( std::nullopt != component.label() ); - CHECK( std::nullopt != component.style() ); - CHECK( std::nullopt != component.unit() ); - - CHECK( 2 == component.index().value() ); - CHECK( "row_energy_bounds" == component.label().value() ); - CHECK( "eV" == component.unit().value() ); - CHECK( enums::GridStyle::boundaries == component.style().value() ); - - CHECK( 2 == component.index() ); - CHECK( "row_energy_bounds" == component.label() ); - CHECK( "eV" == component.unit() ); - CHECK( enums::GridStyle::boundaries == component.style() ); - - decltype(auto) values = std::get< Values >( component.link_values() ); - CHECK( 2 == values.length() ); - CHECK( 0 == values.start() ); - CHECK( "Float64" == values.valueType().value() ); - - CHECK( 2 == values.size() ); - CHECK( 2 == values.doubles().size() ); - - CHECK( 1e-5 == Approx( values.doubles()[0] ) ); - CHECK( 2e+7 == Approx( values.doubles()[1] ) ); -} - -std::string chunkWithLink() { - - return -R"***( - - -)***"; -} - -void verifyChunkWithLink( const Grid& component ) { - - CHECK( std::nullopt != component.index() ); - CHECK( std::nullopt != component.label() ); - CHECK( std::nullopt != component.style() ); - CHECK( std::nullopt != component.unit() ); - - CHECK( 1 == component.index().value() ); - CHECK( "column_energy_bounds" == component.label().value() ); - CHECK( "eV" == component.unit().value() ); - CHECK( enums::GridStyle::link == component.style().value() ); - - CHECK( 1 == component.index() ); - CHECK( "column_energy_bounds" == component.label() ); - CHECK( "eV" == component.unit() ); - CHECK( enums::GridStyle::link == component.style() ); - - decltype(auto) link = std::get< Link >( component.link_values() ); - CHECK( "../../grid[@index='2']/values" == link.href() ); -} - -std::string invalidName() { - - // wrong name for the node - return -R"***( - - -)***"; -} diff --git a/src/GNDStk/v1.9/containers/Link.hpp b/src/GNDStk/v1.9/containers/Link.hpp deleted file mode 100644 index 0367513d2..000000000 --- a/src/GNDStk/v1.9/containers/Link.hpp +++ /dev/null @@ -1,176 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_LINK -#define NJOY_GNDSTK_V1_9_CONTAINERS_LINK - -// core interface -#include "GNDStk.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Link -// ----------------------------------------------------------------------------- - -namespace containers { - -class Link : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Link"; } - static auto GNDSName() { return "link"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::string{} - / Meta<>("href") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::string href; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // href - const std::string &href() const - { return content.href; } - std::string &href() - { return content.href; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // href(value) - Link &href(const std::string &obj) - { href() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Link() : - Component{ - BodyText{}, - content.href - } - { - Component::finish(); - } - - // copy - Link(const Link &other) : - Component{ - other, - content.href - }, - content{other.content} - { - Component::finish(other); - } - - // move - Link(Link &&other) : - Component{ - other, - content.href - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Link(const Node &node) : - Component{ - BodyText{}, - content.href - } - { - Component::finish(node); - } - - // from fields - explicit Link( - const std::string &href - ) : - Component{ - BodyText{}, - content.href - }, - content{ - href - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Link &operator=(const Link &) = default; - - // move - Link &operator=(Link &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Link/src/custom.hpp" - -}; // class Link - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Regions1d.hpp b/src/GNDStk/v1.9/containers/Regions1d.hpp deleted file mode 100644 index c1a3c1002..000000000 --- a/src/GNDStk/v1.9/containers/Regions1d.hpp +++ /dev/null @@ -1,270 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_REGIONS1D -#define NJOY_GNDSTK_V1_9_CONTAINERS_REGIONS1D - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/containers/XYs1d.hpp" -#include "GNDStk/v1.9/containers/Axes.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Regions1d -// ----------------------------------------------------------------------------- - -namespace containers { - -class Regions1d : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Regions1d"; } - static auto GNDSName() { return "regions1d"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("label") | - std::optional{} - / Meta<>("outerDomainValue") | - // children - containers::XYs1d{} - / ++Child<>("XYs1d") | - std::optional{} - / --Child<>("axes") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::optional label; - std::optional outerDomainValue; - // children - std::vector XYs1d; - std::optional axes; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // label - const std::optional &label() const - { return content.label; } - std::optional &label() - { return content.label; } - - // outerDomainValue - const std::optional &outerDomainValue() const - { return content.outerDomainValue; } - std::optional &outerDomainValue() - { return content.outerDomainValue; } - - // XYs1d - const std::vector &XYs1d() const - { return content.XYs1d; } - std::vector &XYs1d() - { return content.XYs1d; } - - // XYs1d(index) - const containers::XYs1d &XYs1d(const std::size_t index) const - { return getter(XYs1d(), index, "XYs1d"); } - containers::XYs1d &XYs1d(const std::size_t index) - { return getter(XYs1d(), index, "XYs1d"); } - - // XYs1d(label) - const containers::XYs1d &XYs1d(const std::string &label) const - { return getter(XYs1d(), label, "XYs1d"); } - containers::XYs1d &XYs1d(const std::string &label) - { return getter(XYs1d(), label, "XYs1d"); } - - // axes - const std::optional &axes() const - { return content.axes; } - std::optional &axes() - { return content.axes; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // label(value) - Regions1d &label(const std::optional &obj) - { label() = obj; return *this; } - - // outerDomainValue(value) - Regions1d &outerDomainValue(const std::optional &obj) - { outerDomainValue() = obj; return *this; } - - // XYs1d(value) - Regions1d &XYs1d(const std::vector &obj) - { XYs1d() = obj; return *this; } - - // XYs1d(index,value) - Regions1d &XYs1d( - const std::size_t index, - const containers::XYs1d &obj - ) { - XYs1d(index) = obj; return *this; - } - - // XYs1d(label,value) - Regions1d &XYs1d( - const std::string &label, - const containers::XYs1d &obj - ) { - XYs1d(label) = obj; return *this; - } - - // axes(value) - Regions1d &axes(const std::optional &obj) - { axes() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Regions1d() : - Component{ - BodyText{}, - content.label, - content.outerDomainValue, - content.XYs1d, - content.axes - } - { - Component::finish(); - } - - // copy - Regions1d(const Regions1d &other) : - Component{ - other, - content.label, - content.outerDomainValue, - content.XYs1d, - content.axes - }, - content{other.content} - { - Component::finish(other); - } - - // move - Regions1d(Regions1d &&other) : - Component{ - other, - content.label, - content.outerDomainValue, - content.XYs1d, - content.axes - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Regions1d(const Node &node) : - Component{ - BodyText{}, - content.label, - content.outerDomainValue, - content.XYs1d, - content.axes - } - { - Component::finish(node); - } - - // from fields - explicit Regions1d( - const std::optional &label, - const std::optional &outerDomainValue, - const std::vector &XYs1d, - const std::optional &axes - ) : - Component{ - BodyText{}, - content.label, - content.outerDomainValue, - content.XYs1d, - content.axes - }, - content{ - label, - outerDomainValue, - XYs1d, - axes - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Regions1d &operator=(const Regions1d &) = default; - - // move - Regions1d &operator=(Regions1d &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Regions1d/src/custom.hpp" - -}; // class Regions1d - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Values.hpp b/src/GNDStk/v1.9/containers/Values.hpp deleted file mode 100644 index 257ea0d1e..000000000 --- a/src/GNDStk/v1.9/containers/Values.hpp +++ /dev/null @@ -1,237 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_VALUES -#define NJOY_GNDSTK_V1_9_CONTAINERS_VALUES - -// core interface -#include "GNDStk.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class Values -// ----------------------------------------------------------------------------- - -namespace containers { - -class Values : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "Values"; } - static auto GNDSName() { return "values"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("length") | - Defaulted{0} - / Meta<>("start") | - Defaulted{"double"} - / Meta<>("valueType") - ; - } - -public: - - using Component::construct; - using BodyText::operator=; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - static inline const int start = 0; - static inline const std::string valueType = "double"; - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - mutable std::optional length; - mutable Defaulted start{0}; - mutable Defaulted valueType{"double"}; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // length - const std::optional &length() const - { return content.length; } - std::optional &length() - { return content.length; } - - // start - const Defaulted &start() const - { return content.start; } - Defaulted &start() - { return content.start; } - - // valueType - const Defaulted &valueType() const - { return content.valueType; } - Defaulted &valueType() - { return content.valueType; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // length(value) - Values &length(const std::optional &obj) - { BodyText::length(length() = obj); return *this; } - - // start(value) - Values &start(const Defaulted &obj) - { BodyText::start(content.start = obj); return *this; } - Values &start(const std::optional &obj) - { BodyText::start(content.start = obj); return *this; } - - // valueType(value) - Values &valueType(const Defaulted &obj) - { BodyText::valueType(content.valueType = obj); return *this; } - Values &valueType(const std::optional &obj) - { BodyText::valueType(content.valueType = obj); return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Values() : - Component{ - BodyText{}, - content.length, - content.start, - content.valueType - } - { - Component::finish(); - } - - // copy - Values(const Values &other) : - Component{ - other, - content.length, - content.start, - content.valueType - }, - content{other.content} - { - Component::finish(other); - } - - // move - Values(Values &&other) : - Component{ - other, - content.length, - content.start, - content.valueType - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Values(const Node &node) : - Component{ - BodyText{}, - content.length, - content.start, - content.valueType - } - { - Component::finish(node); - } - - // from fields - // std::optional replaces Defaulted; this class knows the default(s) - explicit Values( - const std::optional &length, - const std::optional &start, - const std::optional &valueType - ) : - Component{ - BodyText{}, - content.length, - content.start, - content.valueType - }, - content{ - length, - Defaulted(defaults.start,start), - Defaulted(defaults.valueType,valueType) - } - { - Component::finish(); - } - - // from vector - template>> - Values(const std::vector &vector) : - Component{ - BodyText{}, - content.length, - content.start, - content.valueType - } - { - Component::finish(vector); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Values &operator=(const Values &) = default; - - // move - Values &operator=(Values &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/Values/src/custom.hpp" - -}; // class Values - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/containers/Values/src/custom.hpp b/src/GNDStk/v1.9/containers/Values/src/custom.hpp deleted file mode 100644 index 562142c21..000000000 --- a/src/GNDStk/v1.9/containers/Values/src/custom.hpp +++ /dev/null @@ -1,60 +0,0 @@ -private: - - static inline helpMap help = { - - { "", "A GNDS basic component: a list of values\n\n" - "This component is used in the nodes like XYs1D or the grid node." }, - { "constructor", "Initialise the values component\n\n" - "Arguments:\n" - " self the values component\n" - " values the values\n" - " start the starting index of the values\n" - " value_type the value type\n" }, - { "length", "The length of the values" }, - { "start", "The starting index of the values (default = 0)" }, - { "value_type", "The value type (default = 'Float64')" }, - { "doubles", "The underlying values" } - }; - - /** - * Custom construct function - */ - void construct() { - - if ( this->length() != std::nullopt ) { - - if ( this->length() != this->size() + this->start() ) { - - log::error( "Inconsistent size for \"values\" array" ); - log::info( "start: {}", this->start() ); - log::info( "length: {}", this->length().value() ); - log::info( "number of values: {}", this->size() ); - throw std::exception(); - } - } - } - -public: - - template < typename T, - typename = std::enable_if_t< - detail::isAlternative< T, VariantOfScalars > > > - Values( const std::optional< int >& length, - const std::optional< int >& start, - const std::optional< std::string >& valueType, - const std::vector< T >& values ) : - Component{ - BodyText{}, - content.length, - content.start, - content.valueType - } - { - - *this = values; - this->length( length ); - this->start( start ); - this->valueType( valueType ); - - Component::finish(); // ensure that construct() gets called - } diff --git a/src/GNDStk/v1.9/containers/XYs1d.hpp b/src/GNDStk/v1.9/containers/XYs1d.hpp deleted file mode 100644 index 6cf404257..000000000 --- a/src/GNDStk/v1.9/containers/XYs1d.hpp +++ /dev/null @@ -1,286 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_CONTAINERS_XYS1D -#define NJOY_GNDSTK_V1_9_CONTAINERS_XYS1D - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/containers/Axes.hpp" -#include "GNDStk/v1.9/containers/Values.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// containers:: -// class XYs1d -// ----------------------------------------------------------------------------- - -namespace containers { - -class XYs1d : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "containers"; } - static auto className() { return "XYs1d"; } - static auto GNDSName() { return "XYs1d"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::optional{} - / Meta<>("index") | - Defaulted{enums::Interpolation::linlin} - / Meta<>("interpolation") | - std::optional{} - / Meta<>("label") | - std::optional{} - / Meta<>("outerDomainValue") | - // children - std::optional{} - / --Child<>("axes") | - containers::Values{} - / --Child<>("values") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - static inline const enums::Interpolation interpolation = enums::Interpolation::linlin; - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::optional index; - Defaulted interpolation{enums::Interpolation::linlin}; - std::optional label; - std::optional outerDomainValue; - // children - std::optional axes; - containers::Values values; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // index - const std::optional &index() const - { return content.index; } - std::optional &index() - { return content.index; } - - // interpolation - const Defaulted &interpolation() const - { return content.interpolation; } - Defaulted &interpolation() - { return content.interpolation; } - - // label - const std::optional &label() const - { return content.label; } - std::optional &label() - { return content.label; } - - // outerDomainValue - const std::optional &outerDomainValue() const - { return content.outerDomainValue; } - std::optional &outerDomainValue() - { return content.outerDomainValue; } - - // axes - const std::optional &axes() const - { return content.axes; } - std::optional &axes() - { return content.axes; } - - // values - const containers::Values &values() const - { return content.values; } - containers::Values &values() - { return content.values; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // index(value) - XYs1d &index(const std::optional &obj) - { index() = obj; return *this; } - - // interpolation(value) - XYs1d &interpolation(const Defaulted &obj) - { content.interpolation = obj; return *this; } - XYs1d &interpolation(const std::optional &obj) - { content.interpolation = obj; return *this; } - - // label(value) - XYs1d &label(const std::optional &obj) - { label() = obj; return *this; } - - // outerDomainValue(value) - XYs1d &outerDomainValue(const std::optional &obj) - { outerDomainValue() = obj; return *this; } - - // axes(value) - XYs1d &axes(const std::optional &obj) - { axes() = obj; return *this; } - - // values(value) - XYs1d &values(const containers::Values &obj) - { values() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - XYs1d() : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.outerDomainValue, - content.axes, - content.values - } - { - Component::finish(); - } - - // copy - XYs1d(const XYs1d &other) : - Component{ - other, - content.index, - content.interpolation, - content.label, - content.outerDomainValue, - content.axes, - content.values - }, - content{other.content} - { - Component::finish(other); - } - - // move - XYs1d(XYs1d &&other) : - Component{ - other, - content.index, - content.interpolation, - content.label, - content.outerDomainValue, - content.axes, - content.values - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - XYs1d(const Node &node) : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.outerDomainValue, - content.axes, - content.values - } - { - Component::finish(node); - } - - // from fields - // std::optional replaces Defaulted; this class knows the default(s) - explicit XYs1d( - const std::optional &index, - const std::optional &interpolation, - const std::optional &label, - const std::optional &outerDomainValue, - const std::optional &axes, - const containers::Values &values - ) : - Component{ - BodyText{}, - content.index, - content.interpolation, - content.label, - content.outerDomainValue, - content.axes, - content.values - }, - content{ - index, - Defaulted(defaults.interpolation,interpolation), - label, - outerDomainValue, - axes, - values - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - XYs1d &operator=(const XYs1d &) = default; - - // move - XYs1d &operator=(XYs1d &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/containers/XYs1d/src/custom.hpp" - -}; // class XYs1d - -} // namespace containers -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/key.hpp b/src/GNDStk/v1.9/key.hpp deleted file mode 100644 index 214b239e0..000000000 --- a/src/GNDStk/v1.9/key.hpp +++ /dev/null @@ -1,114 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -/* -This file contains Meta and Child objects for metadata and child nodes in the -current GNDS version. These may prove to be useful if you wish to use the Core -Interface in conjunction with the autogenerated classes for this GNDS version. - -Within the outer njoy::GNDStk::version namespace below, the remaining namespace -arrangement was chosen to make the use of these objects smooth and logical. - -Meta and Child objects are collectively called "keys." Meta keys are placed -into key::meta. Child keys correspond to autogenerated classes, each of which -is already in some namespace; we thus use theNamespace::key::child::. That way, -an autogenerated class [ns::Foo] has [ns::key::foo] as its Child object, and -a "using namespace ns" allows the class and the Child object to be [Foo] and -[key::foo], respectively. (If we reordered ns:: and key::, that wouldn't work.) - -Within key::, we use meta:: and child:: around Meta and Child objects, just in -case there exist any identical GNDS metadata names and child-node names. (That -can, in fact, happen). The "using namespace meta" and "using namespace child" -directives then make the Meta<> and Child<> objects appear directly in key::, -so that "meta::" and "child::" are needed only to disambiguate identical names. -*/ - -#ifndef NJOY_GNDSTK_V1_9_KEY -#define NJOY_GNDSTK_V1_9_KEY - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - - -// ----------------------------------------------------------------------------- -// key::meta:: -// ----------------------------------------------------------------------------- - -namespace key { -namespace meta { - -inline const Meta<> ENDF_MT("ENDF_MT"); -inline const Meta<> evaluation("evaluation"); -inline const Meta<> fissionGenre("fissionGenre"); -inline const Meta<> format("format"); -inline const Meta<> href("href"); -inline const Meta<> index("index"); -inline const Meta<> interaction("interaction"); -inline const Meta<> interpolation("interpolation"); -inline const Meta<> label("label"); -inline const Meta<> length("length"); -inline const Meta<> outerDomainValue("outerDomainValue"); -inline const Meta<> projectile("projectile"); -inline const Meta<> projectileFrame("projectileFrame"); -inline const Meta<> start("start"); -inline const Meta<> style("style"); -inline const Meta<> target("target"); -inline const Meta<> unit("unit"); -inline const Meta<> valueType("valueType"); - -} // namespace meta -using namespace meta; -} // namespace key - - -// ----------------------------------------------------------------------------- -// containers::key::child:: -// ----------------------------------------------------------------------------- - -namespace containers { -namespace key { -namespace child { - -inline const Child<> XYs1d("XYs1d"); -inline const Child<> axes("axes"); -inline const Child<> axis("axis"); -inline const Child<> grid("grid"); -inline const Child<> link("link"); -inline const Child<> regions1d("regions1d"); -inline const Child<> values("values"); - -} // namespace child -using namespace child; -} // namespace key -} // namespace containers - - -// ----------------------------------------------------------------------------- -// transport::key::child:: -// ----------------------------------------------------------------------------- - -namespace transport { -namespace key { -namespace child { - -inline const Child<> crossSection("crossSection"); -inline const Child<> reaction("reaction"); -inline const Child<> reactionSuite("reactionSuite"); -inline const Child<> reactions("reactions"); - -} // namespace child -using namespace child; -} // namespace key -} // namespace transport - - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/transport/CrossSection.hpp b/src/GNDStk/v1.9/transport/CrossSection.hpp deleted file mode 100644 index 12aeb298f..000000000 --- a/src/GNDStk/v1.9/transport/CrossSection.hpp +++ /dev/null @@ -1,272 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_TRANSPORT_CROSSSECTION -#define NJOY_GNDSTK_V1_9_TRANSPORT_CROSSSECTION - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/containers/XYs1d.hpp" -#include "GNDStk/v1.9/containers/Regions1d.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// transport:: -// class CrossSection -// ----------------------------------------------------------------------------- - -namespace transport { - -class CrossSection : public Component { - - using XYs1d_regions1d_t = std::variant< - containers::XYs1d, - containers::Regions1d - >; - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "transport"; } - static auto className() { return "CrossSection"; } - static auto GNDSName() { return "crossSection"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // children - XYs1d_regions1d_t{} - / ++(Child<>("XYs1d") || Child<>("regions1d")) - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // children - variant - std::vector XYs1d_regions1d; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // XYs1d_regions1d - const std::vector &XYs1d_regions1d() const - { return content.XYs1d_regions1d; } - std::vector &XYs1d_regions1d() - { return content.XYs1d_regions1d; } - - // XYs1d_regions1d(index) - const XYs1d_regions1d_t &XYs1d_regions1d(const std::size_t index) const - { return getter(XYs1d_regions1d(), index, "XYs1d_regions1d"); } - XYs1d_regions1d_t &XYs1d_regions1d(const std::size_t index) - { return getter(XYs1d_regions1d(), index, "XYs1d_regions1d"); } - - // XYs1d_regions1d(label) - const XYs1d_regions1d_t &XYs1d_regions1d(const std::string &label) const - { return getter(XYs1d_regions1d(), label, "XYs1d_regions1d"); } - XYs1d_regions1d_t &XYs1d_regions1d(const std::string &label) - { return getter(XYs1d_regions1d(), label, "XYs1d_regions1d"); } - - // XYs1d(index) - const containers::XYs1d *XYs1d(const std::size_t index) const - { return getter(XYs1d_regions1d(), index, "XYs1d"); } - containers::XYs1d *XYs1d(const std::size_t index) - { return getter(XYs1d_regions1d(), index, "XYs1d"); } - - // XYs1d(label) - const containers::XYs1d *XYs1d(const std::string &label) const - { return getter(XYs1d_regions1d(), label, "XYs1d"); } - containers::XYs1d *XYs1d(const std::string &label) - { return getter(XYs1d_regions1d(), label, "XYs1d"); } - - // regions1d(index) - const containers::Regions1d *regions1d(const std::size_t index) const - { return getter(XYs1d_regions1d(), index, "regions1d"); } - containers::Regions1d *regions1d(const std::size_t index) - { return getter(XYs1d_regions1d(), index, "regions1d"); } - - // regions1d(label) - const containers::Regions1d *regions1d(const std::string &label) const - { return getter(XYs1d_regions1d(), label, "regions1d"); } - containers::Regions1d *regions1d(const std::string &label) - { return getter(XYs1d_regions1d(), label, "regions1d"); } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // XYs1d_regions1d(value) - CrossSection &XYs1d_regions1d(const std::vector &obj) - { XYs1d_regions1d() = obj; return *this; } - - // XYs1d_regions1d(index,value) - CrossSection &XYs1d_regions1d( - const std::size_t index, - const XYs1d_regions1d_t &obj - ) { - XYs1d_regions1d(index) = obj; return *this; - } - - // XYs1d_regions1d(label,value) - CrossSection &XYs1d_regions1d( - const std::string &label, - const XYs1d_regions1d_t &obj - ) { - XYs1d_regions1d(label) = obj; return *this; - } - - // XYs1d(index,value) - CrossSection &XYs1d( - const std::size_t index, - const std::optional &obj - ) { - if (obj) XYs1d_regions1d(index,obj.value()); - return *this; - } - - // XYs1d(label,value) - CrossSection &XYs1d( - const std::string &label, - const std::optional &obj - ) { - if (obj) XYs1d_regions1d(label,obj.value()); - return *this; - } - - // regions1d(index,value) - CrossSection ®ions1d( - const std::size_t index, - const std::optional &obj - ) { - if (obj) XYs1d_regions1d(index,obj.value()); - return *this; - } - - // regions1d(label,value) - CrossSection ®ions1d( - const std::string &label, - const std::optional &obj - ) { - if (obj) XYs1d_regions1d(label,obj.value()); - return *this; - } - - // ------------------------ - // Construction - // ------------------------ - - // default - CrossSection() : - Component{ - BodyText{}, - content.XYs1d_regions1d - } - { - Component::finish(); - } - - // copy - CrossSection(const CrossSection &other) : - Component{ - other, - content.XYs1d_regions1d - }, - content{other.content} - { - Component::finish(other); - } - - // move - CrossSection(CrossSection &&other) : - Component{ - other, - content.XYs1d_regions1d - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - CrossSection(const Node &node) : - Component{ - BodyText{}, - content.XYs1d_regions1d - } - { - Component::finish(node); - } - - // from fields - explicit CrossSection( - const std::vector &XYs1d_regions1d - ) : - Component{ - BodyText{}, - content.XYs1d_regions1d - }, - content{ - XYs1d_regions1d - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - CrossSection &operator=(const CrossSection &) = default; - - // move - CrossSection &operator=(CrossSection &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/transport/CrossSection/src/custom.hpp" - -}; // class CrossSection - -} // namespace transport -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/transport/Reaction.hpp b/src/GNDStk/v1.9/transport/Reaction.hpp deleted file mode 100644 index bb15a3f88..000000000 --- a/src/GNDStk/v1.9/transport/Reaction.hpp +++ /dev/null @@ -1,241 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_TRANSPORT_REACTION -#define NJOY_GNDSTK_V1_9_TRANSPORT_REACTION - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/transport/CrossSection.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// transport:: -// class Reaction -// ----------------------------------------------------------------------------- - -namespace transport { - -class Reaction : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "transport"; } - static auto className() { return "Reaction"; } - static auto GNDSName() { return "reaction"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - int{} - / Meta<>("ENDF_MT") | - std::optional{} - / Meta<>("fissionGenre") | - std::string{} - / Meta<>("label") | - // children - transport::CrossSection{} - / --Child<>("crossSection") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - int ENDF_MT; - std::optional fissionGenre; - std::string label; - // children - transport::CrossSection crossSection; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // ENDF_MT - const int &ENDF_MT() const - { return content.ENDF_MT; } - int &ENDF_MT() - { return content.ENDF_MT; } - - // fissionGenre - const std::optional &fissionGenre() const - { return content.fissionGenre; } - std::optional &fissionGenre() - { return content.fissionGenre; } - - // label - const std::string &label() const - { return content.label; } - std::string &label() - { return content.label; } - - // crossSection - const transport::CrossSection &crossSection() const - { return content.crossSection; } - transport::CrossSection &crossSection() - { return content.crossSection; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // ENDF_MT(value) - Reaction &ENDF_MT(const int &obj) - { ENDF_MT() = obj; return *this; } - - // fissionGenre(value) - Reaction &fissionGenre(const std::optional &obj) - { fissionGenre() = obj; return *this; } - - // label(value) - Reaction &label(const std::string &obj) - { label() = obj; return *this; } - - // crossSection(value) - Reaction &crossSection(const transport::CrossSection &obj) - { crossSection() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - Reaction() : - Component{ - BodyText{}, - content.ENDF_MT, - content.fissionGenre, - content.label, - content.crossSection - } - { - Component::finish(); - } - - // copy - Reaction(const Reaction &other) : - Component{ - other, - content.ENDF_MT, - content.fissionGenre, - content.label, - content.crossSection - }, - content{other.content} - { - Component::finish(other); - } - - // move - Reaction(Reaction &&other) : - Component{ - other, - content.ENDF_MT, - content.fissionGenre, - content.label, - content.crossSection - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Reaction(const Node &node) : - Component{ - BodyText{}, - content.ENDF_MT, - content.fissionGenre, - content.label, - content.crossSection - } - { - Component::finish(node); - } - - // from fields - explicit Reaction( - const int &ENDF_MT, - const std::optional &fissionGenre, - const std::string &label, - const transport::CrossSection &crossSection - ) : - Component{ - BodyText{}, - content.ENDF_MT, - content.fissionGenre, - content.label, - content.crossSection - }, - content{ - ENDF_MT, - fissionGenre, - label, - crossSection - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Reaction &operator=(const Reaction &) = default; - - // move - Reaction &operator=(Reaction &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/transport/Reaction/src/custom.hpp" - -}; // class Reaction - -} // namespace transport -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/transport/ReactionSuite.hpp b/src/GNDStk/v1.9/transport/ReactionSuite.hpp deleted file mode 100644 index 86601b7d2..000000000 --- a/src/GNDStk/v1.9/transport/ReactionSuite.hpp +++ /dev/null @@ -1,301 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_TRANSPORT_REACTIONSUITE -#define NJOY_GNDSTK_V1_9_TRANSPORT_REACTIONSUITE - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/transport/Reactions.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// transport:: -// class ReactionSuite -// ----------------------------------------------------------------------------- - -namespace transport { - -class ReactionSuite : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "transport"; } - static auto className() { return "ReactionSuite"; } - static auto GNDSName() { return "reactionSuite"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // metadata - std::string{} - / Meta<>("evaluation") | - std::string{} - / Meta<>("format") | - std::optional{} - / Meta<>("interaction") | - std::string{} - / Meta<>("projectile") | - enums::Frame{} - / Meta<>("projectileFrame") | - std::string{} - / Meta<>("target") | - // children - std::optional{} - / --Child<>("reactions") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // metadata - std::string evaluation; - std::string format; - std::optional interaction; - std::string projectile; - enums::Frame projectileFrame; - std::string target; - // children - std::optional reactions; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // evaluation - const std::string &evaluation() const - { return content.evaluation; } - std::string &evaluation() - { return content.evaluation; } - - // format - const std::string &format() const - { return content.format; } - std::string &format() - { return content.format; } - - // interaction - const std::optional &interaction() const - { return content.interaction; } - std::optional &interaction() - { return content.interaction; } - - // projectile - const std::string &projectile() const - { return content.projectile; } - std::string &projectile() - { return content.projectile; } - - // projectileFrame - const enums::Frame &projectileFrame() const - { return content.projectileFrame; } - enums::Frame &projectileFrame() - { return content.projectileFrame; } - - // target - const std::string &target() const - { return content.target; } - std::string &target() - { return content.target; } - - // reactions - const std::optional &reactions() const - { return content.reactions; } - std::optional &reactions() - { return content.reactions; } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // evaluation(value) - ReactionSuite &evaluation(const std::string &obj) - { evaluation() = obj; return *this; } - - // format(value) - ReactionSuite &format(const std::string &obj) - { format() = obj; return *this; } - - // interaction(value) - ReactionSuite &interaction(const std::optional &obj) - { interaction() = obj; return *this; } - - // projectile(value) - ReactionSuite &projectile(const std::string &obj) - { projectile() = obj; return *this; } - - // projectileFrame(value) - ReactionSuite &projectileFrame(const enums::Frame &obj) - { projectileFrame() = obj; return *this; } - - // target(value) - ReactionSuite &target(const std::string &obj) - { target() = obj; return *this; } - - // reactions(value) - ReactionSuite &reactions(const std::optional &obj) - { reactions() = obj; return *this; } - - // ------------------------ - // Construction - // ------------------------ - - // default - ReactionSuite() : - Component{ - BodyText{}, - content.evaluation, - content.format, - content.interaction, - content.projectile, - content.projectileFrame, - content.target, - content.reactions - } - { - Component::finish(); - } - - // copy - ReactionSuite(const ReactionSuite &other) : - Component{ - other, - content.evaluation, - content.format, - content.interaction, - content.projectile, - content.projectileFrame, - content.target, - content.reactions - }, - content{other.content} - { - Component::finish(other); - } - - // move - ReactionSuite(ReactionSuite &&other) : - Component{ - other, - content.evaluation, - content.format, - content.interaction, - content.projectile, - content.projectileFrame, - content.target, - content.reactions - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - ReactionSuite(const Node &node) : - Component{ - BodyText{}, - content.evaluation, - content.format, - content.interaction, - content.projectile, - content.projectileFrame, - content.target, - content.reactions - } - { - Component::finish(node); - } - - // from fields - explicit ReactionSuite( - const std::string &evaluation, - const std::string &format, - const std::optional &interaction, - const std::string &projectile, - const enums::Frame &projectileFrame, - const std::string &target, - const std::optional &reactions - ) : - Component{ - BodyText{}, - content.evaluation, - content.format, - content.interaction, - content.projectile, - content.projectileFrame, - content.target, - content.reactions - }, - content{ - evaluation, - format, - interaction, - projectile, - projectileFrame, - target, - reactions - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - ReactionSuite &operator=(const ReactionSuite &) = default; - - // move - ReactionSuite &operator=(ReactionSuite &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/transport/ReactionSuite/src/custom.hpp" - -}; // class ReactionSuite - -} // namespace transport -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v1.9/transport/Reactions.hpp b/src/GNDStk/v1.9/transport/Reactions.hpp deleted file mode 100644 index bf92b5bdc..000000000 --- a/src/GNDStk/v1.9/transport/Reactions.hpp +++ /dev/null @@ -1,207 +0,0 @@ - -// THIS FILE WAS AUTOGENERATED! -// DO NOT MODIFY! - -#ifndef NJOY_GNDSTK_V1_9_TRANSPORT_REACTIONS -#define NJOY_GNDSTK_V1_9_TRANSPORT_REACTIONS - -// core interface -#include "GNDStk.hpp" - -// v1.9 dependencies -#include "GNDStk/v1.9/transport/Reaction.hpp" - -namespace njoy { -namespace GNDStk { -namespace v1_9 { - -using namespace njoy::GNDStk::core; - - - -// ----------------------------------------------------------------------------- -// transport:: -// class Reactions -// ----------------------------------------------------------------------------- - -namespace transport { - -class Reactions : public Component { - - - // ------------------------ - // For Component - // ------------------------ - - friend class Component; - - // Current namespace, current class, and GNDS node name - static auto namespaceName() { return "transport"; } - static auto className() { return "Reactions"; } - static auto GNDSName() { return "reactions"; } - - // Core Interface multi-query to extract metadata and child nodes - static auto keys() - { - return - // children - transport::Reaction{} - / ++Child<>("reaction") - ; - } - -public: - - using Component::construct; - - // ------------------------ - // Relevant defaults - // FYI for users - // ------------------------ - - static inline const struct Defaults { - } defaults; - - // ------------------------ - // Raw GNDS content - // ------------------------ - - struct { - // children - std::vector reaction; - } content; - - // ------------------------ - // Getters - // const and non-const - // ------------------------ - - // reaction - const std::vector &reaction() const - { return content.reaction; } - std::vector &reaction() - { return content.reaction; } - - // reaction(index) - const transport::Reaction &reaction(const std::size_t index) const - { return getter(reaction(), index, "reaction"); } - transport::Reaction &reaction(const std::size_t index) - { return getter(reaction(), index, "reaction"); } - - // reaction(label) - const transport::Reaction &reaction(const std::string &label) const - { return getter(reaction(), label, "reaction"); } - transport::Reaction &reaction(const std::string &label) - { return getter(reaction(), label, "reaction"); } - - // ------------------------ - // Setters - // non-const - // All return *this - // ------------------------ - - // reaction(value) - Reactions &reaction(const std::vector &obj) - { reaction() = obj; return *this; } - - // reaction(index,value) - Reactions &reaction( - const std::size_t index, - const transport::Reaction &obj - ) { - reaction(index) = obj; return *this; - } - - // reaction(label,value) - Reactions &reaction( - const std::string &label, - const transport::Reaction &obj - ) { - reaction(label) = obj; return *this; - } - - // ------------------------ - // Construction - // ------------------------ - - // default - Reactions() : - Component{ - BodyText{}, - content.reaction - } - { - Component::finish(); - } - - // copy - Reactions(const Reactions &other) : - Component{ - other, - content.reaction - }, - content{other.content} - { - Component::finish(other); - } - - // move - Reactions(Reactions &&other) : - Component{ - other, - content.reaction - }, - content{std::move(other.content)} - { - Component::finish(other); - } - - // from node - Reactions(const Node &node) : - Component{ - BodyText{}, - content.reaction - } - { - Component::finish(node); - } - - // from fields - explicit Reactions( - const std::vector &reaction - ) : - Component{ - BodyText{}, - content.reaction - }, - content{ - reaction - } - { - Component::finish(); - } - - // ------------------------ - // Assignment - // ------------------------ - - // copy - Reactions &operator=(const Reactions &) = default; - - // move - Reactions &operator=(Reactions &&) = default; - - // ------------------------ - // Custom functionality - // ------------------------ - - #include "GNDStk/v1.9/transport/Reactions/src/custom.hpp" - -}; // class Reactions - -} // namespace transport -} // namespace v1_9 -} // namespace GNDStk -} // namespace njoy - -#endif diff --git a/src/GNDStk/v2.0.hpp b/src/GNDStk/v2.0.hpp new file mode 100644 index 000000000..19e8146c2 --- /dev/null +++ b/src/GNDStk/v2.0.hpp @@ -0,0 +1,358 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef NJOY_GNDSTK_V2_0 +#define NJOY_GNDSTK_V2_0 + +#include "GNDStk/v2.0/abstract/Functional.hpp" +#include "GNDStk/v2.0/abstract/Label.hpp" +#include "GNDStk/v2.0/abstract/PhysicalQuantity.hpp" +#include "GNDStk/v2.0/abstract/Text.hpp" + +#include "GNDStk/v2.0/appData/ApplicationData.hpp" +#include "GNDStk/v2.0/appData/Conversion.hpp" +#include "GNDStk/v2.0/appData/ENDFconversionFlags.hpp" +#include "GNDStk/v2.0/appData/Institution.hpp" + +#include "GNDStk/v2.0/atomic/CoherentPhotonScattering.hpp" +#include "GNDStk/v2.0/atomic/FormFactor.hpp" +#include "GNDStk/v2.0/atomic/ImaginaryAnomalousFactor.hpp" +#include "GNDStk/v2.0/atomic/IncoherentPhotonScattering.hpp" +#include "GNDStk/v2.0/atomic/RealAnomalousFactor.hpp" +#include "GNDStk/v2.0/atomic/ScatteringFactor.hpp" + +#include "GNDStk/v2.0/common/Energy.hpp" +#include "GNDStk/v2.0/common/ExternalFile.hpp" +#include "GNDStk/v2.0/common/ExternalFiles.hpp" +#include "GNDStk/v2.0/common/Mass.hpp" +#include "GNDStk/v2.0/common/Probability.hpp" +#include "GNDStk/v2.0/common/Product.hpp" +#include "GNDStk/v2.0/common/Products.hpp" +#include "GNDStk/v2.0/common/Q.hpp" +#include "GNDStk/v2.0/common/Temperature.hpp" + +#include "GNDStk/v2.0/containers/Array.hpp" +#include "GNDStk/v2.0/containers/Axes.hpp" +#include "GNDStk/v2.0/containers/Axis.hpp" +#include "GNDStk/v2.0/containers/Column.hpp" +#include "GNDStk/v2.0/containers/ColumnHeaders.hpp" +#include "GNDStk/v2.0/containers/Constant1d.hpp" +#include "GNDStk/v2.0/containers/Data.hpp" +#include "GNDStk/v2.0/containers/Double.hpp" +#include "GNDStk/v2.0/containers/Fraction.hpp" +#include "GNDStk/v2.0/containers/Function1ds.hpp" +#include "GNDStk/v2.0/containers/Function2ds.hpp" +#include "GNDStk/v2.0/containers/Function3ds.hpp" +#include "GNDStk/v2.0/containers/Grid.hpp" +#include "GNDStk/v2.0/containers/Gridded1d.hpp" +#include "GNDStk/v2.0/containers/Gridded2d.hpp" +#include "GNDStk/v2.0/containers/Gridded3d.hpp" +#include "GNDStk/v2.0/containers/Integer.hpp" +#include "GNDStk/v2.0/containers/Legendre.hpp" +#include "GNDStk/v2.0/containers/Link.hpp" +#include "GNDStk/v2.0/containers/Polynomial1d.hpp" +#include "GNDStk/v2.0/containers/Regions1d.hpp" +#include "GNDStk/v2.0/containers/Regions2d.hpp" +#include "GNDStk/v2.0/containers/Regions3d.hpp" +#include "GNDStk/v2.0/containers/String.hpp" +#include "GNDStk/v2.0/containers/Table.hpp" +#include "GNDStk/v2.0/containers/Values.hpp" +#include "GNDStk/v2.0/containers/XYs1d.hpp" +#include "GNDStk/v2.0/containers/XYs2d.hpp" +#include "GNDStk/v2.0/containers/XYs3d.hpp" +#include "GNDStk/v2.0/containers/Ys1d.hpp" + +#include "GNDStk/v2.0/covariance/AverageParameterCovariance.hpp" +#include "GNDStk/v2.0/covariance/ColumnData.hpp" +#include "GNDStk/v2.0/covariance/ColumnSensitivity.hpp" +#include "GNDStk/v2.0/covariance/Covariance.hpp" +#include "GNDStk/v2.0/covariance/CovarianceMatrix.hpp" +#include "GNDStk/v2.0/covariance/CovarianceSection.hpp" +#include "GNDStk/v2.0/covariance/CovarianceSections.hpp" +#include "GNDStk/v2.0/covariance/CovarianceSuite.hpp" +#include "GNDStk/v2.0/covariance/Mixed.hpp" +#include "GNDStk/v2.0/covariance/ParameterCovariancMatrix.hpp" +#include "GNDStk/v2.0/covariance/ParameterCovariance.hpp" +#include "GNDStk/v2.0/covariance/ParameterCovariances.hpp" +#include "GNDStk/v2.0/covariance/ParameterLink.hpp" +#include "GNDStk/v2.0/covariance/Parameters.hpp" +#include "GNDStk/v2.0/covariance/RowData.hpp" +#include "GNDStk/v2.0/covariance/RowSensitivity.hpp" +#include "GNDStk/v2.0/covariance/SandwichProduct.hpp" +#include "GNDStk/v2.0/covariance/ShortRangeSelfScalingVariance.hpp" +#include "GNDStk/v2.0/covariance/Slice.hpp" +#include "GNDStk/v2.0/covariance/Slices.hpp" +#include "GNDStk/v2.0/covariance/Sum.hpp" +#include "GNDStk/v2.0/covariance/Summand.hpp" + +#include "GNDStk/v2.0/cpTransport/CoulombPlusNuclearElastic.hpp" +#include "GNDStk/v2.0/cpTransport/ImaginaryInterferenceTerm.hpp" +#include "GNDStk/v2.0/cpTransport/NuclearAmplitudeExpansion.hpp" +#include "GNDStk/v2.0/cpTransport/NuclearPlusInterference.hpp" +#include "GNDStk/v2.0/cpTransport/NuclearTerm.hpp" +#include "GNDStk/v2.0/cpTransport/RealInterferenceTerm.hpp" +#include "GNDStk/v2.0/cpTransport/RutherfordScattering.hpp" + +#include "GNDStk/v2.0/documentation/Acknowledgement.hpp" +#include "GNDStk/v2.0/documentation/Acknowledgements.hpp" +#include "GNDStk/v2.0/documentation/Affiliation.hpp" +#include "GNDStk/v2.0/documentation/Affiliations.hpp" +#include "GNDStk/v2.0/documentation/Author.hpp" +#include "GNDStk/v2.0/documentation/Authors.hpp" +#include "GNDStk/v2.0/documentation/Bibitem.hpp" +#include "GNDStk/v2.0/documentation/Bibliography.hpp" +#include "GNDStk/v2.0/documentation/CodeRepo.hpp" +#include "GNDStk/v2.0/documentation/Collaboration.hpp" +#include "GNDStk/v2.0/documentation/Collaborations.hpp" +#include "GNDStk/v2.0/documentation/ComputerCode.hpp" +#include "GNDStk/v2.0/documentation/ComputerCodes.hpp" +#include "GNDStk/v2.0/documentation/Contributor.hpp" +#include "GNDStk/v2.0/documentation/Contributors.hpp" +#include "GNDStk/v2.0/documentation/Copyright.hpp" +#include "GNDStk/v2.0/documentation/Date.hpp" +#include "GNDStk/v2.0/documentation/Dates.hpp" +#include "GNDStk/v2.0/documentation/Documentation.hpp" +#include "GNDStk/v2.0/documentation/ExforDataSet.hpp" +#include "GNDStk/v2.0/documentation/ExforDataSets.hpp" +#include "GNDStk/v2.0/documentation/ExperimentalDataSets.hpp" +#include "GNDStk/v2.0/documentation/InputDeck.hpp" +#include "GNDStk/v2.0/documentation/InputDecks.hpp" +#include "GNDStk/v2.0/documentation/Keyword.hpp" +#include "GNDStk/v2.0/documentation/Keywords.hpp" +#include "GNDStk/v2.0/documentation/OutputDeck.hpp" +#include "GNDStk/v2.0/documentation/OutputDecks.hpp" +#include "GNDStk/v2.0/documentation/RelatedItem.hpp" +#include "GNDStk/v2.0/documentation/RelatedItems.hpp" + +#include "GNDStk/v2.0/fissionFragmentData/DelayedNeutron.hpp" +#include "GNDStk/v2.0/fissionFragmentData/DelayedNeutrons.hpp" +#include "GNDStk/v2.0/fissionFragmentData/FissionFragmentData.hpp" +#include "GNDStk/v2.0/fissionFragmentData/Rate.hpp" + +#include "GNDStk/v2.0/fissionTransport/B.hpp" +#include "GNDStk/v2.0/fissionTransport/DelayedBetaEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/DelayedGammaEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/DelayedNeutronKE.hpp" +#include "GNDStk/v2.0/fissionTransport/EFH.hpp" +#include "GNDStk/v2.0/fissionTransport/EFL.hpp" +#include "GNDStk/v2.0/fissionTransport/FissionComponent.hpp" +#include "GNDStk/v2.0/fissionTransport/FissionComponents.hpp" +#include "GNDStk/v2.0/fissionTransport/FissionEnergyReleased.hpp" +#include "GNDStk/v2.0/fissionTransport/MadlandNix.hpp" +#include "GNDStk/v2.0/fissionTransport/NeutrinoEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/NonNeutrinoEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/PromptGammaEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/PromptNeutronKE.hpp" +#include "GNDStk/v2.0/fissionTransport/PromptProductKE.hpp" +#include "GNDStk/v2.0/fissionTransport/SimpleMaxwellianFission.hpp" +#include "GNDStk/v2.0/fissionTransport/T_M.hpp" +#include "GNDStk/v2.0/fissionTransport/TotalEnergy.hpp" +#include "GNDStk/v2.0/fissionTransport/Watt.hpp" + +#include "GNDStk/v2.0/fpy/ElapsedTime.hpp" +#include "GNDStk/v2.0/fpy/ElapsedTimes.hpp" +#include "GNDStk/v2.0/fpy/Energy.hpp" +#include "GNDStk/v2.0/fpy/IncidentEnergies.hpp" +#include "GNDStk/v2.0/fpy/IncidentEnergy.hpp" +#include "GNDStk/v2.0/fpy/Nuclides.hpp" +#include "GNDStk/v2.0/fpy/ProductYield.hpp" +#include "GNDStk/v2.0/fpy/ProductYields.hpp" +#include "GNDStk/v2.0/fpy/Time.hpp" +#include "GNDStk/v2.0/fpy/Yields.hpp" + +#include "GNDStk/v2.0/pops/Alias.hpp" +#include "GNDStk/v2.0/pops/Aliases.hpp" +#include "GNDStk/v2.0/pops/Atomic.hpp" +#include "GNDStk/v2.0/pops/AverageEnergies.hpp" +#include "GNDStk/v2.0/pops/AverageEnergy.hpp" +#include "GNDStk/v2.0/pops/Baryon.hpp" +#include "GNDStk/v2.0/pops/Baryons.hpp" +#include "GNDStk/v2.0/pops/BindingEnergy.hpp" +#include "GNDStk/v2.0/pops/Charge.hpp" +#include "GNDStk/v2.0/pops/ChemicalElement.hpp" +#include "GNDStk/v2.0/pops/ChemicalElements.hpp" +#include "GNDStk/v2.0/pops/Configuration.hpp" +#include "GNDStk/v2.0/pops/Configurations.hpp" +#include "GNDStk/v2.0/pops/Continuum.hpp" +#include "GNDStk/v2.0/pops/Decay.hpp" +#include "GNDStk/v2.0/pops/DecayData.hpp" +#include "GNDStk/v2.0/pops/DecayMode.hpp" +#include "GNDStk/v2.0/pops/DecayModes.hpp" +#include "GNDStk/v2.0/pops/DecayPath.hpp" +#include "GNDStk/v2.0/pops/Discrete.hpp" +#include "GNDStk/v2.0/pops/Energy.hpp" +#include "GNDStk/v2.0/pops/GaugeBoson.hpp" +#include "GNDStk/v2.0/pops/GaugeBosons.hpp" +#include "GNDStk/v2.0/pops/Halflife.hpp" +#include "GNDStk/v2.0/pops/Intensity.hpp" +#include "GNDStk/v2.0/pops/InternalConversionCoefficients.hpp" +#include "GNDStk/v2.0/pops/InternalPairFormationCoefficient.hpp" +#include "GNDStk/v2.0/pops/Isotope.hpp" +#include "GNDStk/v2.0/pops/Isotopes.hpp" +#include "GNDStk/v2.0/pops/Lepton.hpp" +#include "GNDStk/v2.0/pops/Leptons.hpp" +#include "GNDStk/v2.0/pops/Mass.hpp" +#include "GNDStk/v2.0/pops/MetaStable.hpp" +#include "GNDStk/v2.0/pops/Nucleus.hpp" +#include "GNDStk/v2.0/pops/Nuclide.hpp" +#include "GNDStk/v2.0/pops/Nuclides.hpp" +#include "GNDStk/v2.0/pops/Parity.hpp" +#include "GNDStk/v2.0/pops/PhotonEmissionProbabilities.hpp" +#include "GNDStk/v2.0/pops/PoPs.hpp" +#include "GNDStk/v2.0/pops/Probability.hpp" +#include "GNDStk/v2.0/pops/Product.hpp" +#include "GNDStk/v2.0/pops/Products.hpp" +#include "GNDStk/v2.0/pops/Q.hpp" +#include "GNDStk/v2.0/pops/Shell.hpp" +#include "GNDStk/v2.0/pops/Spectra.hpp" +#include "GNDStk/v2.0/pops/Spectrum.hpp" +#include "GNDStk/v2.0/pops/Spin.hpp" +#include "GNDStk/v2.0/pops/Unorthodox.hpp" +#include "GNDStk/v2.0/pops/Unorthodoxes.hpp" + +#include "GNDStk/v2.0/processed/AngularEnergyMC.hpp" +#include "GNDStk/v2.0/processed/AvailableEnergy.hpp" +#include "GNDStk/v2.0/processed/AvailableMomentum.hpp" +#include "GNDStk/v2.0/processed/AverageProductEnergy.hpp" +#include "GNDStk/v2.0/processed/AverageProductMomentum.hpp" +#include "GNDStk/v2.0/processed/EnergyAngularMC.hpp" +#include "GNDStk/v2.0/processed/MultiGroup3d.hpp" + +#include "GNDStk/v2.0/resonances/BreitWigner.hpp" +#include "GNDStk/v2.0/resonances/Channel.hpp" +#include "GNDStk/v2.0/resonances/Channels.hpp" +#include "GNDStk/v2.0/resonances/EnergyInterval.hpp" +#include "GNDStk/v2.0/resonances/EnergyIntervals.hpp" +#include "GNDStk/v2.0/resonances/ExternalRMatrix.hpp" +#include "GNDStk/v2.0/resonances/HardSphereRadius.hpp" +#include "GNDStk/v2.0/resonances/J.hpp" +#include "GNDStk/v2.0/resonances/Js.hpp" +#include "GNDStk/v2.0/resonances/L.hpp" +#include "GNDStk/v2.0/resonances/LevelSpacing.hpp" +#include "GNDStk/v2.0/resonances/Ls.hpp" +#include "GNDStk/v2.0/resonances/RMatrix.hpp" +#include "GNDStk/v2.0/resonances/Resolved.hpp" +#include "GNDStk/v2.0/resonances/ResonanceParameters.hpp" +#include "GNDStk/v2.0/resonances/ResonanceReaction.hpp" +#include "GNDStk/v2.0/resonances/ResonanceReactions.hpp" +#include "GNDStk/v2.0/resonances/Resonances.hpp" +#include "GNDStk/v2.0/resonances/ScatteringRadius.hpp" +#include "GNDStk/v2.0/resonances/SpinGroup.hpp" +#include "GNDStk/v2.0/resonances/SpinGroups.hpp" +#include "GNDStk/v2.0/resonances/TabulatedWidths.hpp" +#include "GNDStk/v2.0/resonances/Unresolved.hpp" +#include "GNDStk/v2.0/resonances/Width.hpp" +#include "GNDStk/v2.0/resonances/Widths.hpp" + +#include "GNDStk/v2.0/styles/AngularDistributionReconstructed.hpp" +#include "GNDStk/v2.0/styles/AverageProductData.hpp" +#include "GNDStk/v2.0/styles/Bondarenko.hpp" +#include "GNDStk/v2.0/styles/CoulombPlusNuclearElasticMuCutoff.hpp" +#include "GNDStk/v2.0/styles/CrossSectionReconstructed.hpp" +#include "GNDStk/v2.0/styles/EqualProbableBins.hpp" +#include "GNDStk/v2.0/styles/Evaluated.hpp" +#include "GNDStk/v2.0/styles/Flux.hpp" +#include "GNDStk/v2.0/styles/GriddedCrossSection.hpp" +#include "GNDStk/v2.0/styles/Heated.hpp" +#include "GNDStk/v2.0/styles/HeatedMultiGroup.hpp" +#include "GNDStk/v2.0/styles/InverseSpeed.hpp" +#include "GNDStk/v2.0/styles/MonteCarlo_cdf.hpp" +#include "GNDStk/v2.0/styles/MultiBand.hpp" +#include "GNDStk/v2.0/styles/MultiGroup.hpp" +#include "GNDStk/v2.0/styles/ProjectileEnergyDomain.hpp" +#include "GNDStk/v2.0/styles/Realization.hpp" +#include "GNDStk/v2.0/styles/SigmaZeros.hpp" +#include "GNDStk/v2.0/styles/SnElasticUpScatter.hpp" +#include "GNDStk/v2.0/styles/Styles.hpp" +#include "GNDStk/v2.0/styles/Temperature.hpp" +#include "GNDStk/v2.0/styles/Transportable.hpp" +#include "GNDStk/v2.0/styles/Transportables.hpp" +#include "GNDStk/v2.0/styles/URR_probabilityTables.hpp" + +#include "GNDStk/v2.0/transport/A.hpp" +#include "GNDStk/v2.0/transport/Add.hpp" +#include "GNDStk/v2.0/transport/Angular.hpp" +#include "GNDStk/v2.0/transport/AngularEnergy.hpp" +#include "GNDStk/v2.0/transport/AngularTwoBody.hpp" +#include "GNDStk/v2.0/transport/Background.hpp" +#include "GNDStk/v2.0/transport/Branching1d.hpp" +#include "GNDStk/v2.0/transport/Branching3d.hpp" +#include "GNDStk/v2.0/transport/CoherentPhoton.hpp" +#include "GNDStk/v2.0/transport/CrossSection.hpp" +#include "GNDStk/v2.0/transport/CrossSectionSum.hpp" +#include "GNDStk/v2.0/transport/CrossSectionSums.hpp" +#include "GNDStk/v2.0/transport/DiscreteGamma.hpp" +#include "GNDStk/v2.0/transport/Distribution.hpp" +#include "GNDStk/v2.0/transport/DoubleDifferentialCrossSection.hpp" +#include "GNDStk/v2.0/transport/Energy.hpp" +#include "GNDStk/v2.0/transport/EnergyAngular.hpp" +#include "GNDStk/v2.0/transport/Evaporation.hpp" +#include "GNDStk/v2.0/transport/F.hpp" +#include "GNDStk/v2.0/transport/FastRegion.hpp" +#include "GNDStk/v2.0/transport/Forward.hpp" +#include "GNDStk/v2.0/transport/G.hpp" +#include "GNDStk/v2.0/transport/GeneralEvaporation.hpp" +#include "GNDStk/v2.0/transport/IncoherentPhoton.hpp" +#include "GNDStk/v2.0/transport/IncompleteReactions.hpp" +#include "GNDStk/v2.0/transport/Isotropic2d.hpp" +#include "GNDStk/v2.0/transport/KalbachMann.hpp" +#include "GNDStk/v2.0/transport/Multiplicity.hpp" +#include "GNDStk/v2.0/transport/MultiplicitySum.hpp" +#include "GNDStk/v2.0/transport/MultiplicitySums.hpp" +#include "GNDStk/v2.0/transport/NBodyPhaseSpace.hpp" +#include "GNDStk/v2.0/transport/OrphanProduct.hpp" +#include "GNDStk/v2.0/transport/OrphanProducts.hpp" +#include "GNDStk/v2.0/transport/OutputChannel.hpp" +#include "GNDStk/v2.0/transport/PhotonEmissionProbabilities.hpp" +#include "GNDStk/v2.0/transport/PrimaryGamma.hpp" +#include "GNDStk/v2.0/transport/Production.hpp" +#include "GNDStk/v2.0/transport/Productions.hpp" +#include "GNDStk/v2.0/transport/R.hpp" +#include "GNDStk/v2.0/transport/Reaction.hpp" +#include "GNDStk/v2.0/transport/ReactionSuite.hpp" +#include "GNDStk/v2.0/transport/Reactions.hpp" +#include "GNDStk/v2.0/transport/Recoil.hpp" +#include "GNDStk/v2.0/transport/Reference.hpp" +#include "GNDStk/v2.0/transport/ResolvedRegion.hpp" +#include "GNDStk/v2.0/transport/Resonances.hpp" +#include "GNDStk/v2.0/transport/ResonancesWithBackground.hpp" +#include "GNDStk/v2.0/transport/ScatteringMatrix.hpp" +#include "GNDStk/v2.0/transport/Summands.hpp" +#include "GNDStk/v2.0/transport/Sums.hpp" +#include "GNDStk/v2.0/transport/Theta.hpp" +#include "GNDStk/v2.0/transport/U.hpp" +#include "GNDStk/v2.0/transport/URR_probabilityTables1d.hpp" +#include "GNDStk/v2.0/transport/Uncorrelated.hpp" +#include "GNDStk/v2.0/transport/UnresolvedRegion.hpp" +#include "GNDStk/v2.0/transport/Unspecified.hpp" +#include "GNDStk/v2.0/transport/Weighted.hpp" +#include "GNDStk/v2.0/transport/WeightedFunctionals.hpp" + +#include "GNDStk/v2.0/tsl/BoundAtomCrossSection.hpp" +#include "GNDStk/v2.0/tsl/BraggEdge.hpp" +#include "GNDStk/v2.0/tsl/BraggEdges.hpp" +#include "GNDStk/v2.0/tsl/BraggEnergy.hpp" +#include "GNDStk/v2.0/tsl/CoherentAtomCrossSection.hpp" +#include "GNDStk/v2.0/tsl/DebyeWallerIntegral.hpp" +#include "GNDStk/v2.0/tsl/DistinctScatteringKernel.hpp" +#include "GNDStk/v2.0/tsl/E_critical.hpp" +#include "GNDStk/v2.0/tsl/E_max.hpp" +#include "GNDStk/v2.0/tsl/PhononSpectrum.hpp" +#include "GNDStk/v2.0/tsl/S_table.hpp" +#include "GNDStk/v2.0/tsl/ScatteringAtom.hpp" +#include "GNDStk/v2.0/tsl/ScatteringAtoms.hpp" +#include "GNDStk/v2.0/tsl/SelfScatteringKernel.hpp" +#include "GNDStk/v2.0/tsl/SelfScatteringKernelGaussianApproximation.hpp" +#include "GNDStk/v2.0/tsl/SelfScatteringKernelSCTApproximation.hpp" +#include "GNDStk/v2.0/tsl/StructureFactor.hpp" +#include "GNDStk/v2.0/tsl/T_effective.hpp" +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw.hpp" +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw1d.hpp" +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_coherentElastic.hpp" +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentElastic.hpp" +#include "GNDStk/v2.0/tsl/ThermalNeutronScatteringLaw_incoherentInelastic.hpp" + +#include "GNDStk/v2.0/key.hpp" + +#endif diff --git a/src/GNDStk/v2.0/abstract/Functional.hpp b/src/GNDStk/v2.0/abstract/Functional.hpp new file mode 100644 index 000000000..7b4be8e9d --- /dev/null +++ b/src/GNDStk/v2.0/abstract/Functional.hpp @@ -0,0 +1,288 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef NJOY_GNDSTK_V2_0_ABSTRACT_FUNCTIONAL +#define NJOY_GNDSTK_V2_0_ABSTRACT_FUNCTIONAL + +// core interface +#include "GNDStk.hpp" + +// v2.0 dependencies +#include "GNDStk/v2.0/containers/Axes.hpp" +#include "GNDStk/v2.0/unknownNamespace/Uncertainty.hpp" +#include "GNDStk/v2.0/containers/Values.hpp" + +namespace njoy { +namespace GNDStk { +namespace v2_0 { + +using namespace njoy::GNDStk::core; + + + +// ----------------------------------------------------------------------------- +// abstract:: +// class Functional +// ----------------------------------------------------------------------------- + +namespace abstract { + +class Functional : public Component { + + using _t = std::variant< + abstract::Functional, + containers::Values + >; + + // ------------------------ + // For Component + // ------------------------ + + friend class Component; + + // Current namespace, current class, and GNDS node name + static auto namespaceName() { return "abstract"; } + static auto className() { return "Functional"; } + static auto GNDSName() { return "functional"; } + + // Core Interface multi-query to extract metadata and child nodes + static auto keys() + { + return + // metadata + std::optional{} + / Meta<>("label") | + std::optional{} + / Meta<>("outerDomainValue") | + // children + containers::Axes{} + / --Child<>("axes") | + std::optional{} + / --Child<>("uncertainty") | + _t{} + / --(Child<>("functional") || Child<>("values")) + ; + } + +public: + + using Component::construct; + + // ------------------------ + // Relevant defaults + // FYI for users + // ------------------------ + + static inline const struct Defaults { + } defaults; + + // ------------------------ + // Raw GNDS content + // ------------------------ + + struct { + // metadata + std::optional label; + std::optional outerDomainValue; + // children + containers::Axes axes; + std::optional uncertainty; + // children - variant + _t _functionalvalues; + } content; + + // ------------------------ + // Getters + // const and non-const + // ------------------------ + + // label + const std::optional &label() const + { return content.label; } + std::optional &label() + { return content.label; } + + // outerDomainValue + const std::optional &outerDomainValue() const + { return content.outerDomainValue; } + std::optional &outerDomainValue() + { return content.outerDomainValue; } + + // axes + const containers::Axes &axes() const + { return content.axes; } + containers::Axes &axes() + { return content.axes; } + + // uncertainty + const std::optional &uncertainty() const + { return content.uncertainty; } + std::optional &uncertainty() + { return content.uncertainty; } + + // _functionalvalues + const _t &_functionalvalues() const + { return content._functionalvalues; } + _t &_functionalvalues() + { return content._functionalvalues; } + + // functional + const abstract::Functional *functional() const + { return getter(_functionalvalues(), "functional"); } + abstract::Functional *functional() + { return getter(_functionalvalues(), "functional"); } + + // values + const containers::Values *values() const + { return getter(_functionalvalues(), "values"); } + containers::Values *values() + { return getter(_functionalvalues(), "values"); } + + // ------------------------ + // Setters + // non-const + // All return *this + // ------------------------ + + // label(value) + Functional &label(const std::optional &obj) + { label() = obj; return *this; } + + // outerDomainValue(value) + Functional &outerDomainValue(const std::optional &obj) + { outerDomainValue() = obj; return *this; } + + // axes(value) + Functional &axes(const containers::Axes &obj) + { axes() = obj; return *this; } + + // uncertainty(value) + Functional &uncertainty(const std::optional &obj) + { uncertainty() = obj; return *this; } + + // _functionalvalues(value) + Functional &_functionalvalues(const _t &obj) + { _functionalvalues() = obj; return *this; } + + // functional(value) + Functional &functional(const std::optional &obj) + { if (obj) _functionalvalues(obj.value()); return *this; } + + // values(value) + Functional &values(const std::optional &obj) + { if (obj) _functionalvalues(obj.value()); return *this; } + + // ------------------------ + // Construction + // ------------------------ + + // default + Functional() : + Component{ + BodyText{}, + content.label, + content.outerDomainValue, + content.axes, + content.uncertainty, + content._functionalvalues + } + { + Component::finish(); + } + + // copy + Functional(const Functional &other) : + Component{ + other, + content.label, + content.outerDomainValue, + content.axes, + content.uncertainty, + content._functionalvalues + }, + content{other.content} + { + Component::finish(other); + } + + // move + Functional(Functional &&other) : + Component{ + other, + content.label, + content.outerDomainValue, + content.axes, + content.uncertainty, + content._functionalvalues + }, + content{std::move(other.content)} + { + Component::finish(other); + } + + // from node + Functional(const Node &node) : + Component{ + BodyText{}, + content.label, + content.outerDomainValue, + content.axes, + content.uncertainty, + content._functionalvalues + } + { + Component::finish(node); + } + + // from fields + explicit Functional( + const std::optional &label, + const std::optional &outerDomainValue, + const containers::Axes &axes, + const std::optional &uncertainty, + const _t &_functionalvalues + ) : + Component{ + BodyText{}, + content.label, + content.outerDomainValue, + content.axes, + content.uncertainty, + content._functionalvalues + }, + content{ + label, + outerDomainValue, + axes, + uncertainty, + _functionalvalues + } + { + Component::finish(); + } + + // ------------------------ + // Assignment + // ------------------------ + + // copy + Functional &operator=(const Functional &) = default; + + // move + Functional &operator=(Functional &&) = default; + + // ------------------------ + // Custom functionality + // ------------------------ + + #include "GNDStk/v2.0/abstract/Functional/src/custom.hpp" + +}; // class Functional + +} // namespace abstract +} // namespace v2_0 +} // namespace GNDStk +} // namespace njoy + +#endif diff --git a/src/GNDStk/v2.0/abstract/Functional/src/custom.hpp b/src/GNDStk/v2.0/abstract/Functional/src/custom.hpp new file mode 100644 index 000000000..9bf4b251a --- /dev/null +++ b/src/GNDStk/v2.0/abstract/Functional/src/custom.hpp @@ -0,0 +1,4 @@ + +private: + + static inline helpMap help = {}; diff --git a/src/GNDStk/v2.0/abstract/Label.hpp b/src/GNDStk/v2.0/abstract/Label.hpp new file mode 100644 index 000000000..522d717bc --- /dev/null +++ b/src/GNDStk/v2.0/abstract/Label.hpp @@ -0,0 +1,176 @@ + +// THIS FILE WAS AUTOGENERATED! +// DO NOT MODIFY! + +#ifndef NJOY_GNDSTK_V2_0_ABSTRACT_LABEL +#define NJOY_GNDSTK_V2_0_ABSTRACT_LABEL + +// core interface +#include "GNDStk.hpp" + +namespace njoy { +namespace GNDStk { +namespace v2_0 { + +using namespace njoy::GNDStk::core; + + + +// ----------------------------------------------------------------------------- +// abstract:: +// class Label +// ----------------------------------------------------------------------------- + +namespace abstract { + +class Label : public Component