2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-09-27 20:49:06 +00:00

Rename QPDFObject::shallowCopy to copy

Add optional parameter shallow. Change logic errors to runtime errors.
This commit is contained in:
m-holger 2022-11-14 17:54:12 +00:00 committed by Jay Berkenbilt
parent 34a6f8938f
commit dbc5f07b90
31 changed files with 34 additions and 34 deletions

View File

@ -2223,7 +2223,7 @@ QPDFObjectHandle::shallowCopyInternal(
QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream"); QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream");
throw std::runtime_error("attempt to make a shallow copy of a stream"); throw std::runtime_error("attempt to make a shallow copy of a stream");
} }
new_obj = QPDFObjectHandle(obj->shallowCopy()); new_obj = QPDFObjectHandle(obj->copy(true));
std::set<QPDFObjGen> visited; std::set<QPDFObjGen> visited;
new_obj.copyObject(visited, false, first_level_only, false); new_obj.copyObject(visited, false, first_level_only, false);
@ -2268,7 +2268,7 @@ QPDFObjectHandle::copyObject(
if (isBool() || isInteger() || isName() || isNull() || isReal() || if (isBool() || isInteger() || isName() || isNull() || isReal() ||
isString()) { isString()) {
new_obj = obj->shallowCopy(); new_obj = obj->copy(true);
} else if (isArray()) { } else if (isArray()) {
std::vector<QPDFObjectHandle> items; std::vector<QPDFObjectHandle> items;
auto array = asArray(); auto array = asArray();

View File

@ -29,7 +29,7 @@ QPDF_Array::create(SparseOHArray const& items)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Array::shallowCopy() QPDF_Array::copy(bool shallow)
{ {
return create(elements); return create(elements);
} }

View File

@ -13,7 +13,7 @@ QPDF_Bool::create(bool value)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Bool::shallowCopy() QPDF_Bool::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -15,7 +15,7 @@ QPDF_Destroyed::getInstance()
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Destroyed::shallowCopy() QPDF_Destroyed::copy(bool shallow)
{ {
throw std::logic_error( throw std::logic_error(
"attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); "attempted to shallow copy QPDFObjectHandle from destroyed QPDF");

View File

@ -16,7 +16,7 @@ QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Dictionary::shallowCopy() QPDF_Dictionary::copy(bool shallow)
{ {
return create(items); return create(items);
} }

View File

@ -13,7 +13,7 @@ QPDF_InlineImage::create(std::string const& val)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_InlineImage::shallowCopy() QPDF_InlineImage::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -15,7 +15,7 @@ QPDF_Integer::create(long long value)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Integer::shallowCopy() QPDF_Integer::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -17,7 +17,7 @@ QPDF_Name::create(std::string const& name)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Name::shallowCopy() QPDF_Name::copy(bool shallow)
{ {
return create(name); return create(name);
} }

View File

@ -12,7 +12,7 @@ QPDF_Null::create()
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Null::shallowCopy() QPDF_Null::copy(bool shallow)
{ {
return create(); return create();
} }

View File

@ -13,7 +13,7 @@ QPDF_Operator::create(std::string const& val)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Operator::shallowCopy() QPDF_Operator::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -29,7 +29,7 @@ QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Real::shallowCopy() QPDF_Real::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -14,7 +14,7 @@ QPDF_Reserved::create()
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Reserved::shallowCopy() QPDF_Reserved::copy(bool shallow)
{ {
return create(); return create();
} }

View File

@ -140,9 +140,9 @@ QPDF_Stream::create(
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Stream::shallowCopy() QPDF_Stream::copy(bool shallow)
{ {
throw std::logic_error("stream objects cannot be cloned"); throw std::runtime_error("stream objects cannot be cloned");
} }
void void

View File

@ -37,7 +37,7 @@ QPDF_String::create_utf16(std::string const& utf8_val)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_String::shallowCopy() QPDF_String::copy(bool shallow)
{ {
return create(val); return create(val);
} }

View File

@ -14,7 +14,7 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Unresolved::shallowCopy() QPDF_Unresolved::copy(bool shallow)
{ {
throw std::logic_error( throw std::logic_error(
"attempted to shallow copy an unresolved QPDFObjectHandle"); "attempted to shallow copy an unresolved QPDFObjectHandle");

View File

@ -24,9 +24,9 @@ class QPDFObject
QPDFObject() = default; QPDFObject() = default;
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
shallowCopy() copy(bool shallow = false)
{ {
return value->shallowCopy(); return value->copy(shallow);
} }
std::string std::string
unparse() unparse()

View File

@ -20,7 +20,7 @@ class QPDFValue
public: public:
virtual ~QPDFValue() = default; virtual ~QPDFValue() = default;
virtual std::shared_ptr<QPDFObject> shallowCopy() = 0; virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
virtual std::string unparse() = 0; virtual std::string unparse() = 0;
virtual JSON getJSON(int json_version) = 0; virtual JSON getJSON(int json_version) = 0;
virtual void virtual void

View File

@ -14,7 +14,7 @@ class QPDF_Array: public QPDFValue
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create(std::vector<QPDFObjectHandle> const& items); create(std::vector<QPDFObjectHandle> const& items);
static std::shared_ptr<QPDFObject> create(SparseOHArray const& items); static std::shared_ptr<QPDFObject> create(SparseOHArray const& items);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
virtual void disconnect(); virtual void disconnect();

View File

@ -8,7 +8,7 @@ class QPDF_Bool: public QPDFValue
public: public:
virtual ~QPDF_Bool() = default; virtual ~QPDF_Bool() = default;
static std::shared_ptr<QPDFObject> create(bool val); static std::shared_ptr<QPDFObject> create(bool val);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
bool getVal() const; bool getVal() const;

View File

@ -7,7 +7,7 @@ class QPDF_Destroyed: public QPDFValue
{ {
public: public:
virtual ~QPDF_Destroyed() = default; virtual ~QPDF_Destroyed() = default;
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
static std::shared_ptr<QPDFValue> getInstance(); static std::shared_ptr<QPDFValue> getInstance();

View File

@ -14,7 +14,7 @@ class QPDF_Dictionary: public QPDFValue
virtual ~QPDF_Dictionary() = default; virtual ~QPDF_Dictionary() = default;
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create(std::map<std::string, QPDFObjectHandle> const& items); create(std::map<std::string, QPDFObjectHandle> const& items);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
virtual void disconnect(); virtual void disconnect();

View File

@ -8,7 +8,7 @@ class QPDF_InlineImage: public QPDFValue
public: public:
virtual ~QPDF_InlineImage() = default; virtual ~QPDF_InlineImage() = default;
static std::shared_ptr<QPDFObject> create(std::string const& val); static std::shared_ptr<QPDFObject> create(std::string const& val);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
std::string getVal() const; std::string getVal() const;

View File

@ -8,7 +8,7 @@ class QPDF_Integer: public QPDFValue
public: public:
virtual ~QPDF_Integer() = default; virtual ~QPDF_Integer() = default;
static std::shared_ptr<QPDFObject> create(long long value); static std::shared_ptr<QPDFObject> create(long long value);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
long long getVal() const; long long getVal() const;

View File

@ -8,7 +8,7 @@ class QPDF_Name: public QPDFValue
public: public:
virtual ~QPDF_Name() = default; virtual ~QPDF_Name() = default;
static std::shared_ptr<QPDFObject> create(std::string const& name); static std::shared_ptr<QPDFObject> create(std::string const& name);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
std::string getName() const; std::string getName() const;

View File

@ -8,7 +8,7 @@ class QPDF_Null: public QPDFValue
public: public:
virtual ~QPDF_Null() = default; virtual ~QPDF_Null() = default;
static std::shared_ptr<QPDFObject> create(); static std::shared_ptr<QPDFObject> create();
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);

View File

@ -8,7 +8,7 @@ class QPDF_Operator: public QPDFValue
public: public:
virtual ~QPDF_Operator() = default; virtual ~QPDF_Operator() = default;
static std::shared_ptr<QPDFObject> create(std::string const& val); static std::shared_ptr<QPDFObject> create(std::string const& val);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
std::string getVal() const; std::string getVal() const;

View File

@ -10,7 +10,7 @@ class QPDF_Real: public QPDFValue
static std::shared_ptr<QPDFObject> create(std::string const& val); static std::shared_ptr<QPDFObject> create(std::string const& val);
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create(double value, int decimal_places, bool trim_trailing_zeroes); create(double value, int decimal_places, bool trim_trailing_zeroes);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
std::string getVal(); std::string getVal();

View File

@ -8,7 +8,7 @@ class QPDF_Reserved: public QPDFValue
public: public:
virtual ~QPDF_Reserved() = default; virtual ~QPDF_Reserved() = default;
static std::shared_ptr<QPDFObject> create(); static std::shared_ptr<QPDFObject> create();
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);

View File

@ -23,7 +23,7 @@ class QPDF_Stream: public QPDFValue
QPDFObjectHandle stream_dict, QPDFObjectHandle stream_dict,
qpdf_offset_t offset, qpdf_offset_t offset,
size_t length); size_t length);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
virtual void setDescription(QPDF*, std::string const&); virtual void setDescription(QPDF*, std::string const&);

View File

@ -14,7 +14,7 @@ class QPDF_String: public QPDFValue
static std::shared_ptr<QPDFObject> create(std::string const& val); static std::shared_ptr<QPDFObject> create(std::string const& val);
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create_utf16(std::string const& utf8_val); create_utf16(std::string const& utf8_val);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
std::string unparse(bool force_binary); std::string unparse(bool force_binary);
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);

View File

@ -8,7 +8,7 @@ class QPDF_Unresolved: public QPDFValue
public: public:
virtual ~QPDF_Unresolved() = default; virtual ~QPDF_Unresolved() = default;
static std::shared_ptr<QPDFObject> create(QPDF* qpdf, QPDFObjGen const& og); static std::shared_ptr<QPDFObject> create(QPDF* qpdf, QPDFObjGen const& og);
virtual std::shared_ptr<QPDFObject> shallowCopy(); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);