mirror of
https://github.com/RGBCube/serenity
synced 2025-06-02 15:08:15 +00:00

IndirectValueRef is so simple that it can be stored directly in the Value class instead of being heap allocated. As the comment in Value says, however, in theory the max bits needed to store is 48 (16 for the generation index and 32(?) for the object index), but 32 should be good enough for now. We can increase it to u64 later if necessary.
65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
/*
|
|
* 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();
|
|
}
|
|
|
|
}
|