blob: a254d78ea07fa745c411446ac496477604534aee (
plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibPDF/Object.h>
#include <LibPDF/Value.h>
namespace PDF {
Value::~Value()
{
if (is_object())
m_as_object->unref();
}
Value& Value::operator=(const Value& other)
{
m_type = other.m_type;
switch (m_type) {
case Type::Null:
break;
case Type::Bool:
m_as_bool = other.m_as_bool;
break;
case Type::Int:
m_as_int = other.m_as_int;
break;
case Type::Float:
m_as_float = other.m_as_float;
break;
case Type::Ref:
m_as_ref = other.m_as_ref;
break;
case Type::Object:
m_as_object = other.m_as_object;
if (m_as_object)
m_as_object->ref();
break;
}
return *this;
}
String Value::to_string(int indent) const
{
switch (m_type) {
case Type::Null:
return "null";
case Type::Bool:
return as_bool() ? "true" : "false";
case Type::Int:
return String::number(as_int());
case Type::Float:
return String::number(as_float());
case Type::Ref:
return String::formatted("{} {} R", as_ref_index(), as_ref_generation_index());
case Type::Object:
return as_object()->to_string(indent);
}
VERIFY_NOT_REACHED();
}
}
|