Commit 6ad16cd1fdd25b195cec64582be589622dbb0f16

Authored by m-holger
1 parent f49f43fe

In FUTURE make QPDFObjectHandle methods const and noexcept where possible

include/qpdf/QPDFObjectHandle.hh
... ... @@ -1371,12 +1371,12 @@ class QPDFObjectHandle
1371 1371 QPDF_Real* asReal() const;
1372 1372 QPDF_Reserved* asReserved() const;
1373 1373 QPDF_Stream* asStream() const;
1374   - QPDF_Stream* asStreamWithAssert();
  1374 + QPDF_Stream* asStreamWithAssert() const;
1375 1375 QPDF_String* asString() const;
1376 1376  
1377   - void typeWarning(char const* expected_type, std::string const& warning);
1378   - void objectWarning(std::string const& warning);
1379   - void assertType(char const* type_name, bool istype);
  1377 + void typeWarning(char const* expected_type, std::string const& warning) const;
  1378 + void objectWarning(std::string const& warning) const;
  1379 + void assertType(char const* type_name, bool istype) const;
1380 1380 void makeDirect(QPDFObjGen::set& visited, bool stop_at_streams);
1381 1381 void disconnect();
1382 1382 void setParsedOffset(qpdf_offset_t offset);
... ...
include/qpdf/QPDFObjectHandle_future.hh
... ... @@ -296,48 +296,48 @@ class QPDFObjectHandle
296 296 QPDFObjectHandle& operator=(QPDFObjectHandle&&) = default;
297 297  
298 298 QPDF_DLL
299   - inline bool isInitialized() const;
  299 + inline bool isInitialized() const noexcept;
300 300  
301 301 // This method returns true if the QPDFObjectHandle objects point to exactly the same underlying
302 302 // object, meaning that changes to one are reflected in the other, or "if you paint one, the
303 303 // other one changes color." This does not perform a structural comparison of the contents of
304 304 // the objects.
305 305 QPDF_DLL
306   - bool isSameObjectAs(QPDFObjectHandle const&) const;
  306 + bool isSameObjectAs(QPDFObjectHandle const&) const noexcept;
307 307  
308 308 // Return type code and type name of underlying object. These are useful for doing rapid type
309 309 // tests (like switch statements) or for testing and debugging.
310 310 QPDF_DLL
311   - qpdf_object_type_e getTypeCode();
  311 + qpdf_object_type_e getTypeCode() const;
312 312 QPDF_DLL
313   - char const* getTypeName();
  313 + char const* getTypeName() const;
314 314  
315 315 // Exactly one of these will return true for any initialized object. Operator and InlineImage
316 316 // are only allowed in content streams.
317 317 QPDF_DLL
318   - bool isBool();
  318 + bool isBool() const;
319 319 QPDF_DLL
320   - bool isNull();
  320 + bool isNull() const;
321 321 QPDF_DLL
322   - bool isInteger();
  322 + bool isInteger() const;
323 323 QPDF_DLL
324   - bool isReal();
  324 + bool isReal() const;
325 325 QPDF_DLL
326   - bool isName();
  326 + bool isName() const;
327 327 QPDF_DLL
328   - bool isString();
  328 + bool isString() const;
329 329 QPDF_DLL
330   - bool isOperator();
  330 + bool isOperator() const;
331 331 QPDF_DLL
332   - bool isInlineImage();
  332 + bool isInlineImage() const;
333 333 QPDF_DLL
334   - bool isArray();
  334 + bool isArray() const;
335 335 QPDF_DLL
336   - bool isDictionary();
  336 + bool isDictionary() const;
337 337 QPDF_DLL
338   - bool isStream();
  338 + bool isStream() const;
339 339 QPDF_DLL
340   - bool isReserved();
  340 + bool isReserved() const;
341 341  
342 342 // True for objects that are direct nulls. Does not attempt to resolve objects. This is intended
343 343 // for internal use, but it can be used as an efficient way to check for nulls that are not
... ... @@ -352,23 +352,23 @@ class QPDFObjectHandle
352 352 // This returns true for indirect objects from a QPDF that has been destroyed. Trying unparse
353 353 // such an object will throw a logic_error.
354 354 QPDF_DLL
355   - bool isDestroyed();
  355 + bool isDestroyed() const;
356 356  
357 357 // True for everything except array, dictionary, stream, word, and inline image.
358 358 QPDF_DLL
359   - bool isScalar();
  359 + bool isScalar() const;
360 360  
361 361 // True if the object is a name object representing the provided name.
362 362 QPDF_DLL
363   - bool isNameAndEquals(std::string const& name);
  363 + bool isNameAndEquals(std::string const& name) const;
364 364  
365 365 // True if the object is a dictionary of the specified type and subtype, if any.
366 366 QPDF_DLL
367   - bool isDictionaryOfType(std::string const& type, std::string const& subtype = "");
  367 + bool isDictionaryOfType(std::string const& type, std::string const& subtype = "") const;
368 368  
369 369 // True if the object is a stream of the specified type and subtype, if any.
370 370 QPDF_DLL
371   - bool isStreamOfType(std::string const& type, std::string const& subtype = "");
  371 + bool isStreamOfType(std::string const& type, std::string const& subtype = "") const;
372 372  
373 373 // Public factory methods
374 374  
... ... @@ -413,7 +413,7 @@ class QPDFObjectHandle
413 413 // object was created without parsing. If the object is in a stream, the offset is from the
414 414 // beginning of the stream. Otherwise, the offset is from the beginning of the file.
415 415 QPDF_DLL
416   - qpdf_offset_t getParsedOffset();
  416 + qpdf_offset_t getParsedOffset() const;
417 417  
418 418 // Older method: stream_or_array should be the value of /Contents from a page object. It's more
419 419 // convenient to just call QPDFPageObjectHelper::parsePageContents on the page object, and error
... ... @@ -585,7 +585,7 @@ class QPDFObjectHandle
585 585 QPDF_DLL
586 586 void setObjectDescription(QPDF* owning_qpdf, std::string const& object_description);
587 587 QPDF_DLL
588   - bool hasObjectDescription();
  588 + bool hasObjectDescription() const;
589 589  
590 590 // Accessor methods
591 591 //
... ... @@ -635,57 +635,57 @@ class QPDFObjectHandle
635 635  
636 636 // Methods for bool objects
637 637 QPDF_DLL
638   - bool getBoolValue();
  638 + bool getBoolValue() const;
639 639 QPDF_DLL
640   - bool getValueAsBool(bool&);
  640 + bool getValueAsBool(bool&) const;
641 641  
642 642 // Methods for integer objects. Note: if an integer value is too big (too far away from zero in
643 643 // either direction) to fit in the requested return type, the maximum or minimum value for that
644 644 // return type may be returned. For example, on a system with 32-bit int, a numeric object with
645 645 // a value of 2^40 (or anything too big for 32 bits) will be returned as INT_MAX.
646 646 QPDF_DLL
647   - long long getIntValue();
  647 + long long getIntValue() const;
648 648 QPDF_DLL
649   - bool getValueAsInt(long long&);
  649 + bool getValueAsInt(long long&) const;
650 650 QPDF_DLL
651   - int getIntValueAsInt();
  651 + int getIntValueAsInt() const;
652 652 QPDF_DLL
653   - bool getValueAsInt(int&);
  653 + bool getValueAsInt(int&) const;
654 654 QPDF_DLL
655   - unsigned long long getUIntValue();
  655 + unsigned long long getUIntValue() const;
656 656 QPDF_DLL
657   - bool getValueAsUInt(unsigned long long&);
  657 + bool getValueAsUInt(unsigned long long&) const;
658 658 QPDF_DLL
659   - unsigned int getUIntValueAsUInt();
  659 + unsigned int getUIntValueAsUInt() const;
660 660 QPDF_DLL
661   - bool getValueAsUInt(unsigned int&);
  661 + bool getValueAsUInt(unsigned int&) const;
662 662  
663 663 // Methods for real objects
664 664 QPDF_DLL
665   - std::string getRealValue();
  665 + std::string getRealValue() const;
666 666 QPDF_DLL
667   - bool getValueAsReal(std::string&);
  667 + bool getValueAsReal(std::string&) const;
668 668  
669 669 // Methods that work for both integer and real objects
670 670 QPDF_DLL
671   - bool isNumber();
  671 + bool isNumber() const;
672 672 QPDF_DLL
673   - double getNumericValue();
  673 + double getNumericValue() const;
674 674 QPDF_DLL
675   - bool getValueAsNumber(double&);
  675 + bool getValueAsNumber(double&) const;
676 676  
677 677 // Methods for name objects. The returned name value is in qpdf's canonical form with all
678 678 // escaping resolved. See comments for newName() for details.
679 679 QPDF_DLL
680   - std::string getName();
  680 + std::string getName() const;
