General Purpose Geodetic Library
SgVersion.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 
24 #include <QtCore/QDataStream>
25 #include <QtCore/QString>
26 #include <QtCore/QStringList>
27 #include <QtCore/QRegExp>
28 
29 
30 #include <SgLogger.h>
31 #include <SgMJD.h>
32 #include <SgVersion.h>
33 
34 
35 /*=====================================================================================================*/
36 //
37 // common variable:
38 //
39 SgVersion libraryVersion( "SgLib", 0, 7, 5,
40  "Tuscarora (rc1)",
41  SgMJD( 2022, 2, 18,
42  17, 34));
43 /*=====================================================================================================*/
44 
45 
46 
47 
48 /*=======================================================================================================
49 *
50 * METHODS:
51 *
52 *======================================================================================================*/
53 //
54 QString SgVersion::name(NameFormat fmt) const
55 {
56  QString name;
57  switch (fmt)
58  {
59  case NF_Human:
60  name.sprintf("%s-%1d.%d.%d",
62  if (codeName_.size())
63  name += " (" + codeName_ + ")";
64  break;
65  case NF_Cylon:
66  break;
67  case NF_Petrov:
68  name.sprintf("%s %s",
69  qPrintable(softwareName_), qPrintable(releaseEpoch_.toString(SgMJD::F_YYYYMMDDDD)));
70  break;
71  };
72  return name;
73 };
74 
75 
76 
77 //
79 {
81  if (s.status() != QDataStream::Ok)
82  {
84  ": saveIntermediateResults(): error writting data");
85  return false;
86  };
88  {
90  ": saveIntermediateResults(): error writting data for the epoch");
91  return false;
92  };
93  return s.status() == QDataStream::Ok;
94 };
95 
96 
97 
98 //
100 {
101  QString softwareName, codeName;
102  int majorNumber, minorNumber, teenyNumber;
103  SgMJD releaseEpoch;
104  //
105  s >> softwareName >> majorNumber >> minorNumber >> teenyNumber >> codeName;
106  if (s.status() != QDataStream::Ok)
107  {
109  ": loadIntermediateResults(): error reading data: " +
110  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
111  return false;
112  };
114  {
116  ": loadIntermediateResults(): error reading data for the epoch: " +
117  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
118  return false;
119  };
120  if (getSoftwareName() != softwareName)
121  {
123  ": loadIntermediateResults(): error reading data: wrong order, name mismatch: got [" +
124  softwareName + "], expected [" + getSoftwareName() + "]");
125  return false;
126  };
127  setSoftwareName(softwareName);
128  setMajorNumber(majorNumber);
129  setMinorNumber(minorNumber);
130  setTeenyNumber(teenyNumber);
131  setCodeName(codeName);
132  setReleaseEpoch(releaseEpoch);
133  //
134  return s.status()==QDataStream::Ok;
135 };
136 
137 
138 
139 //
140 bool SgVersion::parseString(const QString& str)
141 {
142  bool isOk;
143  QRegExp reIsStdName("(.+)-(\\d+\\.\\d+\\.\\d+)\\s+\\(\\s*(.+)\\s*\\).*");
144 
145  isOk = false;
146 
147  if (reIsStdName.indexIn(str) != -1)
148  {
149  QStringList lst=reIsStdName.cap(2).split(".");
150  majorNumber_ = lst.at(0).toInt(&isOk);
151  if (isOk)
152  {
153  minorNumber_ = lst.at(1).toInt(&isOk);
154  if (isOk)
155  {
156  teenyNumber_ = lst.at(2).toInt(&isOk);
157  softwareName_ = reIsStdName.cap(1);
158  codeName_ = reIsStdName.cap(3);
159  };
160  };
161  };
162  return isOk;
163 };
164 /*=======================================================================================================
165 *
166 * FRIENDS:
167 *
168 *======================================================================================================*/
169 //
170 
171 
172 
173 /*=====================================================================================================*/
174 //
175 // aux functions:
176 //
177 
178 
179 
180 // i/o:
181 
182 
183 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
SgVersion libraryVersion("SgLib", 0, 7, 5, "Tuscarora (rc1)", SgMJD(2022, 2, 18, 17, 34))
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_BIN
Definition: SgLogger.h:64
Definition: SgMJD.h:59
@ F_YYYYMMDDDD
Digits, date and seconds: 20100402613636.
Definition: SgMJD.h:71
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1007
bool saveIntermediateResults(QDataStream &) const
Definition: SgMJD.cpp:1314
bool loadIntermediateResults(QDataStream &)
Definition: SgMJD.cpp:1329
@ NF_Human
Definition: SgVersion.h:57
@ NF_Cylon
Definition: SgVersion.h:58
@ NF_Petrov
Definition: SgVersion.h:59
void setTeenyNumber(int)
Definition: SgVersion.h:328
bool loadIntermediateResults(QDataStream &)
Definition: SgVersion.cpp:99
void setCodeName(const QString &)
Definition: SgVersion.h:336
bool saveIntermediateResults(QDataStream &) const
Definition: SgVersion.cpp:78
const QString & getSoftwareName() const
Definition: SgVersion.h:254
QString codeName_
Definition: SgVersion.h:178
void setReleaseEpoch(const SgMJD &)
Definition: SgVersion.h:344
SgMJD releaseEpoch_
Definition: SgVersion.h:179
int minorNumber_
Definition: SgVersion.h:176
QString className() const
Definition: SgVersion.h:125
QString name(NameFormat fmt=NF_Human) const
Definition: SgVersion.cpp:54
void setMinorNumber(int)
Definition: SgVersion.h:320
QString softwareName_
Definition: SgVersion.h:174
void setMajorNumber(int)
Definition: SgVersion.h:312
void setSoftwareName(const QString &)
Definition: SgVersion.h:304
int teenyNumber_
Definition: SgVersion.h:177
int majorNumber_
Definition: SgVersion.h:175
bool parseString(const QString &str)
Definition: SgVersion.cpp:140