26 const char OPTIONS_SEPARATOR =
',';
39 JParameter(
const std::string& variable) :
52 friend bool operator==(
const JParameter& first,
const JParameter& second)
54 return (first.name == second.name &&
55 first.value == second.value);
67 inline std::istream&
read(std::istream& in)
69 return in >> this->value;
81 inline std::ostream&
write(std::ostream& out)
const
83 return out << this->value;
100 inline std::istream& JParameter<std::string>::read(std::istream& in)
102 return std::getline(in, this->value);
115 inline std::istream& JParameter<bool>::read(std::istream& in)
130 inline std::ostream& JParameter<bool>::write(std::ostream& out)
const
132 return out << (this->value ?
"1" :
"0");
144 inline std::istream&
operator>>(std::istream& in, JParameter<T>& parameter)
146 return parameter.read(in);
158 inline std::ostream&
operator<<(std::ostream& out,
const JParameter<T>& parameter)
160 return parameter.write(out);
167 template<
class T = JNullType>
189 __terminate__(false),
197 virtual ~JShellParser()
206 virtual void terminate(
const int status)
208 __terminate__ =
true;
209 __exit_code__ = status;
239 gexit(__exit_code__);
257 struct JShellParser :
258 public JShellParser<>
260 typedef JShellParser<>::key_type key_type;
261 typedef JParameter<T> parameter_type;
268 void evaluate()
const
270 for (
typename data_type::const_iterator i = this->
data.begin(); i != this->data.end(); ++i) {
272 std::ostringstream os;
297 struct JEnvironment<
std::string> :
298 public JShellParser<std::string>
300 typedef JShellParser<std::string>::key_type key_type;
318 friend inline std::istream&
operator>>(std::istream& in, JEnvironment& environment)
329 if (!has_facet<JEquationFacet>(in.getloc())) {
330 in.imbue(locale(in.getloc(), facet.clone()));
333 if (in >> c >> key >> equation) {
335 if (c ==
'-' && !equation.
getKey().empty()) {
337 environment.data.push_back(parameter_type(equation.
getKey()));
339 parameter_type& parameter = environment.data.back();
345 istringstream is(equation.
getValue());
349 for (parameter_type buffer(parameter.name);
getline(is, buffer.value, OPTIONS_SEPARATOR); ) {
351 buffer.value =
trim(buffer.value);
353 possible_values.push_back(buffer);
378 struct JEnvironment<bool> :
379 public JShellParser<bool>
381 typedef JShellParser<bool>::key_type key_type;
399 friend inline std::istream&
operator>>(std::istream& in, JEnvironment& environment)
410 if (!has_facet<JEquationFacet>(in.getloc())) {
411 in.imbue(locale(in.getloc(), facet.clone()));
414 if (in >> c >> key >> equation) {
416 if (c ==
'-' && !equation.
getKey().empty()) {
418 environment.data.push_back(parameter_type(equation.
getKey()));
420 parameter_type& parameter = environment.data.back();
459 JEnvironment<bool> boolean;
460 JEnvironment<string> regular;
467 const JArgs options = zap(argc, argv);
469 JShellParser<> buffer;
471 buffer.join(
boolean);
472 buffer.join(regular);
479 catch(
const exception& error) {
480 return gexit(2, error.what());
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int main(int argc, char **argv)
Data structure to store command line arguments.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
Simple data structure to support I/O of equations (see class JLANG::JEquation).
General purpose equation class.
const std::string & getKey() const
Get key.
const std::string & getValue() const
Get value.
const char getSeparator() const
Get separator.
Exception for parsing value.
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
Utility class to parse command line options.
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
bool operator==(const Head &first, const Head &second)
Equal operator.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
std::istream & operator>>(std::istream &in, JAHRSCalibration &calibration)
Read AHRS calibration from input stream.
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
std::string trim(const std::string &buffer)
Trim string.
JParserTemplateElement< JType_t > getOption(JType_t &object, const std::string &name, const std::string &help="")
Auxiliary method for creation of template parser element object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
int gexit(int status, const std::string &message="")
Exit method.
void gprint(const std::string &message)
Print method.
void set_variable(const std::string &name, const std::string &value)
Set environment variable.
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Auxiliary class for no type definition.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...