Some clean-up and simplification for JobObject class.
[MUtilities.git] / src / Version.cpp
blob739233f06fcc37f54cdbb745171145597230692d
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
22 //MUtils
23 #include <MUtils/Version.h>
24 #include <MUtils/Global.h>
25 #include <MUtils/Exception.h>
26 #include <MUtils/OSSupport.h>
28 //Internal
29 #define MUTILS_INC_CONFIG 1
30 #include "Config.h"
32 ///////////////////////////////////////////////////////////////////////////////
33 // HELPER FUNCTIONS
34 ///////////////////////////////////////////////////////////////////////////////
36 static const char *g_months_lut[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
38 static int month_str2int(const char *str)
40 int ret = 0;
42 for(int j = 0; j < 12; j++)
44 if(!_strnicmp(str, g_months_lut[j], 3))
46 ret = j+1;
47 break;
51 return ret;
54 static const QDate decode_date_str(const char *const date_str) //Mmm dd yyyy
56 int date[3] = {0, 0, 0};
58 if(sscanf_s(date_str, "%*3s %2d %4d", &date[2], &date[0]) != 2)
60 MUTILS_THROW("Internal error: Date format could not be recognized!");
63 if((date[1] = month_str2int(date_str)) < 1)
65 MUTILS_THROW("Internal error: Date format could not be recognized!");
68 //qWarning("MUtils::Version::build_date: y=%d, m=%d, d=%d", date[0], date[1], date[2]);
69 return QDate(date[0], date[1], date[2]);
72 static const QTime decode_time_str(const char *const time_str) //hh:mm:ss
74 int time[3] = {0, 0, 0};
76 if(sscanf_s(time_str, "%2d:%2d:%2d", &time[0], &time[1], &time[2]) != 3)
78 MUTILS_THROW("Internal error: Time format could not be recognized!");
81 //qWarning("MUtils::Version::build_date: h=%d, m=%d, s=%d", time[0], time[1], time[2]);
82 return QTime(time[0], time[1], time[2]);
85 ///////////////////////////////////////////////////////////////////////////////
86 // LIB VERSION
87 ///////////////////////////////////////////////////////////////////////////////
89 const QDate MUtils::Version::lib_build_date(void)
91 static const char *const BUILD_DATE = __DATE__;
92 return decode_date_str(BUILD_DATE);
95 const QTime MUtils::Version::lib_build_time(void)
97 static const char *const BUILD_TIME = __TIME__;
98 return decode_time_str(BUILD_TIME);
101 const quint32 &MUtils::Version::lib_version_major(void)
103 static const quint32 VERSION_MAJOR = VER_MUTILS_MAJOR;
104 return VERSION_MAJOR;
107 const quint32 &MUtils::Version::lib_version_minor(void)
109 static const quint32 VERSION_MINOR = (10 * VER_MUTILS_MINOR_HI) + VER_MUTILS_MINOR_LO;
110 return VERSION_MINOR;
114 ///////////////////////////////////////////////////////////////////////////////
115 // APP VERSION
116 ///////////////////////////////////////////////////////////////////////////////
118 const QDate MUtils::Version::app_build_date(const char *const date_str)
120 return decode_date_str(date_str);
123 const QTime MUtils::Version::app_build_time(const char *const time_str)
125 return decode_time_str(time_str);
128 ///////////////////////////////////////////////////////////////////////////////