"Fossies" - the Fresh Open Source Software Archive

Member "kaffeine-2.0.18/src/shareddata.h" (14 May 2019, 2089 Bytes) of package /linux/misc/kaffeine-2.0.18.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "shareddata.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.0.16_vs_2.0.17.

    1 /*
    2  * shareddata.h
    3  *
    4  * Copyright (C) 2011 Christoph Pfister <christophpfister@gmail.com>
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * This program 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
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License along
   17  * with this program; if not, write to the Free Software Foundation, Inc.,
   18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19  */
   20 
   21 #ifndef SHAREDDATA_H
   22 #define SHAREDDATA_H
   23 
   24 #include <QSharedData>
   25 
   26 class SharedData : public QSharedData
   27 {
   28 public:
   29     SharedData() { }
   30     SharedData(const SharedData &sh) : QSharedData(sh) { }
   31     ~SharedData() { }
   32 
   33     SharedData &operator=(const SharedData &)
   34     {
   35         return *this;
   36     }
   37 };
   38 
   39 template<class T> class ExplicitlySharedDataPointer
   40 {
   41 public:
   42     explicit ExplicitlySharedDataPointer(T *data_ = NULL) : data(data_) { }
   43     ~ExplicitlySharedDataPointer() { }
   44 
   45     bool isValid() const
   46     {
   47         return (data.constData() != NULL);
   48     }
   49 
   50     const T *constData() const
   51     {
   52         return data.constData();
   53     }
   54 
   55     const T &operator*() const
   56     {
   57         return *data;
   58     }
   59 
   60     const T *operator->() const
   61     {
   62         return data.constData();
   63     }
   64 
   65     bool operator==(const ExplicitlySharedDataPointer<T> &other) const
   66     {
   67         return (data.constData() == other.data.constData());
   68     }
   69 
   70     bool operator!=(const ExplicitlySharedDataPointer<T> &other) const
   71     {
   72         return (data.constData() != other.data.constData());
   73     }
   74 
   75     bool operator<(const ExplicitlySharedDataPointer<T> &other) const
   76     {
   77         return (data.constData() < other.data.constData());
   78     }
   79 
   80     friend uint qHash(const ExplicitlySharedDataPointer<T> &pointer)
   81     {
   82         return qHash(pointer.data.constData());
   83     }
   84 
   85 private:
   86     QExplicitlySharedDataPointer<T> data;
   87 };
   88 
   89 #endif /* SHAREDDATA_H */