2
This file is part of the Grantlee template system.
4
Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2 of the Licence, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
27
std::cout << "QString operation 1" << std::endl;
31
std::cout << "QString operation 2" << std::endl;
39
QVariant(const QString &) {
40
std::cout << "QVariant::QVariant(QString)" << std::endl;
44
class SafeString : public QString
47
operator QVariant() const {
48
std::cout << "SafeString::operator QVariant()" << std::endl;
53
class WrappingSafeString
56
WrappingSafeString() {}
58
WrappingSafeString(const QString &) {
59
std::cout << "WrappingSafeString::WrappingSafeString(QString)" << std::endl;
62
operator QVariant() const {
63
std::cout << "WrappingSafeString::operator QVariant()" << std::endl;
67
operator QString() const {
68
std::cout << "WrappingSafeString::operator QString()" << std::endl;
73
class WrappingSubclassSafeString
76
WrappingSubclassSafeString() : m_isSafe(false), m_wrappedSubclass(this) {}
78
WrappingSubclassSafeString(const QString &) : m_isSafe(false), m_wrappedSubclass(this) {
79
std::cout << "WrappingSubclassSafeString::WrappingSubclassSafeString(QString)" << std::endl;
82
bool isSafe() const { return m_isSafe; };
83
void setSafe(bool safe) { m_isSafe = safe; }
85
class Subclass : public QString
87
friend class WrappingSubclassSafeString;
88
Subclass(WrappingSubclassSafeString *wsss) : m_wsss(wsss) {}
89
WrappingSubclassSafeString *m_wsss;
94
m_wsss->m_isSafe = false;
95
std::cout << "overridden string operation 2 (wrapping)" << std::endl;
99
Subclass m_wrappedSubclass;
101
Subclass* operator->()
103
return &m_wrappedSubclass;
106
operator QVariant() const {
107
std::cout << "WrappingSubclassSafeString::operator QVariant()" << std::endl;
111
operator QString() const {
112
std::cout << "WrappingSubclassSafeString::operator QString()" << std::endl;
113
return m_wrappedSubclass;
120
class UsingSafeString : private QString
124
UsingSafeString(const QString &) {}
127
std::cout << "overridden string operation 2 (using)" << std::endl;
130
using QString::operation1;
152
return WrappingSafeString();
156
return WrappingSafeString();
159
WrappingSafeString f5() {
164
return WrappingSubclassSafeString();
168
return WrappingSubclassSafeString();
171
WrappingSubclassSafeString f8() {
178
return UsingSafeString();
182
return UsingSafeString();
185
UsingSafeString f11() {
191
int main(int argc, char ** argv)
207
WrappingSubclassSafeString wsss;
210
std::cout << ( wsss.isSafe() ? "IsSafe" : "IsNotSafe" ) << std::endl;
212
std::cout << ( wsss.isSafe() ? "IsSafe" : "IsNotSafe" ) << std::endl;