13#include <boost/date_time.hpp>
14#include <boost/endian/conversion.hpp>
15#include <boost/uuid/uuid.hpp>
16#include <boost/uuid/uuid_generators.hpp>
17#include <boost/uuid/uuid_io.hpp>
19#include "boost/date_time/c_local_time_adjustor.hpp"
31 boost::uuids::uuid uuid = boost::uuids::random_generator()();
32 std::string uuidStr = boost::uuids::to_string(uuid);
45 boost::date_time::c_local_adjustor<boost::posix_time::ptime>;
46 boost::posix_time::time_facet* f =
new boost::posix_time::time_facet();
47 f->time_duration_format(
"%+%H:%M");
50 auto now = boost::posix_time::microsec_clock::universal_time();
51 auto utc_now = local_adj::utc_to_local(now);
52 boost::posix_time::time_duration td = utc_now - now;
55 std::ostringstream oss_offset;
56 oss_offset.imbue(std::locale(oss_offset.getloc(), f));
59 std::string currentTime = to_iso_extended_string(utc_now);
60 currentTime += oss_offset.str();
77 const std::string iso8601Pattern =
78 R
"(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[+-]\d{2}:\d{2}$)";
79 std::regex pattern(iso8601Pattern);
82 return std::regex_match(dateStr, pattern);
89static inline std::shared_ptr<IO::BaseIO>
createIO(
const std::string& type,
90 const std::string& filename)
93 return std::make_shared<AQNWB::IO::HDF5::HDF5IO>(filename);
95 throw std::invalid_argument(
"Invalid IO type");
112static inline std::string
mergePaths(
const std::string& path1,
113 const std::string& path2)
115 std::string result = path1;
117 while (!result.empty() && result.back() ==
'/' && result !=
"/") {
122 while (start < path2.size() && path2[start] ==
'/') {
126 std::string path2Clean = path2.substr(start);
127 while (!path2Clean.empty() && path2Clean.back() ==
'/' && path2Clean !=
"/") {
128 path2Clean.pop_back();
131 if (!result.empty() && !path2Clean.empty()) {
134 result += path2Clean;
137 size_t pos = result.find(
"//");
138 while (pos != std::string::npos) {
139 result.replace(pos, 2,
"/");
140 pos = result.find(
"//", pos);
144 while (!result.empty() && result.back() ==
'/' && result !=
"/") {
166 auto maxVal =
static_cast<double>(0x7fff);
167 auto intData =
static_cast<char*
>(dest);
169 for (
SizeType i = 0; i < numSamples; ++i) {
171 std::clamp(maxVal *
static_cast<double>(source[i]), -maxVal, maxVal);
173 static_cast<uint16_t
>(
static_cast<int16_t
>(std::round(clampedValue)));
174 intValue = boost::endian::native_to_little(intValue);
175 *
reinterpret_cast<uint16_t*
>(intData) = intValue;
187 SizeType numSamples,
float conversion_factor,
const float* data)
189 std::unique_ptr<float[]> scaledData = std::make_unique<float[]>(numSamples);
190 std::unique_ptr<int16_t[]> intData = std::make_unique<int16_t[]>(numSamples);
193 float multFactor = 1.0f / (32767.0f * conversion_factor);
197 [multFactor](
float value) { return value * multFactor; });
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
The main namespace for AqNWB.
Definition Channel.hpp:11
static std::unique_ptr< int16_t[]> transformToInt16(SizeType numSamples, float conversion_factor, const float *data)
Method to scale float values and convert to int16 values.
Definition Utils.hpp:186
static void convertFloatToInt16LE(const float *source, void *dest, SizeType numSamples)
Method to convert float values to uint16 values. This method was adapted from JUCE AudioDataConverter...
Definition Utils.hpp:159
static std::string mergePaths(const std::string &path1, const std::string &path2)
Merge two paths into a single path, handling extra trailing and starting "/".
Definition Utils.hpp:112
static bool isISO8601Date(const std::string &dateStr)
Check that a string is formatted in ISO8601 format.
Definition Utils.hpp:73
static std::string generateUuid()
Generates a UUID (Universally Unique Identifier) as a string.
Definition Utils.hpp:29
static std::shared_ptr< IO::BaseIO > createIO(const std::string &type, const std::string &filename)
Factory method to create an IO object.
Definition Utils.hpp:89
static std::string getCurrentTime()
Get the current time in ISO 8601 format with the UTC offset.
Definition Utils.hpp:41