feat(standard-abundances): added raw data accessor

This commit is contained in:
2026-06-11 07:31:03 -04:00
parent c12dc2c853
commit 3e3b7ad5b1
4 changed files with 49 additions and 45 deletions

View File

@@ -48,7 +48,7 @@ PROJECT_NAME = fourdst::libcomposition
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = v2.4.2
PROJECT_NUMBER = v2.4.3
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewers a

View File

@@ -18,7 +18,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# *********************************************************************** #
project('libcomposition', 'cpp', version: 'v2.4.2', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
project('libcomposition', 'cpp', version: 'v2.4.3', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
# Add default visibility for all C++ targets
add_project_arguments('-fvisibility=default', language: 'cpp')

View File

@@ -62,6 +62,12 @@ namespace fourdst::composition::io {
{IsotopicPercentages::L09, "L09_data"}
};
/**
* @brief Fetch the raw byte array of the standard solar composition data
* @return Raw Byte array to be used with ChemicalFileParser
*/
std::span<const unsigned char> get_raw_standard_solar_composition_data();
/**
* @class ChemicalFileParser
* @brief An abstract base class for chemical file parsers.
@@ -104,8 +110,8 @@ namespace fourdst::composition::io {
* }
* @endcode
*/
[[nodiscard]] CompositionData parse_compositon_data(const std::vector<char>& data,const std::string& scheme) const ;
[[nodiscard]] IsotopicPercentage parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme) const ;
[[nodiscard]] static CompositionData parse_composition_data(const std::vector<char>& data,const std::string& scheme);
[[nodiscard]] static IsotopicPercentage parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme);
};

View File

@@ -17,56 +17,56 @@
#include <ranges>
#include <cctype>
namespace fourdst:: composition::io {
namespace {
inline void ltrim(std::string &s) {
s.erase(
s.begin(),
std::ranges::find_if(s,
[](const unsigned char ch) {
return !std::isspace(ch);
})
);
}
inline void rtrim(std::string &s) {
s.erase(
std::find_if(
s.rbegin(),
s.rend(),
[](const unsigned char ch) {
return !std::isspace(ch);
}).base(),
s.end()
);
}
inline void trim(std::string &s) {
ltrim(s);
rtrim(s);
}
namespace {
void ltrim(std::string &s) {
s.erase(
s.begin(),
std::ranges::find_if(s,
[](const unsigned char ch) {
return !std::isspace(ch);
})
);
}
void rtrim(std::string &s) {
s.erase(
std::find_if(
s.rbegin(),
s.rend(),
[](const unsigned char ch) {
return !std::isspace(ch);
}).base(),
s.end()
);
}
void trim(std::string &s) {
ltrim(s);
rtrim(s);
}
bool to_bool(std::string s) {
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c){ return std::tolower(c); });
std::ranges::transform(s, s.begin(),
[](const unsigned char c){ return std::tolower(c); });
return s == "true";
}
CompositionData ChemicalFileParser::parse_compositon_data(const std::vector<char>& data,const std::string& scheme) const {
}
namespace fourdst:: composition::io {
std::span<const unsigned char> get_raw_standard_solar_composition_data() {
return StandardMetalFractions;
}
CompositionData ChemicalFileParser::parse_composition_data(const std::vector<char>& data,const std::string& scheme) {
// get file and metal_fraction_scheme
// Load the file
// find the metal_fraction_scheme
// return abundances
// LOG_TRACE_L1(m_logger, "Parsing chemical abundance for: {}", scheme);
bool debug = false;
std::istringstream stream(std::string(data.begin(), data.end()));
// add error message if something goes wrong
@@ -141,7 +141,7 @@ namespace fourdst:: composition::io {
}
IsotopicPercentage ChemicalFileParser::parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme) const {
IsotopicPercentage ChemicalFileParser::parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme) {
// get file and iso_scheme
// Load the file
@@ -149,8 +149,6 @@ namespace fourdst:: composition::io {
// get iso_comp data
// IsotopicPercentage object
bool debug = false;
std::istringstream stream(std::string(data.begin(), data.end()));
// add error message if something goes wrong
@@ -240,7 +238,7 @@ namespace fourdst::composition {
data = std::ranges::to<std::vector<char>>(StandardMetalFractions);
metals = parser.parse_compositon_data(data,metal_fraction_scheme);
metals = parser.parse_composition_data(data,metal_fraction_scheme);
isotopes = parser.parse_isotopic_percentage(data,isotopic_percentage_scheme);
std::string name;