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