Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
findmark.h File Reference

Go to the source code of this file.

Functions

int findmark (std::istream &file, const char *s)
 
template<class T >
int findmark_a (std::istream &file, T ws, long qws, long &nbeg, long &nnext)
 
template<class T >
int findmark_b (std::istream &file, T ws, long qws, long &nbeg, long &nnext, char &prev)
 
int findmark_other_repeat (std::istream &file, std::ostream &outfile, const char *s)
 
int find1ofnmark (std::istream &file, int q, char *s[])
 
int find1ofnmark (std::istream &file, int q, const String str[])
 

Function Documentation

◆ find1ofnmark() [1/2]

int find1ofnmark ( std::istream &  file,
int  q,
char *  s[] 
)

Definition at line 89 of file findmark.cpp.

89 {
90 //mcout<<"find1ofnmark is started\n";
91 //char c;
92 int ic;
93 int *l = new int[q];
94 int *pos_fs = new int[q];
95 int s_init_pos_fs = 0;
96 int i;
97 int l_max = -1;
98 for (i = 0; i < q; i++) {
99 l[i] = strlen(s[i]); // length does not include end symbol
100 if (l[i] > l_max) l_max = l[i];
101 }
102 //l_max++;
103 //Iprintn(mcout, q);
104 //Iprintn(mcout, l_max);
105 char *fs = new char[l_max + 1];
106 //int qfs=0; // number of symbols in fs
107 for (i = 0; i < q; i++) {
108 pos_fs[i] = l_max;
109 }
110 fs[l_max] = '\0';
111 //Iprintn(mcout, file.good());
112 //Iprintn(mcout, file.eof());
113 //Iprintn(mcout, file.fail());
114 //Iprintn(mcout, file.bad());
115 //mcout<<"State:"<< file.rdstate() <<'\n';
116 while ((ic = file.get()) != EOF) {
117 //Iprintn(mcout, ic);
118 for (i = 1; i < l_max; i++) {
119 fs[i - 1] = fs[i];
120 }
121 fs[l_max - 1] = ic; // new symbol
122 if (s_init_pos_fs == 0) { // shift positions
123 int ss = 1;
124 for (i = 0; i < q; i++) {
125 if (l_max - pos_fs[i] < l[i]) {
126 pos_fs[i]--;
127 ss = 0;
128 //mcout<<"s[i]="<<s[i]<<'\n';
129 //mcout<<"i="<<i<<" l_max="<<l_max<<" pos_fs[i]="<<pos_fs[i]
130 // <<" l[i]="<<l[i]<<" "<< &(fs[ pos_fs[i] ])<<'\n';
131 }
132 }
133 if (ss == 1) s_init_pos_fs = 1;
134 }
135 for (i = 0; i < q; i++) {
136 if (strcmp(&(fs[pos_fs[i]]), s[i]) == 0) {
137 delete[] l;
138 delete[] fs;
139 delete[] pos_fs;
140 return i;
141 }
142 }
143 }
144 //Iprintn(mcout, ic);
145 delete[] l;
146 delete[] fs;
147 delete[] pos_fs;
148 return -1;
149}

Referenced by find1ofnmark().

◆ find1ofnmark() [2/2]

int find1ofnmark ( std::istream &  file,
int  q,
const String  str[] 
)

Definition at line 151 of file findmark.cpp.

153 {
154 char **s = new char *[q];
155 int i;
156 for (i = 0; i < q; i++) {
157#ifdef USE_STLSTRING
158 s[i] = new char[strlen(str[i].c_str()) + 1];
159 strcpy(s[i], str[i].c_str());
160//Iprint(mcout, s[i]);
161#else
162 s[i] = new char[strlen(str[i]) + 1];
163 strcpy(s[i], str[i]);
164#endif
165 }
166 int iret = find1ofnmark(file, q, s);
167 for (i = 0; i < q; i++) {
168 delete[] s[i];
169 }
170 delete[] s;
171 return iret;
172}
int find1ofnmark(std::istream &file, int q, char *s[])
Definition: findmark.cpp:89

◆ findmark()

int findmark ( std::istream &  file,
const char *  s 
)

Definition at line 18 of file findmark.cpp.

18 {
19 int ic;
20 int l = strlen(s); // length does not include end symbol
21 int n;
22 char *fs = new char[l + 1];
23 for (n = 0; n < l; n++) {
24 if ((ic = file.get()) == EOF) {
25 delete[] fs;
26 return 0;
27 } else {
28 fs[n] = ic;
29 }
30 }
31 fs[l] = '\0';
32 while (strcmp(fs, s) != 0) {
33 for (n = 1; n < l; n++)
34 fs[n - 1] = fs[n];
35 if ((ic = file.get()) == EOF) {
36 delete[] fs;
37 return 0;
38 }
39 fs[l - 1] = ic;
40 fs[l] = '\0';
41 }
42 delete[] fs;
43 return 1;
44}

Referenced by definp_double(), definp_int(), definp_long(), definp_String(), Heed::ElElasticScat::ElElasticScat(), Heed::ElElasticScatLowSigma::ElElasticScatLowSigma(), Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS(), and Heed::SimpleAtomPhotoAbsCS::SimpleAtomPhotoAbsCS().

◆ findmark_a()

template<class T >
int findmark_a ( std::istream &  file,
ws,
long  qws,
long &  nbeg,
long &  nnext 
)

