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 File Reference
#include <string.h>
#include <iostream>
#include "wcpplib/stream/prstream.h"
#include "wcpplib/util/String.h"
#include "wcpplib/util/FunNameStack.h"
#include "wcpplib/safetl/AbsArr.h"

Go to the source code of this file.

Classes

class  definp_endpar
 

Macros

#define DEFINPPAREND   dep
 
#define DEFINPAP(name)   definp_any_par(name, String(#name "="), DEFINPPAREND)
 

Functions

int definp_int (const String &str=String())
 
long definp_long (const String &str=String())
 
double definp_double (const String &str=String())
 
String definp_String (const String &str=String())
 
long set_position (const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
 
template<class T >
void definp_any_par (T &inp, const String &word, const definp_endpar &dep, int fs_short=0)
 
template<class T >
void definp_any_2par (T &inp1, T &inp2, const String &word, const definp_endpar &dep, int fs_short=0)
 
void remove_end_comments (std::istream &istr, String commark, DynLinArr< char > &istring)
 

Macro Definition Documentation

◆ DEFINPAP

#define DEFINPAP (   name)    definp_any_par(name, String(#name "="), DEFINPPAREND)

Definition at line 91 of file definp.h.

◆ DEFINPPAREND

#define DEFINPPAREND   dep

Definition at line 90 of file definp.h.

Function Documentation

◆ definp_any_2par()

template<class T >
void definp_any_2par ( T &  inp1,
T &  inp2,
const String word,
const definp_endpar dep,
int  fs_short = 0 
)

Definition at line 98 of file definp.h.

99 {
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}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
#define mfunnamep(string)
Definition: FunNameStack.h:77
int s_rewind
Definition: definp.h:42
int s_short
Definition: definp.h:45
std::istream * istrm
Definition: definp.h:38
int s_req_sep
Definition: definp.h:43
int s_print
Definition: definp.h:44
long set_position(const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
Definition: definp.cpp:71
#define mcerr
Definition: prstream.h:135
#define Imcout
Definition: prstream.h:208

◆ definp_any_par()

template<class T >
void definp_any_par ( T &  inp,
const String word,
const definp_endpar dep,
int  fs_short = 0 
)

Definition at line 66 of file definp.h.

67 {
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}

Referenced by operator>>().

◆ definp_double()

double definp_double ( const String str = String())

Definition at line 39 of file definp.cpp.

39 {
40 mfunnamep("int definp_double(void)");
41 double d;
42 mcout << "definp_double: starting, read double " << str << "\n";
43 if (str != String()) {
44 // search for mark
45 int i_ret = findmark(cin, str.c_str());
46 check_econd11(i_ret, != 1, mcerr);
47 }
48 cin >> d;
49 Iprintn(mcout, d);
50 check_econd11(cin.good(), != 1, mcerr);
51 mcout << "double is read\n";
52 return d;
53}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
std::string String
Definition: String.h:75
int findmark(std::istream &file, const char *s)
Definition: findmark.cpp:18
#define mcout
Definition: prstream.h:133
#define Iprintn(file, name)
Definition: prstream.h:216

◆ definp_int()

int definp_int ( const String str = String())

Definition at line 7 of file definp.cpp.

7 {
8 mfunnamep("int definp_int(const String& str)");
9 int i = 0;
10 mcout << "definp_int: starting, read int " << str << "\n";
11 if (str != String()) {
12 // search for mark
13 int i_ret = findmark(std::cin, str.c_str());
14 check_econd11(i_ret, != 1, mcerr);
15 }
16 cin >> i;
17 Iprintn(mcout, i);
18 check_econd11(cin.good(), != 1, mcerr);
19 mcout << "int is read\n";
20 return i;
21}

◆ definp_long()

long definp_long ( const String str = String())

Definition at line 23 of file definp.cpp.

23 {
24 mfunnamep("int definp_long(const String& str)");
25 long i = 0;
26 mcout << "definp_long: starting, read long " << str << "\n";
27 if (str != String()) {
28 // search for mark
29 int i_ret = findmark(cin, str.c_str());
30 check_econd11(i_ret, != 1, mcerr);
31 }
32 cin >> i;
33 Iprintn(mcout, i);
34 check_econd11(cin.good(), != 1, mcerr);
35 mcout << "long is read\n";
36 return i;
37}

◆ definp_String()

String definp_String ( const String str = String())

Definition at line 55 of file definp.cpp.

55 {
56 mfunnamep("int definp_String(const String& str)");
57 String istr;
58 mcout << "definp_String: starting, read String " << str << "\n";
59 if (str != String()) {
60 // search for mark
61 int i_ret = findmark(cin, str.c_str());
62 check_econd11(i_ret, != 1, mcerr);
63 }
64 cin >> istr;
65 Iprintn(mcout, istr);
66 check_econd11(cin.good(), != 1, mcerr);
67 mcout << "String is read\n";
68 return istr;
69}

◆ remove_end_comments()

void remove_end_comments ( std::istream &  istr,
String  commark,
DynLinArr< char > &  istring 
)

Definition at line 114 of file definp.cpp.

115 {
116 mfunnamep("void remove_end_comments(...)");
117 //mcout<<"remove_end_comments is started\n";
118 long marklen = commark.length();
119 //Iprintn(mcout, marklen);
120 DynLinArr<char> inpmark(marklen +
121 1); // temporary array for testing for "mark"
122 // +1 for '\0'
123 inpmark[marklen] = '\0';
124 long qel = 0;
125 istring.put_qel(1);
126 int ic;
127 int s_com = 0; // sign of comment
128 while ((ic = istr.get()) != EOF) {
129 //mcout<<"read new ic="<<char(ic)<<'\n';
130 //Iprint2n(mcout, qel, s_com);
131 if (s_com == 1) {
132 if (ic == '\n') {
133 //mcout<<"comment will be annulled\n";
134 s_com = 0;
135
136 if (qel >= istring.get_qel() - 2) {
137 istring.put_qel(istring.get_qel() * 2);
138 //Iprint2n(mcout, qel, istring.get_qel());
139 }
140 istring[qel++] = ic;
141 }
142 } else {
143 long n;
144 for (n = 1; n < marklen; n++) {
145 inpmark[n - 1] = inpmark[n];
146 }
147 inpmark[marklen - 1] = ic;
148 //Iprintn(mcout, inpmark);
149 if (strcmp(commark.c_str(), &(inpmark[0])) ==
150 0) { // yes, mark of comment is found
151 //mcout<<"comment is recognized\n";
152 s_com = 1;
153 qel = qel - (marklen - 1); // to annul beginning of the comment mark
154 } else { // just add new symbol
155 if (qel >= istring.get_qel() - 2) {
156 istring.put_qel(istring.get_qel() * 2);
157 //Iprint2n(mcout, qel, istring.get_qel());
158 }
159 //for debug:
160 //if(char(ic) == ' ')
161 // istring[qel++] = '_';
162 //else
163 istring[qel++] = ic;
164 }
165 }
166 }
167 istring[qel++] = '\0';
168 //mcout<<"remove_end_comments is finished\n";
169}
long get_qel(void) const
Definition: AbsArr.h:420
void put_qel(long fqel)
Definition: AbsArr.h:774

◆ set_position()

long set_position ( const String word,
std::istream &  istrm,
int  s_rewind,
int  s_req_sep 
)

Definition at line 71 of file definp.cpp.

72 {
73 mfunnamep("int set_position(const String& word, std::istream& istrm, int "
74 "s_rewind, int s_req_sep)");
75 check_econd11a(istrm.good(), != 1,
76 "before seekg, call for variable named " << word << '\n',
77 mcerr);
78 long nbeg, nnext;
79 char prev;
80 if (s_rewind == 1) istrm.seekg(0);
81 if (s_req_sep == 0) {
82 //int iret = findmark(istrm, word.c_str());
83 int iret = findmark_b(istrm, word, word.length(), nbeg, nnext, prev);
84
85 check_econd11a(iret, != 1,
86 "The keyword \"" << word.c_str() << "\" is not found\n",
87 mcerr);
89 istrm.good(), != 1,
90 "after the call of findmark for variable named " << word << '\n',
91 mcerr);
92 } else {
93 do {
94 int iret = findmark_b(istrm, word, word.length(),
95 // DynLinArr< T > ws, long qws,
96 nbeg, nnext, prev);
97 check_econd11a(iret, != 1,
98 "The keyword \"" << word.c_str() << "\" is not found\n",
99 mcerr);
101 istrm.good(), != 1,
102 "after the call of findmark for variable named " << word << '\n',
103 mcerr);
104 if (nbeg == 0) return nbeg; // no need to search for separator
105 if (prev == '\n' || prev == ' ') return nbeg; // good separator
106 } while (1); // infinite loop
107 }
108 check_econd11a(istrm.good(), != 1,
109 "after findmark_b, call for variable named " << word << '\n',
110 mcerr);
111 return nbeg;
112}
int findmark_b(std::istream &file, T ws, long qws, long &nbeg, long &nnext, char &prev)
Definition: findmark.h:105

Referenced by definp_any_2par(), definp_any_par(), and operator>>().