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

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

Collaboration diagram for Journal:

Classes

class  iterator
 An iterator wrapping JournalBase::iterator but with Parameters as value_type. More...
 

Public Types

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

Public Member Functions

 KRATOS_CLASS_POINTER_DEFINITION (Journal)
 
 Journal ()
 Construct the object with an empty file name (invalid). More...
 
 Journal (const std::filesystem::path &rJournalPath)
 Construct a registry given an associated file path and a no-op extractor. More...
 
 Journal (const std::filesystem::path &rJournalPath, const Extractor &rExtractor)
 Construct a registry given an associated file path and extractor. More...
 
 Journal (Journal &&rOther)=delete
 The move constructor is deleted because it's ambiguous what should happen to the associated file. More...
 
 Journal (const Journal &rOther)=default
 Copy constructor. More...
 
Journaloperator= (Journal &&rOther)=delete
 The move assignment operator is deleted because it's ambiguous what should happen to the associated file. More...
 
Journaloperator= (const Journal &rOther)=default
 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 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 ()
 JournalBase::Clear() 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 is a wrapper class around JournalBase, but writes entries via Parameters objects instead of raw strings, offering a bit more convenience.

Member Typedef Documentation

◆ const_iterator

◆ Extractor

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

◆ size_type

using size_type = std::size_t

◆ value_type

Constructor & Destructor Documentation

◆ Journal() [1/5]

Journal ( )

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

◆ Journal() [2/5]

Journal ( 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.

◆ Journal() [3/5]

Journal ( 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.

◆ Journal() [4/5]

Journal ( Journal &&  rOther)
delete

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

◆ Journal() [5/5]

Journal ( const Journal rOther)
explicitdefault

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 ( )

◆ 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 ( Journal  )

◆ operator=() [1/2]

Journal& operator= ( const Journal rOther)
default

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]

Journal& operator= ( Journal &&  rOther)
delete

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

◆ Push()

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).

◆ 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: