Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::API::ScriptBuilder Class Reference

This class build a sttring which cana be executed as a python script. More...

#include <ScriptBuilder.h>

Public Member Functions

const std::string build ()
 build a python script from the history view More...
 
 ScriptBuilder (const std::shared_ptr< HistoryView > &view, std::string versionSpecificity="old", bool appendTimestamp=false, std::vector< std::string > ignoreTheseAlgs={}, std::vector< std::vector< std::string > > ignoreTheseAlgProperties={}, bool appendExecCount=false)
 
virtual ~ScriptBuilder ()=default
 

Private Member Functions

const std::string buildAlgorithmString (const AlgorithmHistory &algHistory)
 Build the script output for a single algorithm. More...
 
void buildChildren (std::ostringstream &os, std::vector< HistoryItem >::const_iterator &iter, int depth=1)
 Iterate over each of the items children and output them to the script. More...
 
const std::string buildCommentString (const AlgorithmHistory &algHistory)
 Build the script output for a single comment. More...
 
const std::string buildPropertyString (const Mantid::Kernel::PropertyHistory &propHistory, const std::string &algName)
 Build the script output for a single property. More...
 
void createStringForAlg (std::ostringstream &os, std::shared_ptr< const Mantid::API::AlgorithmHistory > &algHistory)
 
void writeHistoryToStream (std::ostringstream &os, std::vector< HistoryItem >::const_iterator &iter, int depth=1)
 Write out an algorithm to the script. More...
 

Private Attributes

std::vector< std::string > m_algsToIgnore
 
bool m_execCount
 
const std::vector< HistoryItemm_historyItems
 
std::string m_output
 
std::vector< std::vector< std::string > > m_propertiesToIgnore
 
bool m_timestampCommands
 
std::string m_versionSpecificity
 

Detailed Description

This class build a sttring which cana be executed as a python script.

Author
Samuel Jackson, ISIS, RAL
Date
21/01/2008

Definition at line 31 of file ScriptBuilder.h.

Constructor & Destructor Documentation

◆ ScriptBuilder()

Mantid::API::ScriptBuilder::ScriptBuilder ( const std::shared_ptr< HistoryView > &  view,
std::string  versionSpecificity = "old",
bool  appendTimestamp = false,
std::vector< std::string >  ignoreTheseAlgs = {},
std::vector< std::vector< std::string > >  ignoreTheseAlgProperties = {},
bool  appendExecCount = false 
)

Definition at line 38 of file ScriptBuilder.cpp.

◆ ~ScriptBuilder()

virtual Mantid::API::ScriptBuilder::~ScriptBuilder ( )
virtualdefault

Member Function Documentation

◆ build()

const std::string Mantid::API::ScriptBuilder::build ( )

build a python script from the history view

Build a python script for each algorithm included in the history view.

Returns
a formatted python string of the history

Definition at line 50 of file ScriptBuilder.cpp.

References m_historyItems, and writeHistoryToStream().

Referenced by AlgorithmHistoryWindow::copytoClipboard(), Mantid::Algorithms::GeneratePythonScript::exec(), and AlgorithmHistoryWindow::writeToScriptFile().

◆ buildAlgorithmString()

const std::string Mantid::API::ScriptBuilder::buildAlgorithmString ( const AlgorithmHistory algHistory)
private

◆ buildChildren()

void Mantid::API::ScriptBuilder::buildChildren ( std::ostringstream &  os,
std::vector< HistoryItem >::const_iterator &  iter,
int  depth = 1 
)
private

Iterate over each of the items children and output them to the script.

This moves the iterator forward over each of the child records and writes them to the stream.

Parameters
os:: output string stream to append algorithms to.
iter:: reference to the iterator pointing to the vector of history items
depth:: count of how far we've recursed into the history

Definition at line 132 of file ScriptBuilder.cpp.

References m_historyItems, and writeHistoryToStream().

Referenced by writeHistoryToStream().

◆ buildCommentString()

