D5709: Implicitly shared class template: improve method declarations

Friedrich W. H. Kossebau noreply at phabricator.kde.org
Thu May 4 12:57:15 UTC 2017


kossebau added a comment.


  Example result, for class name = "Foo", one member "QString bar", all default methods enabled:
  
  foo.cpp:
  
    #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)
    {
        if (this != &other) {
            d = other.d;
        }
    
        return *this;
    }
    
    QString Foo::bar() const
    {
        return d->bar;
    }
    
    void Foo::setBar(const QString& bar)
    {
        if (d->bar == bar) {
            return;
        }
    
        d.detach();
        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

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D5709

To: kossebau, #kdevelop
Cc: kdevelop-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170504/8abd22f6/attachment.html>


More information about the KDevelop-devel mailing list