Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
classdef2code.cc
Go to the documentation of this file.
1 #include <filesystem>
2 #include <fstream>
3 #include <iomanip>
4 #include <iostream>
5 #include <regex>
6 #include <sstream>
7 #include <stdexcept>
8 #include <string>
9 #include <vector>
10 
11 using namespace std;
12 
13 struct Includes {
17 };
18 
19 void outputTypes(std::ostream &out, const Includes &includes) {
20  out << R"(#ifndef __JDB__JDBTypes__ #define __JDB__JDBTypes__ /** * @file * This file is automatically created by classdef2code during CMake build. */ namespace JDATABASE { )";
21 
22  for (auto v1 : includes.api) {
23  out << " class " << v1 << ";\n";
24  }
25 
26  out << "\n namespace APIV2 {\n\n";
27  for (auto v2 : includes.apiV2) {
28  out << " class " << v2 << ";\n";
29  }
30 
31  out << R"( } } #endif )";
32 }
33 
34 void outputIncludes(std::ostream &out, const Includes &includes) {
35  out << R"(/** * @file * This file is automatically created by classdef2code during CMake build. */ )";
36  for (auto i : includes.files) {
38  out << "#include \"JDB/" << p.filename().string() << "\"\n";
39  }
40 }
41 
43  Includes cn;
44  for (auto infile : includes) {
45  ifstream in(infile);
46  if (!in.is_open()) {
47  std::cerr << "Cannot open input file " << infile << "\n";
48  exit(1);
49  }
50  string line;
51  std::regex classDefRegex(R"(ClassDef\s*(?:NV)?\(\s*(.*)\s*,\s*(\d*))");
52  std::regex apiV2Regex("namespace.*APIV2");
53  std::smatch classDefMatch;
54  bool v2{false};
55  string stype{""};
56  bool used{false};
57  while (getline(in, line)) {
58  if (std::regex_search(line, apiV2Regex)) {
59  v2 = true;
60  }
61  if (std::regex_search(line, classDefMatch, classDefRegex)) {
62  // classDefMatch[2] is the version, if needed.
63  stype = classDefMatch[1];
64  if (v2) {
65  cn.apiV2.emplace_back(stype);
66  used = true;
67  } else {
68  cn.api.emplace_back(stype);
69  used = true;
70  }
71  }
72  }
73  if (used) {
74  cn.files.emplace_back(infile);
75  }
76  }
77  return cn;
78 }
79 
80 /**
81  * Helper program to create includes files for types and includes
82  * from a list of JDB includes
83  *
84  */
85 int main(int argc, char **argv) {
86  if (argc < 5) {
87  throw runtime_error("need at least 4 arguments");
88  }
89  string outfile = argv[1]; // output file name
90  string outputType = argv[2]; // output type ("types" or "includes")
91  vector<string> classdefs; // input include files (absolute paths or relative
92  // to current dir)
93  for (int i = 3; i < argc; i++) {
94  classdefs.emplace_back(argv[i]);
95  }
96 
97  auto includes = parseIncludes(classdefs);
98 
99  ofstream out(outfile);
100  if (!out.is_open()) {
101  std::cerr << "Cannot open output file " << outfile << "\n";
102  exit(1);
103  }
105  if (outputType == "types") {
106  outputTypes(out, includes);
107  } else if (outputType == "includes") {
108  outputIncludes(out, includes);
109  } else {
110  std::cerr << "don't know what to do with outputType " << outputType
111  << " : I only know 'types' or 'includes'\n";
112  exit(2);
113  }
114 
115  return 0;
116 }
117 
int main(int argc, char *argv[])
Definition: Main.cc:15
void outputTypes(std::ostream &out, const Includes &includes)
exit
Definition: JPizza.sh:36
void outputIncludes(std::ostream &out, const Includes &includes)
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DQSIM<$WORKDIR/ev_configure_dqsimulator.txt > RC_DWRT path
then usage $script< detector file >< PMTparametersfile > nThe list of optional parameters includes
std::vector< std::string > api
std::vector< std::string > files
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Includes parseIncludes(const std::vector< std::string > &includes)
std::vector< std::string > apiV2