• Stephan Bergmann's avatar
    New o3tl::try/doGet to obtain value from Any · 0d7c5823
    Stephan Bergmann yazdı
    ...in an attempt to reduce usage of type-unsafe
    
      void const * css::uno::Any::getValue()
    
    These new functions are often more convenient to use than the existing ">>=" and
    Any::get<T>.  Note how they are careful to provide a pointer directly into the
    given Any, instead of creating temporaries.
    
    As an example, replaced most calls of getValue across xmloff:
    
    * Cases that first check for a specific type (via getValueType etc.) and then
      call getValue can instead call tryGet.  (But beware that tryGet supports some
      conversions, which a check for a specific type may have missed---either
      intentionally or by accident.  Also beware the somewhat common idiom of
      checking for TypeClass_ENUM and then using getValue to obtain a sal_Int32;
      this cannot be replaced with a call to tryGet.)
    
    * Cases that seem confident that the Any is of the correct type when calling
      getValue (but apparently are confident due to some higher-layer protocol, as
      the surrounding code does not do any checking via getValueType or similar) can
      instead call doGet.  It throws an exception if it turns out the confidence
      wasn't warranted.  (Many of the existing calls that directly dereferenced the
      return value of getValue as sal_Bool look suspicious, in that the author might
      have thought the given code would also cover a VOID Any---which technically it
      even would have happened to do.  If any RuntimeExceptions thrown from these
      doGet calls start to crop up, these changes need to be revisited.  Some may
      even be rewritten as uses of ">>=".  But at least "make check" did not show
      any such problems.  Also note that casting the value obtained from getValue to
      any css::uno::Reference<X> with X being anything but the base
      css::uno::XInterface was always prone to producing a bad pointer, in case the
      interface actually stored in the Any derived from X via multiple inheritance.)
    
    * Should there ever be cases where an Any is known to be of the requested type,
      some additional forceGet could be introduced (which would assert instead of
      throwing an exception).
    
    Change-Id: I2d8739e86314eff73abfcafe01d806f5bc5c34db
    0d7c5823
XMLIndexMarkExport.cxx 8.47 KB