Encoding.hxx.in 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef @KWSYS_NAMESPACE@_Encoding_hxx
  11. #define @KWSYS_NAMESPACE@_Encoding_hxx
  12. #include <@KWSYS_NAMESPACE@/Configure.hxx>
  13. #include <string>
  14. #include <vector>
  15. namespace @KWSYS_NAMESPACE@
  16. {
  17. class @KWSYS_NAMESPACE@_EXPORT Encoding
  18. {
  19. public:
  20. // Container class for argc/argv.
  21. class CommandLineArguments
  22. {
  23. public:
  24. // On Windows, get the program command line arguments
  25. // in this Encoding module's 8 bit encoding.
  26. // On other platforms the given argc/argv is used, and
  27. // to be consistent, should be the argc/argv from main().
  28. static CommandLineArguments Main(int argc, char const* const* argv);
  29. // Construct CommandLineArguments with the given
  30. // argc/argv. It is assumed that the string is already
  31. // in the encoding used by this module.
  32. CommandLineArguments(int argc, char const* const* argv);
  33. // Construct CommandLineArguments with the given
  34. // argc and wide argv. This is useful if wmain() is used.
  35. CommandLineArguments(int argc, wchar_t const* const* argv);
  36. ~CommandLineArguments();
  37. CommandLineArguments(const CommandLineArguments&);
  38. CommandLineArguments& operator=(const CommandLineArguments&);
  39. int argc() const;
  40. char const* const* argv() const;
  41. protected:
  42. std::vector<char*> argv_;
  43. };
  44. /**
  45. * Convert between char and wchar_t
  46. */
  47. #if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  48. // Convert a narrow string to a wide string.
  49. // On Windows, UTF-8 is assumed, and on other platforms,
  50. // the current locale is assumed.
  51. static std::wstring ToWide(const std::string& str);
  52. static std::wstring ToWide(const char* str);
  53. // Convert a wide string to a narrow string.
  54. // On Windows, UTF-8 is assumed, and on other platforms,
  55. // the current locale is assumed.
  56. static std::string ToNarrow(const std::wstring& str);
  57. static std::string ToNarrow(const wchar_t* str);
  58. #endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  59. }; // class Encoding
  60. } // namespace @KWSYS_NAMESPACE@
  61. #endif