1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/******************************************************************************
*
* package: Log4Qt
* file: properties.h
* created: September
* author: Martin Heinrich
*
*
* Copyright 2007 Martin Heinrich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef LOG4QT_PROPERTIES_H
#define LOG4QT_PROPERTIES_H
#include "../log4qtshared.h"
/******************************************************************************
* Dependencies
******************************************************************************/
#include <QtCore/QHash>
#include <QtCore/QStringList>
/******************************************************************************
* Declarations
******************************************************************************/
class QIODevice;
class QSettings;
namespace Log4Qt
{
/*!
* \brief The class Properties implements a JAVA property hash.
*/
class LOG4QT_EXPORT Properties : public QHash<QString, QString>
{
public:
Properties(Properties *pDefaultProperties = 0);
// virtual ~Properties(); // Use compiler default
// Properties(const Properties &rOther); // Use compiler default
// Properties &operator=(const Properties &rOther); // Not implemented
public:
Properties *defaultProperties() const;
QString property(const QString &rKey) const;
QString property(const QString &rKey,
const QString &rDefaultValue) const;
void setDefaultProperties(Properties *pDefault);
void setProperty(const QString &rKey,
const QString &rValue);
// JAVA: void list(QTextStream &rTextStream);
void load(QIODevice *pDevice);
/*!
* Reads all child keys from the QSettings object \a rSettings and
* inserts them into this object. The value is created using
* QVariant::toString(). Types that do not support toString() are
* resulting in an empty string.
*
* \code
* QSettings settings;
* settings.setValue("Package", "Full");
* settings.setValue("Background", Qt::white);
* settings.setValue("Support", true);
* settings.setValue("Help/Language", "en_UK");
*
* Properties properties
* properties.load(&settings)
*
* // properties (("Package", "Full"), ("Background", ""), ("Support", "true"))
* \endcode
*/
void load(const QSettings &rSettings);
QStringList propertyNames() const;
// JAVA: void save(QIODevice *pDevice) const;
private:
void parseProperty(const QString &rProperty,
int line);
static int hexDigitValue(const QChar &rDigit);
static QString trimLeft(const QString &rString);
private:
Properties *mpDefaultProperties;
static const char msEscapeChar;
static const char *msValueEscapeCodes;
static const char *msValueEscapeChars;
static const char *msKeyEscapeCodes;
static const char *msKeyEscapeChars;
};
/**************************************************************************
* Operators, Helper
**************************************************************************/
#ifndef QT_NO_DEBUG_STREAM
/*!
* \relates Properties
*
* Writes all object member variables to the given debug stream \a rDebug and
* returns the stream.
*
* <tt>
* %Properties(default:0x0 properties:QHash(("log4j.appender.testAppender.layout", "org.apache.log4j.PatternLayout ")
* ("log4j.appender.testAppender.layout.ConversionPattern", "[%t] %-5p %l: %m%n")
* ("log4j.appender.testAppender.Append", "false ")
* ("log4j.appender.testAppender.File", "output/temp ")
* ("log4j.rootCategory", "TRACE, testAppender")
* ("log4j.appender.testAppender", "org.apache.log4j.FileAppender")) )
* </tt>
* \sa QDebug
*/
QDebug operator<<(QDebug debug,
const Properties &rProperties);
#endif // QT_NO_DEBUG_STREAM
/**************************************************************************
* Inline
**************************************************************************/
inline Properties::Properties(Properties *pDefaultProperties) :
mpDefaultProperties(pDefaultProperties)
{}
inline Properties *Properties::defaultProperties() const
{ return mpDefaultProperties; }
inline void Properties::setDefaultProperties(Properties *pDefaultProperties)
{ mpDefaultProperties = pDefaultProperties; }
inline void Properties::setProperty(const QString &rKey,
const QString &rValue)
{ insert(rKey, rValue); }
} // namespace Log4Qt
Q_DECLARE_TYPEINFO(Log4Qt::Properties, Q_MOVABLE_TYPE);
#endif // LOG4QT_PROPERTIES_H
|