src/Format.h

Mon, 10 Mar 2014 14:12:28 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 10 Mar 2014 14:12:28 +0200
changeset 698
16e6d7d87982
parent 651
747e84062279
child 654
a74f2ff353b8
permissions
-rw-r--r--

- refactor

645
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
1 /*
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
2 * LDForge: LDraw parts authoring CAD
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
4 *
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
5 * This program is free software: you can redistribute it and/or modify
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
6 * it under the terms of the GNU General Public License as published by
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
8 * (at your option) any later version.
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
9 *
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
10 * This program is distributed in the hope that it will be useful,
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
13 * GNU General Public License for more details.
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
14 *
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
15 * You should have received a copy of the GNU General Public License
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
17 */
c0708f2d22b3 - added license header to format.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 644
diff changeset
18
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #pragma once
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QString>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "Types.h"
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
651
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
23 //! \file Format.h
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
24 //! Contains string formatting-related functions and classes.
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
25
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 //! Converts a given value into a string that can be retrieved with text().
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 //! Used as the argument type to the formatting functions, hence its name.
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 class StringFormatArg
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 public:
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 StringFormatArg (const QString& a) : m_text (a) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 StringFormatArg (const char& a) : m_text (a) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 StringFormatArg (const uchar& a) : m_text (a) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 StringFormatArg (const QChar& a) : m_text (a) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 StringFormatArg (int a) : m_text (QString::number (a)) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 StringFormatArg (const float& a) : m_text (QString::number (a)) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 StringFormatArg (const double& a) : m_text (QString::number (a)) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 StringFormatArg (const Vertex& a) : m_text (a.toString (false)) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 StringFormatArg (const Matrix& a) : m_text (a.toString()) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 StringFormatArg (const char* a) : m_text (a) {}
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 StringFormatArg (const void* a)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 m_text.sprintf ("%p", a);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 template<typename T>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 StringFormatArg (const QList<T>& a)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 m_text = "{";
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 for (const T& it : a)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 if (&it != &a.first())
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 m_text += ", ";
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 StringFormatArg arg (it);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 m_text += arg.text();
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 m_text += "}";
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 inline QString text() const
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 return m_text;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 private:
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 QString m_text;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 };
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 //!
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
76 //! Helper function for \c format
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 template<typename Arg1, typename... Rest>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 void formatHelper (QString& str, Arg1 arg1, Rest... rest)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 str = str.arg (StringFormatArg (arg1).text());
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 formatHelper (str, rest...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 //!
651
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
86 //! Overload of \c formatHelper() with no template args
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 static void formatHelper (QString& str) __attribute__ ((unused));
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 static void formatHelper (QString& str)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 (void) str;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 //!
651
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
95 //! @brief Format the message with the given args.
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
96 //!
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
97 //! The formatting ultimately uses QString's arg() method to actually format
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
98 //! the args so the format string should be prepared accordingly, with %1
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
99 //! referring to the first arg, %2 to the second, etc.
747e84062279 - doxygenified Version.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 650
diff changeset
100 //!
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
101 //! \param fmtstr The string to format
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
102 //! \param args The args to format with
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
103 //! \return The formatted string
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 template<typename... Args>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 QString format (QString fmtstr, Args... args)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 formatHelper (fmtstr, args...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 return fmtstr;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 //! From MessageLog.cc - declared here so that I don't need to include
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 //! MessageLog.h here. Prints the given message to log.
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 void printToLog (const QString& msg);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 //! Format and print the given args to the message log.
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
120 //! \param fmtstr The string to format
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
121 //! \param args The args to format with
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 template<typename... Args>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 void print (QString fmtstr, Args... args)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 formatHelper (fmtstr, args...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 printToLog (fmtstr);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 //! Format and print the given args to the given file descriptor
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
132 //! \param fp The file descriptor to print to
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
133 //! \param fmtstr The string to format
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
134 //! \param args The args to format with
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 template<typename... Args>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 void fprint (FILE* fp, QString fmtstr, Args... args)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 formatHelper (fmtstr, args...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 fprintf (fp, "%s", qPrintable (fmtstr));
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 //!
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
144 //! Overload of \c fprint with a QIODevice
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
145 //! \param dev The IO device to print to
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
146 //! \param fmtstr The string to format
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
147 //! \param args The args to format with
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 template<typename... Args>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 void fprint (QIODevice& dev, QString fmtstr, Args... args)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 formatHelper (fmtstr, args...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 dev.write (fmtstr.toUtf8());
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 }
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 //! Exactly like print() except no-op in release builds.
650
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
158 //! \param fmtstr The string to format
db7146a87ae4 - changed doxygen entity style from @argh to \argh
Santeri Piippo <crimsondusk64@gmail.com>
parents: 645
diff changeset
159 //! \param args The args to format with
644
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 //!
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 template<typename... Args>
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 void dprint (QString fmtstr, Args... args)
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 {
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 #ifndef RELEASE
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 formatHelper (fmtstr, args...);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 printToLog (fmtstr);
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 #else
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 (void) fmtstr;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 (void) args;
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 #endif
93dcd1a0e4bd - replaced the fmt/log/dlog/fprint macros in favor of template functions. renamed to format, print, dprint and fprint respectively.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 }

mercurial