aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/qpdf/QPDF_Array.hh
blob: 4762bb6ef4af3f2ff9b87971142ff416b1fcbc03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef QPDF_ARRAY_HH
#define QPDF_ARRAY_HH

#include <qpdf/QPDFValue.hh>

#include <map>
#include <vector>

class QPDF_Array: public QPDFValue
{
  public:
    virtual ~QPDF_Array() = default;
    static std::shared_ptr<QPDFObject>
    create(std::vector<QPDFObjectHandle> const& items);
    static std::shared_ptr<QPDFObject>
    create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse);
    virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
    virtual std::string unparse();
    virtual JSON getJSON(int json_version);
    virtual void disconnect();

    int
    size() const noexcept
    {
        return sparse ? sp_size : int(elements.size());
    }
    QPDFObjectHandle at(int n) const noexcept;
    bool setAt(int n, QPDFObjectHandle const& oh);
    std::vector<QPDFObjectHandle> getAsVector() const;
    void setFromVector(std::vector<QPDFObjectHandle> const& items);
    bool insert(int at, QPDFObjectHandle const& item);
    void push_back(QPDFObjectHandle const& item);
    bool erase(int at);

  private:
    QPDF_Array();
    QPDF_Array(QPDF_Array const&);
    QPDF_Array(std::vector<QPDFObjectHandle> const& items);
    QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse);

    void checkOwnership(QPDFObjectHandle const& item) const;

    bool sparse{false};
    int sp_size{0};
    std::map<int, std::shared_ptr<QPDFObject>> sp_elements;
    std::vector<std::shared_ptr<QPDFObject>> elements;
};

#endif // QPDF_ARRAY_HH