--- a/src/types.h Mon Jun 01 17:06:13 2015 +0300 +++ b/src/types.h Fri Jun 05 18:33:51 2015 +0300 @@ -1,6 +1,6 @@ /* * ZCinema: Zandronum demo launcher - * Copyright (C) 2013 Santeri Piippo + * Copyright (C) 2013-2015 Teemu Piippo * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,19 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef ZCINEMA_TYPES_H -#define ZCINEMA_TYPES_H - +#pragma once #include "main.h" #include <QString> #include <QList> #include <QVariant> -typedef QString str; template<class T> using list = QList<T>; -typedef unsigned int uint; -typedef unsigned short ushort; -typedef unsigned long ulong; template<class T> using initlist = std::initializer_list<T>; using std::size_t; @@ -45,85 +39,21 @@ typedef void FILE; #endif -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -// StringFormatArg -// -// Converts a given value into a string that can be retrieved with ::value (). -// Used as the argument type to the formatting functions, hence its name. -// ============================================================================= -class StringFormatArg { -public: - StringFormatArg (const str& v); - StringFormatArg (const char& v); - StringFormatArg (const uchar& v); - StringFormatArg (const QChar& v); - -#define NUMERIC_FORMAT_ARG(T,C) \ - StringFormatArg (const T& v) { \ - char valstr[32]; \ - sprintf (valstr, "%" #C, v); \ - m_val = valstr; \ - } - - NUMERIC_FORMAT_ARG (int, d) - NUMERIC_FORMAT_ARG (short, d) - NUMERIC_FORMAT_ARG (long, ld) - NUMERIC_FORMAT_ARG (uint, u) - NUMERIC_FORMAT_ARG (ushort, u) - NUMERIC_FORMAT_ARG (ulong, lu) - - StringFormatArg (const float& v); - StringFormatArg (const double& v); - StringFormatArg (const char* v); - StringFormatArg (const void* v); - - template<class T> StringFormatArg (const list<T>& v) { - m_val = "{ "; - uint i = 0; - const bool isString = typeid (T) == typeid (str); - - for (const T& it : v) { - if (i++) - m_val += ", "; - - StringFormatArg arg (it); - - if (isString) - m_val += "\"" + arg.value() + "\""; - else - m_val += arg.value(); - } - - if (i) - m_val += " "; - - m_val += "}"; - } - - str value() const { - return m_val; - } -private: - str m_val; +struct ZandronumVersion +{ + ZandronumVersion (QString name, bool isRelease, QString binaryPath) : + name (name), + binaryPath (binaryPath), + isRelease (isRelease) {} + + ZandronumVersion() : + isRelease (false) {} + + QString name; + QString binaryPath; + bool isRelease; }; -// Formatter function -str doFormat (initlist<StringFormatArg> args); - -// printf replacement -void doPrint (FILE* fp, initlist<StringFormatArg> args); +Q_DECLARE_METATYPE (ZandronumVersion) +typedef QList<ZandronumVersion> VersionList; -// Macros to access these functions -#ifndef IN_IDE_PARSER -# define fmt(...) doFormat({ __VA_ARGS__ }) -# define print(...) doPrint (stdout, { __VA_ARGS__ }) -# define fprint(FP, ...) doPrint (FP, { __VA_ARGS__ }) -#else -str fmt (const char* fmtstr, ...); -void print (const char* fmtstr, ...); -void fprint (FILE* fp, const char* fmtstr, ...); -#endif - -#endif // ZCINEMA_TYPES_H \ No newline at end of file