ctkRequirePlugin.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 "ctkRequirePlugin_p.h"
  16. #include "ctkPluginConstants.h"
  17. #include "ctkPluginPrivate_p.h"
  18. ctkRequirePlugin::ctkRequirePlugin(ctkPluginPrivate* requestor,
  19. const QString& name, const QString& res,
  20. const QString& range)
  21. : name(name),
  22. resolution(res.isEmpty() ? PluginConstants::RESOLUTION_MANDATORY : res),
  23. pluginRange(range.isEmpty() ? ctkVersionRange::defaultVersionRange() : range)
  24. {
  25. if (resolution != PluginConstants::RESOLUTION_MANDATORY &&
  26. resolution != PluginConstants::RESOLUTION_OPTIONAL )
  27. {
  28. QString what = QString("Invalid directive : '")
  29. + PluginConstants::RESOLUTION_DIRECTIVE + ":=" + this->resolution
  30. + "' in manifest header '"
  31. + PluginConstants::REQUIRE_PLUGIN + ": " + this->name
  32. + "' of plugin with id " + requestor->id
  33. + " (" + requestor->symbolicName + ")"
  34. + ". The value must be either '"
  35. + PluginConstants::RESOLUTION_MANDATORY + "' or '"
  36. + PluginConstants::RESOLUTION_OPTIONAL + "'.";
  37. throw std::invalid_argument(what.toStdString());
  38. }
  39. }
  40. bool ctkRequirePlugin::overlap(const ctkRequirePlugin& rp) const
  41. {
  42. if (resolution == PluginConstants::RESOLUTION_MANDATORY &&
  43. rp.resolution != PluginConstants::RESOLUTION_MANDATORY)
  44. {
  45. return false;
  46. }
  47. return pluginRange.withinRange(rp.pluginRange);
  48. }