utils.cxx
Go to the documentation of this file.
1 #include "utils.h"
2 
3 #include <stdexcept>
4 #include <string.h>
5 
6 namespace VLN {
7 
8 Flavor parseFlavor(const std::string &flavStr)
9 {
10  if (flavStr == "numu") {
11  return Flavor::NuMu;
12  }
13 
14  if (flavStr.empty() || (flavStr == "any")) {
15  return Flavor::Any;
16  }
17 
18  throw std::invalid_argument(
19  "Unknown flavor: " + flavStr
20  + ". Supported Flavors: 'numu', 'any', ''"
21  );
22 }
23 
24 Format parseFormat(const std::string &formatStr)
25 {
26  if (formatStr == "csv") {
27  return Format::CSV;
28  }
29 
30  throw std::invalid_argument(
31  "Unknown format: " + formatStr + ". Supported Formats: 'csv'"
32  );
33 }
34 
36  const std::string &path, const std::string &root, Format format
37 )
38 {
39  std::string filename(basename(path.c_str()));
40  const size_t dotIdx = filename.find_last_of('.');
41 
42  if (dotIdx != std::string::npos) {
43  filename.resize(dotIdx);
44  }
45 
46  switch (format) {
47  case Format::CSV:
48  return filename + ".csv";
49  default:
50  throw std::invalid_argument("Unknown format");
51  }
52 }
53 
54 }
55 
Format
Definition: utils.h:7
Format parseFormat(const std::string &formatStr)
Definition: utils.cxx:24
std::string string
Definition: nybbler.cc:12
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
string filename
Definition: train.py:213
Flavor
Definition: utils.h:6
std::string convertFilename(const std::string &path, const std::string &root, Format format)
Definition: utils.cxx:35
Definition: utils.cxx:6
Flavor parseFlavor(const std::string &flavStr)
Definition: utils.cxx:8