ctkServiceProperties.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "ctkServiceProperties_p.h"
  16. #include <ctkException.h>
  17. //----------------------------------------------------------------------------
  18. ctkServiceProperties::ctkServiceProperties(const ctkProperties& props)
  19. {
  20. for(ctkProperties::ConstIterator i = props.begin(), end = props.end();
  21. i != end; ++i)
  22. {
  23. if (find(i.key()) != -1)
  24. {
  25. QString msg("ctkProperties object contains case variants of the key: ");
  26. msg += i.key();
  27. throw ctkInvalidArgumentException(msg);
  28. }
  29. ks.append(i.key());
  30. vs.append(i.value());
  31. }
  32. }
  33. //----------------------------------------------------------------------------
  34. QVariant ctkServiceProperties::value(const QString &key) const
  35. {
  36. int index = find(key);
  37. if (index < 0) return QVariant();
  38. return vs[index];
  39. }
  40. //----------------------------------------------------------------------------
  41. QVariant ctkServiceProperties::value(int index) const
  42. {
  43. return (index < 0 || index >= vs.size()) ? QVariant() : vs[index];
  44. }
  45. //----------------------------------------------------------------------------
  46. QStringList ctkServiceProperties::keys() const
  47. {
  48. QStringList result;
  49. for(int i = 0; i < ks.size(); ++i)
  50. {
  51. result.append(ks[i]);
  52. }
  53. return result;
  54. }
  55. //----------------------------------------------------------------------------
  56. int ctkServiceProperties::find(const QString &key) const
  57. {
  58. for (int i = 0; i < ks.size(); ++i)
  59. {
  60. if (ks[i].compare(key, Qt::CaseInsensitive) == 0)
  61. return i;
  62. }
  63. return -1;
  64. }
  65. //----------------------------------------------------------------------------
  66. int ctkServiceProperties::findCaseSensitive(const QString &key) const
  67. {
  68. for (int i = 0; i < ks.size(); ++i)
  69. {
  70. if (ks[i] == key)
  71. return i;
  72. }
  73. return -1;
  74. }