EntropyEngine::Core::IO::WriteBatch
EntropyEngine::Core::IO::WriteBatch
Section titled “EntropyEngine::Core::IO::WriteBatch”WriteBatch - Collects multiple write operations and applies them atomically. More…
#include <WriteBatch.h>
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~WriteBatch() =default | |
| WriteBatch & | writeLines(const std::map< size_t, std::string > & lines) Overwrite multiple specific lines in one call. |
| WriteBatch & | writeLine(size_t lineNumber, std::string_view content) Overwrite a line at index (0-based). |
| void | reset() Clears all pending operations without writing. |
| WriteBatch & | replaceAll(std::string_view content) Replace entire file content with the provided text. |
| FileOperationHandle | preview() const Build the resulting content without writing it (debugging aid). |
| size_t | pendingOperations() const Number of pending operations in the batch. |
| WriteBatch & | insertLines(size_t startLine, const std::vector< std::string > & lines) Insert multiple lines starting at position. |
| WriteBatch & | insertLine(size_t lineNumber, std::string_view content) Insert a line at index (shifts existing lines down). |
| const std::string & | getPath() const Target file path for this batch. |
| bool | empty() const Returns true if no operations are pending. |
| WriteBatch & | deleteRange(size_t startLine, size_t endLine) Delete a range of lines [startLine, endLine). |
| WriteBatch & | deleteLine(size_t lineNumber) Delete a line at index (shifts remaining lines up). |
| FileOperationHandle | commit() Apply all pending operations atomically. |
| FileOperationHandle | commit(const WriteOptions & opts) Apply all pending operations atomically with per-commit options. |
| WriteBatch & | clear() Clear the file (equivalent to truncate to zero). |
| WriteBatch & | appendLine(std::string_view content) Append a line to the end of the file. |
| WriteBatch(VirtualFileSystem * vfs, std::string path) |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::IO::WriteBatch;WriteBatch - Collects multiple write operations and applies them atomically.
This allows for efficient batch processing of file modifications without repeatedly reading and writing the entire file. All operations are collected in memory and then applied in a single atomic operation.
Usage: auto batch = vfs->createWriteBatch(“myfile.txt”); batch->writeLine(0, “First line”); batch->writeLine(5, “Sixth line”); batch->insertLine(2, “New third line”); batch->deleteLine(10); auto handle = batch->commit(); // Applies all changes atomically handle.wait();
Public Functions Documentation
Section titled “Public Functions Documentation”function ~WriteBatch
Section titled “function ~WriteBatch”~WriteBatch() =defaultfunction writeLines
Section titled “function writeLines”WriteBatch & writeLines( const std::map< size_t, std::string > & lines)Overwrite multiple specific lines in one call.
Parameters:
- lines Map of line index -> content; sparse indices allowed
Return: Reference to this batch for chaining
function writeLine
Section titled “function writeLine”WriteBatch & writeLine( size_t lineNumber, std::string_view content)Overwrite a line at index (0-based).
Parameters:
- lineNumber Line index to write
- content New content (no newline)
Return: Reference to this batch for chaining
function reset
Section titled “function reset”void reset()Clears all pending operations without writing.
function replaceAll
Section titled “function replaceAll”WriteBatch & replaceAll( std::string_view content)Replace entire file content with the provided text.
Parameters:
- content New content (may contain multiple lines)
Return: Reference to this batch for chaining
function preview
Section titled “function preview”FileOperationHandle preview() constBuild the resulting content without writing it (debugging aid).
Return: Handle whose contentsText() contains the preview after wait()
function pendingOperations
Section titled “function pendingOperations”inline size_t pendingOperations() constNumber of pending operations in the batch.
function insertLines
Section titled “function insertLines”WriteBatch & insertLines( size_t startLine, const std::vector< std::string > & lines)Insert multiple lines starting at position.
Parameters:
- startLine First index at which to insert
- lines Lines to insert
Return: Reference to this batch for chaining
function insertLine
Section titled “function insertLine”WriteBatch & insertLine( size_t lineNumber, std::string_view content)Insert a line at index (shifts existing lines down).
Parameters:
- lineNumber Insert position
- content Line content
Return: Reference to this batch for chaining
function getPath
Section titled “function getPath”inline const std::string & getPath() constTarget file path for this batch.
function empty
Section titled “function empty”inline bool empty() constReturns true if no operations are pending.
function deleteRange
Section titled “function deleteRange”WriteBatch & deleteRange( size_t startLine, size_t endLine)Delete a range of lines [startLine, endLine).
Parameters:
- startLine First line to delete (inclusive)
- endLine One past the last line to delete (exclusive)
Return: Reference to this batch for chaining
function deleteLine
Section titled “function deleteLine”WriteBatch & deleteLine( size_t lineNumber)Delete a line at index (shifts remaining lines up).
Parameters:
- lineNumber Line to delete
Return: Reference to this batch for chaining
function commit
Section titled “function commit”FileOperationHandle commit()Apply all pending operations atomically.
Return: Handle for the asynchronous commit
auto batch = vfs.createWriteBatch("file.txt");batch->writeLine(0, "Hello").appendLine("World");auto h = batch->commit(); h.wait();Uses VFS defaults for parent directory creation and preserves the original file’s line-ending style and trailing-newline policy when possible.
function commit
Section titled “function commit”FileOperationHandle commit( const WriteOptions & opts)Apply all pending operations atomically with per-commit options.
Parameters:
-
opts WriteOptions controlling behavior:
-
createParentDirs: per-commit override for creating parent directories
-
ensureFinalNewline: force presence/absence of a final newline on whole-file rewrites
Return: Handle for the asynchronous commit
Note: Line endings are detected from the original file and preserved (LF vs CRLF), avoiding mixed endings. See VirtualFileSystemExample.cpp for usage.
function clear
Section titled “function clear”WriteBatch & clear()Clear the file (equivalent to truncate to zero).
Return: Reference to this batch for chaining
function appendLine
Section titled “function appendLine”WriteBatch & appendLine( std::string_view content)Append a line to the end of the file.
Parameters:
- content Line content (no newline)
Return: Reference to this batch for chaining
function WriteBatch
Section titled “function WriteBatch”WriteBatch( VirtualFileSystem * vfs, std::string path)Updated on 2026-01-26 at 16:50:32 -0500