1// Aseprite
2// Copyright (C) 2018 Igara Studio S.A.
3// Copyright (c) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_DOCS_H_INCLUDED
9#define APP_DOCS_H_INCLUDED
10#pragma once
11
12#include "app/docs_observer.h"
13#include "base/disable_copying.h"
14#include "doc/color_mode.h"
15#include "doc/object_id.h"
16#include "obs/observable.h"
17
18#include <vector>
19
20namespace app {
21
22 class Context;
23 class Doc;
24
25 class Docs : public obs::observable<DocsObserver> {
26 public:
27 typedef std::vector<Doc*>::iterator iterator;
28 typedef std::vector<Doc*>::const_iterator const_iterator;
29
30 Docs(Context* ctx);
31 ~Docs();
32
33 iterator begin() { return m_docs.begin(); }
34 iterator end() { return m_docs.end(); }
35 const_iterator begin() const { return m_docs.begin(); }
36 const_iterator end() const { return m_docs.end(); }
37
38 Doc* front() const { return m_docs.front(); }
39 Doc* back() const { return m_docs.back(); }
40 Doc* lastAdded() const { return front(); }
41
42 int size() const { return (int)m_docs.size(); }
43 bool empty() const { return m_docs.empty(); }
44
45 // Add a new documents to the list.
46 Doc* add(Doc* doc);
47
48 // Easy function for testing
49 Doc* add(int width, int height,
50 doc::ColorMode colorMode = doc::ColorMode::RGB,
51 int ncolors = 256);
52
53 // Removes a document from the list without deleting it. You must
54 // to delete the document after removing it.
55 void remove(Doc* doc);
56
57 // Moves the document to the given location in the same
58 // list. E.g. It is used to reorder documents when they are
59 // selected as active.
60 void move(Doc* doc, int index);
61
62 Doc* operator[](int index) const { return m_docs[index]; }
63 Doc* getById(doc::ObjectId id) const;
64 Doc* getByName(const std::string& name) const;
65 Doc* getByFileName(const std::string& filename) const;
66
67 private:
68 // Deletes all documents in the list (calling "delete" operation).
69 void deleteAll();
70
71 Context* m_ctx;
72 std::vector<Doc*> m_docs;
73
74 DISABLE_COPYING(Docs);
75 };
76
77} // namespace app
78
79#endif
80