1 // Aseprite 2 // Copyright (C) 2001-2015 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_CRASH_INTERNALS_H_INCLUDED 8 #define APP_CRASH_INTERNALS_H_INCLUDED 9 #pragma once 10 11 #include "doc/object.h" 12 13 #include <algorithm> 14 #include <functional> 15 #include <map> 16 17 namespace app { 18 namespace crash { 19 20 const uint32_t MAGIC_NUMBER = 0x454E4946; // 'FINE' in ASCII 21 22 class ObjVersions { 23 public: ObjVersions()24 ObjVersions() { 25 m_vers[0] = 0; 26 m_vers[1] = 0; 27 m_vers[2] = 0; 28 } 29 size()30 size_t size() const { return 3; } 31 doc::ObjectVersion operator[](int i) const { return m_vers[i]; } 32 newer()33 doc::ObjectVersion newer() { return m_vers[0]; } older()34 doc::ObjectVersion older() { return m_vers[2]; } 35 36 // Adds a newer version rotateRevisions(doc::ObjectVersion newer)37 void rotateRevisions(doc::ObjectVersion newer) { 38 // Rotate versions 39 m_vers[2] = m_vers[1]; 40 m_vers[1] = m_vers[0]; 41 m_vers[0] = newer; 42 } 43 44 // Adds a version (we don't know if the version if the latest one) add(doc::ObjectVersion ver)45 void add(doc::ObjectVersion ver) { 46 auto minver = std::min_element(m_vers, m_vers+2); 47 if (*minver < ver) { 48 *minver = ver; 49 std::sort(m_vers, m_vers+2, std::greater<doc::ObjectVersion>()); 50 } 51 } 52 53 private: 54 doc::ObjectVersion m_vers[3]; 55 }; 56 57 typedef std::map<doc::ObjectId, ObjVersions> ObjVersionsMap; 58 59 } // namespace crash 60 } // namespace app 61 62 #endif 63