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 File Reference
#include <cstdio>
#include "wcpplib/stream/definp.h"
#include "wcpplib/stream/findmark.h"

Go to the source code of this file.

Functions

int definp_int (const String &str)
 
long definp_long (const String &str)
 
double definp_double (const String &str)
 
String definp_String (const String &str)
 
long set_position (const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
 
void remove_end_comments (std::istream &istr, String commark, DynLinArr< char > &istring)
 

Function Documentation

◆ definp_double()

double definp_double ( const String str)

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
#define mfunnamep(string)
Definition: FunNameStack.h:77
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 mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216

◆ definp_int()

int definp_int ( const String str)

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)

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)

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}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
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>>().