Commit 9504421ecd6f8f57e42e44e29667578e303f1901

Authored by m-holger
1 parent dab919e5

Move QPDFObject::unparse to BaseHandle

include/qpdf/ObjectHandle.hh
... ... @@ -61,6 +61,7 @@ namespace qpdf
61 61 inline QPDF* qpdf() const;
62 62 inline qpdf_object_type_e raw_type_code() const;
63 63 inline qpdf_object_type_e type_code() const;
  64 + std::string unparse() const;
64 65  
65 66 protected:
66 67 BaseHandle() = default;
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -369,9 +369,9 @@ BaseHandle::copy(bool shallow) const
369 369 }
370 370  
371 371 std::string
372   -QPDFObject::unparse()
  372 +BaseHandle::unparse() const
373 373 {
374   - switch (getResolvedTypeCode()) {
  374 + switch (type_code()) {
375 375 case ::ot_uninitialized:
376 376 throw std::logic_error("QPDFObjectHandle: attempting to unparse an uninitialized object");
377 377 return ""; // does not return
... ... @@ -381,18 +381,18 @@ QPDFObject::unparse()
381 381 case ::ot_null:
382 382 return "null";
383 383 case ::ot_boolean:
384   - return std::get<QPDF_Bool>(value).val ? "true" : "false";
  384 + return std::get<QPDF_Bool>(obj->value).val ? "true" : "false";
385 385 case ::ot_integer:
386   - return std::to_string(std::get<QPDF_Integer>(value).val);
  386 + return std::to_string(std::get<QPDF_Integer>(obj->value).val);
387 387 case ::ot_real:
388   - return std::get<QPDF_Real>(value).val;
  388 + return std::get<QPDF_Real>(obj->value).val;
389 389 case ::ot_string:
390   - return std::get<QPDF_String>(value).unparse(false);
  390 + return std::get<QPDF_String>(obj->value).unparse(false);
391 391 case ::ot_name:
392   - return Name::normalize(std::get<QPDF_Name>(value).name);
  392 + return Name::normalize(std::get<QPDF_Name>(obj->value).name);
393 393 case ::ot_array:
394 394 {
395   - auto const& a = std::get<QPDF_Array>(value);
  395 + auto const& a = std::get<QPDF_Array>(obj->value);
396 396 std::string result = "[ ";
397 397 if (a.sp) {
398 398 int next = 0;
... ... @@ -401,9 +401,7 @@ QPDFObject::unparse()
401 401 for (int j = next; j < key; ++j) {
402 402 result += "null ";
403 403 }
404   - auto item_og = item.second.id_gen();
405   - result += item_og.isIndirect() ? item_og.unparse(' ') + " R "
406   - : item.second.getObj()->unparse() + " ";
  404 + result += item.second.unparse() + " ";
407 405 next = ++key;
408 406 }
409 407 for (int j = next; j < a.sp->size; ++j) {
... ... @@ -411,9 +409,7 @@ QPDFObject::unparse()
411 409 }
412 410 } else {
413 411 for (auto const& item: a.elements) {
414   - auto item_og = item.id_gen();
415   - result += item_og.isIndirect() ? item_og.unparse(' ') + " R "
416   - : item.getObj()->unparse() + " ";
  412 + result += item.unparse() + " ";
417 413 }
418 414 }
419 415 result += "]";
... ... @@ -421,7 +417,7 @@ QPDFObject::unparse()
421 417 }
422 418 case ::ot_dictionary:
423 419 {
424   - auto const& items = std::get<QPDF_Dictionary>(value).items;
  420 + auto const& items = std::get<QPDF_Dictionary>(obj->value).items;
425 421 std::string result = "<< ";
426 422 for (auto& iter: items) {
427 423 if (!iter.second.null()) {
... ... @@ -432,11 +428,11 @@ QPDFObject::unparse()
432 428 return result;
433 429 }
434 430 case ::ot_stream:
435   - return og.unparse(' ') + " R";
  431 + return obj->og.unparse(' ') + " R";
436 432 case ::ot_operator:
437   - return std::get<QPDF_Operator>(value).val;
  433 + return std::get<QPDF_Operator>(obj->value).val;
438 434 case ::ot_inlineimage:
439   - return std::get<QPDF_InlineImage>(value).val;
  435 + return std::get<QPDF_InlineImage>(obj->value).val;
440 436 case ::ot_unresolved:
441 437 throw std::logic_error("QPDFObjectHandle: attempting to unparse a unresolved object");
442 438 return ""; // does not return
... ... @@ -444,7 +440,7 @@ QPDFObject::unparse()
444 440 throw std::logic_error("attempted to unparse a QPDFObjectHandle from a destroyed QPDF");
445 441 return ""; // does not return
446 442 case ::ot_reference:
447   - return og.unparse(' ') + " R";
  443 + return obj->og.unparse(' ') + " R";
448 444 }
449 445 return {}; // unreachable
450 446 }
... ... @@ -1438,7 +1434,7 @@ QPDFObjectHandle::unparseResolved() const
1438 1434 if (!obj) {
1439 1435 throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle");
1440 1436 }
1441   - return obj->unparse();
  1437 + return BaseHandle::unparse();
1442 1438 }
1443 1439  
1444 1440 std::string
... ...
libqpdf/qpdf/QPDFObject_private.hh
... ... @@ -295,7 +295,6 @@ class QPDFObject
295 295 qpdf, og, std::forward<T>(T(std::forward<Args>(args)...)));
296 296 }
297 297  
298   - std::string unparse();
299 298 void write_json(int json_version, JSON::Writer& p);
300 299 void disconnect();
301 300 std::string getStringValue() const;
... ...
libtests/sparse_array.cc
... ... @@ -95,7 +95,9 @@ main()
95 95 assert(b.at(3).second.isNull());
96 96 assert(b.at(8).second.isNull());
97 97 assert(b.at(5).second.isIndirect());
98   - assert(obj->unparse() == "[ null null null null null 3 0 R null [ 0 1 2 3 ] null null ]");
  98 + assert(
  99 + QPDFObjectHandle(obj).unparse() ==
  100 + "[ null null null null null 3 0 R null [ 0 1 2 3 ] null null ]");
99 101 auto c = QPDFObjectHandle(obj).unsafeShallowCopy();
100 102 auto d = QPDFObjectHandle(obj).shallowCopy();
101 103 b.at(7).second.setArrayItem(2, "42"_qpdf);
... ...