ctkCaseInsensitiveString.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. * ctkCaseInsensitiveString wraps a QString and can be
  21. * used in Qt container classes as a key type representing
  22. * case insensitive strings. However, case is preserved when
  23. * retrieving the actual QString.
  24. */
  25. class CTK_PLUGINFW_EXPORT ctkCaseInsensitiveString
  26. {
  27. public:
  28. /**
  29. * Wraps a null QString.
  30. */
  31. ctkCaseInsensitiveString();
  32. /**
  33. * Wraps the given character sequence.
  34. *
  35. * @param str The characters to be wrapped by this ctkCaseInsensitiveString
  36. */
  37. ctkCaseInsensitiveString(const char* str);
  38. /**
  39. * Wraps the given QString.
  40. *
  41. * @param str The QString to be wrapped by this ctkCaseInsensitiveString
  42. */
  43. ctkCaseInsensitiveString(const QString& str);
  44. /**
  45. * Copy constructor.
  46. *
  47. * @param str The ctkCaseInsensitiveString instance to copy.
  48. */
  49. ctkCaseInsensitiveString(const ctkCaseInsensitiveString& str);
  50. /**
  51. * Assignment operator.
  52. *
  53. * @param str The ctkCaseInsensitiveString instance which should be
  54. * assigned.
  55. */
  56. ctkCaseInsensitiveString& operator=(const ctkCaseInsensitiveString& str);
  57. /**
  58. * String comparison ignoring case.
  59. *
  60. * @param str The string with which to compare this instance.
  61. * @return <code>true</code> if both strings are equal after being
  62. * converted to lower case strings, <code>false</code> otherwise.
  63. */
  64. bool operator==(const ctkCaseInsensitiveString& str) const;
  65. /**
  66. * Less than operator ignoring case.
  67. *
  68. * @param str The string with which to compare this instance.
  69. * @return <code>true</code> if the lower case variant of the
  70. * current string is lexicographically less then
  71. * the lower case variant of <code>str</code>, <code>false</code>
  72. * otherwise.
  73. */
  74. bool operator<(const ctkCaseInsensitiveString& str) const;
  75. /**
  76. * Converts this ctkCaseInsensitiveString instance to a QString,
  77. * preserving the original case.
  78. */
  79. operator QString() const;
  80. private:
  81. QString str;
  82. };
  83. /**
  84. * Returns a hash value for the lower case string.
  85. *
  86. * @param str The string to be hashed.
  87. */
  88. uint CTK_PLUGINFW_EXPORT qHash(const ctkCaseInsensitiveString& str);
  89. CTK_PLUGINFW_EXPORT QDataStream& operator<<(QDataStream &out, const ctkCaseInsensitiveString& str);
  90. CTK_PLUGINFW_EXPORT QDataStream& operator>>(QDataStream &in, ctkCaseInsensitiveString& str);
  91. #endif // CTKCASEINSENSITIVESTRING_P_H