ctkCmdLineModuleDefaultPathBuilder.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * and then call getDirectoryList() to get a StringList of directory locations.
  29. *
  30. * The choices are:
  31. * <pre>
  32. * 1. The directory defined by the CTK_MODULE_LOAD_PATH environment variable or any sub-directory under this.
  33. * 2. The directory defined by the users HOME directory, or any sub-directory under this.
  34. * 3. The directory defined by the current working directory, or any sub-directory under this.
  35. * 4. The directory defined by the application installation directory or any sub-directory under this.
  36. * </pre>
  37. *
  38. * A strictMode flag exists to decide if this class only returns directories that already exist.
  39. */
  40. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleDefaultPathBuilder
  41. {
  42. public:
  43. ctkCmdLineModuleDefaultPathBuilder();
  44. ~ctkCmdLineModuleDefaultPathBuilder();
  45. /**
  46. * @brief Clears the current list of directories.
  47. */
  48. virtual void clear();
  49. /**
  50. * @brief Sets strict mode which checks that all directories already exist.
  51. * @param strict if true this object will only return existing directories,
  52. * if false, the return StringList is un-checked.
  53. */
  54. virtual void setStrictMode(const bool& strict);
  55. /**
  56. * @brief Returns the strict mode flag.
  57. */
  58. virtual bool strictMode() const;
  59. /**
  60. * @brief Adds the users home directory, or if specified a sub-directory.
  61. *
  62. * This depends on QDir::home() existing. If this is not the case,
  63. * then this method will do nothing and ignore the request.
  64. */
  65. virtual void addHomeDir(const QString& subFolder = QString());
  66. /**
  67. * @brief Adds the current working directory, or if specified a sub-directory.
  68. *
  69. * This depends on QDir::current() existing. If this is not the case,
  70. * then this method will do nothing and ignore the request.
  71. */
  72. virtual void addCurrentDir(const QString& subFolder = QString());
  73. /**
  74. * @brief Adds the application installation directory, or if specified a sub-directory.
  75. */
  76. virtual void addApplicationDir(const QString& subFolder = QString());
  77. /**
  78. * @brief Adds the directory denoted by the environment variable CTK_MODULE_LOAD_PATH,
  79. * or if specified a sub-directory.
  80. */
  81. virtual void addCtkModuleLoadPathDir(const QString& subFolder = QString());
  82. /**
  83. * @brief Returns the QStringList containing directories.
  84. * @return QStringList of directories or, if in strict mode, directories that already exist.
  85. */
  86. virtual QStringList getDirectoryList() const;
  87. private:
  88. QScopedPointer<ctkCmdLineModuleDefaultPathBuilderPrivate> d;
  89. Q_DISABLE_COPY(ctkCmdLineModuleDefaultPathBuilder)
  90. };
  91. #endif