souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Attributes | Private Member Functions
souffle::CmdOptions Class Reference

A utility class for parsing command line arguments within generated query programs. More...

#include <CompiledOptions.h>

Collaboration diagram for souffle::CmdOptions:
Collaboration graph

Public Member Functions

 CmdOptions (const char *s, const char *id, const char *od, bool pe, const char *pfn, size_t nj)
 
const std::string & getInputFileDir () const
 get input directory More...
 
size_t getNumJobs () const
 get number of jobs More...
 
const std::string & getOutputFileDir () const
 get output directory More...
 
const std::string & getProfileName () const
 get filename of profile More...
 
const std::string & getSourceFileName () const
 get source code name More...
 
bool isProfiling () const
 is profiling switched on More...
 
bool parse (int argc, char **argv)
 Parses the given command line parameters, handles -h help requests or errors and returns whether the parsing was successful or not. More...
 

Protected Attributes

std::string input_dir
 fact directory More...
 
size_t num_jobs
 number of threads More...
 
std::string output_dir
 output directory More...
 
std::string profile_name
 profile filename More...
 
bool profiling
 profiling flag More...
 
std::string src
 source file More...
 

Private Member Functions

bool existDir (const std::string &name) const
 Check whether a directory exists in the file system. More...
 
bool existFile (const std::string &name) const
 Check whether a file exists in the file system. More...
 
void printHelpPage (const std::string &exec_name) const
 Prints the help page if it has been requested or there was a typo in the command line arguments. More...
 

Detailed Description

A utility class for parsing command line arguments within generated query programs.

Definition at line 40 of file CompiledOptions.h.

Constructor & Destructor Documentation

◆ CmdOptions()

souffle::CmdOptions::CmdOptions ( const char *  s,
const char *  id,
const char *  od,
bool  pe,
const char *  pfn,
size_t  nj 
)
inline

Definition at line 81 of file CompiledOptions.h.

Member Function Documentation

◆ existDir()

bool souffle::CmdOptions::existDir ( const std::string &  name) const
inlineprivate

Check whether a directory exists in the file system.

Definition at line 256 of file CompiledOptions.h.

◆ existFile()

bool souffle::CmdOptions::existFile ( const std::string &  name) const
inlineprivate

Check whether a file exists in the file system.

Definition at line 243 of file CompiledOptions.h.

244  {
245  if ((buffer.st_mode & S_IFDIR) != 0) {
246  return true;
247  }
248  }
249  return false;
250  }
251 };

◆ getInputFileDir()

const std::string& souffle::CmdOptions::getInputFileDir ( ) const
inline

get input directory

Definition at line 94 of file CompiledOptions.h.

94  {
95  return profiling;
96  }

References profiling.

◆ getNumJobs()

size_t souffle::CmdOptions::getNumJobs ( ) const
inline

get number of jobs

Definition at line 122 of file CompiledOptions.h.

◆ getOutputFileDir()

const std::string& souffle::CmdOptions::getOutputFileDir ( ) const
inline

get output directory

Definition at line 101 of file CompiledOptions.h.

101  {
102  return profile_name;
103  }

References profile_name.

◆ getProfileName()

const std::string& souffle::CmdOptions::getProfileName ( ) const
inline

get filename of profile

Definition at line 115 of file CompiledOptions.h.

