Garfield++ v1r0
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 <string.h>
5#include <iostream>
9
10/* Four functions below looks for string in cin input stream,
11read a value of a corresponding type and return it.
12They may be dangerous because they do not require a separator in front of
13string.
14Therefore the longer name which has the same ending can be erroneously taken
15instead of the looked one.
16The rewind is not made. Therefore the names should appear in order.
17The returning the read value is useful because such a functions can be used
18for initialization of global variables.
19*/
20int definp_int(const String& str = String());
21long definp_long(const String& str = String());
22double definp_double(const String& str = String());
23String definp_String(const String& str = String());
24
25/*
26New experimental routines
27*/
28
29long set_position(const String& word, std::istream& istrm, int s_rewind,
30 int s_req_sep);
31
32// Below "endpar" means that this class invelops a few parameters,
33// which are typical for functions reading something from stream.
34// Previously these parameters appeared at the end of parameter list.
35// From this this notation has evolved.
37 public:
38 std::istream* istrm; // exclusion from rules.
39 // Rationale: actually here should be derivatives from istream.
40 // If to declare here derivative from istream and RegPassivePtr,
41 // the standard derivatives from istream will not be appropriate instances.
43 int s_req_sep; // recognized separators are '\n' and ' '
45 int s_short; // if 1, assumes that the names are not output and not
46 // searched for at reading.
48 : istrm(NULL), s_rewind(0), s_req_sep(0), s_print(0), s_short(0) {
49 ;
50 }
51 definp_endpar(std::istream* fistrm, int fs_rewind, int fs_req_sep,
52 int fs_print = 1, int fs_short = 0)
53 : istrm(fistrm),
54 s_rewind(fs_rewind),
55 s_req_sep(fs_req_sep),
56 s_print(fs_print),
57 s_short(fs_short) {
58 ;
59 }
60};
61
62//template< class T > void definp_any_par
63// (T& inp, String& word, std::istream& istrm, int s_rewind, int s_req_sep,
64// int s_print=1 )
65template <class T>
66void definp_any_par(T& inp, const String& word, const definp_endpar& dep,
67 int fs_short = 0) {
68 mfunnamep("template< class T > definp_any_par(...)");
69 check_econd11a(dep.istrm->good(), != 1,
70 "before input of variable named " << word << '\n', mcerr);
71 //mcout<<"definp_any_par:\n";
72 //Iprint2n(mcout, word, dep.s_short);
73 if (fs_short == 0)
74 if (dep.s_short == 0)
75 set_position(word, *dep.istrm, dep.s_rewind, dep.s_req_sep);
76 (*(dep.istrm)) >> inp;
77 if (dep.s_print == 1)
78 //Iprintn(mcout, dep.s_print);
79 Imcout << "definp_any_par: " << word << ' ' << inp << '\n';
80 //Iprintn(mcout, inp);
81 check_econd11a(dep.istrm->good(), != 1,
82 "after input of variable named "
83 << word << "\nwhose input value is " << inp << '\n',
84 mcerr);
85}
86
87//#define DEFINPPAREND definp_stream, s_rewind, s_req_sep, s_print
88//#define DEFINPAP(name) definp_any_par(name, String(#name##"="), DEFINPPAREND
89//)
90#define DEFINPPAREND dep
91#define DEFINPAP(name) definp_any_par(name, String(#name "="), DEFINPPAREND)
92
93//template< class T > void definp_any_2par
94// (T& inp1, T& inp2, String& word, std::istream& istrm, int s_rewind, int
95//s_req_sep,
96// int s_print=1 )
97template <class T>
98void definp_any_2par(T& inp1, T& inp2, const String& word,
99 const definp_endpar& dep, int fs_short = 0) {
100 mfunnamep("template< class T > definp_any_par(...)");
101 if (fs_short == 0)
102 if (dep.s_short == 0)
103 set_position(word, *dep.istrm, dep.s_rewind, dep.s_req_sep);
104 (*(dep.istrm)) >> inp1 >> inp2;
105 if (dep.s_print == 1)
106 Imcout << "definp_any_par: " << word << ' ' << inp1 << ' ' << inp2 << '\n';
107 //Iprintn(mcout, inp);
109 dep.istrm->good(), != 1,
110 "after input of variables after word "
111 << word << "\nwhose input values are " << inp1 << ' ' << inp2 << '\n',
112 mcerr);
113}
114
115#include "wcpplib/safetl/AbsArr.h" // If to put it at the beginning,
116// many things are not compiled because file AbsArr.h includes this file
117// and it cannot be realy scanned since DEFINP_H is already set up.
118
119void remove_end_comments(std::istream& istr, String commark,
120 DynLinArr<char>& istring);
121
122/*
123With these macros the programmer can reduce the volume of program inputting
124many parameters to a minimum. For example, to input variable "varname"
125it needs just to say
126 DEFINPAP(varname);
127provided that the following declarations (with not necessarily these values)
128appear somewhere before:
129 definp_endpar dep(&std::cin, 0, 0, 0);
130 //std::istream& definp_stream = std::cin;
131 //int s_rewind = 1;
132 //int s_req_sep = 1;
133 //int s_print = 1;
134 int varname = 0;
135*/
136
137/*
138class DefInput
139{
140public:
141 static DefInput
142*/
143
144#endif
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
#define mfunnamep(string)
Definition: FunNameStack.h:77
std::string String
Definition: String.h:75
definp_endpar(void)
Definition: definp.h:47
int s_rewind
Definition: definp.h:42
int s_short
Definition: definp.h:45
definp_endpar(std::istream *fistrm, int fs_rewind, int fs_req_sep, int fs_print=1, int fs_short=0)
Definition: definp.h:51
std::istream * istrm
Definition: definp.h:38
int s_req_sep
Definition: definp.h:43
int s_print
Definition: definp.h:44
int definp_int(const String &str=String())
Definition: definp.cpp:7
void definp_any_par(T &inp, const String &word, const definp_endpar &dep, int fs_short=0)
Definition: definp.h:66
long definp_long(const String &str=String())
Definition: definp.cpp:23
long set_position(const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
Definition: definp.cpp:71
void definp_any_2par(T &inp1, T &inp2, const String &word, const definp_endpar &dep, int fs_short=0)
Definition: definp.h:98
double definp_double(const String &str=String())
Definition: definp.cpp:39
void remove_end_comments(std::istream &istr, String commark, DynLinArr< char > &istring)
Definition: definp.cpp:114
String definp_String(const String &str=String())
Definition: definp.cpp:55
#define mcerr
Definition: prstream.h:135
#define Imcout
Definition: prstream.h:208