a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
FilePlaceholderManager.hpp
Go to the documentation of this file.
1/*
2 * FilePlaceholderManager.hpp
3 *
4 * Created on: Oct 10, 2013
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 *
7 * This file is part of BOLlib, released under the
8 * GNU General Public License. Please see the accompanying
9 * README.BOLlib.txt file for a full list of files, brief documentation
10 * on how to use these classes, and further details on the license.
11 */
12
13#ifndef FILEPLACEHOLDERMANAGER_HPP_
14#define FILEPLACEHOLDERMANAGER_HPP_
15
16#include <cstdio>
17#include <cstdlib>
18#include <string>
19#include <vector>
20#include <fstream>
21#include <stdexcept>
22#include <dirent.h>
23#include "UsefulStuff.hpp"
24
25namespace BOL
26{
27 // this struct is just a convenient grouping of data for the following class.
29 {
30 std::string inputFile;
31 std::string placeholderFile;
32 std::string outputFile;
33 };
34
35 /* this class manages triples of filenames with the intention that each
36 * triple consists of a name for an input file, a name for a placeholder
37 * file to indicate that the output file is currently being worked on, and a
38 * name for an output file.
39 */
41 {
42 public:
43 FilePlaceholderManager( std::string const inputSuffix = "",
44 std::string const placeholderSuffix = "",
45 std::string const outputSuffix = "" );
47
48 void
49 prepareFilenames( std::string const& inputDirectory,
50 std::string const& placeholderDirectory = "",
51 std::string const& outputDirectory = "" );
52 /* this takes all the names of all the files in the directory given by
53 * inputDirectory which end in inputSuffixToStrip, and places each in a
54 * FilenameTriple with the placeholder filename given by replacing
55 * inputSuffixToStrip with placeholderSuffixToAdd, replacing the directory
56 * path with placeholderDirectory if placeholderDirectory is not empty, and
57 * the same for the output file using outputSuffixToAdd and outputDirectory
58 * if not empty.
59 */
60 void
61 prepareFilenames( std::vector< std::string > const& baseFilenames,
62 std::string const inputDirectory = "",
63 std::string placeholderDirectory = "",
64 std::string outputDirectory = "" );
65 /* this takes all the names of all the files in baseFilenames and places
66 * each in a FilenameTriple with inputSuffixToAdd appended as the input
67 * filename, with placeholderSuffixToAdd appended as the placeholder
68 * filename, replacing the directory path with placeholderDirectory if
69 * placeholderDirectory is not empty, and with outputSuffixToAdd appended
70 * as the output file, replacing the directory path with outputDirectory if
71 * outputDirectory is not empty.
72 */
73 bool
74 holdNextPlace( bool const deleteLastPlaceholder = true );
75 /* this looks to find the first FilenameTriple in filenameTriples which
76 * has both a placeholder filename and an output filename which do not yet
77 * exist in the file system, and returns true if there was such a triple.
78 * if deleteLastPlaceholder is true, the previous placeholder is also
79 * deleted, obviously.
80 */
81 std::string const&
82 getInput() const;
83 std::string const&
84 getPlaceholder() const;
85 std::string const&
86 getOutput() const;
87
88
89 protected:
90 std::string const inputSuffix;
91 std::string const placeholderSuffix;
92 std::string const outputSuffix;
93 std::vector< FilenameTriple > filenameTriples;
94 std::vector< FilenameTriple >::const_iterator whichTriple;
96 std::string currentSuffix;
97 std::string lastPlaceholder;
98 };
99
100
101
102 inline std::string const&
104 {
105 return whichTriple->inputFile;
106 }
107
108 inline std::string const&
110 {
111 return whichTriple->placeholderFile;
112 }
113
114 inline std::string const&
116 {
117 return whichTriple->outputFile;
118 }
119
120} /* namespace BOL */
121#endif /* FILEPLACEHOLDERMANAGER_HPP_ */
bool holdNextPlace(bool const deleteLastPlaceholder=true)
FilePlaceholderManager(std::string const inputSuffix="", std::string const placeholderSuffix="", std::string const outputSuffix="")
std::vector< FilenameTriple > filenameTriples
std::string const & getOutput() const
std::vector< FilenameTriple >::const_iterator whichTriple
std::string const & getPlaceholder() const
std::string const & getInput() const
void prepareFilenames(std::string const &inputDirectory, std::string const &placeholderDirectory="", std::string const &outputDirectory="")