- Create special definitions for
- default constructor
- copy constructor
- assign operator
- Use common macros for method signature lines instead of own copies
- Add definitions for any {public,protected,private}_functions
Details
Details
- Reviewers
mwolff - Group Reviewers
KDevelop - Commits
- R32:e2ce6d9f2846: Implicitly shared class template: improve method declarations
Diff Detail
Diff Detail
- Repository
- R32 KDevelop
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Comment Actions
Example result, for class name = "KDevelop::Foo", one member "QString bar", all default methods enabled:
foo.cpp (updated to latest version):
#include "foo.h" #include <QSharedData> using namespace KDevelop; class KDevelop::FooData : public QSharedData { public: QString bar; }; Foo::Foo() : d(new FooData()) { } Foo::Foo(const Foo& other) : d(other.d) { } Foo::~Foo() { } Foo& Foo::operator=(const Foo& other) { d = other.d; return *this; } QString Foo::bar() const { return d->bar; } void Foo::setBar(const QString& bar) { d->bar = bar; }
Respective foo.h, as before:
#ifndef KDEVELOP_FOO_H #define KDEVELOP_FOO_H #include <QSharedDataPointer> namespace KDevelop { class FooData; /** * @todo write docs */ class Foo { public: /** * Default constructor */ Foo(); /** * Copy Constructor * * @param other TODO */ Foo(const Foo& other); /** * Destructor */ ~Foo(); /** * @todo write docs * * @param other TODO * @return TODO */ Foo& operator=(const Foo& other); public: /** * @return the bar */ QString bar() const; /** * Sets the bar. * * @param bar the new bar */ void setBar(const QString& bar); private: QSharedDataPointer<FooData> d; }; } #endif // KDEVELOP_FOO_H
Comment Actions
http://doc.qt.io/qt-5/qshareddatapointer.html -> your change looks sane for *explicitly* shared data members, but not for implicit ones which will call detach in non-const operator->() automatically
this also means that your setter will always detach, the equality check is really not needed and just code noise.
Comment Actions
Eek, was not aware of that automatic detach for non-const methods. Will have to check some code of mine then :) Though first update of this patch...
Comment Actions
- remove useless explicit detach
- remove no-change check (optimization only depending on usage)
- simplify operator= code, rely on self-check of QSharedDataPointer