File indexing completed on 2025-01-26 04:07:39

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_OFFSET_KEEPER_H
0008 #define __KIS_OFFSET_KEEPER_H
0009 
0010 #include "kritapsdutils_export.h"
0011 
0012 #include <QIODevice>
0013 #include <kis_debug.h>
0014 
0015 /**
0016  * Restore the offset of the io device on exit from the current
0017  * namespace
0018  */
0019 
0020 class KisOffsetKeeper
0021 {
0022 public:
0023     KisOffsetKeeper(QIODevice &device)
0024         : m_device(device)
0025     {
0026         m_expectedPos = m_device.pos();
0027     }
0028 
0029     ~KisOffsetKeeper()
0030     {
0031         if (m_device.pos() != m_expectedPos) {
0032             m_device.seek(m_expectedPos);
0033         }
0034     }
0035 
0036 private:
0037     QIODevice &m_device;
0038     qint64 m_expectedPos;
0039 };
0040 
0041 #endif /* __KIS_OFFSET_KEEPER_H */