WRApplication
External kratos "application" for multiscale time integration.
JournalBase Class Reference

A class for keeping administrational text data throughout an analysis. More...

Collaboration diagram for JournalBase:

Classes

class  ThreadID
 A wrapper class for identifying threads. More...
 

Public Types

using iterator = FileStringIterator
 
using const_iterator = iterator
 
using value_type = iterator::value_type
 
using size_type = std::size_t
 
using Extractor = std::function< value_type(const Model &)>
 

Public Member Functions

 KRATOS_CLASS_POINTER_DEFINITION (JournalBase)
 
 JournalBase ()
 Construct the object with an empty file name (invalid). More...
 
 JournalBase (const std::filesystem::path &rJournalPath)
 Construct a registry given an associated file path and a no-op extractor. More...
 
 JournalBase (const std::filesystem::path &rJournalPath, const Extractor &rExtractor)
 Construct a registry given an associated file path and extractor. More...
 
 JournalBase (JournalBase &&rOther)=delete
 The move constructor is deleted because it's ambiguous what should happen to the associated file. More...
 
 JournalBase (const JournalBase &rOther)
 Copy constructor. More...
 
JournalBaseoperator= (JournalBase &&rOther)=delete
 The move assignment operator is deleted because it's ambiguous what should happen to the associated file. More...
 
JournalBaseoperator= (const JournalBase &rOther)
 Copy assignment operator. More...
 
const std::filesystem::path & GetFilePath () const noexcept
 Get the path to the associated file. More...
 
void SetExtractor (Extractor &&rExtractor)
 Set the extractor handling the conversion from Model to a string. More...
 
void SetExtractor (const Extractor &rExtractor)
 
void Push (const Model &rModel)
 Call the extractor and append the results to the associated file. More...
 
void Push (const value_type &rEntry)
 Call the extractor and append the results to the associated file. More...
 
void Erase (const_iterator itEntry)
 Erase an entry from the associated file. More...
 
void Erase (const_iterator Begin, const_iterator End)
 Erase a range of entries from the associated file. More...
 
void EraseIf (const std::function< bool(const value_type &)> &rPredicate)
 Erase all lines from the associated file matching the input predicate. More...
 
void Clear ()
 Delete the associated file. More...
 
bool IsOpen () const noexcept
 Check whether the associated file is opened by this object. More...
 
const_iterator begin () const
 Create an iterator to the first line of the associated file. More...
 
const_iterator end () const
 Create an iterator to the last (empty) line of the associated file. More...
 
size_type size () const
 Count the number of lines in the file (including the last empty one). More...
 

Detailed Description

A class for keeping administrational text data throughout an analysis.

This class is primarily meant to keep track of output files generated during a simulation, though extra flexibility is provided to extend its purpose as necessary. An associated text file can be written to via JournalBase::Push. On each push, a Model is taken as input, parsed, and a string consisting of a single line is appended to the file. Generating the output string from the input Model is the job of a functor that can be set in the constructor, or in JournalBase::SetExtractor.

Warning
The associated file must be empty or end with an empty line.

Member Typedef Documentation

◆ const_iterator

◆ Extractor

using Extractor = std::function<value_type(const Model&)>

◆ iterator

◆ size_type

using size_type = std::size_t

◆ value_type

Constructor & Destructor Documentation

◆ JournalBase() [1/5]

Construct the object with an empty file name (invalid).

◆ JournalBase() [2/5]

JournalBase ( const std::filesystem::path &  rJournalPath)

Construct a registry given an associated file path and a no-op extractor.

Note
Should the file already exist, it will be appended to instead of overwritten.

◆ JournalBase() [3/5]

JournalBase ( const std::filesystem::path &  rJournalPath,
const Extractor rExtractor 
)

Construct a registry given an associated file path and extractor.

Note
Should the file already exist, it will be appended to instead of overwritten.

◆ JournalBase() [4/5]

JournalBase ( JournalBase &&  rOther)
delete

The move constructor is deleted because it's ambiguous what should happen to the associated file.

◆ JournalBase() [5/5]

JournalBase ( const JournalBase rOther)
explicit

Copy constructor.

Warning
Deletes the associated file if the incoming instance has another one.
The associated file must not be open.

Member Function Documentation

◆ begin()

const_iterator begin ( ) const

Create an iterator to the first line of the associated file.

Warning
The file remains open for the iterator's lifetime.

◆ Clear()

void Clear ( )

Delete the associated file.

Warning
The associated file must not be open.

◆ end()

const_iterator end ( ) const

Create an iterator to the last (empty) line of the associated file.

Warning
The file remains open for the iterator's lifetime.

◆ Erase() [1/2]

void Erase ( const_iterator  Begin,
const_iterator  End 
)

Erase a range of entries from the associated file.

Warning
The associated file must not be open.

This operation is extremely inefficient, as a new new file has to be written that contains every line of the currently associated file except those to be erased.

Todo:
Make this function thread safe.

◆ Erase() [2/2]

void Erase ( const_iterator  itEntry)

Erase an entry from the associated file.

Warning
The associated file must not be open.

This operation is extremely inefficient, as a new new file has to be written that contains every line of the currently associated file except the erased one.

Todo:
Make this function thread safe.

◆ EraseIf()

void EraseIf ( const std::function< bool(const value_type &)> &  rPredicate)

Erase all lines from the associated file matching the input predicate.

  • rPredicate Functor returning true for lines to be deleted.
    Warning
    The associated file must not be open.
    This function iterates through all lines in the associated file one by one and calls JournalBase::Erase on each that matches the predicate.

◆ GetFilePath()

const std::filesystem::path& GetFilePath ( ) const
noexcept

Get the path to the associated file.

◆ IsOpen()

bool IsOpen ( ) const
noexcept

Check whether the associated file is opened by this object.

◆ KRATOS_CLASS_POINTER_DEFINITION()

KRATOS_CLASS_POINTER_DEFINITION ( JournalBase  )

◆ operator=() [1/2]

JournalBase& operator= ( const JournalBase rOther)

Copy assignment operator.

Warning
Deletes the associated file if the incoming instance has another one.
The associated file must not be open.

◆ operator=() [2/2]

JournalBase& operator= ( JournalBase &&  rOther)
delete

The move assignment operator is deleted because it's ambiguous what should happen to the associated file.

◆ Push() [1/2]

void Push ( const Model &  rModel)

Call the extractor and append the results to the associated file.

Warning
The associated file must not be open.
Only the thread that assigned the extractor can successfully invoke this function. Otherwise a warning is issued but no further operation is taken (associated file is not written to).

◆ Push() [2/2]

void Push ( const value_type rEntry)

Call the extractor and append the results to the associated file.

Warning
The associated file must not be open.
Only the thread that assigned the extractor can successfully invoke this function. Otherwise a warning is issued but no further operation is taken (associated file is not written to).

◆ SetExtractor() [1/2]

void SetExtractor ( const Extractor rExtractor)

◆ SetExtractor() [2/2]

void SetExtractor ( Extractor &&  rExtractor)

Set the extractor handling the conversion from Model to a string.

The extractor must generate a string without any line breaks.

Warning
Once SetExtractor is called, the ID of the caller thread is stored and only that thread is allowed to invoke JournalBase::Push. This is necessary to support python function objects (avoid hanging at the global interpreter lock).

◆ size()

size_type size ( ) const

Count the number of lines in the file (including the last empty one).


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