116  {
117  // get executable name

◆ getSourceFileName()

const std::string& souffle::CmdOptions::getSourceFileName ( ) const
inline

get source code name

Definition at line 87 of file CompiledOptions.h.

87  {
88  return output_dir;
89  }

References output_dir.

◆ isProfiling()

bool souffle::CmdOptions::isProfiling ( ) const
inline

is profiling switched on

Definition at line 108 of file CompiledOptions.h.

108  {
109  return num_jobs;
110  }

References num_jobs.

◆ parse()

bool souffle::CmdOptions::parse ( int  argc,
char **  argv 
)
inline

Parses the given command line parameters, handles -h help requests or errors and returns whether the parsing was successful or not.

Definition at line 130 of file CompiledOptions.h.

131  {nullptr, false, nullptr, 0}};
132 
133  // check whether all options are fine
134  bool ok = true;
135 
136  int c; /* command-line arguments processing */
137  while ((c = getopt_long(argc, argv, "D:F:hp:j:i:", longOptions, nullptr)) != EOF) {
138  switch (c) {
139  /* Fact directories */
140  case 'F':
141  if (!existDir(optarg)) {
142  printf("Fact directory %s does not exists!\n", optarg);
143  ok = false;
144  }
145  fact_dir = optarg;
146  break;
147  /* Output directory for resulting .csv files */
148  case 'D':
149  if (*optarg && !existDir(optarg)) {
150  printf("Output directory %s does not exists!\n", optarg);
151  ok = false;
152  }
153  out_dir = optarg;
154  break;
155  case 'p':
156  if (!profiling) {
157  std::cerr << "\nError: profiling was not enabled in compilation\n\n";
158  printHelpPage(exec_name);
159  exit(EXIT_FAILURE);
160  }
161  profile_name = optarg;
162  break;
163  case 'j':
164 #ifdef _OPENMP
165  if (std::string(optarg) == "auto") {
166  num_jobs = 0;
167  } else {
168  int num = atoi(optarg);
169  if (num > 0) {
170  num_jobs = num;
171  } else {
172  std::cerr << "Invalid number of jobs [-j]: " << optarg << "\n";
173  ok = false;
174  }
175  }
176 #else
177  std::cerr << "\nWarning: OpenMP was not enabled in compilation\n\n";
178 #endif
179  break;
180  default: printHelpPage(exec_name); return false;
181  }
182  }
183 
184  // update member fields
185  input_dir = fact_dir;
186  output_dir = out_dir;
187 
188  // return success state
189  return ok;
190  }
191 
192 private:
193  /**
194  * Prints the help page if it has been requested or there was a typo in the command line arguments.
195  */
196  void printHelpPage(const std::string& exec_name) const {
197  std::cerr << "====================================================================\n";
198  std::cerr << " Datalog Program: " << src << "\n";
199  std::cerr << " Usage: " << exec_name << " [OPTION]\n\n";
200  std::cerr << " Options:\n";
201  std::cerr << " -D <DIR>, --output=<DIR> -- Specify directory for output relations\n";
202  std::cerr << " (default: " << output_dir << ")\n";
203  std::cerr << " (suppress output with \"\")\n";
204  std::cerr << " -F <DIR>, --facts=<DIR> -- Specify directory for fact files\n";

◆ printHelpPage()

void souffle::CmdOptions::printHelpPage ( const std::string &  exec_name) const
inlineprivate

Prints the help page if it has been requested or there was a typo in the command line arguments.

Definition at line 210 of file CompiledOptions.h.

212  {
213  std::cerr << " (default: " << num_jobs << ")\n";
214  } else {
215  std::cerr << " (default: auto)\n";
216  }
217 #endif
218  std::cerr << " -h -- prints this help page.\n";
219  std::cerr << "--------------------------------------------------------------------\n";
220  std::cout << " Copyright (c) 2016-20 The Souffle Developers." << std::endl;
221  std::cout << " Copyright (c) 2013-16 Oracle and/or its affiliates." << std::endl;
222  std::cerr << " All rights reserved.\n";
223  std::cerr << "====================================================================\n";
224  }
225 
226  /**
227  * Check whether a file exists in the file system
228  */
229  inline bool existFile(const std::string& name) const {
230  struct stat buffer;
231  if (stat(name.c_str(), &buffer) == 0) {
232  if ((buffer.st_mode & S_IFREG) != 0) {
233  return true;
234  }
235  }
236  return false;
237  }
238 

References num_jobs.

Field Documentation

◆ input_dir

std::string souffle::CmdOptions::input_dir
protected

fact directory

Definition at line 57 of file CompiledOptions.h.

◆ num_jobs

size_t souffle::CmdOptions::num_jobs
protected

number of threads

Definition at line 77 of file CompiledOptions.h.

Referenced by isProfiling(), and printHelpPage().

◆ output_dir

std::string souffle::CmdOptions::output_dir
protected

output directory

Definition at line 62 of file CompiledOptions.h.

Referenced by getSourceFileName().

◆ profile_name

std::string souffle::CmdOptions::profile_name
protected

profile filename

Definition at line 72 of file CompiledOptions.h.

Referenced by getOutputFileDir().

◆ profiling

bool souffle::CmdOptions::profiling
protected

profiling flag

Definition at line 67 of file CompiledOptions.h.

Referenced by getInputFileDir().

◆ src

std::string souffle::CmdOptions::src
protected

source file

Definition at line 52 of file CompiledOptions.h.


The documentation for this class was generated from the following file:
tinyformat::printf
void printf(const char *fmt)
Definition: tinyformat.h:1101
souffle::CmdOptions::existFile
bool existFile(const std::string &name) const
Check whether a file exists in the file system.
Definition: CompiledOptions.h:243
souffle::CmdOptions::profile_name
std::string profile_name
profile filename
Definition: CompiledOptions.h:72
souffle::CmdOptions::num_jobs
size_t num_jobs
number of threads
Definition: CompiledOptions.h:77
souffle::CmdOptions::src
std::string src
source file
Definition: CompiledOptions.h:52
souffle::CmdOptions::output_dir
std::string output_dir
output directory
Definition: CompiledOptions.h:62
souffle::CmdOptions::profiling
bool profiling
profiling flag
Definition: CompiledOptions.h:67
souffle::CmdOptions::input_dir
std::string input_dir
fact directory
Definition: CompiledOptions.h:57
souffle::CmdOptions::existDir
bool existDir(const std::string &name) const
Check whether a directory exists in the file system.
Definition: CompiledOptions.h:256
souffle::CmdOptions::printHelpPage
void printHelpPage(const std::string &exec_name) const
Prints the help page if it has been requested or there was a typo in the command line arguments.
Definition: CompiledOptions.h:210