ctkCmdLineModuleDefaultPathBuilder.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) University College London
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================================*/
  14. #ifndef __ctkCmdLineModuleDefaultPathBuilder_h
  15. #define __ctkCmdLineModuleDefaultPathBuilder_h
  16. #include "ctkCommandLineModulesCoreExport.h"
  17. #include <QStringList>
  18. #include <QScopedPointer>
  19. struct ctkCmdLineModuleDefaultPathBuilderPrivate;
  20. /**
  21. * \class ctkCmdLineModuleDefaultPathBuilder
  22. * \brief Builds up a list of directory paths to search for command line modules.
  23. * \ingroup CommandLineModulesCore_API
  24. * \author m.clarkson@ucl.ac.uk
  25. *
  26. * Simple class to enable the user to easily add various directories
  27. * to a list of directories. You create this object, add a load of directories
  28. * by repeatedly calling add..() functions, and then call getDirectoryList()
  29. * to get the final StringList of directory locations.
  30. *
  31. * The choices are:
  32. * <pre>
  33. * 1. The directory or list of directories defined by the CTK_MODULE_LOAD_PATH environment variable.
  34. * Uses usual PATH semantics such as colon separator on *nix systems and semi-colon on Windows.
  35. * 2. The directory defined by the users HOME directory, or any sub-directory under this.
  36. * 3. The directory defined by the current working directory, or any sub-directory under this.
  37. * 4. The directory defined by the application installation directory or any sub-directory under this.
  38. * </pre>
  39. *
  40. * A strictMode flag exists to decide if this class only returns directories that already exist.
  41. */
  42. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleDefaultPathBuilder
  43. {
  44. public:
  45. ctkCmdLineModuleDefaultPathBuilder();
  46. ~ctkCmdLineModuleDefaultPathBuilder();
  47. /**
  48. * @brief Clears the current list of directories.
  49. */
  50. virtual void clear();
  51. /**
  52. * @brief Sets strict mode which checks that all directories already exist.
  53. * @param strict if true this object will only return existing directories,
  54. * if false, the return StringList is un-checked.
  55. */
  56. virtual void setStrictMode(const bool& strict);
  57. /**
  58. * @brief Returns the strict mode flag.
  59. */
  60. virtual bool strictMode() const;
  61. /**
  62. * @brief Adds the users home directory, or if specified a sub-directory.
  63. *
  64. * This depends on QDir::home() existing. If this is not the case,
  65. * then this method will do nothing and ignore the request.
  66. */
  67. virtual void addHomeDir(const QString& subFolder = QString());
  68. /**
  69. * @brief Adds the current working directory, or if specified a sub-directory.
  70. *
  71. * This depends on QDir::current() existing. If this is not the case,
  72. * then this method will do nothing and ignore the request.
  73. */
  74. virtual void addCurrentDir(const QString& subFolder = QString());
  75. /**
  76. * @brief Adds the application installation directory, or if specified a sub-directory.
  77. */
  78. virtual void addApplicationDir(const QString& subFolder = QString());
  79. /**
  80. * @brief Adds the directories denoted by the environment variable CTK_MODULE_LOAD_PATH.
  81. *
  82. * Semi-colon separated lists of directories are allowed.
  83. */
  84. virtual void addCtkModuleLoadPath();
  85. /**
  86. * @brief Returns the QStringList containing directories.
  87. * @return QStringList of directories or, if in strict mode, directories that already exist.
  88. */
  89. virtual QStringList getDirectoryList() const;
  90. private:
  91. QScopedPointer<ctkCmdLineModuleDefaultPathBuilderPrivate> d;
  92. Q_DISABLE_COPY(ctkCmdLineModuleDefaultPathBuilder)
  93. };
  94. #endif