Commit dbc5f07b90954c18445ebe725b1a445745726864

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 34a6f893

Rename QPDFObject::shallowCopy to copy

Add optional parameter shallow. Change logic errors to runtime errors.
libqpdf/QPDFObjectHandle.cc
@@ -2223,7 +2223,7 @@ QPDFObjectHandle::shallowCopyInternal( @@ -2223,7 +2223,7 @@ QPDFObjectHandle::shallowCopyInternal(
2223 QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream"); 2223 QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream");
2224 throw std::runtime_error("attempt to make a shallow copy of a stream"); 2224 throw std::runtime_error("attempt to make a shallow copy of a stream");
2225 } 2225 }
2226 - new_obj = QPDFObjectHandle(obj->shallowCopy()); 2226 + new_obj = QPDFObjectHandle(obj->copy(true));
2227 2227
2228 std::set<QPDFObjGen> visited; 2228 std::set<QPDFObjGen> visited;
2229 new_obj.copyObject(visited, false, first_level_only, false); 2229 new_obj.copyObject(visited, false, first_level_only, false);
@@ -2268,7 +2268,7 @@ QPDFObjectHandle::copyObject( @@ -2268,7 +2268,7 @@ QPDFObjectHandle::copyObject(
2268 2268
2269 if (isBool() || isInteger() || isName() || isNull() || isReal() || 2269 if (isBool() || isInteger() || isName() || isNull() || isReal() ||
2270 isString()) { 2270 isString()) {
2271 - new_obj = obj->shallowCopy(); 2271 + new_obj = obj->copy(true);
2272 } else if (isArray()) { 2272 } else if (isArray()) {
2273 std::vector<QPDFObjectHandle> items; 2273 std::vector<QPDFObjectHandle> items;
2274 auto array = asArray(); 2274 auto array = asArray();
libqpdf/QPDF_Array.cc
@@ -29,7 +29,7 @@ QPDF_Array::create(SparseOHArray const&amp; items) @@ -29,7 +29,7 @@ QPDF_Array::create(SparseOHArray const&amp; items)
29 } 29 }
30 30
31 std::shared_ptr<QPDFObject> 31 std::shared_ptr<QPDFObject>
32 -QPDF_Array::shallowCopy() 32 +QPDF_Array::copy(bool shallow)
33 { 33 {
34 return create(elements); 34 return create(elements);
35 } 35 }
libqpdf/QPDF_Bool.cc
@@ -13,7 +13,7 @@ QPDF_Bool::create(bool value) @@ -13,7 +13,7 @@ QPDF_Bool::create(bool value)
13 } 13 }
14 14
15 std::shared_ptr<QPDFObject> 15 std::shared_ptr<QPDFObject>
16 -QPDF_Bool::shallowCopy() 16 +QPDF_Bool::copy(bool shallow)
17 { 17 {
18 return create(val); 18 return create(val);
19 } 19 }
libqpdf/QPDF_Destroyed.cc
@@ -15,7 +15,7 @@ QPDF_Destroyed::getInstance() @@ -15,7 +15,7 @@ QPDF_Destroyed::getInstance()
15 } 15 }
16 16
17 std::shared_ptr<QPDFObject> 17 std::shared_ptr<QPDFObject>
18 -QPDF_Destroyed::shallowCopy() 18 +QPDF_Destroyed::copy(bool shallow)
19 { 19 {
20 throw std::logic_error( 20 throw std::logic_error(
21 "attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); 21 "attempted to shallow copy QPDFObjectHandle from destroyed QPDF");
libqpdf/QPDF_Dictionary.cc
@@ -16,7 +16,7 @@ QPDF_Dictionary::create(std::map&lt;std::string, QPDFObjectHandle&gt; const&amp; items) @@ -16,7 +16,7 @@ QPDF_Dictionary::create(std::map&lt;std::string, QPDFObjectHandle&gt; const&amp; items)
16 } 16 }
17 17
18 std::shared_ptr<QPDFObject> 18 std::shared_ptr<QPDFObject>
19 -QPDF_Dictionary::shallowCopy() 19 +QPDF_Dictionary::copy(bool shallow)
20 { 20 {
21 return create(items); 21 return create(items);
22 } 22 }
libqpdf/QPDF_InlineImage.cc
@@ -13,7 +13,7 @@ QPDF_InlineImage::create(std::string const&amp; val) @@ -13,7 +13,7 @@ QPDF_InlineImage::create(std::string const&amp; val)
13 } 13 }
14 14
15 std::shared_ptr<QPDFObject> 15 std::shared_ptr<QPDFObject>
16 -QPDF_InlineImage::shallowCopy() 16 +QPDF_InlineImage::copy(bool shallow)
17 { 17 {
18 return create(val); 18 return create(val);
19 } 19 }
libqpdf/QPDF_Integer.cc
@@ -15,7 +15,7 @@ QPDF_Integer::create(long long value) @@ -15,7 +15,7 @@ QPDF_Integer::create(long long value)
15 } 15 }
16 16
17 std::shared_ptr<QPDFObject> 17 std::shared_ptr<QPDFObject>
18 -QPDF_Integer::shallowCopy() 18 +QPDF_Integer::copy(bool shallow)
19 { 19 {
20 return create(val); 20 return create(val);
21 } 21 }
libqpdf/QPDF_Name.cc
@@ -17,7 +17,7 @@ QPDF_Name::create(std::string const&amp; name) @@ -17,7 +17,7 @@ QPDF_Name::create(std::string const&amp; name)
17 } 17 }
18 18
19 std::shared_ptr<QPDFObject> 19 std::shared_ptr<QPDFObject>
20 -QPDF_Name::shallowCopy() 20 +QPDF_Name::copy(bool shallow)
21 { 21 {
22 return create(name); 22 return create(name);
23 } 23 }
libqpdf/QPDF_Null.cc
@@ -12,7 +12,7 @@ QPDF_Null::create() @@ -12,7 +12,7 @@ QPDF_Null::create()
12 } 12 }
13 13
14 std::shared_ptr<QPDFObject> 14 std::shared_ptr<QPDFObject>
15 -QPDF_Null::shallowCopy() 15 +QPDF_Null::copy(bool shallow)
16 { 16 {
17 return create(); 17 return create();
18 } 18 }
libqpdf/QPDF_Operator.cc
@@ -13,7 +13,7 @@ QPDF_Operator::create(std::string const&amp; val) @@ -13,7 +13,7 @@ QPDF_Operator::create(std::string const&amp; val)
13 } 13 }
14 14
15 std::shared_ptr<QPDFObject> 15 std::shared_ptr<QPDFObject>
16 -QPDF_Operator::shallowCopy() 16 +QPDF_Operator::copy(bool shallow)
17 { 17 {
18 return create(val); 18 return create(val);
19 } 19 }
libqpdf/QPDF_Real.cc
@@ -29,7 +29,7 @@ QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes) @@ -29,7 +29,7 @@ QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes)
29 } 29 }
30 30
31 std::shared_ptr<QPDFObject> 31 std::shared_ptr<QPDFObject>
32 -QPDF_Real::shallowCopy() 32 +QPDF_Real::copy(bool shallow)
33 { 33 {
34 return create(val); 34 return create(val);
35 } 35 }
libqpdf/QPDF_Reserved.cc
@@ -14,7 +14,7 @@ QPDF_Reserved::create() @@ -14,7 +14,7 @@ QPDF_Reserved::create()
14 } 14 }
15 15
16 std::shared_ptr<QPDFObject> 16 std::shared_ptr<QPDFObject>
17 -QPDF_Reserved::shallowCopy() 17 +QPDF_Reserved::copy(bool shallow)
18 { 18 {
19 return create(); 19 return create();
20 } 20 }
libqpdf/QPDF_Stream.cc
@@ -140,9 +140,9 @@ QPDF_Stream::create( @@ -140,9 +140,9 @@ QPDF_Stream::create(
140 } 140 }
141 141
142 std::shared_ptr<QPDFObject> 142 std::shared_ptr<QPDFObject>
143 -QPDF_Stream::shallowCopy() 143 +QPDF_Stream::copy(bool shallow)
144 { 144 {
145 - throw std::logic_error("stream objects cannot be cloned"); 145 + throw std::runtime_error("stream objects cannot be cloned");
146 } 146 }
147 147
148 void 148 void
libqpdf/QPDF_String.cc
@@ -37,7 +37,7 @@ QPDF_String::create_utf16(std::string const&amp; utf8_val) @@ -37,7 +37,7 @@ QPDF_String::create_utf16(std::string const&amp; utf8_val)
37 } 37 }
38 38
39 std::shared_ptr<QPDFObject> 39 std::shared_ptr<QPDFObject>
40 -QPDF_String::shallowCopy() 40 +QPDF_String::copy(bool shallow)
41 { 41 {
42 return create(val); 42 return create(val);
43 } 43 }
libqpdf/QPDF_Unresolved.cc
@@ -14,7 +14,7 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const&amp; og) @@ -14,7 +14,7 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const&amp; og)
14 } 14 }
15 15
16 std::shared_ptr<QPDFObject> 16 std::shared_ptr<QPDFObject>
17 -QPDF_Unresolved::shallowCopy() 17 +QPDF_Unresolved::copy(bool shallow)
18 { 18 {
19 throw std::logic_error( 19 throw std::logic_error(
20 "attempted to shallow copy an unresolved QPDFObjectHandle"); 20 "attempted to shallow copy an unresolved QPDFObjectHandle");
libqpdf/qpdf/QPDFObject_private.hh
@@ -24,9 +24,9 @@ class QPDFObject @@ -24,9 +24,9 @@ class QPDFObject
24 QPDFObject() = default; 24 QPDFObject() = default;
25 25
26 std::shared_ptr<QPDFObject> 26 std::shared_ptr<QPDFObject>
27 - shallowCopy() 27 + copy(bool shallow = false)
28 { 28 {
29 - return value->shallowCopy(); 29 + return value->copy(shallow);
30 } 30 }
31 std::string 31 std::string
32 unparse() 32 unparse()
libqpdf/qpdf/QPDFValue.hh
@@ -20,7 +20,7 @@ class QPDFValue @@ -20,7 +20,7 @@ class QPDFValue
20 public: 20 public:
21 virtual ~QPDFValue() = default; 21 virtual ~QPDFValue() = default;
22 22
23 - virtual std::shared_ptr<QPDFObject> shallowCopy() = 0; 23 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
24 virtual std::string unparse() = 0; 24 virtual std::string unparse() = 0;
25 virtual JSON getJSON(int json_version) = 0; 25 virtual JSON getJSON(int json_version) = 0;
26 virtual void 26 virtual void
libqpdf/qpdf/QPDF_Array.hh
@@ -14,7 +14,7 @@ class QPDF_Array: public QPDFValue @@ -14,7 +14,7 @@ class QPDF_Array: public QPDFValue
14 static std::shared_ptr<QPDFObject> 14 static std::shared_ptr<QPDFObject>
15 create(std::vector<QPDFObjectHandle> const& items); 15 create(std::vector<QPDFObjectHandle> const& items);
16 static std::shared_ptr<QPDFObject> create(SparseOHArray const& items); 16 static std::shared_ptr<QPDFObject> create(SparseOHArray const& items);
17 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 17 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
18 virtual std::string unparse(); 18 virtual std::string unparse();
19 virtual JSON getJSON(int json_version); 19 virtual JSON getJSON(int json_version);
20 virtual void disconnect(); 20 virtual void disconnect();
libqpdf/qpdf/QPDF_Bool.hh
@@ -8,7 +8,7 @@ class QPDF_Bool: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Bool: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Bool() = default; 9 virtual ~QPDF_Bool() = default;
10 static std::shared_ptr<QPDFObject> create(bool val); 10 static std::shared_ptr<QPDFObject> create(bool val);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 bool getVal() const; 14 bool getVal() const;
libqpdf/qpdf/QPDF_Destroyed.hh
@@ -7,7 +7,7 @@ class QPDF_Destroyed: public QPDFValue @@ -7,7 +7,7 @@ class QPDF_Destroyed: public QPDFValue
7 { 7 {
8 public: 8 public:
9 virtual ~QPDF_Destroyed() = default; 9 virtual ~QPDF_Destroyed() = default;
10 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 10 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
11 virtual std::string unparse(); 11 virtual std::string unparse();
12 virtual JSON getJSON(int json_version); 12 virtual JSON getJSON(int json_version);
13 static std::shared_ptr<QPDFValue> getInstance(); 13 static std::shared_ptr<QPDFValue> getInstance();
libqpdf/qpdf/QPDF_Dictionary.hh
@@ -14,7 +14,7 @@ class QPDF_Dictionary: public QPDFValue @@ -14,7 +14,7 @@ class QPDF_Dictionary: public QPDFValue
14 virtual ~QPDF_Dictionary() = default; 14 virtual ~QPDF_Dictionary() = default;
15 static std::shared_ptr<QPDFObject> 15 static std::shared_ptr<QPDFObject>
16 create(std::map<std::string, QPDFObjectHandle> const& items); 16 create(std::map<std::string, QPDFObjectHandle> const& items);
17 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 17 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
18 virtual std::string unparse(); 18 virtual std::string unparse();
19 virtual JSON getJSON(int json_version); 19 virtual JSON getJSON(int json_version);
20 virtual void disconnect(); 20 virtual void disconnect();
libqpdf/qpdf/QPDF_InlineImage.hh
@@ -8,7 +8,7 @@ class QPDF_InlineImage: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_InlineImage: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_InlineImage() = default; 9 virtual ~QPDF_InlineImage() = default;
10 static std::shared_ptr<QPDFObject> create(std::string const& val); 10 static std::shared_ptr<QPDFObject> create(std::string const& val);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 std::string getVal() const; 14 std::string getVal() const;
libqpdf/qpdf/QPDF_Integer.hh
@@ -8,7 +8,7 @@ class QPDF_Integer: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Integer: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Integer() = default; 9 virtual ~QPDF_Integer() = default;
10 static std::shared_ptr<QPDFObject> create(long long value); 10 static std::shared_ptr<QPDFObject> create(long long value);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 long long getVal() const; 14 long long getVal() const;
libqpdf/qpdf/QPDF_Name.hh
@@ -8,7 +8,7 @@ class QPDF_Name: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Name: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Name() = default; 9 virtual ~QPDF_Name() = default;
10 static std::shared_ptr<QPDFObject> create(std::string const& name); 10 static std::shared_ptr<QPDFObject> create(std::string const& name);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 std::string getName() const; 14 std::string getName() const;
libqpdf/qpdf/QPDF_Null.hh
@@ -8,7 +8,7 @@ class QPDF_Null: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Null: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Null() = default; 9 virtual ~QPDF_Null() = default;
10 static std::shared_ptr<QPDFObject> create(); 10 static std::shared_ptr<QPDFObject> create();
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 14
libqpdf/qpdf/QPDF_Operator.hh
@@ -8,7 +8,7 @@ class QPDF_Operator: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Operator: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Operator() = default; 9 virtual ~QPDF_Operator() = default;
10 static std::shared_ptr<QPDFObject> create(std::string const& val); 10 static std::shared_ptr<QPDFObject> create(std::string const& val);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 std::string getVal() const; 14 std::string getVal() const;
libqpdf/qpdf/QPDF_Real.hh
@@ -10,7 +10,7 @@ class QPDF_Real: public QPDFValue @@ -10,7 +10,7 @@ class QPDF_Real: public QPDFValue
10 static std::shared_ptr<QPDFObject> create(std::string const& val); 10 static std::shared_ptr<QPDFObject> create(std::string const& val);
11 static std::shared_ptr<QPDFObject> 11 static std::shared_ptr<QPDFObject>
12 create(double value, int decimal_places, bool trim_trailing_zeroes); 12 create(double value, int decimal_places, bool trim_trailing_zeroes);
13 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 13 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
14 virtual std::string unparse(); 14 virtual std::string unparse();
15 virtual JSON getJSON(int json_version); 15 virtual JSON getJSON(int json_version);
16 std::string getVal(); 16 std::string getVal();
libqpdf/qpdf/QPDF_Reserved.hh
@@ -8,7 +8,7 @@ class QPDF_Reserved: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Reserved: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Reserved() = default; 9 virtual ~QPDF_Reserved() = default;
10 static std::shared_ptr<QPDFObject> create(); 10 static std::shared_ptr<QPDFObject> create();
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 14
libqpdf/qpdf/QPDF_Stream.hh
@@ -23,7 +23,7 @@ class QPDF_Stream: public QPDFValue @@ -23,7 +23,7 @@ class QPDF_Stream: public QPDFValue
23 QPDFObjectHandle stream_dict, 23 QPDFObjectHandle stream_dict,
24 qpdf_offset_t offset, 24 qpdf_offset_t offset,
25 size_t length); 25 size_t length);
26 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 26 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
27 virtual std::string unparse(); 27 virtual std::string unparse();
28 virtual JSON getJSON(int json_version); 28 virtual JSON getJSON(int json_version);
29 virtual void setDescription(QPDF*, std::string const&); 29 virtual void setDescription(QPDF*, std::string const&);
libqpdf/qpdf/QPDF_String.hh
@@ -14,7 +14,7 @@ class QPDF_String: public QPDFValue @@ -14,7 +14,7 @@ class QPDF_String: public QPDFValue
14 static std::shared_ptr<QPDFObject> create(std::string const& val); 14 static std::shared_ptr<QPDFObject> create(std::string const& val);
15 static std::shared_ptr<QPDFObject> 15 static std::shared_ptr<QPDFObject>
16 create_utf16(std::string const& utf8_val); 16 create_utf16(std::string const& utf8_val);
17 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 17 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
18 virtual std::string unparse(); 18 virtual std::string unparse();
19 std::string unparse(bool force_binary); 19 std::string unparse(bool force_binary);
20 virtual JSON getJSON(int json_version); 20 virtual JSON getJSON(int json_version);
libqpdf/qpdf/QPDF_Unresolved.hh
@@ -8,7 +8,7 @@ class QPDF_Unresolved: public QPDFValue @@ -8,7 +8,7 @@ class QPDF_Unresolved: public QPDFValue
8 public: 8 public:
9 virtual ~QPDF_Unresolved() = default; 9 virtual ~QPDF_Unresolved() = default;
10 static std::shared_ptr<QPDFObject> create(QPDF* qpdf, QPDFObjGen const& og); 10 static std::shared_ptr<QPDFObject> create(QPDF* qpdf, QPDFObjGen const& og);
11 - virtual std::shared_ptr<QPDFObject> shallowCopy(); 11 + virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
12 virtual std::string unparse(); 12 virtual std::string unparse();
13 virtual JSON getJSON(int json_version); 13 virtual JSON getJSON(int json_version);
14 14