1// Aseprite Document Library
2// Copyright (c) 2019 Igara Studio S.A.
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifndef DOC_TILESETS_H_INCLUDED
8#define DOC_TILESETS_H_INCLUDED
9#pragma once
10
11#include "doc/tileset.h"
12
13#include <vector>
14
15namespace doc {
16
17 class Tilesets : public Object {
18 public:
19 typedef std::vector<Tileset*> Array;
20 typedef Array::iterator iterator;
21 typedef Array::const_iterator const_iterator;
22
23 Tilesets();
24 ~Tilesets();
25
26 int getMemSize() const override;
27
28 iterator begin() { return m_tilesets.begin(); }
29 iterator end() { return m_tilesets.end(); }
30 const_iterator begin() const { return m_tilesets.begin(); }
31 const_iterator end() const { return m_tilesets.end(); }
32 tileset_index size() const { return (tileset_index)m_tilesets.size(); }
33
34 tileset_index add(Tileset* tileset);
35
36 Tileset* get(const tileset_index tsi) {
37 if (tsi < size())
38 return m_tilesets[tsi];
39 else
40 return nullptr;
41 }
42
43 void set(const tileset_index tsi, Tileset* tileset) {
44 if (tsi >= m_tilesets.size())
45 m_tilesets.resize(tsi+1, nullptr);
46 m_tilesets[tsi] = tileset;
47 }
48
49 void erase(const tileset_index tsi) {
50 // Do not m_tilesets.erase() the tileset so other tilesets
51 // indexes/IDs are kept intact.
52 if (tsi == size()-1)
53 m_tilesets.erase(--m_tilesets.end());
54 else
55 m_tilesets[tsi] = nullptr;
56 }
57
58 private:
59 Array m_tilesets;
60 };
61
62} // namespace doc
63
64#endif
65