<commit_before>/*
    Copyright (C) 2009-2010  <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QGLIB_TYPE_H
#define QGLIB_TYPE_H

#include "global.h"
#include <QtCore/QList>

namespace QGlib {

/*! \headerfile type.h <QGlib/Type>
 * \brief Wrapper class for GType
 *
 * A GType is a numerical value which represents the unique identifier
 * of a registered type. The GType API is the foundation of the GObject system.
 * It provides the facilities for registering and managing all fundamental data types,
 * user-defined object and interface types.
 *
 * As a wrapper, this class provides only methods for querying existing types,
 * not registering new ones. You should never need to use it directly, although
 * it might come in handy in some cases.
 *
 * To retrieve a Type for a certain class, use GetType().
 *
 * \note This class is a thin wrapper around an unsigned long. There is no overhead
 * in copying it around, since it is just an integer.
 */
class Type
{
public:
    enum FundamentalType {
        Invalid = 0,
        None = 1<<2,
        Interface = 2<<2,
        Char = 3<<2,
        Uchar = 4<<2,
        Boolean = 5<<2,
        Int = 6<<2,
        Uint = 7<<2,
        Long = 8<<2,
        Ulong = 9<<2,
        Int64 = 10<<2,
        Uint64 = 11<<2,
        Enum = 12<<2,
        Flags = 13<<2,
        Float = 14<<2,
        Double = 15<<2,
        String = 16<<2,
        Pointer = 17<<2,
        Boxed = 18<<2,
        Param = 19<<2,
        Object = 20<<2
    };

    inline Type() : m_type(0) {}
    inline Type(unsigned long gtype) : m_type(gtype) {}
    inline Type(FundamentalType ftype) : m_type(ftype) {}
    inline Type(const Type & other) : m_type(other.m_type) {}

    inline Type & operator=(Type other);
    inline bool operator==(Type other) const;
    inline operator unsigned long() const { return m_type; }

    template<class T>
    static Type fromInstance(const RefPointer<T> & instance);
    static Type fromInstance(void *nativeInstance);
    static Type fromName(const char *name);

    QString name() const;
    Quark qname() const;

    bool isAbstract() const;
    bool isDerived() const;
    bool isFundamental() const;
    bool isValueType() const;
    bool hasValueTable() const;
    bool isClassed() const;
    bool isInstantiatable() const;
    bool isDerivable() const;
    bool isDeepDerivable() const;
    bool isInterface() const;

    FundamentalType fundamental() const;
    Type parent() const;
    uint depth() const;
    Type nextBase(Type rootType) const;
    bool isA(Type is_a_type) const;

    QList<Type> children() const;
    QList<Type> interfaces() const;
    QList<Type> interfacePrerequisites() const;

    void *quarkData(const Quark & qname) const;
    void setQuarkData(const Quark & qname, void *data);

private:
    unsigned long m_type;
};

inline Type & Type::operator=(Type other)
{
    m_type = other.m_type;
    return *this;
}

inline bool Type::operator==(Type other) const
{
    return m_type == other.m_type;
}

template <class T>
Type Type::fromInstance(const RefPointer<T> & instance)
{
    return fromInstance(static_cast<void*>(static_cast<typename T::CType*>(instance)));
}

//***************
// -- GetType --
//***************<commit_msg>Add a GType definition and make it have the same size/signature as the C GType.<commit_after>/*
    Copyright (C) 2009-2010  <NAME> <<EMAIL>>
    Copyright (C) 2010 Collabora Ltd.
      @author <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QGLIB_TYPE_H
#define QGLIB_TYPE_H

#include "global.h"
#include <QtCore/QList>
#include <boost/mpl/if.hpp>

/*
 * This is a re-definition of GType inside the QGlib::Private namespace.
 * It is used in the headers to avoid including <glib-object.h>.
 *
 * According to gtype.h, GType is ulong in C++ for historic reasons,
 * but only if sizeof(size_t) == sizeof(ulong). This template trick
 * here attempts to express the same logic wigh C++ templates.
 */
namespace QGlib {
namespace Private {
    typedef boost::mpl::if_c<
        sizeof(size_t) == sizeof(unsigned long),
        unsigned long,
        QIntegerForSizeof<size_t>::Unsigned
    >::type GType;
} //namespace Private
} //namespace QGlib

namespace QGlib { //closing and re-opening namespace QGlib is required to trick codegen

/*! \headerfile type.h <QGlib/Type>
 * \brief Wrapper class for GType
 *
 * A GType is a numerical value which represents the unique identifier
 * of a registered type. The GType API is the foundation of the GObject system.
 * It provides the facilities for registering and managing all fundamental data types,
 * user-defined object and interface types.
 *
 * As a wrapper, this class provides only methods for querying existing types,
 * not registering new ones. You should never need to use it directly, although
 * it might come in handy in some cases.
 *
 * To retrieve a Type for a certain class, use GetType().
 *
 * \note This class is a thin wrapper around an unsigned long. There is no overhead
 * in copying it around, since it is just an integer.
 */
class Type
{
public:
    enum FundamentalType {
        Invalid = 0,
        None = 1<<2,
        Interface = 2<<2,
        Char = 3<<2,
        Uchar = 4<<2,
        Boolean = 5<<2,
        Int = 6<<2,
        Uint = 7<<2,
        Long = 8<<2,
        Ulong = 9<<2,
        Int64 = 10<<2,
        Uint64 = 11<<2,
        Enum = 12<<2,
        Flags = 13<<2,
        Float = 14<<2,
        Double = 15<<2,
        String = 16<<2,
        Pointer = 17<<2,
        Boxed = 18<<2,
        Param = 19<<2,
        Object = 20<<2
    };

    inline Type() : m_type(0) {}
    inline Type(Private::GType gtype) : m_type(gtype) {}
    inline Type(FundamentalType ftype) : m_type(ftype) {}
    inline Type(const Type & other) : m_type(other.m_type) {}

    inline Type & operator=(Type other);
    inline bool operator==(Type other) const;
    inline operator Private::GType() const { return m_type; }

    template<class T>
    static Type fromInstance(const RefPointer<T> & instance);
    static Type fromInstance(void *nativeInstance);
    static Type fromName(const char *name);

    QString name() const;
    Quark qname() const;

    bool isAbstract() const;
    bool isDerived() const;
    bool isFundamental() const;
    bool isValueType() const;
    bool hasValueTable() const;
    bool isClassed() const;
    bool isInstantiatable() const;
    bool isDerivable() const;
    bool isDeepDerivable() const;
    bool isInterface() const;

    FundamentalType fundamental() const;
    Type parent() const;
    uint depth() const;
    Type nextBase(Type rootType) const;
    bool isA(Type is_a_type) const;

    QList<Type> children() const;
    QList<Type> interfaces() const;
    QList<Type> interfacePrerequisites() const;

    void *quarkData(const Quark & qname) const;
    void setQuarkData(const Quark & qname, void *data);

private:
    Private::GType m_type;
};

inline Type & Type::operator=(Type other)
{
    m_type = other.m_type;
    return *this;
}

inline bool Type::operator==(Type other) const
{
    return m_type == other.m_type;
}

template <class T>
Type Type::fromInstance(const RefPointer<T> & instance)
{
    return fromInstance(static_cast<void*>(static_cast<typename T::CType*>(instance)));
}

//***************
// -- GetType --
//***************
{'fraction_non_alphanumeric': 0.10684357541899442, 'fraction_numerical': 0.01606145251396648, 'mean_word_length': 3.0609640831758034, 'pattern_counts': {'":': 0, '<': 120, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2080568', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2513, 'n_words': 968}