const std::string Mantid::API::ScriptBuilder::buildCommentString ( const AlgorithmHistory algHistory)
private

Build the script output for a single comment.

Parameters
algHistory:: pointer to an algorithm history object
Returns
std::string to run this algorithm

Definition at line 147 of file ScriptBuilder.cpp.

References Mantid::API::COMMENT_ALG, Mantid::API::AlgorithmHistory::getProperties(), and Mantid::API::AlgorithmHistory::name().

Referenced by buildAlgorithmString().

◆ buildPropertyString()

const std::string Mantid::API::ScriptBuilder::buildPropertyString ( const Mantid::Kernel::PropertyHistory propHistory,
const std::string &  algName 
)
private

Build the script output for a single property.

Parameters
propHistory:: reference to a property history object
algName:: reference to the algorithm that the property is from's name
Returns
std::string for this property

Definition at line 256 of file ScriptBuilder.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::Kernel::PropertyHistory::direction(), Mantid::API::g_log, Mantid::Kernel::PropertyHistory::isDefault(), m_algsToIgnore, m_propertiesToIgnore, Mantid::Kernel::PropertyHistory::name(), Mantid::Kernel::Direction::Output, Mantid::Kernel::PropertyHistory::type(), value, and Mantid::Kernel::PropertyHistory::value().

Referenced by buildAlgorithmString().

◆ createStringForAlg()

void Mantid::API::ScriptBuilder::createStringForAlg ( std::ostringstream &  os,
std::shared_ptr< const Mantid::API::AlgorithmHistory > &  algHistory 
)
private

Definition at line 102 of file ScriptBuilder.cpp.

References buildAlgorithmString(), m_execCount, and m_timestampCommands.

Referenced by writeHistoryToStream().

◆ writeHistoryToStream()

void Mantid::API::ScriptBuilder::writeHistoryToStream ( std::ostringstream &  os,
std::vector< HistoryItem >::const_iterator &  iter,
int  depth = 1 
)
private

Write out an algorithm to the script.

If the entry is unrolled this will recurse and output the children of that entry instead. If not, it will just output the algorithm to the stream.

Parameters
os:: output string stream to append algorithms to.
iter:: reference to the iterator pointing to the vector of history items
depth:: count of how far we've recursed into the history

Definition at line 71 of file ScriptBuilder.cpp.

References buildChildren(), createStringForAlg(), m_algsToIgnore, m_historyItems, and m_timestampCommands.

Referenced by build(), and buildChildren().

Member Data Documentation

◆ m_algsToIgnore

std::vector<std::string> Mantid::API::ScriptBuilder::m_algsToIgnore
private

Definition at line 52 of file ScriptBuilder.h.

Referenced by buildPropertyString(), and writeHistoryToStream().

◆ m_execCount

bool Mantid::API::ScriptBuilder::m_execCount
private

Definition at line 54 of file ScriptBuilder.h.

Referenced by createStringForAlg().

◆ m_historyItems

const std::vector<HistoryItem> Mantid::API::ScriptBuilder::m_historyItems
private

Definition at line 48 of file ScriptBuilder.h.

Referenced by build(), buildChildren(), and writeHistoryToStream().

◆ m_output

std::string Mantid::API::ScriptBuilder::m_output
private

Definition at line 49 of file ScriptBuilder.h.

◆ m_propertiesToIgnore

std::vector<std::vector<std::string> > Mantid::API::ScriptBuilder::m_propertiesToIgnore
private

Definition at line 53 of file ScriptBuilder.h.

Referenced by buildPropertyString().

◆ m_timestampCommands

bool Mantid::API::ScriptBuilder::m_timestampCommands
private

Definition at line 51 of file ScriptBuilder.h.

Referenced by createStringForAlg(), and writeHistoryToStream().

◆ m_versionSpecificity

std::string Mantid::API::ScriptBuilder::m_versionSpecificity
private

Definition at line 50 of file ScriptBuilder.h.

Referenced by buildAlgorithmString().


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