//-***************************************************************************** void HDF5HierarchyWriter::writeHierarchy(hid_t iFile ) { std::vector<hobj_ref_t> objectRefs; std::vector<uint32_t> childrenSizes; std::vector<std::string> childrenNames; std::vector<hobj_ref_t> childrenRefs; std::vector<uint32_t> attrSizes; std::vector<std::string> attrNames; std::vector<char> hasMask; std::vector<uint32_t> maskBits; std::vector<char> hasMeta; std::vector<std::string> metaStrs; m_H5H.makeCompactObjectHierarchy( objectRefs, childrenSizes, childrenNames, childrenRefs, attrSizes, attrNames, hasMask, maskBits, hasMeta, metaStrs ); WriteReferences( iFile, "object_references", objectRefs.size(), &objectRefs.front() ); // Children H5LTset_attribute_uint( iFile, ".", "children_sizes", &childrenSizes.front(), childrenSizes.size() ); WriteStrings( iFile, "children_names", childrenNames.size(), &childrenNames.front() ); WriteReferences( iFile, "children_references", childrenRefs.size(), &childrenRefs.front() ); // Attributes H5LTset_attribute_uint( iFile , ".", "attr_sizes", &attrSizes.front(), attrSizes.size() ); WriteStrings( iFile, "attr_names", attrNames.size(), &attrNames.front() ); // Masks H5LTset_attribute_char( iFile, ".", "mask_on", &hasMask.front(), hasMask.size() ); H5LTset_attribute_uint( iFile, ".", "mask_bits", &maskBits.front(), maskBits.size() ); // Metadata H5LTset_attribute_char( iFile, ".", "meta_on", &hasMeta.front(), hasMeta.size() ); WriteStrings( iFile, "meta_strs", metaStrs.size(), &metaStrs.front() ); }
//-***************************************************************************** void SpwImpl::copyPreviousSample( hid_t iGroup, const std::string &iSampleName, index_t iSampleIndex ) { assert( iGroup >= 0 ); assert( m_previousSample.getData() ); // Write the sample. const AbcA::DataType &dtype = m_header->getDataType(); if ( dtype.getPod() == kStringPOD ) { const std::string *strings = reinterpret_cast<const std::string *>( m_previousSample.getData() ); if ( dtype.getExtent() == 1 ) { WriteString( iGroup, iSampleName, *strings ); } else { WriteStrings( iGroup, iSampleName, dtype.getExtent(), strings ); } } else if ( dtype.getPod() == kWstringPOD ) { const std::wstring *wstrings = reinterpret_cast<const std::wstring *>( m_previousSample.getData() ); if ( dtype.getExtent() == 1 ) { WriteWstring( iGroup, iSampleName, *wstrings ); } else { WriteWstrings( iGroup, iSampleName, dtype.getExtent(), wstrings ); } } else { assert( m_fileDataType >= 0 ); assert( m_nativeDataType >= 0 ); WriteScalar( iGroup, iSampleName, m_fileDataType, m_nativeDataType, m_previousSample.getData() ); } }
bool WriteStringsToFile(const string& path, const string& header, StringTable& strings, bool escape) { ofstream* f = UIOpenWrite(path.c_str()); bool success = false; if (f->is_open()) { success = WriteStrings(*f, header, strings, escape); f->close(); } delete f; return success; }
//=============================================================================================== // FUNCTION: Write // PURPOSE: Writes the complete protocol to the data file. // BOOL CProtocolWriterABF2::Write( const ABF_FileInfo *pOldFileInfo, ABFFileHeader *pFH ) { MEMBERASSERT(); RPTRASSERT( pFH ); m_pFH = pFH; BOOL bOK = TRUE; // Clear the existing file contents if no data has been written. if( m_pFI->GetAcquiredSamples() == 0 ) bOK &= m_pFI->SetEndOfFile(); if( pOldFileInfo ) m_FileInfo.StringsSection = pOldFileInfo->StringsSection; // Clear the strings since we are about to re-write them. m_Strings.Clear(); // Write out the various bits. bOK &= WriteFileInfo(); bOK &= WriteProtocolInfo(); bOK &= WriteADCInfo(); bOK &= WriteDACInfo(); bOK &= WriteEpochs(); bOK &= WriteStats(); bOK &= WriteUserList(); bOK &= WriteMathInfo(); // Write out the protocol strings. bOK &= WriteStrings(); // Now re-write the FileInfo to update the the section info. bOK &= m_pFI->Seek( 0L, FILE_BEGIN); bOK &= m_pFI->Write( &m_FileInfo, sizeof( m_FileInfo ) ); bOK &= m_pFI->Seek( 0L, FILE_END); m_pFI->FillToNextBlock( &m_lNextBlock ); if( m_pFI->GetAcquiredSamples() == 0 ) { m_FileInfo.DataSection.uBlockIndex = m_lNextBlock; m_pFH->lDataSectionPtr = m_lNextBlock; } return bOK; }
void TestCustomReadWrite(void) { Strings strings = NewStringsTable(3); String carl = InsertString(strings, "Carl"); String john = InsertString(strings, "John"); String peter = InsertString(strings, "Peter"); const char* c = GetString(strings, carl); const char* j = GetString(strings, john); const char* p = GetString(strings, peter); assert(strcmp(c, "Carl") == 0); assert(strcmp(j, "John") == 0); assert(strcmp(p, "Peter") == 0); // Save data. const char* file = "testfiles/test-strings.bin"; FILE *f = fopen(file, "w"); WriteStrings(strings, f); fclose(f); // Release memory. FreeStringsTable(&strings); f = fopen(file, "r"); strings = ReadStrings(f); fclose(f); assert(strings.table->len == 3); assert(strings.table->cap == 3); assert(strings.table->column_len == 1); c = GetString(strings, carl); j = GetString(strings, john); p = GetString(strings, peter); assert(strcmp(c, "Carl") == 0); assert(strcmp(j, "John") == 0); assert(strcmp(p, "Peter") == 0); FreeStringsTable(&strings); assert(strings.table == NULL); }
static void RunPatch() { int vers = 0; ULONG gIntVal = GetInt(0x00BE15D4); if (gIntVal == 0xa77f40) vers = 23; else if (GetInt(0x00BE38BC) == 0xa76044) vers = 24; else Bailout("Sorry, your cityofheroes.exe file is not a supported version."); InitCoh(vers); WriteStrings(); WriteData(); RelocateCode(); FixupCode(vers); WriteCode(); if (vers == 23) PatchI23(); else if (vers == 24) PatchI24(); }