681 681 QPDF_DLL
682   - bool getValueAsName(std::string&);
  682 + bool getValueAsName(std::string&) const;
683 683  
684 684 // Methods for string objects
685 685 QPDF_DLL
686   - std::string getStringValue();
  686 + std::string getStringValue() const;
687 687 QPDF_DLL
688   - bool getValueAsString(std::string&);
  688 + bool getValueAsString(std::string&) const;
689 689  
690 690 // If a string starts with the UTF-16 marker, it is converted from UTF-16 to UTF-8. Otherwise,
691 691 // it is treated as a string encoded with PDF Doc Encoding. PDF Doc Encoding is identical to
... ... @@ -693,19 +693,19 @@ class QPDFObjectHandle
693 693 // to Unicode. QPDF versions prior to version 8.0.0 erroneously left characters in that range
694 694 // unmapped.
695 695 QPDF_DLL
696   - std::string getUTF8Value();
  696 + std::string getUTF8Value() const;
697 697 QPDF_DLL
698   - bool getValueAsUTF8(std::string&);
  698 + bool getValueAsUTF8(std::string&) const;
699 699  
700 700 // Methods for content stream objects
701 701 QPDF_DLL
702   - std::string getOperatorValue();
  702 + std::string getOperatorValue() const;
703 703 QPDF_DLL
704   - bool getValueAsOperator(std::string&);
  704 + bool getValueAsOperator(std::string&) const;
705 705 QPDF_DLL
706   - std::string getInlineImageValue();
  706 + std::string getInlineImageValue() const;
707 707 QPDF_DLL
708   - bool getValueAsInlineImage(std::string&);
  708 + bool getValueAsInlineImage(std::string&) const;
709 709  
710 710 // Methods for array objects; see also name and array objects.
711 711  
... ... @@ -720,26 +720,26 @@ class QPDFObjectHandle
720 720 QPDFArrayItems aitems();
721 721  
722 722 QPDF_DLL
723   - int getArrayNItems();
  723 + int getArrayNItems() const;
724 724 QPDF_DLL
725   - QPDFObjectHandle getArrayItem(int n);
  725 + QPDFObjectHandle getArrayItem(int n) const;
726 726 // Note: QPDF arrays internally optimize memory for arrays containing lots of nulls. Calling
727 727 // getArrayAsVector may cause a lot of memory to be allocated for very large arrays with lots of
728 728 // nulls.
729 729 QPDF_DLL
730   - std::vector<QPDFObjectHandle> getArrayAsVector();
  730 + std::vector<QPDFObjectHandle> getArrayAsVector() const;
731 731 QPDF_DLL
732   - bool isRectangle();
  732 + bool isRectangle() const;
733 733 // If the array is an array of four numeric values, return as a rectangle. Otherwise, return the
734 734 // rectangle [0, 0, 0, 0]
735 735 QPDF_DLL
736   - Rectangle getArrayAsRectangle();
  736 + Rectangle getArrayAsRectangle() const;
737 737 QPDF_DLL
738   - bool isMatrix();
  738 + bool isMatrix() const;
739 739 // If the array is an array of six numeric values, return as a matrix. Otherwise, return the
740 740 // matrix [1, 0, 0, 1, 0, 0]
741 741 QPDF_DLL
742   - Matrix getArrayAsMatrix();
  742 + Matrix getArrayAsMatrix() const;
743 743  
744 744 // Methods for dictionary objects. In all dictionary methods, keys are specified/represented as
745 745 // canonical name strings starting with a leading slash and not containing any PDF syntax
... ... @@ -759,27 +759,27 @@ class QPDFObjectHandle
759 759 // Return true if key is present. Keys with null values are treated as if they are not present.
760 760 // This is as per the PDF spec.
761 761 QPDF_DLL
762   - bool hasKey(std::string const&);
  762 + bool hasKey(std::string const&) const;
763 763 // Return the value for the key. If the key is not present, null is returned.
764 764 QPDF_DLL
765   - QPDFObjectHandle getKey(std::string const&);
  765 + QPDFObjectHandle getKey(std::string const&) const;
766 766 // If the object is null, return null. Otherwise, call getKey(). This makes it easier to access
767 767 // lower-level dictionaries, as in
768 768 // auto font = page.getKeyIfDict("/Resources").getKeyIfDict("/Font");
769 769 QPDF_DLL
770   - QPDFObjectHandle getKeyIfDict(std::string const&);
  770 + QPDFObjectHandle getKeyIfDict(std::string const&) const;
771 771 // Return all keys. Keys with null values are treated as if they are not present. This is as
772 772 // per the PDF spec.
773 773 QPDF_DLL
774   - std::set<std::string> getKeys();
  774 + std::set<std::string> getKeys() const;
775 775 // Return dictionary as a map. Entries with null values are included.
776 776 QPDF_DLL
777   - std::map<std::string, QPDFObjectHandle> getDictAsMap();
  777 + std::map<std::string, QPDFObjectHandle> getDictAsMap() const;
778 778  
779 779 // Methods for name and array objects. The name value is in qpdf's canonical form with all
780 780 // escaping resolved. See comments for newName() for details.
781 781 QPDF_DLL
782   - bool isOrHasName(std::string const&);
  782 + bool isOrHasName(std::string const&) const;
783 783  
784 784 // Make all resources in a resource dictionary indirect. This just goes through all entries of
785 785 // top-level subdictionaries and converts any direct objects to indirect objects. This can be
... ... @@ -829,7 +829,7 @@ class QPDFObjectHandle
829 829 // method returns a set of all the keys in all top-level subdictionaries. For resources
830 830 // dictionaries, this is the collection of names that may be referenced in the content stream.
831 831 QPDF_DLL
832   - std::set<std::string> getResourceNames();
  832 + std::set<std::string> getResourceNames() const;
833 833  
834 834 // Find a unique name within a resource dictionary starting with a given prefix. This method
835 835 // works by appending a number to the given prefix. It searches starting with min_suffix and
... ... @@ -844,7 +844,7 @@ class QPDFObjectHandle
844 844 std::string getUniqueResourceName(
845 845 std::string const& prefix,
846 846 int& min_suffix,
847   - std::set<std::string>* resource_names = nullptr);
  847 + std::set<std::string>* resource_names = nullptr) const;
848 848  
849 849 // A QPDFObjectHandle has an owning QPDF if it is associated with ("owned by") a specific QPDF
850 850 // object. Indirect objects always have an owning QPDF. Direct objects that are read from the
... ... @@ -964,7 +964,7 @@ class QPDFObjectHandle
964 964  
965 965 // Methods for stream objects
966 966 QPDF_DLL
967   - QPDFObjectHandle getDict();
  967 + QPDFObjectHandle getDict() const;
968 968  
969 969 // By default, or if true passed, QPDFWriter will attempt to filter a stream based on decode
970 970 // level, whether compression is enabled, and its ability to filter. Passing false will prevent
... ... @@ -1153,12 +1153,12 @@ class QPDFObjectHandle
1153 1153 inline int getGeneration() const;
1154 1154  
1155 1155 QPDF_DLL
1156   - std::string unparse();
  1156 + std::string unparse() const;
1157 1157 QPDF_DLL
1158   - std::string unparseResolved();
  1158 + std::string unparseResolved() const;
1159 1159 // For strings only, force binary representation. Otherwise, same as unparse.
1160 1160 QPDF_DLL
1161   - std::string unparseBinary();
  1161 + std::string unparseBinary() const;
1162 1162  
1163 1163 // Return encoded as JSON. The constant JSON::LATEST can be used to specify the latest available
1164 1164 // JSON version. The JSON is generated as follows:
... ... @@ -1192,19 +1192,19 @@ class QPDFObjectHandle
1192 1192 // the object. The effect of dereference_indirect applies only to this object. It is not
1193 1193 // recursive.
1194 1194 QPDF_DLL
1195   - JSON getJSON(int json_version, bool dereference_indirect = false);
  1195 + JSON getJSON(int json_version, bool dereference_indirect = false) const;
1196 1196  
1197 1197 // Write the object encoded as JSON to a pipeline. This is equivalent to, but more efficient
1198 1198 // than, calling getJSON(json_version, dereference_indirect).write(p, depth). See the
1199 1199 // documentation for getJSON and JSON::write for further detail.
1200 1200 QPDF_DLL
1201   - void
1202   - writeJSON(int json_version, Pipeline* p, bool dereference_indirect = false, size_t depth = 0);
  1201 + void writeJSON(
  1202 + int json_version, Pipeline* p, bool dereference_indirect = false, size_t depth = 0) const;
1203 1203  
1204 1204 // Deprecated version uses v1 for backward compatibility.
1205 1205 // ABI: remove for qpdf 12
1206 1206 [[deprecated("Use getJSON(int version)")]] QPDF_DLL JSON
1207   - getJSON(bool dereference_indirect = false);
  1207 + getJSON(bool dereference_indirect = false) const;
