void DFA_Interface::save_to(FILE* fp) const { using namespace febird; FileStream file; file.attach(fp); file.disbuf(); try { NativeDataOutput<OutputBuffer> dio; dio.attach(&file); #define ON_CLASS_IO(Class) \ if (const Class* au = dynamic_cast<const Class*>(this)) { \ dio << fstring(BOOST_STRINGIZE(Class)); \ dio << *au; \ dio.flush(); \ file.detach(); \ return;\ } #include "dfa_class_io.hpp" } catch (...) { file.detach(); throw; } file.detach(); string_appender<> msg; msg << BOOST_CURRENT_FUNCTION << ": unknown Automata class: " << typeid(*this).name(); throw std::invalid_argument(msg); }
void MockWritableSegment::saveRecordStore(PathRef dir) const { fs::path fpath = dir / "rows"; FileStream fp(fpath.string().c_str(), "wb"); fp.disbuf(); NativeDataOutput<OutputBuffer> dio; dio.attach(&fp); dio << m_rows; }
void ZipIntKeyIndex::save(PathRef path) const { auto fpath = path + ".zint"; NativeDataOutput<FileStream> dio; dio.open(fpath.string().c_str(), "wb"); Header h; h.rows = m_index.size(); h.keyBits = m_keys.uintbits(); h.keyType = uint8_t(m_keyType); h.isUnique = m_isUnique; h.padding = 0; h.minKey = m_minKey; dio.ensureWrite(&h, sizeof(h)); dio.ensureWrite(m_keys .data(), m_keys .mem_size()); dio.ensureWrite(m_index.data(), m_index.mem_size()); }
void MockReadonlyIndex::save(PathRef fpath) const { FileStream fp(fpath.string().c_str(), "wb"); fp.disbuf(); NativeDataOutput<OutputBuffer> dio; dio.attach(&fp); size_t rows = m_ids.size(); dio << uint64_t(m_fixedLen); dio << uint64_t(rows); dio << uint64_t(m_keys.strpool.size()); dio.ensureWrite(m_ids.data(), m_ids.used_mem_size()); if (m_fixedLen) { assert(m_keys.size() == 0); assert(m_keys.strpool.size() == m_fixedLen * rows); } else { assert(m_keys.size() == rows); dio.ensureWrite(m_keys.offsets.data(), m_keys.offsets.used_mem_size()); } dio.ensureWrite(m_keys.strpool.data(), m_keys.strpool.used_mem_size()); }
void MockReadonlyStore::save(PathRef path) const { std::string fpath = path.string() + ".mock"; FileStream fp(fpath.c_str(), "wb"); fp.disbuf(); NativeDataOutput<OutputBuffer> dio; dio.attach(&fp); size_t rows = m_fixedLen ? m_rows.strpool.size() / m_fixedLen : m_rows.size(); dio << uint64_t(m_fixedLen); dio << uint64_t(rows); dio << uint64_t(m_rows.strpool.size()); if (0 == m_fixedLen) { #if !defined(NDEBUG) assert(m_rows.strpool.size() == m_rows.offsets.back()); for (size_t i = 0; i < rows; ++i) { assert(m_rows.offsets[i] < m_rows.offsets[i+1]); } #endif dio.ensureWrite(m_rows.offsets.data(), m_rows.offsets.used_mem_size()); } else { assert(m_rows.strpool.size() % m_fixedLen == 0); } dio.ensureWrite(m_rows.strpool.data(), m_rows.strpool.used_mem_size()); }
void MockWritableIndex<Key>::save(PathRef fpath) const { FileStream fp(fpath.string().c_str(), "wb"); fp.disbuf(); NativeDataOutput<OutputBuffer> dio; dio.attach(&fp); dio << m_kv; }