Commit ec778ef98b0b20e2bf4592b00d0a6ac39b69c511

Authored by Jay Berkenbilt
1 parent fa0b6384

Add additional comments about new accessor methods

include/qpdf/QPDFObjectHandle.hh
... ... @@ -657,13 +657,25 @@ class QPDFObjectHandle
657 657 //
658 658 // In PDF files, objects have specific types, but there is nothing
659 659 // that prevents PDF files from containing objects of types that
660   - // aren't expected by the specification. Many of the accessors
661   - // here expect objects of a particular type. Prior to qpdf 8,
662   - // calling an accessor on a method of the wrong type, such as
663   - // trying to get a dictionary key from an array, trying to get the
664   - // string value of a number, etc., would throw an exception, but
665   - // since qpdf 8, qpdf issues a warning and recovers using the
666   - // following behavior:
  660 + // aren't expected by the specification.
  661 + //
  662 + // There are two flavors of accessor methods:
  663 + //
  664 + // * getSomethingValue() returns the value and issues a type
  665 + // warning if the type is incorrect.
  666 + //
  667 + // * getValueAsSomething() returns false if the value is the wrong
  668 + // type. Otherwise, it returns true and initializes a reference
  669 + // of the appropriate type. These methods never issue type
  670 + // warnings.
  671 + //
  672 + // The getSomethingValue() accessors and some of the other methods
  673 + // expect objects of a particular type. Prior to qpdf 8, calling
  674 + // an accessor on a method of the wrong type, such as trying to
  675 + // get a dictionary key from an array, trying to get the string
  676 + // value of a number, etc., would throw an exception, but since
  677 + // qpdf 8, qpdf issues a warning and recovers using the following
  678 + // behavior:
667 679 //
668 680 // * Requesting a value of the wrong type (int value from string,
669 681 // array item from a scalar or dictionary, etc.) will return a
... ...
manual/design.rst
... ... @@ -746,6 +746,15 @@ and set return values in passed-in pointers, but this would complicate
746 746 both the implementation and the use of the library for a case that is
747 747 actually quite rare and largely avoidable.
748 748  
  749 +*How can I avoid type warnings altogether?* For each
  750 +``getSomethingValue`` accessor that returns a value of the requested
  751 +type and issues a warning for objects of the wrong type, there is also
  752 +a ``getValueAsSomething`` method (since qpdf 10.6) that returns false
  753 +for objects of the wrong type and otherwise returns true and
  754 +initializes a reference. These methods never generate type warnings
  755 +and provide an alternative to explicitly checking the type of an
  756 +object before calling an accessor method.
  757 +
749 758 .. _smart-pointers:
750 759  
751 760 Smart Pointers
... ...
manual/release-notes.rst
... ... @@ -99,7 +99,7 @@ For a detailed list of changes, please see the file
99 99  
100 100 - The newer accessor methods return a boolean indicating whether
101 101 or not the object is of the expected type. If it is, a
102   - reference of the correct type is returned.
  102 + reference to a variable of the correct type is initialized.
103 103  
104 104 In many cases, the new interfaces will enable more compact code
105 105 and will also never generate type warnings. Thanks to M. Holger
... ...