1208 1208  
1209 1209 // This method can be called on a stream to get a more extended JSON representation of the
1210 1210 // stream that includes the stream's data. The JSON object returned is always a dictionary whose
... ... @@ -1257,7 +1257,7 @@ class QPDFObjectHandle
1257 1257 // normally from the file have descriptions. See comments on setObjectDescription for additional
1258 1258 // details.
1259 1259 QPDF_DLL
1260   - void warnIfPossible(std::string const& warning);
  1260 + void warnIfPossible(std::string const& warning) const;
1261 1261  
1262 1262 // Provide access to specific classes for recursive disconnected().
1263 1263 class DisconnectAccess
... ... @@ -1280,55 +1280,55 @@ class QPDFObjectHandle
1280 1280 void assertInitialized() const;
1281 1281  
1282 1282 QPDF_DLL
1283   - void assertNull();
  1283 + void assertNull() const;
1284 1284 QPDF_DLL
1285   - void assertBool();
  1285 + void assertBool() const;
1286 1286 QPDF_DLL
1287   - void assertInteger();
  1287 + void assertInteger() const;
1288 1288 QPDF_DLL
1289   - void assertReal();
  1289 + void assertReal() const;
1290 1290 QPDF_DLL
1291   - void assertName();
  1291 + void assertName() const;
1292 1292 QPDF_DLL
1293   - void assertString();
  1293 + void assertString() const;
1294 1294 QPDF_DLL
1295   - void assertOperator();
  1295 + void assertOperator() const;
1296 1296 QPDF_DLL
1297   - void assertInlineImage();
  1297 + void assertInlineImage() const;
1298 1298 QPDF_DLL
1299   - void assertArray();
  1299 + void assertArray() const;
1300 1300 QPDF_DLL
1301   - void assertDictionary();
  1301 + void assertDictionary() const;
1302 1302 QPDF_DLL
1303   - void assertStream();
  1303 + void assertStream() const;
1304 1304 QPDF_DLL
1305   - void assertReserved();
  1305 + void assertReserved() const;
1306 1306  
1307 1307 QPDF_DLL
1308   - void assertIndirect();
  1308 + void assertIndirect() const;
1309 1309 QPDF_DLL
1310   - void assertScalar();
  1310 + void assertScalar() const;
1311 1311 QPDF_DLL
1312   - void assertNumber();
  1312 + void assertNumber() const;
1313 1313  
1314 1314 // The isPageObject method checks the /Type key of the object. This is not completely reliable
1315 1315 // as there are some otherwise valid files whose /Type is wrong for page objects. qpdf is
1316 1316 // slightly more accepting but may still return false here when treating the object as a page
1317 1317 // would work. Use this sparingly.
1318 1318 QPDF_DLL
1319   - bool isPageObject();
  1319 + bool isPageObject() const;
1320 1320 QPDF_DLL
1321   - bool isPagesObject();
  1321 + bool isPagesObject() const;
1322 1322 QPDF_DLL
1323   - void assertPageObject();
  1323 + void assertPageObject() const;
1324 1324  
1325 1325 QPDF_DLL
1326   - bool isFormXObject();
  1326 + bool isFormXObject() const;
1327 1327  
1328 1328 // Indicate if this is an image. If exclude_imagemask is true, don't count image masks as
1329 1329 // images.
1330 1330 QPDF_DLL
1331   - bool isImage(bool exclude_imagemask = true);
  1331 + bool isImage(bool exclude_imagemask = true) const;
1332 1332  
1333 1333 // The following methods do not form part of the public API and are for internal use only.
1334 1334  
... ... @@ -1357,7 +1357,7 @@ class QPDFObjectHandle
1357 1357 return obj.get();
1358 1358 }
1359 1359  
1360   - void writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect = false);
  1360 + void writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect = false) const;
1361 1361  
1362 1362 private:
1363 1363 QPDF_Array* asArray() const;
... ... @@ -1371,12 +1371,12 @@ class QPDFObjectHandle
1371 1371 QPDF_Real* asReal() const;
1372 1372 QPDF_Reserved* asReserved() const;
1373 1373 QPDF_Stream* asStream() const;
1374   - QPDF_Stream* asStreamWithAssert();
  1374 + QPDF_Stream* asStreamWithAssert() const;
1375 1375 QPDF_String* asString() const;
1376 1376  
1377   - void typeWarning(char const* expected_type, std::string const& warning);
1378   - void objectWarning(std::string const& warning);
1379   - void assertType(char const* type_name, bool istype);
  1377 + void typeWarning(char const* expected_type, std::string const& warning) const;
  1378 + void objectWarning(std::string const& warning) const;
  1379 + void assertType(char const* type_name, bool istype) const;
1380 1380 void makeDirect(QPDFObjGen::set& visited, bool stop_at_streams);
1381 1381 void disconnect();
1382 1382 void setParsedOffset(qpdf_offset_t offset);
... ... @@ -1405,11 +1405,11 @@ class QPDFObjectHandle
1405 1405 // from being here.
1406 1406  
1407 1407 /* clang-format off */
1408   -// Disable formatting for this declaration: emacs font-lock in cc-mode (as of 28.1) treats the rest
1409   -// of the file as a string if clang-format removes the space after "operator", and as of
1410   -// clang-format 15, there's no way to prevent it from doing so.
1411   -QPDF_DLL
1412   -QPDFObjectHandle operator ""_qpdf(char const* v, size_t len);
  1408 + // Disable formatting for this declaration: emacs font-lock in cc-mode (as of 28.1) treats the rest
  1409 + // of the file as a string if clang-format removes the space after "operator", and as of
  1410 + // clang-format 15, there's no way to prevent it from doing so.
  1411 + QPDF_DLL
  1412 + QPDFObjectHandle operator ""_qpdf(char const* v, size_t len);
1413 1413 /* clang-format on */
1414 1414  
1415 1415 #endif // QPDF_NO_QPDF_STRING
... ... @@ -1629,7 +1629,7 @@ QPDFObjectHandle::isIndirect() const
1629 1629 }
1630 1630  
1631 1631 inline bool
1632   -QPDFObjectHandle::isInitialized() const
  1632 +QPDFObjectHandle::isInitialized() const noexcept
1633 1633 {
1634 1634 return obj != nullptr;
1635 1635 }
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -220,12 +220,19 @@ LastChar::getLastChar()
220 220 return this->last_char;
221 221 }
222 222  
  223 +#ifndef QPDF_FUTURE
223 224 bool
224 225 QPDFObjectHandle::isSameObjectAs(QPDFObjectHandle const& rhs) const
225 226 {
226 227 return this->obj == rhs.obj;
227 228 }
228   -
  229 +#else
  230 +bool
  231 +QPDFObjectHandle::isSameObjectAs(QPDFObjectHandle const& rhs) const noexcept
  232 +{
  233 + return this->obj == rhs.obj;
  234 +}
  235 +#endif
229 236 void
230 237 QPDFObjectHandle::disconnect()
231 238 {
... ... @@ -237,14 +244,24 @@ QPDFObjectHandle::disconnect()
237 244 }
238 245 }
239 246  
  247 +#ifndef QPDF_FUTURE
240 248 qpdf_object_type_e
241 249 QPDFObjectHandle::getTypeCode()
  250 +#else
  251 +qpdf_object_type_e
  252 +QPDFObjectHandle::getTypeCode() const
  253 +#endif
242 254 {
243 255 return obj ? obj->getResolvedTypeCode() : ::ot_uninitialized;
244 256 }
245 257  
  258 +#ifndef QPDF_FUTURE
246 259 char const*
247 260 QPDFObjectHandle::getTypeName()
  261 +#else
  262 +char const*
  263 +QPDFObjectHandle::getTypeName() const
  264 +#endif
248 265 {
249 266 return obj ? obj->getTypeName() : "uninitialized";
250 267 }
... ... @@ -316,7 +333,7 @@ QPDFObjectHandle::asStream() const
316 333 }
317 334  
318 335 QPDF_Stream*
319   -QPDFObjectHandle::asStreamWithAssert()
  336 +QPDFObjectHandle::asStreamWithAssert() const
320 337 {
321 338 auto stream = asStream();
322 339 assertType("stream", stream);
... ... @@ -329,14 +346,24 @@ QPDFObjectHandle::asString() const
329 346 return obj ? obj->as<QPDF_String>() : nullptr;
330 347 }
331 348  
  349 +#ifndef QPDF_FUTURE
332 350 bool
333 351 QPDFObjectHandle::isDestroyed()
  352 +#else
  353 +bool
  354 +QPDFObjectHandle::isDestroyed() const
  355 +#endif
334 356 {
335 357 return obj && obj->getResolvedTypeCode() == ::ot_destroyed;
336 358 }
337 359  
  360 +#ifndef QPDF_FUTURE
