provenance.cpp format.hpp bit chrono ctime iomanip limits locale sstream thread nameof.hpp magic_enum/magic_enum.hpp serif/config.hpp serif serif::utils serif::utils::serialize serif::utils::serialize::detail #include"format.hpp" #include<bit> #include<chrono> #include<ctime> #include<iomanip> #include<limits> #include<locale> #include<sstream> #include<thread> #include<nameof.hpp> #include<magic_enum/magic_enum.hpp> #include"serif/config.hpp" #ifdefined(__unix__)||defined(__APPLE__) #include<sys/utsname.h> #endif namespaceserif::utils::serialize::detail{ namespace{ std::stringtimestamp(){ conststd::time_tnow=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::tmutc{}; #ifdefined(_WIN32) gmtime_s(&utc,&now); #else gmtime_r(&now,&utc); #endif std::ostringstreamoutput; output.imbue(std::locale::classic()); output<<std::put_time(&utc,"%Y-%m-%dT%H:%M:%SZ"); returnoutput.str(); } std::stringversion(intmajor,intminor,intpatch){ returnstd::to_string(major)+"."+std::to_string(minor)+"."+std::to_string(patch); } Nodehost_information(){ Nodehost=object("host", field("operating_system",std::string{SERIF_BUILD_SYSTEM}), field("architecture",std::string{SERIF_BUILD_ARCHITECTURE}), field("hardware_threads",std::thread::hardware_concurrency()), field("pointer_bits",static_cast<unsignedint>(8*sizeof(void*))), field("byte_order",std::string{std::endian::native==std::endian::little?"little":"big"})); #ifdefined(__unix__)||defined(__APPLE__) structutsnameinformation{}; if(uname(&information)==0){ host.children.emplace("name",encode(std::string{information.nodename})); host.children.emplace("kernel",encode(std::string{information.sysname})); host.children.emplace("kernel_release",encode(std::string{information.release})); host.children.emplace("kernel_version",encode(std::string{information.version})); host.children.emplace("machine",encode(std::string{information.machine})); } #endif returnhost; } } Nodeprovenance(constWriteOptions&options){ static_assert(sizeof(double)==8&&std::numeric_limits<double>::is_iec559, "ThenativearchivecurrentlyrepresentsIEEE-754binary64coefficients."); Nodelibraries=object("libraries", field("nameof",version(NAMEOF_VERSION_MAJOR,NAMEOF_VERSION_MINOR,NAMEOF_VERSION_PATCH)), field("magic_enum",version(MAGIC_ENUM_VERSION_MAJOR,MAGIC_ENUM_VERSION_MINOR,MAGIC_ENUM_VERSION_PATCH)), field("mfem_build_dependency",std::string{SERIF_MFEM_BUILD_VERSION})); #ifdefined(_LIBCPP_VERSION) libraries.children.emplace("libcxx",encode(std::to_string(_LIBCPP_VERSION))); #elifdefined(__GLIBCXX__) libraries.children.emplace("libstdcxx",encode(std::to_string(__GLIBCXX__))); #endif Nodeannotations{.type="metadata"}; for(constauto&[key,value]:options.metadata){ annotations.children.emplace(key,encode(value)); } returnobject("provenance", field("written_utc",timestamp()),field("serif_version",std::string{SERIF_VERSION}), field("host",host_information()),field("libraries",libraries), field("compiler",std::string{SERIF_BUILD_COMPILER}),field("build_type",std::string{SERIF_BUILD_TYPE}), field("author",options.author),field("comment",options.comment),field("metadata",annotations)); } }