ctkCaseInsensitiveString.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCASEINSENSITIVESTRING_P_H
  16. #define CTKCASEINSENSITIVESTRING_P_H
  17. #include <QString>
  18. #include <ctkPluginFrameworkExport.h>
  19. /**
  20. * \ingroup PluginFramework
  21. *
  22. * ctkCaseInsensitiveString wraps a QString and can be
  23. * used in Qt container classes as a key type representing
  24. * case insensitive strings. However, case is preserved when
  25. * retrieving the actual QString.
  26. */
  27. class CTK_PLUGINFW_EXPORT ctkCaseInsensitiveString
  28. {
  29. public:
  30. /**
  31. * Wraps a null QString.
  32. */
  33. ctkCaseInsensitiveString();
  34. /**
  35. * Wraps the given character sequence.
  36. *
  37. * @param str The characters to be wrapped by this ctkCaseInsensitiveString
  38. */
  39. ctkCaseInsensitiveString(const char* str);
  40. /**
  41. * Wraps the given QString.
  42. *
  43. * @param str The QString to be wrapped by this ctkCaseInsensitiveString
  44. */
  45. ctkCaseInsensitiveString(const QString& str);
  46. /**
  47. * Copy constructor.
  48. *
  49. * @param str The ctkCaseInsensitiveString instance to copy.
  50. */
  51. ctkCaseInsensitiveString(const ctkCaseInsensitiveString& str);
  52. /**
  53. * Assignment operator.
  54. *
  55. * @param str The ctkCaseInsensitiveString instance which should be
  56. * assigned.
  57. */
  58. ctkCaseInsensitiveString& operator=(const ctkCaseInsensitiveString& str);
  59. /**
  60. * String comparison ignoring case.
  61. *
  62. * @param str The string with which to compare this instance.
  63. * @return <code>true</code> if both strings are equal after being
  64. * converted to lower case strings, <code>false</code> otherwise.
  65. */
  66. bool operator==(const ctkCaseInsensitiveString& str) const;
  67. /**
  68. * Less than operator ignoring case.
  69. *
  70. * @param str The string with which to compare this instance.
  71. * @return <code>true</code> if the lower case variant of the
  72. * current string is lexicographically less then
  73. * the lower case variant of <code>str</code>, <code>false</code>
  74. * otherwise.
  75. */
  76. bool operator<(const ctkCaseInsensitiveString& str) const;
  77. /**
  78. * Converts this ctkCaseInsensitiveString instance to a QString,
  79. * preserving the original case.
  80. */
  81. operator QString() const;
  82. private:
  83. QString str;
  84. };
  85. /**
  86. * \ingroup PluginFramework
  87. * @{
  88. *
  89. * Returns a hash value for the lower case string.
  90. *
  91. * @param str The string to be hashed.
  92. */
  93. uint CTK_PLUGINFW_EXPORT qHash(const ctkCaseInsensitiveString& str);
  94. CTK_PLUGINFW_EXPORT QDataStream& operator<<(QDataStream &out, const ctkCaseInsensitiveString& str);
  95. CTK_PLUGINFW_EXPORT QDataStream& operator>>(QDataStream &in, ctkCaseInsensitiveString& str);
  96. /** @}*/
  97. #endif // CTKCASEINSENSITIVESTRING_P_H