a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BOL::FilePlaceholderManager Class Reference

#include <FilePlaceholderManager.hpp>

Detailed Description

Definition at line 40 of file FilePlaceholderManager.hpp.

Public Member Functions

 FilePlaceholderManager (std::string const inputSuffix="", std::string const placeholderSuffix="", std::string const outputSuffix="")
 
std::string const & getInput () const
 
std::string const & getOutput () const
 
std::string const & getPlaceholder () const
 
bool holdNextPlace (bool const deleteLastPlaceholder=true)
 
void prepareFilenames (std::string const &inputDirectory, std::string const &placeholderDirectory="", std::string const &outputDirectory="")
 
void prepareFilenames (std::vector< std::string > const &baseFilenames, std::string const inputDirectory="", std::string placeholderDirectory="", std::string outputDirectory="")
 
 ~FilePlaceholderManager ()
 

Protected Attributes

std::string currentSuffix
 
FilenameTriple currentTriple
 
std::vector< FilenameTriplefilenameTriples
 
std::string const inputSuffix
 
std::string lastPlaceholder
 
std::string const outputSuffix
 
std::string const placeholderSuffix
 
std::vector< FilenameTriple >::const_iterator whichTriple
 

Constructor & Destructor Documentation

◆ FilePlaceholderManager()

BOL::FilePlaceholderManager::FilePlaceholderManager ( std::string const  inputSuffix = "",
std::string const  placeholderSuffix = "",
std::string const  outputSuffix = "" 
)

Definition at line 20 of file FilePlaceholderManager.cpp.

23 :
30 currentSuffix( "" ),
31 lastPlaceholder( "" )
32 {
33 // just an initialization list.
34 }
std::vector< FilenameTriple > filenameTriples
std::vector< FilenameTriple >::const_iterator whichTriple

◆ ~FilePlaceholderManager()

BOL::FilePlaceholderManager::~FilePlaceholderManager ( )

Definition at line 36 of file FilePlaceholderManager.cpp.

37 {
38 // does nothing.
39 }

Member Function Documentation

◆ getInput()

std::string const & BOL::FilePlaceholderManager::getInput ( ) const
inline

Definition at line 103 of file FilePlaceholderManager.hpp.

104 {
105 return whichTriple->inputFile;
106 }

◆ getOutput()

std::string const & BOL::FilePlaceholderManager::getOutput ( ) const
inline

Definition at line 115 of file FilePlaceholderManager.hpp.

116 {
117 return whichTriple->outputFile;
118 }

◆ getPlaceholder()

std::string const & BOL::FilePlaceholderManager::getPlaceholder ( ) const
inline

Definition at line 109 of file FilePlaceholderManager.hpp.

110 {
111 return whichTriple->placeholderFile;
112 }

◆ holdNextPlace()

bool BOL::FilePlaceholderManager::holdNextPlace ( bool const  deleteLastPlaceholder = true)

Definition at line 138 of file FilePlaceholderManager.cpp.

145 {
146 while( ( filenameTriples.end() > whichTriple )
147 &&
148 ( UsefulStuff::fileExists( whichTriple->outputFile )
149 ||
150 UsefulStuff::fileExists( whichTriple->placeholderFile )
151 ||
152 !(UsefulStuff::fileExists( whichTriple->inputFile )) ) )
153 {
154 ++whichTriple;
155 }
156 if( deleteLastPlaceholder )
157 {
159 }
160 if( !( filenameTriples.end() > whichTriple ) )
161 {
162 return false;
163 }
164 lastPlaceholder.assign( whichTriple->placeholderFile );
165 std::ofstream placeholderStream( lastPlaceholder.c_str() );
166 placeholderStream << "placeholder" << std::endl;
167 placeholderStream.close();
168 return true;
169 }
static bool fileExists(std::string const &fileName)
static void runSystemCommand(std::string const &systemCommand)

◆ prepareFilenames() [1/2]

void BOL::FilePlaceholderManager::prepareFilenames ( std::string const &  inputDirectory,
std::string const &  placeholderDirectory = "",
std::string const &  outputDirectory = "" 
)

Definition at line 43 of file FilePlaceholderManager.cpp.

