Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
definp.h
Go to the documentation of this file.
1#ifndef DEFINP_H
2#define DEFINP_H
3
4#include <vector>
5#include <iostream>
8
9namespace Heed {
10
11/* The function below looks for string in cin input stream,
12read a value of a corresponding type and return it.
13They may be dangerous because they do not require a separator in front of
14string.
15Therefore the longer name which has the same ending can be erroneously taken
16instead of the looked one.
17The rewind is not made. Therefore the names should appear in order.
18The returning the read value is useful because such a functions can be used
19for initialization of global variables.
20*/
21int definp_int(const std::string& str = std::string());
22
23// New experimental routines
24
25long set_position(const std::string& word, std::istream& istrm, int s_rewind,
26 int s_req_sep);
27
28// Below "endpar" means that this class invelops a few parameters,
29// which are typical for functions reading something from stream.
30// Previously these parameters appeared at the end of parameter list.
31// From this this notation has evolved.
33 public:
34 std::istream* istrm; // exclusion from rules.
35 // Rationale: actually here should be derivatives from istream.
36 // If to declare here derivative from istream and RegPassivePtr,
37 // the standard derivatives from istream will not be appropriate instances.
39 int s_req_sep; // recognized separators are '\n' and ' '
41 int s_short; // if 1, assumes that the names are not output and not
42 // searched for at reading.
44 : istrm(NULL), s_rewind(0), s_req_sep(0), s_print(0), s_short(0) {}
45 definp_endpar(std::istream* fistrm, int fs_rewind, int fs_req_sep,
46 int fs_print = 1, int fs_short = 0)
47 : istrm(fistrm),
48 s_rewind(fs_rewind),
49 s_req_sep(fs_req_sep),
50 s_print(fs_print),
51 s_short(fs_short) {}
52};
53
54template <class T>
55void definp_any_par(T& inp, const std::string& word, const definp_endpar& dep,
56 int fs_short = 0) {
57 mfunnamep("template< class T > definp_any_par(...)");
58 check_econd11a(dep.istrm->good(), != 1,
59 "before input of variable named " << word << '\n', mcerr);
60 // mcout<<"definp_any_par:\n";
61 // Iprint2n(mcout, word, dep.s_short);
62 if (fs_short == 0)
63 if (dep.s_short == 0)
64 set_position(word, *dep.istrm, dep.s_rewind, dep.s_req_sep);
65 (*(dep.istrm)) >> inp;
66 if (dep.s_print == 1)
67 // Iprintn(mcout, dep.s_print);
68 Imcout << "definp_any_par: " << word << ' ' << inp << '\n';
69 // Iprintn(mcout, inp);
70 check_econd11a(dep.istrm->good(), != 1,
71 "after input of variable named "
72 << word << "\nwhose input value is " << inp << '\n',
73 mcerr);
74}
75
76//#define DEFINPPAREND definp_stream, s_rewind, s_req_sep, s_print
77#define DEFINPPAREND dep
78#define DEFINPAP(name) definp_any_par(name, std::string(#name "="), DEFINPPAREND)
79
80/*
81With these macros the programmer can reduce the volume of program inputting
82many parameters to a minimum. For example, to input variable "varname"
83it needs just to say
84 DEFINPAP(varname);
85provided that the following declarations (with not necessarily these values)
86appear somewhere before:
87 definp_endpar dep(&std::cin, 0, 0, 0);
88 //std::istream& definp_stream = std::cin;
89 //int s_rewind = 1;
90 //int s_req_sep = 1;
91 //int s_print = 1;
92 int varname = 0;
93*/
94
95}
96
97#endif
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:172
#define mfunnamep(string)
Definition: FunNameStack.h:49
std::istream * istrm
Definition: definp.h:34
definp_endpar(std::istream *fistrm, int fs_rewind, int fs_req_sep, int fs_print=1, int fs_short=0)
Definition: definp.h:45
Definition: BGMesh.cpp:6
int definp_int(const std::string &str)
Definition: definp.cpp:7
long set_position(const std::string &word, std::istream &istrm, int s_rewind, int s_req_sep)
Definition: definp.cpp:23
void definp_any_par(T &inp, const std::string &word, const definp_endpar &dep, int fs_short=0)
Definition: definp.h:55
#define mcerr
Definition: prstream.h:128
#define Imcout
Definition: prstream.h:197