Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
definp.cpp
Go to the documentation of this file.
1#include <cstdio>
4
5using namespace std;
6
7int definp_int(const String& str) {
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}
22
23long definp_long(const String& str) {
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}
38
39double definp_double(const String& str) {
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}
54
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}
70
71long set_position(const String& word, std::istream& istrm, int s_rewind,
72 int s_req_sep) {
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}
113
114void remove_end_comments(std::istream& istr, String commark,
115 DynLinArr<char>& istring) {
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}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#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
long get_qel(void) const
Definition: AbsArr.h:420
void put_qel(long fqel)
Definition: AbsArr.h:774
double definp_double(const String &str)
Definition: definp.cpp:39
long set_position(const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
Definition: definp.cpp:71
long definp_long(const String &str)
Definition: definp.cpp:23
String definp_String(const String &str)
Definition: definp.cpp:55
int definp_int(const String &str)
Definition: definp.cpp:7
void remove_end_comments(std::istream &istr, String commark, DynLinArr< char > &istring)
Definition: definp.cpp:114
int findmark(std::istream &file, const char *s)
Definition: findmark.cpp:18
int findmark_b(std::istream &file, T ws, long qws, long &nbeg, long &nnext, char &prev)
Definition: findmark.h:105
#define mcout
Definition: prstream.h:133
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216