Definition at line 48 of file findmark.h.

50 {
51 mfunname("int findmark_a(...)");
52 check_econd11(qws, < 1, mcerr);
53 //check_econd12(qws , > , ws.get_qel() , mcerr);
54
55 nbeg = 0;
56 nnext = 0;
57
58 char* s = new char[qws + 1];
59 long n;
60 for (n = 0; n < qws; n++) {
61 s[n] = ws[n];
62 }
63 s[qws] = '\0';
64 int ic;
65
66 char* fs = new char[qws + 1];
67 for (n = 0; n < qws; n++) {
68 if (file.eof() == 1) {
69 delete[] fs;
70 delete[] s;
71 return 0;
72 } else {
73 ic = file.get();
74 fs[n] = ic;
75 }
76 }
77 // if ((ic = file.get()) == EOF) {delete fs; return 0;}
78 // else fs[n] = ic;
79 fs[qws] = '\0';
80 nnext = qws;
81
82 while (strcmp(fs, s) != 0) {
83 for (n = 1; n < qws; n++)
84 fs[n - 1] = fs[n];
85 if (file.eof() == 1) {
86 delete[] fs;
87 delete[] s;
88 return 0;
89 } else {
90 ic = file.get();
91 }
92 //if((ic=file.get())==EOF) { delete fs; return 0; }
93 fs[qws - 1] = ic;
94 //fs[qws]='\0';
95 nbeg++;
96 nnext++;
97 //cout<<fs<<'\n';
98 }
99 delete[] fs;
100 delete[] s;
101 return 1;
102}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunname(string)
Definition: FunNameStack.h:67
#define mcerr
Definition: prstream.h:135

◆ findmark_b()

template<class T >
int findmark_b ( std::istream &  file,
ws,
long  qws,
long &  nbeg,
long &  nnext,
char &  prev 
)

Definition at line 105 of file findmark.h.

107 {
108 mfunname("int findmark_b(...)");
109 check_econd11(qws, < 1, mcerr);
110 //check_econd12(qws , > , ws.get_qel() , mcerr);
111
112 nbeg = 0;
113 nnext = 0;
114 //char c;
115 prev = '\0';
116
117 char* s = new char[qws + 1];
118 long n;
119 for (n = 0; n < qws; n++) {
120 s[n] = ws[n];
121 }
122 s[qws] = '\0';
123 int ic;
124 //int l=strlen(s); // length does not include end symbol
125 //cout<<"l="<<l<<'\n';
126
127 char* fs = new char[qws + 1];
128 for (n = 0; n < qws; n++) {
129 if (file.eof() == 1) {
130 //mcout<<"eof at:\n";
131 //Iprintn(mcout, n);
132 delete[] fs;
133 delete[] s;
134 return 0;
135 } else {
136 ic = file.get();
137 fs[n] = ic;
138 }
139 }
140 // if ((ic = file.get()) == EOF) {delete fs; return 0;}
141 // else fs[n] = ic;
142 fs[qws] = '\0';
143 nnext = qws;
144
145 while (strcmp(fs, s) != 0) {
146 prev = fs[0];
147 for (n = 1; n < qws; n++)
148 fs[n - 1] = fs[n];
149 if (file.eof() == 1) {
150 //mcout<<"eof at:\n";
151 //Iprint2n(mcout, nbeg, nnext);
152 delete[] fs;
153 delete[] s;
154 return 0;
155 } else {
156 ic = file.get();
157 }
158 //if((ic=file.get())==EOF) { delete fs; return 0; }
159 fs[qws - 1] = ic;
160 //fs[qws]='\0';
161 nbeg++;
162 nnext++;
163 }
164 //mcout<<"mark found\n";
165 delete[] fs;
166 delete[] s;
167 return 1;
168}

Referenced by set_position().

◆ findmark_other_repeat()

int findmark_other_repeat ( std::istream &  file,
std::ostream &  outfile,
const char *  s 
)

Definition at line 46 of file findmark.cpp.

47 {
48 int ic;
49 int l = strlen(s); // length does not include end symbol
50 int n;
51 char *fs = new char[l + 1];
52 for (n = 0; n < l; n++) {
53 if ((ic = file.get()) == EOF) {
54 fs[n] = ic;
55 outfile.write(fs, n + 1);
56 delete[] fs;
57 return 0;
58 } else {
59 fs[n] = ic;
60 }
61 }
62 fs[l] = '\0';
63 int s_not_new_line = 0;
64 while (strcmp(fs, s) != 0) {
65 if (fs[0] != '\n') {
66 if ((fs[0] == '\t' || fs[0] == ' ') && s_not_new_line == 0) {
67 ;
68 } else {
69 s_not_new_line = 1;
70 outfile.put(fs[0]);
71 }
72 } else {
73 if (s_not_new_line == 1) outfile.put(fs[0]); // to finish valid line
74 s_not_new_line = 0; // to avoid switching to new line with empty old one
75 }
76 for (n = 1; n < l; n++)
77 fs[n - 1] = fs[n];
78 if ((ic = file.get()) == EOF) {
79 delete[] fs;
80 return 0;
81 }
82 fs[l - 1] = ic;
83 fs[l] = '\0';
84 }
85 delete[] fs;
86 return 1;
87}