JournallingObject.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * JournallingObject.h - declaration of class JournallingObject
  3. *
  4. * Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef JOURNALLING_OBJECT_H
  25. #define JOURNALLING_OBJECT_H
  26. #include <QtCore/QStack>
  27. #include "lmms_basics.h"
  28. #include "SerializingObject.h"
  29. class LMMS_EXPORT JournallingObject : public SerializingObject
  30. {
  31. public:
  32. JournallingObject();
  33. virtual ~JournallingObject();
  34. inline jo_id_t id() const
  35. {
  36. return m_id;
  37. }
  38. void saveJournallingState( const bool newState )
  39. {
  40. m_journallingStateStack.push( m_journalling );
  41. m_journalling = newState;
  42. }
  43. void restoreJournallingState()
  44. {
  45. if( !isJournallingStateStackEmpty())
  46. {
  47. m_journalling = m_journallingStateStack.pop();
  48. }
  49. }
  50. void addJournalCheckPoint();
  51. virtual QDomElement saveState( QDomDocument & _doc,
  52. QDomElement & _parent ) override;
  53. void restoreState( const QDomElement & _this ) override;
  54. inline bool isJournalling() const
  55. {
  56. return m_journalling;
  57. }
  58. inline void setJournalling( const bool _sr )
  59. {
  60. m_journalling = _sr;
  61. }
  62. inline bool testAndSetJournalling( const bool newState )
  63. {
  64. const bool oldJournalling = m_journalling;
  65. m_journalling = newState;
  66. return oldJournalling;
  67. }
  68. bool isJournallingStateStackEmpty() const
  69. {
  70. return m_journallingStateStack.isEmpty();
  71. }
  72. protected:
  73. void changeID( jo_id_t _id );
  74. private:
  75. jo_id_t m_id;
  76. bool m_journalling;
  77. QStack<bool> m_journallingStateStack;
  78. } ;
  79. #endif