SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
sdds::Writer::Impl Struct Reference

Public Member Functions

void writeCurrent (bool keepOpen)
 

Public Attributes

std::filesystem::path path
 
WriterOptions options
 
std::shared_ptr< Layout > layout
 
std::unique_ptr< BufferedStream > stream
 
std::optional< Page > current
 
std::int64_t pageNumber = 0
 
std::int64_t expectedRows = 0
 
std::int64_t updateInterval = 0
 
std::optional< std::uint64_t > pageStart
 
std::optional< std::uint64_t > disconnectedOffset
 
std::unique_ptr< PathLock > lock
 
FileIdentity identity
 
bool snapshotWritten = false
 
bool rewriteLastPage = false
 
bool pathBacked = false
 
bool disconnected = false
 
bool closed = false
 

Detailed Description

Definition at line 3416 of file SDDSModern.cc.

Member Function Documentation

◆ writeCurrent()

void sdds::Writer::Impl::writeCurrent ( bool keepOpen)
inline

Definition at line 3435 of file SDDSModern.cc.

3435 {
3436 if (!current)
3437 throwState("no page has been started");
3438 if (disconnected)
3439 throwState("writer is disconnected");
3440 validatePage(*current, *layout);
3441 if (rewriteLastPage) {
3442 const std::filesystem::path temporary(path.string() + ".sddspp.tmp");
3443 if (std::filesystem::exists(temporary))
3444 throwState("temporary rewrite file already exists: " + temporary.string());
3445 try {
3446 Layout outputLayout = *layout;
3447 BufferedStream output(openOutput(temporary,
3448 compressionFor(path, options.compression), "wb",
3449 options.bufferBytes, options.gzipLevel,
3450 options.lzmaPreset, options.lzmaCheck));
3451 writeLayout(output, outputLayout, options);
3452 std::int64_t number = 0;
3453 Reader source = Reader::open(path);
3454 while (number < pageNumber) {
3455 auto page = source.next();
3456 if (!page)
3457 throwState("source file lost a page during atomic last-page update");
3458 writePageData(output, *page, outputLayout, options, ++number);
3459 }
3460 source.close();
3461 writePageData(output, *current, outputLayout, options, ++number);
3462 output.close();
3463#if defined(_WIN32)
3464 lock.reset();
3465#endif
3466 replaceFile(temporary, path);
3467 identity = fileIdentity(path);
3468 if (options.lockMode != LockMode::None)
3469 lock = acquirePathLock(path, options.lockMode, false);
3470 } catch (...) {
3471 std::error_code ignored;
3472 std::filesystem::remove(temporary, ignored);
3473 throw;
3474 }
3475 snapshotWritten = true;
3476 } else {
3477 if (!stream)
3478 throwState("writer has no output stream");
3479 if (snapshotWritten) {
3480 if (!pageStart || !stream->seekable())
3481 throwState("page update requires a seekable, uncompressed output");
3482 stream->seek(*pageStart);
3483 } else {
3484 pageStart = stream->seekable() ? std::optional<std::uint64_t>(stream->tell())
3485 : std::nullopt;
3486 }
3487 writePageData(*stream, *current, *layout, options, pageNumber + 1);
3488 if (snapshotWritten)
3489 stream->truncate(stream->tell());
3490 snapshotWritten = true;
3491 stream->flush();
3492 }
3493 if (!keepOpen) {
3494 ++pageNumber;
3495 current.reset();
3496 pageStart.reset();
3497 snapshotWritten = false;
3498 }
3499 }

Member Data Documentation

◆ closed

bool sdds::Writer::Impl::closed = false

Definition at line 3433 of file SDDSModern.cc.

◆ current

std::optional<Page> sdds::Writer::Impl::current

Definition at line 3421 of file SDDSModern.cc.

◆ disconnected

bool sdds::Writer::Impl::disconnected = false

Definition at line 3432 of file SDDSModern.cc.

◆ disconnectedOffset

std::optional<std::uint64_t> sdds::Writer::Impl::disconnectedOffset

Definition at line 3426 of file SDDSModern.cc.

◆ expectedRows

std::int64_t sdds::Writer::Impl::expectedRows = 0

Definition at line 3423 of file SDDSModern.cc.

◆ identity

FileIdentity sdds::Writer::Impl::identity

Definition at line 3428 of file SDDSModern.cc.

◆ layout

std::shared_ptr<Layout> sdds::Writer::Impl::layout

Definition at line 3419 of file SDDSModern.cc.

◆ lock

std::unique_ptr<PathLock> sdds::Writer::Impl::lock

Definition at line 3427 of file SDDSModern.cc.

◆ options

WriterOptions sdds::Writer::Impl::options

Definition at line 3418 of file SDDSModern.cc.

◆ pageNumber

std::int64_t sdds::Writer::Impl::pageNumber = 0

Definition at line 3422 of file SDDSModern.cc.

◆ pageStart

std::optional<std::uint64_t> sdds::Writer::Impl::pageStart

Definition at line 3425 of file SDDSModern.cc.

◆ path

std::filesystem::path sdds::Writer::Impl::path

Definition at line 3417 of file SDDSModern.cc.

◆ pathBacked

bool sdds::Writer::Impl::pathBacked = false

Definition at line 3431 of file SDDSModern.cc.

◆ rewriteLastPage

bool sdds::Writer::Impl::rewriteLastPage = false

Definition at line 3430 of file SDDSModern.cc.

◆ snapshotWritten

bool sdds::Writer::Impl::snapshotWritten = false

Definition at line 3429 of file SDDSModern.cc.

◆ stream

std::unique_ptr<BufferedStream> sdds::Writer::Impl::stream

Definition at line 3420 of file SDDSModern.cc.

◆ updateInterval

std::int64_t sdds::Writer::Impl::updateInterval = 0

Definition at line 3424 of file SDDSModern.cc.


The documentation for this struct was generated from the following file: