Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
classdef2code.cc File Reference
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <regex>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

struct  Includes
 

Functions

void outputTypes (std::ostream &out, const Includes &includes)
 
void outputIncludes (std::ostream &out, const Includes &includes)
 
Includes parseIncludes (const std::vector< std::string > &includes)
 
int main (int argc, char **argv)
 Helper program to create includes files for types and includes from a list of JDB includes. More...
 

Function Documentation

void outputTypes ( std::ostream &  out,
const Includes includes 
)

Definition at line 19 of file classdef2code.cc.

19  {
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 
std::vector< std::string > api
std::vector< std::string > apiV2
void outputIncludes ( std::ostream &  out,
const Includes includes 
)

Definition at line 48 of file classdef2code.cc.

48  {
49  out << R"(/** * @file * This file is automatically created by classdef2code during CMake build. */ )";
50  for (auto i : includes.files) {
52  out << "#include \"JDB/" << p.filename().string() << "\"\n";
53  }
54 }
55 
$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
std::vector< std::string > files
Includes parseIncludes ( const std::vector< std::string > &  includes)

Definition at line 61 of file classdef2code.cc.

61  {
62  Includes cn;
63  for (auto infile : includes) {
64  ifstream in(infile);
65  if (!in.is_open()) {
66  std::cerr << "Cannot open input file " << infile << "\n";
67  exit(1);
68  }
69  string line;
70  std::regex classDefRegex(R"(ClassDef\s*(?:NV)?\(\s*(.*)\s*,\s*(\d*))");
71  std::regex apiV2Regex("namespace.*APIV2");
72  std::smatch classDefMatch;
73  bool v2{false};
74  string stype{""};
75  bool used{false};
76  while (getline(in, line)) {
77  if (std::regex_search(line, apiV2Regex)) {
78  v2 = true;
79  }
80  if (std::regex_search(line, classDefMatch, classDefRegex)) {
81  // classDefMatch[2] is the version, if needed.
82  stype = classDefMatch[1];
83  if (v2) {
84  cn.apiV2.emplace_back(stype);
85  used = true;
86  } else {
87  cn.api.emplace_back(stype);
88  used = true;
89  }
90  }
91  }
92  if (used) {
93  cn.files.emplace_back(infile);
94  }
95  }
96  return cn;
97 }
exit
Definition: JPizza.sh:36
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
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
std::vector< std::string > apiV2
int main ( int  argc,
char **  argv 
)

Helper program to create includes files for types and includes from a list of JDB includes.

Definition at line 104 of file classdef2code.cc.

104  {
105  if (argc < 5) {
106  throw runtime_error("need at least 4 arguments");
107  }
108  string outfile = argv[1]; // output file name
109  string outputType = argv[2]; // output type ("types" or "includes")
110  vector<string> classdefs; // input include files (absolute paths or relative
111  // to current dir)
112  for (int i = 3; i < argc; i++) {
113  classdefs.emplace_back(argv[i]);
114  }
115 
116  auto includes = parseIncludes(classdefs);
117 
118  ofstream out(outfile);
119  if (!out.is_open()) {
120  std::cerr << "Cannot open output file " << outfile << "\n";
121  exit(1);
122  }
123 
124  if (outputType == "types") {
125  outputTypes(out, includes);
126  } else if (outputType == "includes") {
127  outputIncludes(out, includes);
128  } else {
129  std::cerr << "don't know what to do with outputType " << outputType
130  << " : I only know 'types' or 'includes'\n";
131  exit(2);
132  }
133 
134  return 0;
135 }
void outputTypes(std::ostream &out, const Includes &includes)
exit
Definition: JPizza.sh:36
void outputIncludes(std::ostream &out, const Includes &includes)
then usage $script< detector file >< PMTparametersfile > nThe list of optional parameters includes
Includes parseIncludes(const std::vector< std::string > &includes)