54 {
55 std::vector< std::string > validBaseFilenames;
56 DIR* directoryPointer( opendir( inputDirectory.c_str() ) );
57 if( NULL == directoryPointer )
58 {
59 throw std::runtime_error( "Could not read directory!" );
60 }
61 std::string currentFile;
62 struct dirent* structPointer( readdir( directoryPointer ) );
63 while( NULL != structPointer )
64 {
65 currentFile.assign( structPointer->d_name );
66 structPointer = readdir( directoryPointer );
67 if( ( 0 == currentFile.compare( "." ) )
68 ||
69 ( 0 == currentFile.compare( ".." ) )
70 ||
71 !( inputSuffix.size() < currentFile.size() ) )
72 {
73 continue;
74 }
75 currentSuffix.assign( currentFile.substr( currentFile.size()
76 - inputSuffix.size() ) );
77 if( 0 == currentSuffix.compare( inputSuffix ) )
78 {
79 validBaseFilenames.push_back( currentFile.substr( 0,
80 ( currentFile.size() - inputSuffix.size() ) ) );
81 }
82 }
83 prepareFilenames( validBaseFilenames,
84 inputDirectory,
85 placeholderDirectory,
86 outputDirectory );
87 }
void prepareFilenames(std::string const &inputDirectory, std::string const &placeholderDirectory="", std::string const &outputDirectory="")

◆ prepareFilenames() [2/2]

void BOL::FilePlaceholderManager::prepareFilenames ( std::vector< std::string > const &  baseFilenames,
std::string const  inputDirectory = "",
std::string  placeholderDirectory = "",
std::string  outputDirectory = "" 
)

Definition at line 90 of file FilePlaceholderManager.cpp.

103 {
104 filenameTriples.clear();
105 if( placeholderDirectory.empty() )
106 {
107 placeholderDirectory.assign( inputDirectory );
108 }
109 else
110 {
111 UsefulStuff::runSystemCommand( "mkdir -p " + placeholderDirectory );
112 }
113 if( outputDirectory.empty() )
114 {
115 outputDirectory.assign( inputDirectory );
116 }
117 else
118 {
119 UsefulStuff::runSystemCommand( "mkdir -p " + outputDirectory );
120 }
121 for( std::vector< std::string >::const_iterator
122 whichBaseFilename( baseFilenames.begin() );
123 baseFilenames.end() > whichBaseFilename;
124 ++whichBaseFilename )
125 {
126 currentTriple.inputFile.assign( inputDirectory + "/"
127 + (*whichBaseFilename) + inputSuffix );
128 currentTriple.placeholderFile.assign( placeholderDirectory + "/"
129 + (*whichBaseFilename) + placeholderSuffix );
130 currentTriple.outputFile.assign( outputDirectory + "/"
131 + (*whichBaseFilename) + outputSuffix );
132 filenameTriples.push_back( currentTriple );
133 }
135 }

Member Data Documentation

◆ currentSuffix

std::string BOL::FilePlaceholderManager::currentSuffix
protected

Definition at line 96 of file FilePlaceholderManager.hpp.

◆ currentTriple

FilenameTriple BOL::FilePlaceholderManager::currentTriple
protected

Definition at line 95 of file FilePlaceholderManager.hpp.

◆ filenameTriples

std::vector< FilenameTriple > BOL::FilePlaceholderManager::filenameTriples
protected

Definition at line 93 of file FilePlaceholderManager.hpp.

◆ inputSuffix

std::string const BOL::FilePlaceholderManager::inputSuffix
protected

Definition at line 90 of file FilePlaceholderManager.hpp.

◆ lastPlaceholder

std::string BOL::FilePlaceholderManager::lastPlaceholder
protected

Definition at line 97 of file FilePlaceholderManager.hpp.

◆ outputSuffix

std::string const BOL::FilePlaceholderManager::outputSuffix
protected

Definition at line 92 of file FilePlaceholderManager.hpp.

◆ placeholderSuffix

std::string const BOL::FilePlaceholderManager::placeholderSuffix
protected

Definition at line 91 of file FilePlaceholderManager.hpp.

◆ whichTriple

std::vector<FilenameTriple>::const_iterator BOL::FilePlaceholderManager::whichTriple
protected

Definition at line 94 of file FilePlaceholderManager.hpp.


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