338 361 bool
339 362 QPDFObjectHandle::isBool()
  363 +#else
  364 +bool
  365 +QPDFObjectHandle::isBool() const
  366 +#endif
340 367 {
341 368 return obj && obj->getResolvedTypeCode() == ::ot_boolean;
342 369 }
... ... @@ -349,47 +376,76 @@ QPDFObjectHandle::isDirectNull() const
349 376 return (obj && getObjectID() == 0 && obj->getTypeCode() == ::ot_null);
350 377 }
351 378  
  379 +#ifndef QPDF_FUTURE
352 380 bool
353 381 QPDFObjectHandle::isNull()
  382 +#else
  383 +bool
  384 +QPDFObjectHandle::isNull() const
  385 +#endif
354 386 {
355 387 return obj && obj->getResolvedTypeCode() == ::ot_null;
356 388 }
357 389  
  390 +#ifndef QPDF_FUTURE
358 391 bool
359 392 QPDFObjectHandle::isInteger()
  393 +#else
  394 +bool
  395 +QPDFObjectHandle::isInteger() const
  396 +#endif
360 397 {
361 398 return obj && obj->getResolvedTypeCode() == ::ot_integer;
362 399 }
363 400  
  401 +#ifndef QPDF_FUTURE
364 402 bool
365 403 QPDFObjectHandle::isReal()
  404 +#else
  405 +bool
  406 +QPDFObjectHandle::isReal() const
  407 +#endif
366 408 {
367 409 return obj && obj->getResolvedTypeCode() == ::ot_real;
368 410 }
369 411  
  412 +#ifndef QPDF_FUTURE
370 413 bool
371 414 QPDFObjectHandle::isNumber()
  415 +#else
  416 +bool
  417 +QPDFObjectHandle::isNumber() const
  418 +#endif
372 419 {
373 420 return (isInteger() || isReal());
374 421 }
375 422  
  423 +#ifndef QPDF_FUTURE
376 424 double
377 425 QPDFObjectHandle::getNumericValue()
  426 +#else
  427 +double
  428 +QPDFObjectHandle::getNumericValue() const
  429 +#endif
378 430 {
379   - double result = 0.0;
380 431 if (isInteger()) {
381   - result = static_cast<double>(getIntValue());
  432 + return static_cast<double>(getIntValue());
382 433 } else if (isReal()) {
383   - result = atof(getRealValue().c_str());
  434 + return atof(getRealValue().c_str());
384 435 } else {
385 436 typeWarning("number", "returning 0");
386 437 QTC::TC("qpdf", "QPDFObjectHandle numeric non-numeric");
  438 + return 0;
387 439 }
388   - return result;
389 440 }
390 441  
  442 +#ifndef QPDF_FUTURE
391 443 bool
392 444 QPDFObjectHandle::getValueAsNumber(double& value)
  445 +#else
  446 +bool
  447 +QPDFObjectHandle::getValueAsNumber(double& value) const
  448 +#endif
393 449 {
394 450 if (!isNumber()) {
395 451 return false;
... ... @@ -398,83 +454,148 @@ QPDFObjectHandle::getValueAsNumber(double&amp; value)
398 454 return true;
399 455 }
400 456  
  457 +#ifndef QPDF_FUTURE
401 458 bool
402 459 QPDFObjectHandle::isName()
  460 +#else
  461 +bool
  462 +QPDFObjectHandle::isName() const
  463 +#endif
403 464 {
404 465 return obj && obj->getResolvedTypeCode() == ::ot_name;
405 466 }
406 467  
  468 +#ifndef QPDF_FUTURE
407 469 bool
408 470 QPDFObjectHandle::isString()
  471 +#else
  472 +bool
  473 +QPDFObjectHandle::isString() const
  474 +#endif
409 475 {
410 476 return obj && obj->getResolvedTypeCode() == ::ot_string;
411 477 }
412 478  
  479 +#ifndef QPDF_FUTURE
413 480 bool
414 481 QPDFObjectHandle::isOperator()
  482 +#else
  483 +bool
  484 +QPDFObjectHandle::isOperator() const
  485 +#endif
415 486 {
416 487 return obj && obj->getResolvedTypeCode() == ::ot_operator;
417 488 }
418 489  
  490 +#ifndef QPDF_FUTURE
419 491 bool
420 492 QPDFObjectHandle::isInlineImage()
  493 +#else
  494 +bool
  495 +QPDFObjectHandle::isInlineImage() const
  496 +#endif
421 497 {
422 498 return obj && obj->getResolvedTypeCode() == ::ot_inlineimage;
423 499 }
424 500  
  501 +#ifndef QPDF_FUTURE
425 502 bool
426 503 QPDFObjectHandle::isArray()
  504 +#else
  505 +bool
  506 +QPDFObjectHandle::isArray() const
  507 +#endif
427 508 {
428 509 return obj && obj->getResolvedTypeCode() == ::ot_array;
429 510 }
430 511  
  512 +#ifndef QPDF_FUTURE
431 513 bool
432 514 QPDFObjectHandle::isDictionary()
  515 +#else
  516 +bool
  517 +QPDFObjectHandle::isDictionary() const
  518 +#endif
433 519 {
434 520 return obj && obj->getResolvedTypeCode() == ::ot_dictionary;
435 521 }
436 522  
  523 +#ifndef QPDF_FUTURE
437 524 bool
438 525 QPDFObjectHandle::isStream()
  526 +#else
  527 +bool
  528 +QPDFObjectHandle::isStream() const
  529 +#endif
439 530 {
440 531 return obj && obj->getResolvedTypeCode() == ::ot_stream;
441 532 }
442 533  
  534 +#ifndef QPDF_FUTURE
443 535 bool
444 536 QPDFObjectHandle::isReserved()
  537 +#else
  538 +bool
  539 +QPDFObjectHandle::isReserved() const
  540 +#endif
445 541 {
446 542 return obj && obj->getResolvedTypeCode() == ::ot_reserved;
447 543 }
448 544  
  545 +#ifndef QPDF_FUTURE
449 546 bool
450 547 QPDFObjectHandle::isScalar()
  548 +#else
  549 +bool
  550 +QPDFObjectHandle::isScalar() const
  551 +#endif
451 552 {
452 553 return isBool() || isInteger() || isName() || isNull() || isReal() || isString();
453 554 }
454 555  
  556 +#ifndef QPDF_FUTURE
455 557 bool
456 558 QPDFObjectHandle::isNameAndEquals(std::string const& name)
  559 +#else
  560 +bool
  561 +QPDFObjectHandle::isNameAndEquals(std::string const& name) const
  562 +#endif
457 563 {
458 564 return isName() && (getName() == name);
459 565 }
460 566  
  567 +#ifndef QPDF_FUTURE
461 568 bool
462 569 QPDFObjectHandle::isDictionaryOfType(std::string const& type, std::string const& subtype)
  570 +#else
  571 +bool
  572 +QPDFObjectHandle::isDictionaryOfType(std::string const& type, std::string const& subtype) const
  573 +#endif
463 574 {
464 575 return isDictionary() && (type.empty() || getKey("/Type").isNameAndEquals(type)) &&
465 576 (subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype));
466 577 }
467 578  
  579 +#ifndef QPDF_FUTURE
468 580 bool
469 581 QPDFObjectHandle::isStreamOfType(std::string const& type, std::string const& subtype)
  582 +#else
  583 +bool
  584 +QPDFObjectHandle::isStreamOfType(std::string const& type, std::string const& subtype) const
  585 +#endif
470 586 {
471 587 return isStream() && getDict().isDictionaryOfType(type, subtype);
472 588 }
473 589  
474 590 // Bool accessors
475 591  
  592 +#ifndef QPDF_FUTURE
476 593 bool
477 594 QPDFObjectHandle::getBoolValue()
  595 +#else
  596 +bool
  597 +QPDFObjectHandle::getBoolValue() const
  598 +#endif
478 599 {
479 600 auto boolean = asBool();
480 601 if (boolean) {
... ... @@ -486,8 +607,13 @@ QPDFObjectHandle::getBoolValue()
486 607 }
487 608 }
488 609  
  610 +#ifndef QPDF_FUTURE
489 611 bool
490 612 QPDFObjectHandle::getValueAsBool(bool& value)
  613 +#else
  614 +bool
  615 +QPDFObjectHandle::getValueAsBool(bool& value) const
  616 +#endif
