status_t BPhotoContactField::Flatten(void* buffer, ssize_t size) const { if (size < FlattenedSize()) return B_ERROR; BMemoryIO flatData(buffer, size); status_t ret = BContactField::Flatten(&flatData); if (ret != B_OK) return ret; ssize_t destSize; if (fBitmap != NULL) { BMessage msg; BMallocIO dest; fBitmap->Archive(&msg); destSize = msg.FlattenedSize(); msg.Flatten(&dest); flatData.Write(&destSize, sizeof(destSize)); flatData.Write(dest.Buffer(), destSize); } else { size = 0; flatData.Write(&size, sizeof(destSize)); } return B_OK; }
status_t BContactField::Flatten(void* buffer, ssize_t size) const { if (buffer == NULL) return B_BAD_VALUE; BMemoryIO flatData(buffer, size); return Flatten(&flatData, size); }
status_t BContactField::Unflatten(type_code code, const void* buffer, ssize_t size) { if (buffer == NULL) return B_BAD_VALUE; BMemoryIO flatData(buffer, size); return Unflatten(code, &flatData); }
status_t BStringContactField::Flatten(void* buffer, ssize_t size) const { if (size < FlattenedSize()) return B_ERROR; BMemoryIO flatData(buffer, size); status_t ret = BContactField::Flatten(&flatData); if (ret != B_OK) return ret; _AddStringToBuffer(&flatData, fValue); return B_OK; }
status_t BAddressContactField::Flatten(void* buffer, ssize_t size) const { if (size < FlattenedSize()) return B_ERROR; BMemoryIO flatData(buffer, size); status_t ret = BContactField::Flatten(&flatData); if (ret != B_OK) return ret; _AddStringToBuffer(&flatData, Value()); flatData.Write(&fWellFormed, sizeof(fWellFormed)); return B_OK; }
OXSXDataSet DataSetIO::LoadDataSet(const std::string& filename_){ // Get Data Set H5::H5File file(filename_, H5F_ACC_RDONLY); H5::DataSet dataSet = file.openDataSet("observations"); // read meta information unsigned nObs = 0; H5::Attribute nameAtt = dataSet.openAttribute("observed_quantities"); H5::Attribute countAtt = dataSet.openAttribute("n_observables"); H5std_string strreadbuf(""); nameAtt.read(nameAtt.getDataType(), strreadbuf); countAtt.read(countAtt.getDataType(), &nObs); // Read data out as 1D array hsize_t nData = 0; dataSet.getSpace().getSimpleExtentDims(&nData, NULL); size_t nEntries = nData/nObs; std::vector<double> flatData(nData, 0); dataSet.read(&flatData.at(0), H5::PredType::NATIVE_DOUBLE); assert(nData%nObs == 0); // logic error in writing file (this class!) if assert fails. // Assemble into an OXSX data set OXSXDataSet oxsxDataSet; // Set the variable names oxsxDataSet.SetObservableNames(UnpackString(strreadbuf, fDelimiter)); // then the data std::vector<double> oneEventObs(nObs, 0); for(size_t i = 0; i < nEntries; i++){ for(size_t j = 0; j < nObs; j++) oneEventObs[j] = flatData.at(i * nObs + j); oxsxDataSet.AddEntry(EventData(oneEventObs)); } return oxsxDataSet; }