Encoding.hxx.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <@KWSYS_NAMESPACE@/stl/string>
  14. #include <@KWSYS_NAMESPACE@/stl/vector>
  15. /* Define these macros temporarily to keep the code readable. */
  16. #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
  17. # define kwsys_stl @KWSYS_NAMESPACE@_stl
  18. #endif
  19. namespace @KWSYS_NAMESPACE@
  20. {
  21. class @KWSYS_NAMESPACE@_EXPORT Encoding
  22. {
  23. public:
  24. // Container class for argc/argv.
  25. class CommandLineArguments
  26. {
  27. public:
  28. // On Windows, get the program command line arguments
  29. // in this Encoding module's 8 bit encoding.
  30. // On other platforms the given argc/argv is used, and
  31. // to be consistent, should be the argc/argv from main().
  32. static CommandLineArguments Main(int argc, char const* const* argv);
  33. // Construct CommandLineArguments with the given
  34. // argc/argv. It is assumed that the string is already
  35. // in the encoding used by this module.
  36. CommandLineArguments(int argc, char const* const* argv);
  37. // Construct CommandLineArguments with the given
  38. // argc and wide argv. This is useful if wmain() is used.
  39. CommandLineArguments(int argc, wchar_t const* const* argv);
  40. ~CommandLineArguments();
  41. CommandLineArguments(const CommandLineArguments&);
  42. CommandLineArguments& operator=(const CommandLineArguments&);
  43. int argc() const;
  44. char const* const* argv() const;
  45. protected:
  46. std::vector<char*> argv_;
  47. };
  48. /**
  49. * Convert between char and wchar_t
  50. */
  51. #if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  52. // Convert a narrow string to a wide string.
  53. // On Windows, UTF-8 is assumed, and on other platforms,
  54. // the current locale is assumed.
  55. static kwsys_stl::wstring ToWide(const kwsys_stl::string& str);
  56. static kwsys_stl::wstring ToWide(const char* str);
  57. // Convert a wide string to a narrow string.
  58. // On Windows, UTF-8 is assumed, and on other platforms,
  59. // the current locale is assumed.
  60. static kwsys_stl::string ToNarrow(const kwsys_stl::wstring& str);
  61. static kwsys_stl::string ToNarrow(const wchar_t* str);
  62. #endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  63. }; // class Encoding
  64. } // namespace @KWSYS_NAMESPACE@
  65. /* Undefine temporary macros. */
  66. #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
  67. # undef kwsys_stl
  68. #endif
  69. #endif