7 #include <boost/program_options.hpp> 20 class CommandLineProcessor
27 std::cerr <<
"No directory specified" << std::endl;
31 if (dir[dir.length() - 1] !=
'/')
38 std::cerr <<
"Directory [" << dir <<
"] does not exist" << std::endl;
42 if (!fs::is_directory(dir))
44 std::cerr <<
"Given directory [" << dir <<
"] is not a directory" << std::endl;
51 bool ValidateOutputFile(std::string& outputFileName)
53 if (outputFileName.empty())
55 std::cerr <<
"No output file name specified" << std::endl;
59 if (fs::exists(outputFileName))
61 std::cerr <<
"Output file [" << outputFileName <<
"] already exists" << std::endl;
65 if (fs::is_directory(outputFileName))
67 std::cerr <<
"Output file [" << outputFileName <<
"] is a directory" << std::endl;
71 fs::path outputPath(outputFileName);
72 if (!fs::exists(outputPath.parent_path()))
74 std::cerr <<
"Directory [" << outputPath.parent_path().c_str() <<
"] does not exist" << std::endl;
81 bool ValidateBindingId(
const std::string&
id)
83 if (!std::all_of(
id.begin(),
id.end(), ::isdigit))
85 std::cerr <<
"Invalid input binding Id" << std::endl;
92 bool ProcessCommandLine(
int argc,
char* argv[])
94 namespace po = boost::program_options;
96 po::options_description desc(
"Options");
100 (
"help,h",
"Display help messages")
101 (
"indir,i", po::value<std::string>(&m_InputDirectory)->required(),
102 "Directory that .raw files are stored in")
103 (
"outfile,o", po::value<std::string>(&m_OutputFileName)->required(),
104 "Output CSV file path")
105 (
"layer-binding-id,l", po::value<std::string>(&m_InputBindingId)->default_value(
"0"),
106 "Input layer binding Id, Defaults to 0");
108 catch (
const std::exception& e)
110 std::cerr <<
"Fatal internal error: [" << e.what() <<
"]" << std::endl;
114 po::variables_map vm;
118 po::store(po::parse_command_line(argc, argv, desc), vm);
120 if (vm.count(
"help"))
122 std::cout << desc << std::endl;
128 catch (
const po::error& e)
130 std::cerr << e.what() << std::endl << std::endl;
131 std::cerr << desc << std::endl;
140 if (!ValidateOutputFile(m_OutputFileName))
145 if(!ValidateBindingId(m_InputBindingId))
153 std::string GetInputDirectory() {
return m_InputDirectory;}
154 std::string GetOutputFileName() {
return m_OutputFileName;}
155 std::string GetInputBindingId() {
return m_InputBindingId;}
158 std::string m_InputDirectory;
159 std::string m_OutputFileName;
160 std::string m_InputBindingId;
165 int main(
int argc,
char* argv[])
167 CommandLineProcessor cmdline;
168 if (!cmdline.ProcessCommandLine(argc, argv))
173 const std::string fileFormat(
".raw");
175 const std::string rawDirectory(cmdline.GetInputDirectory());
176 const std::string outputPath(cmdline.GetOutputFileName());
177 const std::string bindingId(cmdline.GetInputBindingId());
179 std::vector<fs::path> rawFiles;
180 for (
auto& entry : boost::make_iterator_range(fs::directory_iterator(rawDirectory), {}))
182 if (entry.path().extension().c_str() == fileFormat)
184 rawFiles.push_back(entry.path());
188 if (!rawFiles.empty())
190 unsigned int pass = 0;
191 std::ofstream refinementData;
192 refinementData.open(outputPath, std::ofstream::out);
193 if (refinementData.is_open())
195 for (
auto const& raw : rawFiles)
197 refinementData << pass <<
", " << bindingId <<
", " << raw.c_str() <<
"\n";
200 std::cerr <<
"Failed to write to output file: " << outputPath << std::endl;
205 refinementData.close();
209 std::cerr <<
"Failed to open output file: " << outputPath << std::endl;
215 std::cerr <<
"No matching files with the \".raw\" extension found in the directory: " 216 << rawDirectory << std::endl;
int main(int argc, char *argv[])
bool ValidateDirectory(std::string &dir)