491 617 {
492 618 auto boolean = asBool();
493 619 if (boolean == nullptr) {
... ... @@ -499,8 +625,13 @@ QPDFObjectHandle::getValueAsBool(bool&amp; value)
499 625  
500 626 // Integer accessors
501 627  
  628 +#ifndef QPDF_FUTURE
502 629 long long
503 630 QPDFObjectHandle::getIntValue()
  631 +#else
  632 +long long
  633 +QPDFObjectHandle::getIntValue() const
  634 +#endif
504 635 {
505 636 auto integer = asInteger();
506 637 if (integer) {
... ... @@ -512,8 +643,13 @@ QPDFObjectHandle::getIntValue()
512 643 }
513 644 }
514 645  
  646 +#ifndef QPDF_FUTURE
515 647 bool
516 648 QPDFObjectHandle::getValueAsInt(long long& value)
  649 +#else
  650 +bool
  651 +QPDFObjectHandle::getValueAsInt(long long& value) const
  652 +#endif
517 653 {
518 654 auto integer = asInteger();
519 655 if (integer == nullptr) {
... ... @@ -523,8 +659,13 @@ QPDFObjectHandle::getValueAsInt(long long&amp; value)
523 659 return true;
524 660 }
525 661  
  662 +#ifndef QPDF_FUTURE
526 663 int
527 664 QPDFObjectHandle::getIntValueAsInt()
  665 +#else
  666 +int
  667 +QPDFObjectHandle::getIntValueAsInt() const
  668 +#endif
528 669 {
529 670 int result = 0;
530 671 long long v = getIntValue();
... ... @@ -542,8 +683,13 @@ QPDFObjectHandle::getIntValueAsInt()
542 683 return result;
543 684 }
544 685  
  686 +#ifndef QPDF_FUTURE
545 687 bool
546 688 QPDFObjectHandle::getValueAsInt(int& value)
  689 +#else
  690 +bool
  691 +QPDFObjectHandle::getValueAsInt(int& value) const
  692 +#endif
547 693 {
548 694 if (!isInteger()) {
549 695 return false;
... ... @@ -552,22 +698,31 @@ QPDFObjectHandle::getValueAsInt(int&amp; value)
552 698 return true;
553 699 }
554 700  
  701 +#ifndef QPDF_FUTURE
555 702 unsigned long long
556 703 QPDFObjectHandle::getUIntValue()
  704 +#else
  705 +unsigned long long
  706 +QPDFObjectHandle::getUIntValue() const
  707 +#endif
557 708 {
558   - unsigned long long result = 0;
559 709 long long v = getIntValue();
560 710 if (v < 0) {
561 711 QTC::TC("qpdf", "QPDFObjectHandle uint returning 0");
562 712 warnIfPossible("unsigned value request for negative number; returning 0");
  713 + return 0;
563 714 } else {
564   - result = static_cast<unsigned long long>(v);
  715 + return static_cast<unsigned long long>(v);
565 716 }
566   - return result;
567 717 }
568 718  
  719 +#ifndef QPDF_FUTURE
569 720 bool
570 721 QPDFObjectHandle::getValueAsUInt(unsigned long long& value)
  722 +#else
  723 +bool
  724 +QPDFObjectHandle::getValueAsUInt(unsigned long long& value) const
  725 +#endif
571 726 {
572 727 if (!isInteger()) {
573 728 return false;
... ... @@ -576,27 +731,35 @@ QPDFObjectHandle::getValueAsUInt(unsigned long long&amp; value)
576 731 return true;
577 732 }
578 733  
  734 +#ifndef QPDF_FUTURE
579 735 unsigned int
580 736 QPDFObjectHandle::getUIntValueAsUInt()
  737 +#else
  738 +unsigned int
  739 +QPDFObjectHandle::getUIntValueAsUInt() const
  740 +#endif
581 741 {
582   - unsigned int result = 0;
583 742 long long v = getIntValue();
584 743 if (v < 0) {
585 744 QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0");
586 745 warnIfPossible("unsigned integer value request for negative number; returning 0");
587   - result = 0;
  746 + return 0;
588 747 } else if (v > UINT_MAX) {
589 748 QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX");
590 749 warnIfPossible("requested value of unsigned integer is too big; returning UINT_MAX");
591   - result = UINT_MAX;
  750 + return UINT_MAX;
592 751 } else {
593   - result = static_cast<unsigned int>(v);
  752 + return static_cast<unsigned int>(v);
594 753 }
595   - return result;
596 754 }
597 755  
  756 +#ifndef QPDF_FUTURE
598 757 bool
599 758 QPDFObjectHandle::getValueAsUInt(unsigned int& value)
  759 +#else
  760 +bool
  761 +QPDFObjectHandle::getValueAsUInt(unsigned int& value) const
  762 +#endif
600 763 {
601 764 if (!isInteger()) {
602 765 return false;
... ... @@ -607,8 +770,13 @@ QPDFObjectHandle::getValueAsUInt(unsigned int&amp; value)
607 770  
608 771 // Real accessors
609 772  
  773 +#ifndef QPDF_FUTURE
610 774 std::string
611 775 QPDFObjectHandle::getRealValue()
  776 +#else
  777 +std::string
  778 +QPDFObjectHandle::getRealValue() const
  779 +#endif
612 780 {
613 781 if (isReal()) {
614 782 return obj->getStringValue();
... ... @@ -619,8 +787,13 @@ QPDFObjectHandle::getRealValue()
619 787 }
620 788 }
621 789  
  790 +#ifndef QPDF_FUTURE
622 791 bool
623 792 QPDFObjectHandle::getValueAsReal(std::string& value)
  793 +#else
  794 +bool
  795 +QPDFObjectHandle::getValueAsReal(std::string& value) const
  796 +#endif
624 797 {
625 798 if (!isReal()) {
626 799 return false;
... ... @@ -631,8 +804,13 @@ QPDFObjectHandle::getValueAsReal(std::string&amp; value)
631 804  
632 805 // Name accessors
633 806  
  807 +#ifndef QPDF_FUTURE
634 808 std::string
635 809 QPDFObjectHandle::getName()
  810 +#else
  811 +std::string
  812 +QPDFObjectHandle::getName() const
  813 +#endif
636 814 {
637 815 if (isName()) {
638 816 return obj->getStringValue();
... ... @@ -643,8 +821,13 @@ QPDFObjectHandle::getName()
643 821 }
644 822 }
645 823  
  824 +#ifndef QPDF_FUTURE
646 825 bool
647 826 QPDFObjectHandle::getValueAsName(std::string& value)
  827 +#else
  828 +bool
  829 +QPDFObjectHandle::getValueAsName(std::string& value) const
  830 +#endif
648 831 {
649 832 if (!isName()) {
650 833 return false;
... ... @@ -655,8 +838,13 @@ QPDFObjectHandle::getValueAsName(std::string&amp; value)
655 838  
656 839 // String accessors
657 840  
  841 +#ifndef QPDF_FUTURE
658 842 std::string
659 843 QPDFObjectHandle::getStringValue()
  844 +#else
  845 +std::string
  846 +QPDFObjectHandle::getStringValue() const
  847 +#endif
660 848 {
661 849 if (isString()) {
662 850 return obj->getStringValue();
... ... @@ -667,8 +855,13 @@ QPDFObjectHandle::getStringValue()
667 855 }
668 856 }
669 857  
  858 +#ifndef QPDF_FUTURE
670 859 bool
671 860 QPDFObjectHandle::getValueAsString(std::string& value)
  861 +#else
  862 +bool
  863 +QPDFObjectHandle::getValueAsString(std::string& value) const
  864 +#endif
672 865 {
673 866 if (!isString()) {
674 867 return false;
... ... @@ -677,8 +870,13 @@ QPDFObjectHandle::getValueAsString(std::string&amp; value)
677 870 return true;
678 871 }
679 872  
  873 +#ifndef QPDF_FUTURE
680 874 std::string
681 875 QPDFObjectHandle::getUTF8Value()
  876 +#else
  877 +std::string
  878 +QPDFObjectHandle::getUTF8Value() const
  879 +#endif
682 880 {
683 881 auto str = asString();
684 882 if (str) {
... ... @@ -690,8 +888,13 @@ QPDFObjectHandle::getUTF8Value()
690 888 }
691 889 }
692 890  
  891 +#ifndef QPDF_FUTURE
693 892 bool
694 893 QPDFObjectHandle::getValueAsUTF8(std::string& value)
  894 +#else
  895 +bool
  896 +QPDFObjectHandle::getValueAsUTF8(std::string& value) const
  897 +#endif
695 898 {
696 899 auto str = asString();
697 900 if (str == nullptr) {
... ... @@ -703,8 +906,13 @@ QPDFObjectHandle::getValueAsUTF8(std::string&amp; value)
703 906  
704 907 // Operator and Inline Image accessors
705 908  
  909 +#ifndef QPDF_FUTURE
706 910 std::string
707 911 QPDFObjectHandle::getOperatorValue()
  912 +#else
  913 +std::string
  914 +QPDFObjectHandle::getOperatorValue() const
  915 +#endif
708 916 {
709 917 if (isOperator()) {
710 918 return obj->getStringValue();
... ... @@ -715,8 +923,13 @@ QPDFObjectHandle::getOperatorValue()
715 923 }
716 924 }
717 925  
  926 +#ifndef QPDF_FUTURE
718 927 bool
719 928 QPDFObjectHandle::getValueAsOperator(std::string& value)
  929 +#else
  930 +bool
  931 +QPDFObjectHandle::getValueAsOperator(std::string& value) const
  932 +#endif
720 933 {
721 934 if (!isOperator()) {
722 935 return false;
... ... @@ -725,8 +938,13 @@ QPDFObjectHandle::getValueAsOperator(std::string&amp; value)
725 938 return true;
726 939 }
727 940  
  941 +#ifndef QPDF_FUTURE
728 942 std::string
729 943 QPDFObjectHandle::getInlineImageValue()
  944 +#else
  945 +std::string
  946 +QPDFObjectHandle::getInlineImageValue() const
  947 +#endif
730 948 {
731 949 if (isInlineImage()) {
732 950 return obj->getStringValue();
... ... @@ -737,8 +955,13 @@ QPDFObjectHandle::getInlineImageValue()
737 955 }
738 956 }
739 957  
  958 +#ifndef QPDF_FUTURE
740 959 bool
741 960 QPDFObjectHandle::getValueAsInlineImage(std::string& value)
  961 +#else
  962 +bool
  963 +QPDFObjectHandle::getValueAsInlineImage(std::string& value) const
  964 +#endif
742 965 {
743 966 if (!isInlineImage()) {
744 967 return false;
... ... @@ -755,8 +978,13 @@ QPDFObjectHandle::aitems()
755 978 return *this;
756 979 }
757 980  
  981 +#ifndef QPDF_FUTURE
758 982 int
759 983 QPDFObjectHandle::getArrayNItems()
  984 +#else
  985 +int
  986 +QPDFObjectHandle::getArrayNItems() const
  987 +#endif
760 988 {
761 989 if (auto array = asArray()) {
762 990 return array->size();
... ... @@ -767,8 +995,13 @@ QPDFObjectHandle::getArrayNItems()
767 995 }
768 996 }
769 997  
  998 +#ifndef QPDF_FUTURE
770 999 QPDFObjectHandle
771 1000 QPDFObjectHandle::getArrayItem(int n)
  1001 +#else
  1002 +QPDFObjectHandle
  1003 +QPDFObjectHandle::getArrayItem(int n) const
  1004 +#endif
772 1005 {
773 1006 if (auto array = asArray()) {
774 1007 if (auto result = array->at(n); result.obj != nullptr) {
... ... @@ -785,8 +1018,13 @@ QPDFObjectHandle::getArrayItem(int n)
785 1018 return QPDF_Null::create(obj, msg, "");
786 1019 }
787 1020  
  1021 +#ifndef QPDF_FUTURE
788 1022 bool
789 1023 QPDFObjectHandle::isRectangle()
  1024 +#else
  1025 +bool
  1026 +QPDFObjectHandle::isRectangle() const
  1027 +#endif
790 1028 {
791 1029 if (auto array = asArray()) {
792 1030 for (int i = 0; i < 4; ++i) {
... ... @@ -799,8 +1037,13 @@ QPDFObjectHandle::isRectangle()
799 1037 return false;
800 1038 }
801 1039  
  1040 +#ifndef QPDF_FUTURE
802 1041 bool
803 1042 QPDFObjectHandle::isMatrix()
  1043 +#else
  1044 +bool
  1045 +QPDFObjectHandle::isMatrix() const
  1046 +#endif
804 1047 {
805 1048 if (auto array = asArray()) {
806 1049 for (int i = 0; i < 6; ++i) {
... ... @@ -813,8 +1056,13 @@ QPDFObjectHandle::isMatrix()
813 1056 return false;
814 1057 }
815 1058  
  1059 +#ifndef QPDF_FUTURE
816 1060 QPDFObjectHandle::Rectangle
817 1061 QPDFObjectHandle::getArrayAsRectangle()
  1062 +#else
  1063 +QPDFObjectHandle::Rectangle
  1064 +QPDFObjectHandle::getArrayAsRectangle() const
  1065 +#endif
818 1066 {
819 1067 if (auto array = asArray()) {
820 1068 if (array->size() != 4) {
... ... @@ -835,8 +1083,13 @@ QPDFObjectHandle::getArrayAsRectangle()
835 1083 return {};
836 1084 }
837 1085  
  1086 +#ifndef QPDF_FUTURE
838 1087 QPDFObjectHandle::Matrix
839 1088 QPDFObjectHandle::getArrayAsMatrix()
  1089 +#else
  1090 +QPDFObjectHandle::Matrix
  1091 +QPDFObjectHandle::getArrayAsMatrix() const
  1092 +#endif
840 1093 {
841 1094 if (auto array = asArray()) {
842 1095 if (array->size() != 6) {
... ... @@ -853,8 +1106,13 @@ QPDFObjectHandle::getArrayAsMatrix()
853 1106 return {};
854 1107 }
855 1108  
  1109 +#ifndef QPDF_FUTURE
856 1110 std::vector<QPDFObjectHandle>
857 1111 QPDFObjectHandle::getArrayAsVector()
  1112 +#else
  1113 +std::vector<QPDFObjectHandle>
  1114 +QPDFObjectHandle::getArrayAsVector() const
  1115 +#endif
858 1116 {
859 1117 auto array = asArray();
860 1118 if (array) {
... ... @@ -962,8 +1220,13 @@ QPDFObjectHandle::ditems()
962 1220 return {*this};
963 1221 }
964 1222  
  1223 +#ifndef QPDF_FUTURE
965 1224 bool
966 1225 QPDFObjectHandle::hasKey(std::string const& key)
  1226 +#else
  1227 +bool
  1228 +QPDFObjectHandle::hasKey(std::string const& key) const
  1229 +#endif
967 1230 {
968 1231 auto dict = asDictionary();
969 1232 if (dict) {
... ... @@ -975,8 +1238,13 @@ QPDFObjectHandle::hasKey(std::string const&amp; key)
975 1238 }
976 1239 }
977 1240  
  1241 +#ifndef QPDF_FUTURE
978 1242 QPDFObjectHandle
979 1243 QPDFObjectHandle::getKey(std::string const& key)
  1244 +#else
  1245 +QPDFObjectHandle
  1246 +QPDFObjectHandle::getKey(std::string const& key) const
  1247 +#endif
980 1248 {
981 1249 if (auto dict = asDictionary()) {
982 1250 return dict->getKey(key);
... ... @@ -988,14 +1256,24 @@ QPDFObjectHandle::getKey(std::string const&amp; key)
988 1256 }
989 1257 }
990 1258  
  1259 +#ifndef QPDF_FUTURE
991 1260 QPDFObjectHandle
992 1261 QPDFObjectHandle::getKeyIfDict(std::string const& key)
  1262 +#else
  1263 +QPDFObjectHandle
  1264 +QPDFObjectHandle::getKeyIfDict(std::string const& key) const
  1265 +#endif
993 1266 {
994 1267 return isNull() ? newNull() : getKey(key);
995 1268 }
996 1269  
  1270 +#ifndef QPDF_FUTURE
997 1271 std::set<std::string>
998 1272 QPDFObjectHandle::getKeys()
  1273 +#else
  1274 +std::set<std::string>
  1275 +QPDFObjectHandle::getKeys() const
  1276 +#endif
999 1277 {
1000 1278 std::set<std::string> result;
1001 1279 auto dict = asDictionary();
... ... @@ -1008,8 +1286,13 @@ QPDFObjectHandle::getKeys()
1008 1286 return result;
1009 1287 }
1010 1288  
  1289 +#ifndef QPDF_FUTURE
1011 1290 std::map<std::string, QPDFObjectHandle>
1012 1291 QPDFObjectHandle::getDictAsMap()
  1292 +#else
  1293 +std::map<std::string, QPDFObjectHandle>
  1294 +QPDFObjectHandle::getDictAsMap() const
  1295 +#endif
1013 1296 {
1014 1297 std::map<std::string, QPDFObjectHandle> result;
1015 1298 auto dict = asDictionary();
... ... @@ -1023,13 +1306,18 @@ QPDFObjectHandle::getDictAsMap()
1023 1306 }
1024 1307  
1025 1308 // Array and Name accessors
  1309 +#ifndef QPDF_FUTURE
1026 1310 bool
1027 1311 QPDFObjectHandle::isOrHasName(std::string const& value)
  1312 +#else
  1313 +bool
  1314 +QPDFObjectHandle::isOrHasName(std::string const& value) const
  1315 +#endif
1028 1316 {
1029 1317 if (isNameAndEquals(value)) {
1030 1318 return true;
1031 1319 } else if (isArray()) {
1032   - for (auto& item: aitems()) {
  1320 + for (auto& item: getArrayAsVector()) {
1033 1321 if (item.isNameAndEquals(value)) {
1034 1322 return true;
1035 1323 }
... ... @@ -1152,8 +1440,13 @@ QPDFObjectHandle::mergeResources(
1152 1440 }
1153 1441 }
1154 1442  
  1443 +#ifndef QPDF_FUTURE
1155 1444 std::set<std::string>
1156 1445 QPDFObjectHandle::getResourceNames()
  1446 +#else
  1447 +std::set<std::string>
  1448 +QPDFObjectHandle::getResourceNames() const
  1449 +#endif
1157 1450 {
1158 1451 // Return second-level dictionary keys
1159 1452 std::set<std::string> result;
... ... @@ -1171,9 +1464,15 @@ QPDFObjectHandle::getResourceNames()
1171 1464 return result;
1172 1465 }
1173 1466  
  1467 +#ifndef QPDF_FUTURE
1174 1468 std::string
1175 1469 QPDFObjectHandle::getUniqueResourceName(
1176 1470 std::string const& prefix, int& min_suffix, std::set<std::string>* namesp)
  1471 +#else
  1472 +std::string
  1473 +QPDFObjectHandle::getUniqueResourceName(
  1474 + std::string const& prefix, int& min_suffix, std::set<std::string>* namesp) const
  1475 +#endif
1177 1476  
1178 1477 {
1179 1478 std::set<std::string> names = (namesp ? *namesp : getResourceNames());
... ... @@ -1255,8 +1554,13 @@ QPDFObjectHandle::replaceOrRemoveKey(std::string const&amp; key, QPDFObjectHandle co
1255 1554 }
1256 1555  
1257 1556 // Stream accessors
  1557 +#ifndef QPDF_FUTURE
1258 1558 QPDFObjectHandle
1259 1559 QPDFObjectHandle::getDict()
  1560 +#else
  1561 +QPDFObjectHandle
  1562 +QPDFObjectHandle::getDict() const
  1563 +#endif
1260 1564 {
1261 1565 return asStreamWithAssert()->getDict();
1262 1566 }
... ... @@ -1571,20 +1875,28 @@ QPDFObjectHandle::coalesceContentStreams()
1571 1875 new_contents.replaceStreamData(provider, newNull(), newNull());
1572 1876 }
1573 1877  
  1878 +#ifndef QPDF_FUTURE
1574 1879 std::string
1575 1880 QPDFObjectHandle::unparse()
  1881 +#else
  1882 +std::string
  1883 +QPDFObjectHandle::unparse() const
  1884 +#endif
1576 1885 {
1577   - std::string result;
1578 1886 if (this->isIndirect()) {
1579   - result = getObjGen().unparse(' ') + " R";
  1887 + return getObjGen().unparse(' ') + " R";
1580 1888 } else {
1581   - result = unparseResolved();
  1889 + return unparseResolved();
1582 1890 }
1583   - return result;
1584 1891 }
1585 1892  
  1893 +#ifndef QPDF_FUTURE
1586 1894 std::string
1587 1895 QPDFObjectHandle::unparseResolved()
  1896 +#else
  1897 +std::string
  1898 +QPDFObjectHandle::unparseResolved() const
  1899 +#endif
1588 1900 {
1589 1901 if (!obj) {
1590 1902 throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle");
... ... @@ -1592,11 +1904,15 @@ QPDFObjectHandle::unparseResolved()
1592 1904 return obj->unparse();
1593 1905 }
1594 1906  
  1907 +#ifndef QPDF_FUTURE
1595 1908 std::string
1596 1909 QPDFObjectHandle::unparseBinary()
  1910 +#else
  1911 +std::string
  1912 +QPDFObjectHandle::unparseBinary() const
  1913 +#endif
1597 1914 {
1598   - auto str = asString();
1599   - if (str) {
  1915 + if (auto str = asString()) {
1600 1916 return str->unparse(true);
1601 1917 } else {
1602 1918 return unparse();
... ... @@ -1604,14 +1920,24 @@ QPDFObjectHandle::unparseBinary()
1604 1920 }
1605 1921  
1606 1922 // Deprecated versionless getJSON to be removed in qpdf 12
  1923 +#ifndef QPDF_FUTURE
1607 1924 JSON
1608 1925 QPDFObjectHandle::getJSON(bool dereference_indirect)
  1926 +#else
  1927 +JSON
  1928 +QPDFObjectHandle::getJSON(bool dereference_indirect) const
  1929 +#endif
1609 1930 {
1610 1931 return getJSON(1, dereference_indirect);
1611 1932 }
1612 1933  
  1934 +#ifndef QPDF_FUTURE
1613 1935 JSON
1614 1936 QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect)
  1937 +#else
  1938 +JSON
  1939 +QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect) const
  1940 +#endif
1615 1941 {
1616 1942 if ((!dereference_indirect) && isIndirect()) {
1617 1943 return JSON::makeString(unparse());
... ... @@ -1626,8 +1952,13 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect)
1626 1952 }
1627 1953 }
1628 1954  
  1955 +#ifndef QPDF_FUTURE
1629 1956 void
1630 1957 QPDFObjectHandle::writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect)
  1958 +#else
  1959 +void
  1960 +QPDFObjectHandle::writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect) const
  1961 +#endif
1631 1962 {
1632 1963 if (!dereference_indirect && isIndirect()) {
1633 1964 p << "\"" << getObjGen().unparse(' ') << " R\"";
... ... @@ -1638,8 +1969,14 @@ QPDFObjectHandle::writeJSON(int json_version, JSON::Writer&amp; p, bool dereference_
1638 1969 }
1639 1970 }
1640 1971  
  1972 +#ifndef QPDF_FUTURE
1641 1973 void
1642 1974 QPDFObjectHandle::writeJSON(int json_version, Pipeline* p, bool dereference_indirect, size_t depth)
  1975 +#else
  1976 +void
  1977 +QPDFObjectHandle::writeJSON(
  1978 + int json_version, Pipeline* p, bool dereference_indirect, size_t depth) const
  1979 +#endif
1643 1980 {
1644 1981 JSON::Writer jw{p, depth};
1645 1982 writeJSON(json_version, jw, dereference_indirect);
... ... @@ -1871,8 +2208,13 @@ QPDFObjectHandle::parse(
1871 2208 return QPDFParser(input, object_description, tokenizer, decrypter, context).parse(empty, false);
1872 2209 }
1873 2210  
  2211 +#ifndef QPDF_FUTURE
1874 2212 qpdf_offset_t
1875 2213 QPDFObjectHandle::getParsedOffset()
  2214 +#else
  2215 +qpdf_offset_t
  2216 +QPDFObjectHandle::getParsedOffset() const
  2217 +#endif
1876 2218 {
1877 2219 return obj ? obj->getParsedOffset() : -1;
1878 2220 }
... ... @@ -2057,8 +2399,13 @@ QPDFObjectHandle::setObjectDescription(QPDF* owning_qpdf, std::string const&amp; obj
2057 2399 }
2058 2400 }
2059 2401  
  2402 +#ifndef QPDF_FUTURE
2060 2403 bool
2061 2404 QPDFObjectHandle::hasObjectDescription()
  2405 +#else
  2406 +bool
  2407 +QPDFObjectHandle::hasObjectDescription() const
  2408 +#endif
2062 2409 {
2063 2410 return obj && obj->hasDescription();
2064 2411 }
... ... @@ -2160,7 +2507,7 @@ QPDFObjectHandle::assertInitialized() const
2160 2507 }
2161 2508  
2162 2509 void
2163   -QPDFObjectHandle::typeWarning(char const* expected_type, std::string const& warning)
  2510 +QPDFObjectHandle::typeWarning(char const* expected_type, std::string const& warning) const
2164 2511 {
2165 2512 QPDF* context = nullptr;
2166 2513 std::string description;
... ... @@ -2179,11 +2526,16 @@ QPDFObjectHandle::typeWarning(char const* expected_type, std::string const&amp; warn
2179 2526 description,
2180 2527 0,
2181 2528 std::string("operation for ") + expected_type + " attempted on object of type " +
2182   - getTypeName() + ": " + warning));
  2529 + obj->getTypeName() + ": " + warning));
2183 2530 }
2184 2531  
  2532 +#ifndef QPDF_FUTURE
2185 2533 void
2186 2534 QPDFObjectHandle::warnIfPossible(std::string const& warning)
  2535 +#else
  2536 +void
  2537 +QPDFObjectHandle::warnIfPossible(std::string const& warning) const
  2538 +#endif
2187 2539 {
2188 2540 QPDF* context = nullptr;
2189 2541 std::string description;
... ... @@ -2195,7 +2547,7 @@ QPDFObjectHandle::warnIfPossible(std::string const&amp; warning)
2195 2547 }
2196 2548  
2197 2549 void
2198   -QPDFObjectHandle::objectWarning(std::string const& warning)
  2550 +QPDFObjectHandle::objectWarning(std::string const& warning) const
2199 2551 {
2200 2552 QPDF* context = nullptr;
2201 2553 std::string description;
... ... @@ -2206,109 +2558,189 @@ QPDFObjectHandle::objectWarning(std::string const&amp; warning)
2206 2558 }
2207 2559  
2208 2560 void
2209   -QPDFObjectHandle::assertType(char const* type_name, bool istype)
  2561 +QPDFObjectHandle::assertType(char const* type_name, bool istype) const
2210 2562 {
2211 2563 if (!istype) {
2212 2564 throw std::runtime_error(
2213 2565 std::string("operation for ") + type_name + " attempted on object of type " +
2214   - getTypeName());
  2566 + (obj ? obj->getTypeName() : "uninitialized"));
2215 2567 }
2216 2568 }
2217 2569  
  2570 +#ifndef QPDF_FUTURE
2218 2571 void
2219 2572 QPDFObjectHandle::assertNull()
  2573 +#else
  2574 +void
  2575 +QPDFObjectHandle::assertNull() const
  2576 +#endif
2220 2577 {
2221 2578 assertType("null", isNull());
2222 2579 }
2223 2580  
  2581 +#ifndef QPDF_FUTURE
2224 2582 void
2225 2583 QPDFObjectHandle::assertBool()
  2584 +#else
  2585 +void
  2586 +QPDFObjectHandle::assertBool() const
  2587 +#endif
2226 2588 {
2227 2589 assertType("boolean", isBool());
2228 2590 }
2229 2591  
  2592 +#ifndef QPDF_FUTURE
2230 2593 void
2231 2594 QPDFObjectHandle::assertInteger()
  2595 +#else
  2596 +void
  2597 +QPDFObjectHandle::assertInteger() const
  2598 +#endif
2232 2599 {
2233 2600 assertType("integer", isInteger());
2234 2601 }
2235 2602  
  2603 +#ifndef QPDF_FUTURE
2236 2604 void
2237 2605 QPDFObjectHandle::assertReal()
  2606 +#else
  2607 +void
  2608 +QPDFObjectHandle::assertReal() const
  2609 +#endif
2238 2610 {
2239 2611 assertType("real", isReal());
2240 2612 }
2241 2613  
  2614 +#ifndef QPDF_FUTURE
2242 2615 void
2243 2616 QPDFObjectHandle::assertName()
  2617 +#else
  2618 +void
  2619 +QPDFObjectHandle::assertName() const
  2620 +#endif
2244 2621 {
2245 2622 assertType("name", isName());
2246 2623 }
2247 2624  
  2625 +#ifndef QPDF_FUTURE
2248 2626 void
2249 2627 QPDFObjectHandle::assertString()
  2628 +#else
  2629 +void
  2630 +QPDFObjectHandle::assertString() const
  2631 +#endif
2250 2632 {
2251 2633 assertType("string", isString());
2252 2634 }
2253 2635  
  2636 +#ifndef QPDF_FUTURE
2254 2637 void
2255 2638 QPDFObjectHandle::assertOperator()
  2639 +#else
  2640 +void
  2641 +QPDFObjectHandle::assertOperator() const
  2642 +#endif
2256 2643 {
2257 2644 assertType("operator", isOperator());
2258 2645 }
2259 2646  
  2647 +#ifndef QPDF_FUTURE
2260 2648 void
2261 2649 QPDFObjectHandle::assertInlineImage()
  2650 +#else
  2651 +void
  2652 +QPDFObjectHandle::assertInlineImage() const
  2653 +#endif
2262 2654 {
2263 2655 assertType("inlineimage", isInlineImage());
2264 2656 }
2265 2657  
  2658 +#ifndef QPDF_FUTURE
2266 2659 void
2267 2660 QPDFObjectHandle::assertArray()
  2661 +#else
  2662 +void
  2663 +QPDFObjectHandle::assertArray() const
  2664 +#endif
2268 2665 {
2269 2666 assertType("array", isArray());
2270 2667 }
2271 2668  
  2669 +#ifndef QPDF_FUTURE
2272 2670 void
2273 2671 QPDFObjectHandle::assertDictionary()
  2672 +#else
  2673 +void
  2674 +QPDFObjectHandle::assertDictionary() const
  2675 +#endif
2274 2676 {
2275 2677 assertType("dictionary", isDictionary());
2276 2678 }
2277 2679  
  2680 +#ifndef QPDF_FUTURE
2278 2681 void
2279 2682 QPDFObjectHandle::assertStream()
  2683 +#else
  2684 +void
  2685 +QPDFObjectHandle::assertStream() const
  2686 +#endif
2280 2687 {
2281 2688 assertType("stream", isStream());
2282 2689 }
2283 2690  
  2691 +#ifndef QPDF_FUTURE
2284 2692 void
2285 2693 QPDFObjectHandle::assertReserved()
  2694 +#else
  2695 +void
  2696 +QPDFObjectHandle::assertReserved() const
  2697 +#endif
2286 2698 {
2287 2699 assertType("reserved", isReserved());
2288 2700 }
2289 2701  
  2702 +#ifndef QPDF_FUTURE
2290 2703 void
2291 2704 QPDFObjectHandle::assertIndirect()
  2705 +#else
  2706 +void
  2707 +QPDFObjectHandle::assertIndirect() const
  2708 +#endif
2292 2709 {
2293 2710 if (!isIndirect()) {
2294 2711 throw std::logic_error("operation for indirect object attempted on direct object");
2295 2712 }
2296 2713 }
2297 2714  
  2715 +#ifndef QPDF_FUTURE
2298 2716 void
2299 2717 QPDFObjectHandle::assertScalar()
  2718 +#else
  2719 +void
  2720 +QPDFObjectHandle::assertScalar() const
  2721 +#endif
2300 2722 {
2301 2723 assertType("scalar", isScalar());
2302 2724 }
2303 2725  
  2726 +#ifndef QPDF_FUTURE
2304 2727 void
2305 2728 QPDFObjectHandle::assertNumber()
  2729 +#else
  2730 +void
  2731 +QPDFObjectHandle::assertNumber() const
  2732 +#endif
2306 2733 {
2307 2734 assertType("number", isNumber());
2308 2735 }
2309 2736  
  2737 +#ifndef QPDF_FUTURE
2310 2738 bool
2311 2739 QPDFObjectHandle::isPageObject()
  2740 +#else
  2741 +bool
  2742 +QPDFObjectHandle::isPageObject() const
  2743 +#endif
2312 2744 {
2313 2745 // See comments in QPDFObjectHandle.hh.
2314 2746 if (getOwningQPDF() == nullptr) {
... ... @@ -2319,8 +2751,13 @@ QPDFObjectHandle::isPageObject()
2319 2751 return isDictionaryOfType("/Page");
2320 2752 }
2321 2753  
  2754 +#ifndef QPDF_FUTURE
2322 2755 bool
2323 2756 QPDFObjectHandle::isPagesObject()
  2757 +#else
  2758 +bool
  2759 +QPDFObjectHandle::isPagesObject() const
  2760 +#endif
2324 2761 {
2325 2762 if (getOwningQPDF() == nullptr) {
2326 2763 return false;
... ... @@ -2330,14 +2767,24 @@ QPDFObjectHandle::isPagesObject()
2330 2767 return isDictionaryOfType("/Pages");
2331 2768 }
2332 2769  
  2770 +#ifndef QPDF_FUTURE
2333 2771 bool
2334 2772 QPDFObjectHandle::isFormXObject()
  2773 +#else
  2774 +bool
  2775 +QPDFObjectHandle::isFormXObject() const
  2776 +#endif
2335 2777 {
2336 2778 return isStreamOfType("", "/Form");
2337 2779 }
2338 2780  
  2781 +#ifndef QPDF_FUTURE
2339 2782 bool
2340 2783 QPDFObjectHandle::isImage(bool exclude_imagemask)
  2784 +#else
  2785 +bool
  2786 +QPDFObjectHandle::isImage(bool exclude_imagemask) const
  2787 +#endif
2341 2788 {
2342 2789 return (
2343 2790 isStreamOfType("", "/Image") &&
... ... @@ -2358,8 +2805,13 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const&amp; item) const
2358 2805 }
2359 2806 }
2360 2807  
  2808 +#ifndef QPDF_FUTURE
2361 2809 void
2362 2810 QPDFObjectHandle::assertPageObject()
  2811 +#else
  2812 +void
  2813 +QPDFObjectHandle::assertPageObject() const
  2814 +#endif
2363 2815 {
2364 2816 if (!isPageObject()) {
2365 2817 throw std::runtime_error("page operation called on non-Page object");
... ...