GCC Code Coverage Report


./
File: src/XpertMass/CrossLinkerSpec.cpp
Date: 2024-08-24 11:26:06
Lines:
0/51
0.0%
Functions:
0/9
0.0%
Branches:
0/60
0.0%

Line Branch Exec Source
1 /* BEGIN software license
2 *
3 * MsXpertSuite - mass spectrometry software suite
4 * -----------------------------------------------
5 * Copyright(C) 2009,...,2018 Filippo Rusconi
6 *
7 * http://www.msxpertsuite.org
8 *
9 * This file is part of the MsXpertSuite project.
10 *
11 * The MsXpertSuite project is the successor of the massXpert project. This
12 * project now includes various independent modules:
13 *
14 * - massXpert, model polymer chemistries and simulate mass spectrometric data;
15 * - mineXpert, a powerful TIC chromatogram/mass spectrum viewer/miner;
16 *
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * END software license
31 */
32
33
34 /////////////////////// Qt includes
35 #include <QFile>
36 #include <QDebug>
37
38
39 /////////////////////// Local includes
40 #include "CrossLinkerSpec.hpp"
41
42
43 namespace MsXpS
44 {
45
46 namespace libXpertMass
47 {
48
49
50 /*!
51 \class MsXpS::libXpertMass::CrossLinkerSpec
52 \inmodule libXpertMass
53 \ingroup PolChemDefBuildingdBlocks
54 \inheaderfile CrossLinkerSpec.hpp
55
56 \brief The CrossLinkerSpec class provides the specification about how \l
57 CrossLinker objects are represented.
58
59 The CrossLinkerSpec class specifies how a \l CrossLinker object is represented
60 graphically, mainly by connecting its name to a graphics SVG file that
61 is located in the Polymer chemistry definition directory. That connection is
62 performed in the "cross_linker_dictionary" dictionary file itself also located
63 in the polymer chemistry definition directory. Its contents look like this:
64
65 \code
66 DisulfideBond%disulfidebond-cross-link.svg
67 CFP-chromophore%cfp-chromophore.svg
68 \endcode
69
70 The \c{DisulfideBond%disulfidebond-cross-link.svg} line indicates that, when a
71 CrossLinker object by name "DisulfideBond" is
72 to be rendered graphically, the corresponding vignette to be used is in the
73 file named "disulfidebond-cross-link.svg" in the polymer chemistry definition
74 directory.
75 */
76
77
78 /*!
79 \variable int MsXpS::libXpertMass::CrossLinkerSpec::m_name
80
81 \brief The name of the cross-linker.
82 */
83
84 /*!
85 \variable int MsXpS::libXpertMass::CrossLinkerSpec::m_vector
86
87 \brief The filename of the vector representation of the cross-linker.
88 */
89
90 /*!
91 \variable int MsXpS::libXpertMass::CrossLinkerSpec::m_sound
92
93 \brief The file name of the sound for the cross-linker.
94 */
95
96
97 /*!
98 \brief Constructs a CrossLinkerSpec instance.
99 */
100 CrossLinkerSpec::CrossLinkerSpec()
101 {
102 }
103
104 /*!
105 \brief Destructs this CrossLinkerSpec instance.
106 */
107 CrossLinkerSpec::~CrossLinkerSpec()
108 {
109 }
110
111 /*!
112 \brief Sets the cross-linker \a name.
113 */
114 void
115 CrossLinkerSpec::setName(const QString &name)
116 {
117 m_name = name;
118 }
119
120 /*
121 \brief Gets the cross-linker name.
122 */
123 const QString &
124 CrossLinkerSpec::name()
125 {
126 return m_name;
127 }
128
129
130 /*!
131 \brief Sets the vector image file name to \a vector.
132 */void
133 CrossLinkerSpec::setVector(const QString &vector)
134 {
135 m_vector = vector;
136 }
137
138
139 /*!
140 \brief Returns the vector image file name.
141 */
142 const QString &
143 CrossLinkerSpec::vector()
144 {
145 return m_vector;
146 }
147
148
149 /*!
150 \brief Sets the file name of the CrossLinkerSpec's \a sound file.
151 */
152 void
153 CrossLinkerSpec::setSound(const QString &sound)
154 {
155 m_sound = sound;
156 }
157
158
159 /*!
160 \brief Returns the file name of the CrossLinkerSpec's sound file.
161 */
162 const QString &
163 CrossLinkerSpec::sound()
164 {
165 return m_sound;
166 }
167
168
169 /*!
170 \brief Parses the \a file_path dictionary containing the \l CrossLinker
171 specifications.
172
173 At the moment the file has this format:
174
175 \code
176 DisulfideBond%disulfidebond-cross-link.svg
177 CFP-chromophore%cfp-chromophore.svg
178 \endcode
179
180 Upon parsing, the \a cross_linker_spec_list of CrossLinkerSpec instances will
181 be filled with
182 instances created on the basis of each parsed line in the file.
183
184 Returns true if the parsing was successful, false otherwise.
185 */
186 bool
187 CrossLinkerSpec::parseFile(QString &file_path,
188 QList<CrossLinkerSpec *> *cross_linker_spec_list)
189 {
190 CrossLinkerSpec *crossLinkerSpec = 0;
191
192 qint64 lineLength;
193
194 QString line;
195 QString temp;
196
197 char buffer[1024];
198
199 int percentSignIdx = 0;
200
201 Q_ASSERT(cross_linker_spec_list != 0);
202
203 if(file_path.isEmpty())
204 return false;
205
206 QFile file(file_path);
207
208 if(!file.open(QFile::ReadOnly))
209 return false;
210
211 // The lines we have to parse are of the following type:
212 // DisulfideBon%disulfidebond.svg
213 // Any line starting with ' ' or '#' are not parsed.
214
215 // Get the first line of the file. Next we enter in to a
216 // while loop.
217
218 lineLength = file.readLine(buffer, sizeof(buffer));
219
220 while(lineLength != -1)
221 {
222 // The line is now in buffer, and we want to convert
223 // it to Unicode by setting it in a QString.
224 line = buffer;
225
226 // The line that is in line should contain something like:
227 // DisulfideBon%disulfidebond.svg
228 //
229 // Note, however that lines beginning with either '\n'(newline)
230 // or '#' are comments.
231
232 // Remove all the spaces from the borders: Whitespace means any
233 // character for which QChar::isSpace() returns true. This
234 // includes the ASCII characters '\t', '\n', '\v', '\f', '\r',
235 // and ' '.
236
237 line = line.trimmed();
238
239 if(line.isEmpty() || line.startsWith('#', Qt::CaseInsensitive))
240 {
241 lineLength = file.readLine(buffer, sizeof(buffer));
242 continue;
243 }
244
245 // Now some other checks. Remember the format of the line:
246 // DisulfideBon%disulfidebond.svg
247
248 percentSignIdx = line.indexOf('%', 0, Qt::CaseInsensitive);
249
250 if(percentSignIdx == -1 || line.count('%', Qt::CaseInsensitive) > 2)
251 return false;
252
253 // OK, we finally can allocate a new CrossLinkerSpec *.
254 crossLinkerSpec = new CrossLinkerSpec();
255
256 crossLinkerSpec->m_name = line.left(percentSignIdx);
257
258 // Remove from the line the "DisulfideBond%" substring, as we
259 // do not need it anymore.
260 line.remove(0, percentSignIdx + 1);
261
262 // Now we can go on with the graphics files stuff. At this point
263 // all that remains up to the end of the line is the filename
264 // with extension .svg.
265
266 if(!line.endsWith(".svg", Qt::CaseSensitive))
267 {
268 delete crossLinkerSpec;
269 return false;
270 }
271
272 // Ok that's done, we can get the vector graphics filename:
273
274 crossLinkerSpec->m_vector = line;
275
276 cross_linker_spec_list->append(crossLinkerSpec);
277
278 // Continue to next line to further parse the file.
279 lineLength = file.readLine(buffer, sizeof(buffer));
280 }
281
282 return true;
283 }
284
285 } // namespace libXpertMass
286
287 } // namespace MsXpS
288