a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
InputFileToOutputFileClaimer.hpp
Go to the documentation of this file.
1/*
2 * InputFileToOutputFileClaimer.hpp
3 *
4 * Created on: Aug 14, 2012
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 INPUTFILETOOUTPUTFILECLAIMER_HPP_
14#define INPUTFILETOOUTPUTFILECLAIMER_HPP_
15
16#include <string>
17#include <fstream>
18#include "UsefulStuff.hpp"
19#include "StringParser.hpp"
20
21namespace BOL
22{
24 {
25 public:
26 static std::string const claimedSuffix;
27
30 std::vector< std::pair< std::string, std::string > > const&
33
34 void
35 setCopyCommand( std::string const& copyCommand );
36 void
37 setRemoveCommand( std::string const& removeCommand );
38 void
39 addFilenamePair( std::string const& inputFilename,
40 std::string const outputFilename );
41 std::vector< std::pair< std::string, std::string > >&
43 bool
45 std::string const claimString = "claimed, but not ready!" );
46 // this looks for the next output filename in matchedFilePairs that does
47 // not match an existing file's name & also has no corresponding claimed
48 // file. if there is no such filename, false is returned. otherwise it
49 // creates the corresponding claimed file & returns true.
50 int
52 // this returns the index in matchedFilePairs that corresponds to the last
53 // file claimed by this InputFileToOutputFileClaimer.
54 std::pair< std::string, std::string > const&
56 // this returns the filenames in matchedFilePairs that correspond to the
57 // last file claimed by this InputFileToOutputFileClaimer.
58 std::string const&
60 // this returns the input filename in matchedFilePairs that corresponds to
61 // the last file claimed by this InputFileToOutputFileClaimer.
62 std::string const&
64 // this returns the output filename in matchedFilePairs that corresponds to
65 // the last file claimed by this InputFileToOutputFileClaimer.
66 void
67 copyToClaimedOutputFile( std::string const& filenameToCopy );
68 // this copies the file called filenameToCopy to currentOutputFilename.
69
70
71 protected:
72 std::vector< std::pair< std::string, std::string > > matchedFilePairs;
74 std::string claimedFilename;
75 std::string copyCommand;
76 std::string removeCommand;
77 };
78
79
80
81
82
83 inline void
85 std::string const& copyCommand )
86 {
87 this->copyCommand.assign( copyCommand );
88 }
89
90 inline void
92 std::string const& removeCommand )
93 {
94 this->removeCommand.assign( removeCommand );
95 }
96
97 inline void
99 std::string const& inputFilename,
100 std::string const outputFilename )
101 {
102 matchedFilePairs.push_back( std::pair< std::string, std::string >(
103 inputFilename,
104 outputFilename ) );
105 }
106
107 inline std::vector< std::pair< std::string, std::string > >&
109 {
110 return matchedFilePairs;
111 }
112
113 inline int
115 {
116 return fileNumber;
117 }
118
119 inline std::pair< std::string, std::string > const&
121 // this returns the filenames in matchedFilePairs that correspond to the last
122 // file claimed by this InputFileToOutputFileClaimer.
123 {
125 }
126
127 inline std::string const&
129 // this returns the input filename in matchedFilePairs that corresponds to
130 // the last file claimed by this InputFileToOutputFileClaimer.
131 {
132 return matchedFilePairs[ fileNumber ].first;
133 }
134
135 inline std::string const&
137 // this returns the output filename in matchedFilePairs that corresponds to
138 // the last file claimed by this InputFileToOutputFileClaimer.
139 {
140 return matchedFilePairs[ fileNumber ].second;
141 }
142
143 inline void
145 std::string const& filenameToCopy )
146 // this copies the file called filenameToCopy to currentOutputFilename.
147 {
148 std::string systemCommand( copyCommand );
149 systemCommand.append( " " );
150 systemCommand.append( filenameToCopy );
151 systemCommand.append( " " );
152 systemCommand.append( matchedFilePairs[ fileNumber ].second );
153 system( systemCommand.c_str() );
154 systemCommand.assign( removeCommand );
155 systemCommand.append( " " );
156 systemCommand.append( claimedFilename );
157 system( systemCommand.c_str() );
158 }
159
160} /* namespace BOL */
161#endif /* INPUTFILETOOUTPUTFILECLAIMER_HPP_ */
void addFilenamePair(std::string const &inputFilename, std::string const outputFilename)
void setRemoveCommand(std::string const &removeCommand)
std::vector< std::pair< std::string, std::string > > matchedFilePairs
void copyToClaimedOutputFile(std::string const &filenameToCopy)
std::pair< std::string, std::string > const & getFilenamesForLastClaim() const
std::string const & getInputFilenameForLastClaim() const
void setCopyCommand(std::string const &copyCommand)
std::string const & getOutputFilenameForLastClaim() const
bool claimNextUnclaimedFile(std::string const claimString="claimed, but not ready!")
std::vector< std::pair< std::string, std::string > > & getFilenamePairs()