1
0

svc_stringconverter.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _SVC_STRINGCONVERTER_H
  2. #define _SVC_STRINGCONVERTER_H
  3. #include <bfc/dispatch.h>
  4. #include <api/service/services.h>
  5. #include <api/service/svcs/svc_stringtypes.h>
  6. // Porting Rule: A new service to respond to at least OSNATIVE and UTF16 shall be
  7. // provided for every new platform. This service should provide transcoding
  8. // to and from the platform's native internationalized string encoding format
  9. // (ie: MBCS under Win9x, WorldScript on the Mac, etc etc etc).and to and from
  10. // UTF16. If the OSNATIVE string _IS_ UTF16, just respond that you can convert
  11. // both.
  12. class NOVTABLE svc_stringConverter : public Dispatchable {
  13. public:
  14. static FOURCC getServiceType() { return WaSvc::STRINGCONVERTER; }
  15. // test the type.
  16. int canConvert(FOURCC encoding_type);
  17. // The return code is the number of bytes written to the output buffer, or the error.
  18. // A return code of 0 is not an error, other than you passing NULL or a size 0 buffer won't do much interesting.
  19. int convertToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes, char *out_buffer, int size_out_bytes);
  20. int preflightToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes);
  21. int convertFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes, void *out_buffer, int size_out_bytes);
  22. int preflightFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes);
  23. protected:
  24. enum {
  25. CANCONVERT,
  26. CONVERTTOUTF8,
  27. PREFLIGHTTOUTF8,
  28. CONVERTFROMUTF8,
  29. PREFLIGHTFROMUTF8
  30. };
  31. };
  32. inline
  33. int svc_stringConverter::canConvert(FOURCC encoding_type) {
  34. return _call(CANCONVERT, (int)0, encoding_type);
  35. }
  36. inline
  37. int svc_stringConverter::convertToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes, char *out_buffer, int size_out_bytes) {
  38. return _call(CONVERTTOUTF8, (int)0, encoding_type, in_buffer, size_in_bytes, out_buffer, size_out_bytes);
  39. }
  40. inline
  41. int svc_stringConverter::preflightToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes) {
  42. return _call(PREFLIGHTTOUTF8, (int)0, encoding_type, in_buffer, size_in_bytes);
  43. }
  44. inline
  45. int svc_stringConverter::convertFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes, void *out_buffer, int size_out_bytes) {
  46. return _call(CONVERTFROMUTF8, (int)0, encoding_type, in_buffer, size_in_bytes, out_buffer, size_out_bytes);
  47. }
  48. inline
  49. int svc_stringConverter::preflightFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes) {
  50. return _call(PREFLIGHTFROMUTF8, (int)0, encoding_type, in_buffer, size_in_bytes);
  51. }
  52. // implementor derives from this one
  53. class NOVTABLE svc_stringConverterI : public svc_stringConverter {
  54. public:
  55. // test the type
  56. virtual int canConvert(FOURCC encoding_type) = 0;
  57. virtual int convertToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes, char *out_buffer, int size_out_bytes) = 0;
  58. virtual int preflightToUTF8(FOURCC encoding_type, const void *in_buffer, int size_in_bytes) = 0;
  59. virtual int convertFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes, void *out_buffer, int size_out_bytes) = 0;
  60. virtual int preflightFromUTF8(FOURCC encoding_type, const char *in_buffer, int size_in_bytes) = 0;
  61. protected:
  62. RECVS_DISPATCH;
  63. };
  64. #include <api/service/svc_enum.h>
  65. class StringConverterEnum : public SvcEnumT<svc_stringConverter> {
  66. public:
  67. StringConverterEnum(FOURCC enc_type) : encoding_type(enc_type) {}
  68. protected:
  69. virtual int testService(svc_stringConverter *svc) {
  70. return (svc->canConvert(encoding_type));
  71. }
  72. private:
  73. FOURCC encoding_type;
  74. };
  75. #endif // _SVC_STRINGCONVERTER_H