diff --git a/src/engine/documentid.h b/src/engine/documentid.h new file mode 100644 --- /dev/null +++ b/src/engine/documentid.h @@ -0,0 +1,56 @@ +/* + * This file is part of the KDE Baloo Project + * Copyright 2018 Michael Heidelbach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 General Public License + * along with this program. If not, see . + */ + +#ifndef DOCUMENTID_H +#define DOCUMENTID_H + +#include "engine_export.h" +#include + +using DeviceId = quint32; +using Inode = quint32; +using DeviceIdAndInode = quint64; + +namespace Baloo { + +class BALOO_ENGINE_EXPORT DocumentId +{ +public: + DocumentId(); + DocumentId(const DeviceId dev, const Inode ino); + DocumentId(const DeviceIdAndInode combinedId); + //TODO: DocumentId(const QT_STATBUF& stBuf); + ~DocumentId(); + + operator DeviceIdAndInode() const; + + DocumentId operator=(const DeviceIdAndInode devino); + DocumentId operator=(const DocumentId& id); + + Inode inode(); + DeviceId deviceId(); +private: + DeviceId m_device; + Inode m_inode; +}; +} + +#endif // DOCUMENTID_H diff --git a/src/engine/documentid.cpp b/src/engine/documentid.cpp new file mode 100644 --- /dev/null +++ b/src/engine/documentid.cpp @@ -0,0 +1,113 @@ +/* + * This file is part of the KDE Baloo Project + * Copyright 2018 Michael Heidelbach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 General Public License + * along with this program. If not, see . + */ + +#include "documentid.h" + +using namespace Baloo; + +DocumentId::DocumentId() +{ + +} + +DocumentId::DocumentId(const DeviceId dev, const Inode ino) + :m_device(dev), + m_inode(ino) +{ + +} + +DocumentId::DocumentId(const DeviceIdAndInode combinedId) + : m_device(static_cast(combinedId >> 4)), + m_inode(static_cast(combinedId)) +{ +} + + +DocumentId::~DocumentId() +{ + +} + +DocumentId DocumentId::operator=(const DocumentId& id) +{ + return DocumentId(id.m_device, id.m_inode); +} + +DocumentId DocumentId::operator=(const DeviceIdAndInode devino) +{ + return DocumentId(devino); +} + +DocumentId::operator DeviceIdAndInode() const +{ + return (m_device << 4) | m_inode; +} + +// FIXME: +#if(0) +// Due to operator DeviceIdAndInode(), apparently the following +// became obsolete. + +bool DocumentId::operator==(const DocumentId& other) const +{ + return other.m_device == m_device + && other.m_inode == m_inode; +} + +bool DocumentId::operator!=(const DocumentId& other) const +{ + return other.m_device != m_device + || other.m_inode != m_inode; +} + +bool DocumentId::operator==(const DeviceIdAndInode combinedId) const +{ + return static_cast(combinedId >> 4) == m_device + && static_cast(combinedId >> 4) == m_inode; +} + +bool DocumentId::operator!=(const DeviceIdAndInode combinedId) const +{ + return static_cast(combinedId >> 4) != m_device + || static_cast(combinedId >> 4) != m_inode; +} + +bool DocumentId::operator>(const DeviceIdAndInode combinedId) const +{ + DeviceId dev = static_cast(combinedId >> 4); + DeviceId ino = static_cast(combinedId); + return dev > m_device + || ( dev == m_device && ino > m_inode); +} +#endif + +DeviceId DocumentId::deviceId() +{ + return m_device; +} + +Inode DocumentId::inode() +{ + return m_inode; +} + +