Converters.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef Converters_h___
  2. #define Converters_h___
  3. #include "nsIStreamConverter.h"
  4. #include "nsIFactory.h"
  5. #include "nsCOMPtr.h"
  6. #include "nsStringAPI.h"
  7. #include <algorithm>
  8. /* This file defines stream converter components, and their accompanying factory class.
  9. * These converters implement the nsIStreamConverter interface and support both
  10. * asynchronous and synchronous stream conversion.
  11. */
  12. ///////////////////////////////////////////////
  13. // TestConverter
  14. extern const nsCID kTestConverterCID;
  15. class TestConverter : public nsIStreamConverter {
  16. virtual ~TestConverter() {}
  17. public:
  18. NS_DECL_ISUPPORTS
  19. NS_DECL_NSIREQUESTOBSERVER
  20. NS_DECL_NSISTREAMLISTENER
  21. TestConverter();
  22. // nsIStreamConverter methods
  23. NS_IMETHOD Convert(nsIInputStream *aFromStream, const char *aFromType,
  24. const char *aToType, nsISupports *ctxt, nsIInputStream **_retval) override;
  25. NS_IMETHOD AsyncConvertData(const char *aFromType, const char *aToType,
  26. nsIStreamListener *aListener, nsISupports *ctxt) override;
  27. // member data
  28. nsCOMPtr<nsIStreamListener> mListener;
  29. nsCString fromType;
  30. nsCString toType;
  31. };
  32. nsresult CreateTestConverter(nsISupports* aOuter, REFNSIID aIID, void** aResult);
  33. static inline uint32_t
  34. saturated(uint64_t aValue)
  35. {
  36. return (uint32_t) std::min(aValue, (uint64_t) UINT32_MAX);
  37. }
  38. #endif /* !Converters_h___ */