From 15633190baa7e55705f99d4f83cdb25fe94636fa Mon Sep 17 00:00:00 2001 From: Yida Lin Date: Sun, 17 May 2020 02:27:21 -0700 Subject: [PATCH] #25: Refactor the code according to the Google C++ Style Guide --- xdf.cpp | 454 ++++++++++++++++++++++++++++---------------------------- xdf.h | 333 +++++++++++++++++++---------------------- 2 files changed, 379 insertions(+), 408 deletions(-) diff --git a/xdf.cpp b/xdf.cpp index 96c3c81..9195952 100644 --- a/xdf.cpp +++ b/xdf.cpp @@ -33,7 +33,7 @@ Xdf::Xdf() { } -int Xdf::load_xdf(std::string filename) +int Xdf::LoadXdf(std::string filename) { clock_t time; time = clock(); @@ -79,13 +79,13 @@ int Xdf::load_xdf(std::string filename) //for each chunk while (1) { - uint64_t ChLen = readLength(file);//chunk length + uint64_t ChLen = ReadLength(file);//chunk length if (ChLen == 0) break; uint16_t tag; //read tag of the chunk, 6 possibilities - readBin(file, &tag); + ReadBin(file, &tag); switch (tag) { @@ -93,7 +93,7 @@ int Xdf::load_xdf(std::string filename) { char* buffer = new char[ChLen - 2]; file.read(buffer, ChLen - 2); - fileHeader = buffer; + file_header_ = buffer; pugi::xml_document doc; @@ -101,7 +101,7 @@ int Xdf::load_xdf(std::string filename) pugi::xml_node info = doc.child("info"); - version = info.child("version").text().as_float(); + version_ = info.child("version").text().as_float(); delete[] buffer; } @@ -111,13 +111,13 @@ int Xdf::load_xdf(std::string filename) //read [StreamID] uint32_t streamID; int index; - Xdf::readBin(file, &streamID); + Xdf::ReadBin(file, &streamID); std::vector::iterator it {std::find(idmap.begin(),idmap.end(),streamID)}; if (it == idmap.end()) { index = idmap.size(); idmap.emplace_back(streamID); - streams.emplace_back(); + streams_.emplace_back(); } else index = std::distance(idmap.begin(), it); @@ -128,31 +128,31 @@ int Xdf::load_xdf(std::string filename) //read [Content] char* buffer = new char[ChLen - 6]; file.read(buffer, ChLen - 6); - streams[index].streamHeader = buffer; + streams_[index].stream_header = buffer; doc.load_buffer_inplace(buffer, ChLen - 6); pugi::xml_node info = doc.child("info"); pugi::xml_node desc = info.child("desc"); - streams[index].info.channel_count = info.child("channel_count").text().as_int(); - streams[index].info.nominal_srate = info.child("nominal_srate").text().as_double(); - streams[index].info.name = info.child("name").text().get(); - streams[index].info.type = info.child("type").text().get(); - streams[index].info.channel_format = info.child("channel_format").text().get(); + streams_[index].info.channel_count = info.child("channel_count").text().as_int(); + streams_[index].info.nominal_srate = info.child("nominal_srate").text().as_double(); + streams_[index].info.name = info.child("name").text().get(); + streams_[index].info.type = info.child("type").text().get(); + streams_[index].info.channel_format = info.child("channel_format").text().get(); for (auto channel = desc.child("channels").child("channel"); channel; channel = channel.next_sibling("channel")) { - streams[index].info.channels.emplace_back(); + streams_[index].info.channels.emplace_back(); for (auto const &entry : channel.children()) - streams[index].info.channels.back().emplace(entry.name(), entry.child_value()); + streams_[index].info.channels.back().emplace(entry.name(), entry.child_value()); } - if (streams[index].info.nominal_srate > 0) - streams[index].sampling_interval = 1 / streams[index].info.nominal_srate; + if (streams_[index].info.nominal_srate > 0) + streams_[index].sampling_interval = 1 / streams_[index].info.nominal_srate; else - streams[index].sampling_interval = 0; + streams_[index].sampling_interval = 0; delete[] buffer; } @@ -162,262 +162,262 @@ int Xdf::load_xdf(std::string filename) //read [StreamID] uint32_t streamID; int index; - Xdf::readBin(file, &streamID); + Xdf::ReadBin(file, &streamID); std::vector::iterator it {std::find(idmap.begin(),idmap.end(),streamID)}; if (it == idmap.end()) { index = idmap.size(); idmap.emplace_back(streamID); - streams.emplace_back(); + streams_.emplace_back(); } else index = std::distance(idmap.begin(), it); //read [NumSampleBytes], [NumSamples] - uint64_t numSamp = readLength(file); + uint64_t numSamp = ReadLength(file); //check the data type - if (streams[index].info.channel_format.compare("float32") == 0) + if (streams_[index].info.channel_format.compare("float32") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { float data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("double64") == 0) + else if (streams_[index].info.channel_format.compare("double64") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { double data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("int8") == 0) + else if (streams_[index].info.channel_format.compare("int8") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { int8_t data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("int16") == 0) + else if (streams_[index].info.channel_format.compare("int16") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { int16_t data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("int32") == 0) + else if (streams_[index].info.channel_format.compare("int32") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { int32_t data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("int64") == 0) + else if (streams_[index].info.channel_format.compare("int64") == 0) { //if the time series is empty - if (streams[index].time_series.empty()) - streams[index].time_series.resize(streams[index].info.channel_count); + if (streams_[index].time_series.empty()) + streams_[index].time_series.resize(streams_[index].info.channel_count); //for each sample for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) { - Xdf::readBin(file, &ts); - streams[index].time_stamps.emplace_back(ts); + Xdf::ReadBin(file, &ts); + streams_[index].time_stamps.emplace_back(ts); } else { - ts = streams[index].last_timestamp + streams[index].sampling_interval; - streams[index].time_stamps.emplace_back(ts); + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; + streams_[index].time_stamps.emplace_back(ts); } - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; //read the data - for (int v = 0; v < streams[index].info.channel_count; ++v) + for (int v = 0; v < streams_[index].info.channel_count; ++v) { int64_t data; - Xdf::readBin(file, &data); - streams[index].time_series[v].emplace_back(data); + Xdf::ReadBin(file, &data); + streams_[index].time_series[v].emplace_back(data); } } } - else if (streams[index].info.channel_format.compare("string") == 0) + else if (streams_[index].info.channel_format.compare("string") == 0) { //for each event for (size_t i = 0; i < numSamp; i++) { //read or deduce time stamp - auto tsBytes = readBin(file); + auto tsBytes = ReadBin(file); double ts; //temporary time stamp if (tsBytes == 8) - Xdf::readBin(file, &ts); + Xdf::ReadBin(file, &ts); else - ts = streams[index].last_timestamp + streams[index].sampling_interval; + ts = streams_[index].last_timestamp + streams_[index].sampling_interval; //read the event - auto length = Xdf::readLength(file); + auto length = Xdf::ReadLength(file); char* buffer = new char[length + 1]; file.read(buffer, length); buffer[length] = '\0'; - eventMap.emplace_back(std::make_pair(buffer, ts), index); + event_map_.emplace_back(std::make_pair(buffer, ts), index); delete[] buffer; - streams[index].last_timestamp = ts; + streams_[index].last_timestamp = ts; } } } @@ -426,13 +426,13 @@ int Xdf::load_xdf(std::string filename) { uint32_t streamID; int index; - Xdf::readBin(file, &streamID); + Xdf::ReadBin(file, &streamID); std::vector::iterator it {std::find(idmap.begin(),idmap.end(),streamID)}; if (it == idmap.end()) { index = idmap.size(); idmap.emplace_back(streamID); - streams.emplace_back(); + streams_.emplace_back(); } else index = std::distance(idmap.begin(), it); @@ -441,11 +441,11 @@ int Xdf::load_xdf(std::string filename) double collectionTime; double offsetValue; - Xdf::readBin(file, &collectionTime); - Xdf::readBin(file, &offsetValue); + Xdf::ReadBin(file, &collectionTime); + Xdf::ReadBin(file, &offsetValue); - streams[index].clock_times.emplace_back(collectionTime); - streams[index].clock_values.emplace_back(offsetValue); + streams_[index].clock_times.emplace_back(collectionTime); + streams_[index].clock_values.emplace_back(offsetValue); } break; case 6: //read [StreamFooter] chunk @@ -455,13 +455,13 @@ int Xdf::load_xdf(std::string filename) //read [StreamID] uint32_t streamID; int index; - Xdf::readBin(file, &streamID); + Xdf::ReadBin(file, &streamID); std::vector::iterator it {std::find(idmap.begin(),idmap.end(),streamID)}; if (it == idmap.end()) { index = idmap.size(); idmap.emplace_back(streamID); - streams.emplace_back(); + streams_.emplace_back(); } else index = std::distance(idmap.begin(), it); @@ -469,16 +469,16 @@ int Xdf::load_xdf(std::string filename) char* buffer = new char[ChLen - 6]; file.read(buffer, ChLen - 6); - streams[index].streamFooter = buffer; + streams_[index].stream_footer = buffer; doc.load_buffer_inplace(buffer, ChLen - 6); pugi::xml_node info = doc.child("info"); - streams[index].info.first_timestamp = info.child("first_timestamp").text().as_double(); - streams[index].info.last_timestamp = info.child("last_timestamp").text().as_double(); - streams[index].info.measured_srate = info.child("measured_srate").text().as_double(); - streams[index].info.sample_count = info.child("sample_count").text().as_int(); + streams_[index].info.first_timestamp = info.child("first_timestamp").text().as_double(); + streams_[index].info.last_timestamp = info.child("last_timestamp").text().as_double(); + streams_[index].info.measured_sampling_rate = info.child("measured_srate").text().as_double(); + streams_[index].info.sample_count = info.child("sample_count").text().as_int(); delete[] buffer; } break; @@ -503,21 +503,21 @@ int Xdf::load_xdf(std::string filename) //=============find the min and max time stamps============= //========================================================== - syncTimeStamps(); + SyncTimeStamps(); - findMinMax(); + FindMinMaxTimeStamps(); - findMajSR(); + FindMajorSamplingRate(); - getHighestSampleRate(); + FindMaxSampleRate(); - loadSampleRateMap(); + LoadSamplingRateMap(); - calcTotalChannel(); + CalculateChannelCount(); - loadDictionary(); + LoadDictionary(); - calcEffectiveSrate(); + CalculateEffectiveSamplingRate(); //loading finishes, close file file.close(); @@ -531,10 +531,10 @@ int Xdf::load_xdf(std::string filename) return 0; } -void Xdf::syncTimeStamps() +void Xdf::SyncTimeStamps() { // Sync time stamps - for (auto &stream : this->streams) + for (auto &stream : this->streams_) { if (!stream.clock_times.empty()) { @@ -561,15 +561,15 @@ void Xdf::syncTimeStamps() } // Sync event time stamps - for (auto &elem : this->eventMap) + for (auto &elem : this->event_map_) { - if (!this->streams[elem.second].clock_times.empty()) + if (!this->streams_[elem.second].clock_times.empty()) { size_t k = 0; // index iterating through streams[elem.second].clock_times - while (k < this->streams[elem.second].clock_times.size() - 1) + while (k < this->streams_[elem.second].clock_times.size() - 1) { - if (this->streams[elem.second].clock_times[k+1] < elem.first.second) + if (this->streams_[elem.second].clock_times[k+1] < elem.first.second) { k++; } @@ -579,19 +579,19 @@ void Xdf::syncTimeStamps() } } - elem.first.second += this->streams[elem.second].clock_values[k]; // apply the last offset value to the timestamp; if there hasn't yet been an offset value take the first recorded one + elem.first.second += this->streams_[elem.second].clock_values[k]; // apply the last offset value to the timestamp; if there hasn't yet been an offset value take the first recorded one } } // Update first and last time stamps in stream footer - for (size_t k = 0; k < this->streams.size(); k++) + for (size_t k = 0; k < this->streams_.size(); k++) { - if (streams[k].info.channel_format.compare("string") == 0) + if (streams_[k].info.channel_format.compare("string") == 0) { double min = NAN; double max = NAN; - for (auto const &elem : this->eventMap) + for (auto const &elem : this->event_map_) { if (elem.second == (int)k) { @@ -607,18 +607,18 @@ void Xdf::syncTimeStamps() } } - streams[k].info.first_timestamp = min; - streams[k].info.last_timestamp = max; + streams_[k].info.first_timestamp = min; + streams_[k].info.last_timestamp = max; } else { - streams[k].info.first_timestamp = streams[k].time_stamps.front(); - streams[k].info.last_timestamp = streams[k].time_stamps.back(); + streams_[k].info.first_timestamp = streams_[k].time_stamps.front(); + streams_[k].info.last_timestamp = streams_[k].time_stamps.back(); } } } -void Xdf::resample(int userSrate) +void Xdf::Resample(int userSrate) { //if user entered a preferred sample rate, we resample all the channels to that sample rate //Otherwise, we resample all channels to the sample rate that has the most channels @@ -626,7 +626,7 @@ void Xdf::resample(int userSrate) clock_t time = clock(); #define BUF_SIZE 8192 - for (auto &stream : streams) + for (auto &stream : streams_) { if (!stream.time_series.empty() && stream.info.nominal_srate != userSrate && @@ -699,9 +699,9 @@ void Xdf::resample(int userSrate) //====================================================================== - calcTotalLength(userSrate); + CalculateTotalLength(userSrate); - adjustTotalLength(); + AdjustTotalLength(); time = clock() - time; @@ -710,22 +710,22 @@ void Xdf::resample(int userSrate) } //function of reading the length of each chunk -uint64_t Xdf::readLength(std::ifstream &file) +uint64_t Xdf::ReadLength(std::ifstream &file) { uint8_t bytes; - Xdf::readBin(file, &bytes); + Xdf::ReadBin(file, &bytes); uint64_t length = 0; switch (bytes) { case 1: - length = readBin(file); + length = ReadBin(file); break; case 4: - length = readBin(file); + length = ReadBin(file); break; case 8: - length = readBin(file); + length = ReadBin(file); break; default: std::cout << "Invalid variable-length integer length (" @@ -736,32 +736,32 @@ uint64_t Xdf::readLength(std::ifstream &file) return length; } -void Xdf::findMinMax() +void Xdf::FindMinMaxTimeStamps() { //find the smallest timestamp of all streams - for (auto const &stream : streams) + for (auto const &stream : streams_) { if (!std::isnan(stream.info.first_timestamp)) { - minTS = stream.info.first_timestamp; + min_timestamp_ = stream.info.first_timestamp; break; } } - for (auto const &stream : streams) + for (auto const &stream : streams_) { - if (!std::isnan(stream.info.first_timestamp) && stream.info.first_timestamp < minTS) - minTS = stream.info.first_timestamp; + if (!std::isnan(stream.info.first_timestamp) && stream.info.first_timestamp < min_timestamp_) + min_timestamp_ = stream.info.first_timestamp; } //find the max timestamp of all streams - for (auto const &stream : streams) + for (auto const &stream : streams_) { - if (!std::isnan(stream.info.last_timestamp) && stream.info.last_timestamp > maxTS) - maxTS = stream.info.last_timestamp; + if (!std::isnan(stream.info.last_timestamp) && stream.info.last_timestamp > max_timestamp_) + max_timestamp_ = stream.info.last_timestamp; } } -void Xdf::findMajSR() +void Xdf::FindMajorSamplingRate() { // find out which sample rate has the most channels typedef int sampRate; @@ -770,7 +770,7 @@ void Xdf::findMajSR() std::vector > srateMap; // pairs of all the streams //find out whether a sample rate already exists in srateMap - for (auto const &stream : streams) + for (auto const &stream : streams_) { if (stream.info.nominal_srate != 0) { @@ -797,36 +797,36 @@ void Xdf::findMajSR() const std::pair &first) { return largest.second < first.second; }))); - majSR = srateMap[index].first; //the sample rate that has the most channels + major_sampling_rate_ = srateMap[index].first; //the sample rate that has the most channels } else { - majSR = 0; //if there are no streams with a fixed sample reate + major_sampling_rate_ = 0; //if there are no streams with a fixed sample reate } } -void Xdf::calcTotalChannel() +void Xdf::CalculateChannelCount() { //calculating total channel count, and indexing them onto streamMap - for (size_t c = 0; c < streams.size(); c++) + for (size_t c = 0; c < streams_.size(); c++) { - if(!streams[c].time_series.empty()) + if(!streams_[c].time_series.empty()) { - totalCh += streams[c].info.channel_count; + channel_count_ += streams_[c].info.channel_count; - for (int i = 0; i < streams[c].info.channel_count; i++) - streamMap.emplace_back(c); + for (int i = 0; i < streams_[c].info.channel_count; i++) + stream_map_.emplace_back(c); } } } -void Xdf::calcTotalLength(int sampleRate) +void Xdf::CalculateTotalLength(int sampleRate) { - totalLen = (maxTS - minTS) * sampleRate; + total_len_ = (max_timestamp_ - min_timestamp_) * sampleRate; } -void Xdf::freeUpTimeStamps() +void Xdf::FreeUpTimeStamps() { //free up as much memory as possible - for (auto &stream : streams) + for (auto &stream : streams_) { //we don't need to keep all the time stamps unless it's a stream with irregular samples //filter irregular streams and string streams @@ -840,74 +840,74 @@ void Xdf::freeUpTimeStamps() } } -void Xdf::adjustTotalLength() +void Xdf::AdjustTotalLength() { - for (auto const &stream : streams) + for (auto const &stream : streams_) { if(!stream.time_series.empty()) { - if (totalLen < stream.time_series.front().size()) - totalLen = stream.time_series.front().size(); + if (total_len_ < stream.time_series.front().size()) + total_len_ = stream.time_series.front().size(); } } } -void Xdf::getHighestSampleRate() +void Xdf::FindMaxSampleRate() { - for (auto const &stream : streams) + for (auto const &stream : streams_) { - if (stream.info.nominal_srate > maxSR) - maxSR = stream.info.nominal_srate; + if (stream.info.nominal_srate > max_sampling_rate_) + max_sampling_rate_ = stream.info.nominal_srate; } } -void Xdf::loadSampleRateMap() +void Xdf::LoadSamplingRateMap() { - for (auto const &stream : streams) - sampleRateMap.emplace(stream.info.nominal_srate); + for (auto const &stream : streams_) + sampling_rate_map_.emplace(stream.info.nominal_srate); } -void Xdf::detrend() +void Xdf::Detrend() { - for (auto &stream : streams) + for (auto &stream : streams_) { for (auto &row : stream.time_series) { long double init = 0.0; long double mean = std::accumulate(row.begin(), row.end(), init) / row.size(); for(auto &val: row) val -= mean; - offsets.emplace_back(mean); + offsets_.emplace_back(mean); } } } -void Xdf::calcEffectiveSrate() +void Xdf::CalculateEffectiveSamplingRate() { - for (auto &stream : streams) + for (auto &stream : streams_) { if (stream.info.nominal_srate) { try { - stream.info.effective_sample_rate + stream.info.effective_sampling_rate = stream.info.sample_count / (stream.info.last_timestamp - stream.info.first_timestamp); - if (stream.info.effective_sample_rate) - effectiveSampleRateVector.emplace_back(stream.info.effective_sample_rate); + if (stream.info.effective_sampling_rate) + effective_sampling_rates_.emplace_back(stream.info.effective_sampling_rate); pugi::xml_document doc; - doc.load_string(stream.streamFooter.c_str()); + doc.load_string(stream.stream_footer.c_str()); pugi::xml_node sampleCount = doc.child("info").child("sample_count"); pugi::xml_node effectiveSampleRate = doc.child("info").insert_child_after("effective_sample_rate", sampleCount); effectiveSampleRate.append_child(pugi::node_pcdata) - .set_value(std::to_string(stream.info.effective_sample_rate).c_str()); + .set_value(std::to_string(stream.info.effective_sampling_rate).c_str()); std::stringstream buffer; doc.save(buffer); - stream.streamFooter = buffer.str(); + stream.stream_footer = buffer.str(); } catch (std::exception &e) { @@ -918,9 +918,9 @@ void Xdf::calcEffectiveSrate() } } -int Xdf::writeEventsToXDF(std::string file_path) +int Xdf::WriteEventsToXdf(std::string file_path) { - if (userAddedStream) + if (user_added_stream_) { std::fstream file; file.open(file_path, std::ios::app | std::ios::binary); @@ -932,17 +932,17 @@ int Xdf::writeEventsToXDF(std::string file_path) //Num Length Bytes file.put(4); //length - int length = streams[userAddedStream].streamHeader.size() + 6; //+6 because of the length int itself and short int tag + int length = streams_[user_added_stream_].stream_header.size() + 6; //+6 because of the length int itself and short int tag file.write((char*)&length, 4); //tag short tag = 2; file.write((char*)&tag, 2); //streamNumber - int streamNumber = userAddedStream + 1; //+1 because the stream IDs in XDF are 1 based instead of 0 based + int streamNumber = user_added_stream_ + 1; //+1 because the stream IDs in XDF are 1 based instead of 0 based file.write((char*)&streamNumber, 4); //content - file.write(streams[userAddedStream].streamHeader.c_str(), length - 6);//length - 6 is the string length + file.write(streams_[user_added_stream_].stream_header.c_str(), length - 6);//length - 6 is the string length //write samples chunk //Num Length Bytes @@ -950,11 +950,11 @@ int Xdf::writeEventsToXDF(std::string file_path) //length //add the bytes of all following actions together int64_t stringTotalLength = 0; - for (auto const &event : userCreatedEvents) + for (auto const &event : user_created_events_) stringTotalLength += event.first.size(); int64_t sampleChunkLength = 2 + 4 + 1 + 4 + - userCreatedEvents.size() * + user_created_events_.size() * (1 + 8 + 1 + 4) + stringTotalLength; file.write((char*)&sampleChunkLength, 8); @@ -969,11 +969,11 @@ int Xdf::writeEventsToXDF(std::string file_path) file.put(4); //Num Samples - int numSamples = userCreatedEvents.size(); + int numSamples = user_created_events_.size(); file.write((char*)&numSamples, 4); //samples - for (auto const &event : userCreatedEvents) + for (auto const &event : user_created_events_) { //TimeStampBytes file.put(8); @@ -1007,60 +1007,60 @@ int Xdf::writeEventsToXDF(std::string file_path) return 0; //Success } -void Xdf::createLabels() +void Xdf::CreateLabels() { size_t channelCount = 0; - for (size_t st = 0; st < streams.size(); st++) + for (size_t st = 0; st < streams_.size(); st++) { - if (streams[st].info.channels.size()) + if (streams_[st].info.channels.size()) { - for (size_t ch = 0; ch < streams[st].info.channels.size(); ch++) + for (size_t ch = 0; ch < streams_[st].info.channels.size(); ch++) { // +1 for 1 based numbers; for user convenience only. The internal computation is still 0 based std::string label = "Stream " + std::to_string(st + 1) + " - Channel " + std::to_string(ch + 1) - + " - " + std::to_string((int)streams[st].info.nominal_srate) + " Hz\n"; + + " - " + std::to_string((int)streams_[st].info.nominal_srate) + " Hz\n"; - label += streams[st].info.name + '\n'; + label += streams_[st].info.name + '\n'; - for (auto const &entry : streams[st].info.channels[ch]) + for (auto const &entry : streams_[st].info.channels[ch]) { if (entry.second != "") label += entry.first + " : " + entry.second + '\n'; } - if (offsets.size()) + if (offsets_.size()) { - if (offsets[channelCount] >= 0) - label.append("baseline +").append(std::to_string(offsets[channelCount])); + if (offsets_[channelCount] >= 0) + label.append("baseline +").append(std::to_string(offsets_[channelCount])); else - label.append("baseline ").append(std::to_string(offsets[channelCount])); + label.append("baseline ").append(std::to_string(offsets_[channelCount])); } - labels.emplace_back(label); + labels_.emplace_back(label); channelCount++; } } else { - for (size_t ch = 0; ch < streams[st].time_series.size(); ch++) + for (size_t ch = 0; ch < streams_[st].time_series.size(); ch++) { // +1 for 1 based numbers; for user convenience only. The internal computation is still 0 based std::string label = "Stream " + std::to_string(st + 1) + " - Channel " + std::to_string(ch + 1) + " - " + - std::to_string((int)streams[st].info.nominal_srate) + - " Hz\n" + streams[st].info.name + '\n' + streams[st].info.type + '\n'; + std::to_string((int)streams_[st].info.nominal_srate) + + " Hz\n" + streams_[st].info.name + '\n' + streams_[st].info.type + '\n'; - label += streams[st].info.name + '\n'; + label += streams_[st].info.name + '\n'; - if (offsets.size()) + if (offsets_.size()) { - if (offsets[channelCount] >= 0) - label.append("baseline +").append(std::to_string(offsets[channelCount])); + if (offsets_[channelCount] >= 0) + label.append("baseline +").append(std::to_string(offsets_[channelCount])); else - label.append("baseline ").append(std::to_string(offsets[channelCount])); + label.append("baseline ").append(std::to_string(offsets_[channelCount])); } - labels.emplace_back(label); + labels_.emplace_back(label); channelCount++; } @@ -1068,26 +1068,26 @@ void Xdf::createLabels() } } -void Xdf::loadDictionary() +void Xdf::LoadDictionary() { //loop through the eventMap - for (auto const &entry : eventMap) + for (auto const &entry : event_map_) { //search the dictionary to see whether an event is already in it - auto it = std::find(dictionary.begin(),dictionary.end(),entry.first.first); + auto it = std::find(dictionary_.begin(),dictionary_.end(),entry.first.first); //if it isn't yet - if (it == dictionary.end()) + if (it == dictionary_.end()) { //add it to the dictionary, also store its index into eventType vector for future use - eventType.emplace_back(dictionary.size()); - dictionary.emplace_back(entry.first.first); + event_type_.emplace_back(dictionary_.size()); + dictionary_.emplace_back(entry.first.first); } //if it's already in there else //store its index into eventType vector - eventType.emplace_back(std::distance(dictionary.begin(), it)); + event_type_.emplace_back(std::distance(dictionary_.begin(), it)); } } -template T Xdf::readBin(std::istream& is, T* obj) { +template T Xdf::ReadBin(std::istream& is, T* obj) { T dummy; if(!obj) obj = &dummy; is.read(reinterpret_cast(obj), sizeof(T)); diff --git a/xdf.h b/xdf.h index 86892f3..5890c03 100644 --- a/xdf.h +++ b/xdf.h @@ -29,9 +29,9 @@ /*! \class Xdf * - * Xdf class is designed to store the data of an entire XDF file. - * It comes with methods to read XDF files and containers to store - * the data, as well as some additional methods e.g. resampling etc. + * Xdf class stores the data of an entire XDF file. It contains methods to + * read XDF files and containers to store the data, as well as additional + * methods such as resampling etc. */ class Xdf @@ -40,277 +40,248 @@ class Xdf //! Default constructor with no parameter. Xdf(); - //subclass for single streams /*! \class Stream * * XDF files uses stream as the unit to store data. An XDF file usually - * contains multiple streams, while each of them may contain one or more - * channels. - * The Stream class provides a handy way to store all the meta-data, - * time-series, time-stamps and all other information of a single stream - * from an XDF file. + * contains multiple streams, each of which may contain one or more + * channels. The Stream struct provides a way to store meta-data, time-series, + * time-stamps and all other information of a single stream from an XDF file. */ struct Stream { - //! A 2D vector which stores the time series of a stream. Each row represents a channel. - std::vector > time_series; - std::vector time_stamps; /*!< A vector to store time stamps. */ - std::string streamHeader; /*!< Raw XML of stream header chunk. */ - std::string streamFooter; /*!< Raw XML of stream footer chunk. */ + std::vector> time_series; /*!< 2D vector that stores the time series of a stream. Each row represents a channel.*/ + std::vector time_stamps; /*!< Stores the time stamps. */ + std::string stream_header; /*!< Raw XML of stream header chunk. */ + std::string stream_footer; /*!< Raw XML of stream footer chunk. */ struct { - int channel_count; /*!< Number of channels of the current stream */ - double nominal_srate; /*!< The nominal sample rate of the current stream. */ - std::string name; /*!< Name of the current stream. */ - std::string type; /*!< Type of the current stream. */ - std::string channel_format;/*!< Channel format of the current stream. */ - - std::vector > channels;/*!< A vector to store the meta-data of the channels of the current stream. */ - - std::vector > clock_offsets; /*!< A vector to store clock offsets from the ClockOffset chunk. */ - - double first_timestamp; /*!< First time stamp of the stream. */ - double last_timestamp; /*!< Last time stamp of the stream. */ - int sample_count; /*!< Sample count of the stream. */ - double measured_srate; /*!< Measured sample rate of the stream. */ - double effective_sample_rate = 0;/*!< Effective sample rate. */ - } info; /*!< Meta-data from the stream header of the current stream. */ - - double last_timestamp{ 0 }; /*!< For temporary use while loading the vector */ - double sampling_interval; /*!< If srate > 0, sampling_interval = 1/srate; otherwise 0 */ - std::vector clock_times;/*!< Vector of clock times from clock offset chunk (Tag 4). */ - std::vector clock_values;/*!< Vector of clock values from clock offset chunk (Tag 4). */ + int channel_count; /*!< Number of channels in the current stream */ + double nominal_srate; /*!< The nominal sampling rate of the current stream. */ + std::string name; /*!< The name of the current stream. */ + std::string type; /*!< The type of the current stream. */ + std::string channel_format; /*!< The channel format of the current stream. */ + + std::vector > channels; /*!< Stores the meta-data of the channels of the current stream. */ + + std::vector > clock_offsets; /*!< Stores the clock offsets from the ClockOffset chunk. */ + + double first_timestamp; /*!< First time stamp of the stream. */ + double last_timestamp; /*!< Last time stamp of the stream. */ + int sample_count; /*!< Sample count of the stream. */ + double measured_sampling_rate; /*!< Measured sampling rate of the stream. */ + double effective_sampling_rate = 0; /*!< Effective sampling rate. */ + } info; /*!< Meta-data from the stream header of the current stream. */ + + double last_timestamp{0}; /*!< For temporary use while loading the vector */ + double sampling_interval; /*!< sampling_interval = 1/sampling_rate if sampling_rate > 0, otherwise 0 */ + std::vector clock_times; /*!< Stores the clock times from clock offset chunks. */ + std::vector clock_values; /*!< Stores the clock values from clock offset chunks. */ }; - //XDF properties================================================================================= + std::vector streams_; /*!< Stores all streams of the current XDF file. */ + float version_; /*!< The version of the XDF file. */ - std::vector streams; /*!< A vector to store all the streams of the current XDF file. */ - float version; /*!< The version of XDF file */ + uint64_t total_len_ = 0; /*!< The total length is the product of the range between the smallest time stamp and the largest multiplied by major_sampling_rate_. */ - uint64_t totalLen = 0; /*!< The total length is the product of the range between the smallest - *time stamp and the largest multiplied by the major sample rate. */ - - double minTS = 0; /*!< The smallest time stamp across all streams. */ - double maxTS = 0; /*!< The largest time stamp across all streams. */ - size_t totalCh = 0; /*!< The total number of channel count. */ - int majSR = 0; /*!< The sample rate that has the most channels across all streams. */ - int maxSR = 0; /*!< Highest sample rate across all streams. */ - std::vector effectiveSampleRateVector; /*!< Effective Sample Rate of each stream. */ - double fileEffectiveSampleRate = 0; /*!< If effective sample rates in all the streams are the same, this is the value. */ - std::vector streamMap;/*!< A vector indexes which channels belong to which stream. - * The index is the same as channel number; the actual content is the stream Number */ + double min_timestamp_ = 0; /*!< The min time stamp across all streams. */ + double max_timestamp_ = 0; /*!< The max time stamp across all streams. */ + size_t channel_count_ = 0; /*!< The total number of channels. */ + int major_sampling_rate_ = 0; /*!< The sampling rate that was used by the most channels across all streams. */ + int max_sampling_rate_ = 0; /*!< Max sampling rate across all streams. */ + std::vector effective_sampling_rates_; /*!< Effective sampling rates of streams. */ + double file_effective_sampling_rate_ = 0; /*!< If effective_sampling_rates_ in all the streams are the same, this is the value. */ + std::vector stream_map_; /*!< Indexes which channels belong to which stream. The index is the same as channel number; the actual content is the stream number. */ /*! - * \brief Used as `std::vector, int> >` - * in eventMap. + * \brief An alias of std::string type used on event names. * \sa eventMap */ - typedef std::string eventName; + typedef std::string event_name_; /*! - * \brief Used as `std::vector, int> >` - * in eventMap. + * \brief An alias of double type used on event timestamps. * \sa eventMap */ - typedef double eventTimeStamp; - - std::vector, int> > eventMap;/*!< The vector to store all the events across all streams. - * The format is <, streamNum>. */ - std::vector dictionary;/*!< The vector to store unique event types with no repetitions. \sa eventMap */ - std::vector eventType; /*!< The vector to store events by their index in the dictionary.\sa dictionary, eventMap */ - std::vector labels; /*!< The vector to store descriptive labels of each channel. */ - std::set sampleRateMap; /*!< The vector to store all sample rates across all the streams. */ - std::vector offsets; /*!< Offsets of each channel after using subtractMean() function */ + typedef double event_timestamp_; - std::string fileHeader; /*!< Raw XML of the file header. */ - int userAddedStream { 0 }; /*!< For Sigviewer only: if user manually added events in Sigviewer, - * the events will be stored in a new stream after all current streams. - * The index will be userAddedStream. */ - std::vector > userCreatedEvents;/*!< User created events in Sigviewer. */ + std::vector, int>> event_map_; /*!< Stores all events across all streams. */ + std::vector dictionary_; /*!< Stores unique event types with no repetitions. \sa eventMap */ + std::vector event_type_; /*!< Stores events by their indices in the dictionary.\sa dictionary, eventMap */ + std::vector labels_; /*!< Stores descriptive labels of each channel. */ + std::set sampling_rate_map_; /*!< Stores sampling rates of all the streams. */ + std::vector offsets_; /*!< Offsets of each channel after using SubtractMean() method. */ - //Public Functions============================================================================================== + std::string file_header_; /*!< Raw XML of the file header. */ + int user_added_stream_{0}; /*!< Used by SigViewer only: if user manually added events in SigViewer, the events will be stored in a new stream after all current streams with index user_added_stream_. */ + std::vector > user_created_events_; /*!< Events created by user in SigViewer. */ /*! - * \brief Adjust `totalLen` to avoid possible deviation + * \brief Adjusts `total_len_` to avoid possible deviation. * - * `totalLen` is calculated by multiplying the difference between max time - * stamp and minimal time stamp by the `majSR` (major sample rate). + * `total_len_` is calculated by multiplying the difference between + * `max_timestamp_` and `min_timestamp_` by `major_sampling_rate_`. * However, this can be inaccurate. In case any channel is longer than - * `totalLen`, this function will make `totalLen` match the length of - * that channel. + * `total_len_`, this function will make `total_len_` match the length + * of that channel. * - * \sa totalLen, majSR, calcTotalLength() + * \sa total_len_, major_sampling_rate_, CalculateTotalLength() */ - void adjustTotalLength(); + void AdjustTotalLength(); /*! - * \brief Calculate the globle length (in samples). + * \brief Calculates the globle length (in samples). * - * This is calculated by multiplying the rage from the earliest - * time stamp to the last time stamp across all channels by the - * parameter sampleRate. + * This is calculated by multiplying the rage from `min_timestamp_` + * to `max_timestamp_` across all channels by `sampling_rate`. * - * \param sampleRate is the sample rate you wish to use to calculate the - * total length. + * \param sampling_rate The sampling rate used to calculate the total + * length. */ - void calcTotalLength(int sampleRate); + void CalculateTotalLength(int sampling_rate); /*! - * \brief Create labels for each channel and store them in _labels_ vector. - * \sa labels, offsets + * \brief Creates labels for each channel and stores them in `labels_`. + * \sa labels_, offsets_ */ - void createLabels(); + void CreateLabels(); /*! - * \brief Subtract the entire channel by its mean. + * \brief Subtracts all data in a channel by the mean. * - * Sigviewer displays both the channel signals as well as the zero baseline. - * Thus when the mean of a channel is too high or too low it would be very - * hard to see the fluctuation. Subtract the entire channel by its mean - * will make the signal fluctuate around the zero baseline, and has better - * visual effect. The mean of each channel times `-1` will be stored in - * member vector `offsets` + * SigViewer displays both the channel signals as well as the zero baseline. + * When the mean of a channel is too high or too low it becomes difficult to + * see the fluctuation. Subtracting the entire channel by its mean makes the + * signals fluctuate around the zero baseline, thus having better visual + * effect. The mean of each channel times `-1` is stored in `offsets_`. * - * \sa offsets + * \sa offsets_ */ - void detrend(); + void Detrend(); /*! - * \brief Delete the time stamps vectors when no longer needed to - * release some memory. + * \brief Deletes `Stream::time_stamps` when no longer needed (to release + * memory). * - * Sigviewer doesn't demand time stamps to display signals except - * irregular sample rate channels, events, and the first time stamp - * of each channel (used to decide where does a channel start when - * putting all streams together). In this case we can delete the time - * stamps when no longer needed to free up some memory. + * SigViewer doesn't demand time stamps to display signals except irregular + * sampling rate channels, events, and the min timestamp of each channel + * (used to determine where does a channel start when putting all streams + * together). Hence `Stream::time_stamps` can be deleted when no longer + * needed to free up the memory. */ - void freeUpTimeStamps(); + void FreeUpTimeStamps(); /*! - * \brief The main function of loading an XDF file. - * \param filename is the path to the file being loaded including the - * file name. + * \brief Loads an XDF file. + * \param filename The complete path to the target file. */ - int load_xdf(std::string filename); + int LoadXdf(std::string filename); /*! - * \brief Resample all streams and channel to a chosen sample rate - * \param userSrate is recommended to be between integer 1 and - * the highest sample rate of the current file. + * \brief Resamples all streams and channels to `sampling_rate`. + * \param `sampling_rate` in general should be between 1 and the highest + * sampling rate of the current file. */ - void resample(int userSrate); + void Resample(int sampling_rate); /*! - * \brief syncTimeStamps + * \brief Sync the timestamps. */ - void syncTimeStamps(); + void SyncTimeStamps(); /*! - * \brief writeEventsToXDF - * - * If user added some markups and events in Sigviewer, this function can - * store those user created events back to the XDF file in a new stream + * \brief Writes events to the XDF file. Used when user added markups + * and/or events in SigViewer, this method stores the newly created events + * to the XDF file in a new stream. */ - int writeEventsToXDF(std::string file_path); - - //Private Functions: Not intended to be used by external programs====================================== + int WriteEventsToXdf(std::string file_path); private: /*! - * \brief calcEffectiveSrate + * \brief Calculates the effective sampling rate. */ - void calcEffectiveSrate(); + void CalculateEffectiveSamplingRate(); /*! - * \brief Calculate the total channel count and store the result - * in `totalCh`. - * - * Channels of both regular and irregular sample rates are included. - * The streams with the channel format `string` are excluded, and are - * stored in `eventMap` instead. + * \brief Calculates the channel count and stores the result in + * `channel_count_`. Channels of both regular and irregular sampling rates + * are included. Streams with channel format `string` are excluded, and are + * stored in `event_map_` instead. * - * \sa totalCh, eventMap + * \sa channel_count_, event_map_ */ - void calcTotalChannel(); + void CalculateChannelCount(); /*! - * \brief Find the sample rate that has the most channels. + * \brief Finds the sampling rate that is used by the most channels. * * XDF format supports different sample rates across streams, but - * Sigviewer needs to display all channels in a unified sample rate. - * Thus if there are more than one sample rate in the file, some channels - * need to be resampled in order to be displayed. - * - * Libxdf uses third party _smarc_ library to do the resampling task. - * While _smarc_ library is powerful in the sense that it can resample - * signals to almost any sample rate, it's fairly slow, and for performance - * reason it's better to minimize the resampling process. + * SigViewer needs to display all channels in a unified sampling rate. + * If a file contains more than one sampling rate, some channels need + * to be resampled to be displayed. This method finds the sampling + * rate that was used by the most channels thus minimizing the number + * of channels to be resampled. * - * findMajSR() will find which sample rate currently has the most channels - * in the file. If only those channels with a different sample rate are to - * be resampled, the resampling process will be finished in the shortest - * possible period. - * - * \sa majSR, resample(int userSrate) + * \sa major_sampling_rate_, Resample(int sampling_rate) */ - void findMajSR(); + void FindMajorSamplingRate(); /*! - * \brief Find the minimal and maximal time stamps across all streams. + * \brief Finds the max sampling rate of all streams and store it in `max_sampling_rate_`. * - * The results will be stored in member variables `minTS` and `maxTS` respectively. - * \sa minTS, maxTS, calcTotalLength(int sampleRate); + * \sa max_sampling_rate_ */ - void findMinMax(); + void FindMaxSampleRate(); /*! - * \brief Get the highest sample rate of all streams and store - * it in `maxSR`. - * - * \sa maxSR + * \brief Finds the min and max timestamps across all streams. The + * results are stored in `min_timestamp_` and `max_timestamp_`. + * \sa min_timestamp_, max_timestamp_, CalculateTotalLength(int sampling_rate); */ - void getHighestSampleRate(); + void FindMinMaxTimeStamps(); /*! - * \brief Copy all unique types of events from _eventMap_ to - * _dictionary_ with no repeats. - * \sa dictionary, eventMap + * \brief Copies all unique types of events from `event_map_` to + * `dictionary_` excluding duplicates. + * \sa event_map_, dictionary_ */ - void loadDictionary(); + void LoadDictionary(); /*! - * \brief Load every sample rate appeared in the current file into - * member variable `sampleRateMap`. - * \sa sampleRateMap + * \brief Loads every sampling rate that appeared in the current file + * into `sampling_rate_map_`. + * \sa sampling_rate_map_ */ - void loadSampleRateMap(); + void LoadSamplingRateMap(); /*! - * \brief This function will get the length of the upcoming chunk, or the number of samples. + * \brief Gets the length of the upcoming chunk, or the number of samples. + * + * While loading XDF file there are two cases where this method are needed. + * One is to get the length of each chunk, the other is to get the number + * of samples when loading the time series (Chunk tag 3). * - * While loading XDF file there are 2 cases where this function will be - * needed. One is to get the length of each chunk, one is to get the - * number of samples when loading the time series (Chunk tag 3). - * \param file is the XDF file that is being loaded in the type of `std::ifstream`. + * \param file The XDF file that is being loaded in the type of `std::ifstream`. * \return The length of the upcoming chunk (in bytes). */ - uint64_t readLength(std::ifstream &file); + uint64_t ReadLength(std::ifstream &file); - /*! - * \brief Read a binary scalar variable from an input stream. + /*! + * \brief Reads a binary scalar variable from an input stream. + * + * This method is a convenience wrapper for the common + * `file.read((char*) var, sizeof(var))` operation. Examples: + * + * ``` + * double foo = readBin(file); // use return value + * ReadBin(file, &foo); // read directly into foo + * ``` * - * readBin is a convenience wrapper for the common - * file.read((char*) var, sizeof(var)) - * operation. Examples: - * double foo = readBin(file); // use return value - * readBin(file, &foo); // read directly into foo - * \param is an input stream to read from - * \param obj pointer to a variable to load the data into or nullptr - * \return the read data + * \param is An input stream to read from. + * \param obj Pointer to a variable to load the data into or nullptr. + * \return The read data. */ - template T readBin(std::istream& is, T* obj = nullptr); + template T ReadBin(std::istream& is, T* obj = nullptr); }; #endif // XDF_H