Path.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ///
  2. /// \file Plugin/Path.hpp
  3. ///
  4. /// Plugin path represents a UNIX-style path for the plugin hierarchy.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2018 Josh Blum
  8. /// 2019 Nicholas Corgan
  9. /// SPDX-License-Identifier: BSL-1.0
  10. ///
  11. #pragma once
  12. #include <Pothos/Config.hpp>
  13. #include <vector>
  14. #include <string>
  15. namespace Pothos {
  16. /*!
  17. * Plugin path represents a UNIX-style path for the plugin hierarchy.
  18. * All paths must be absolute and start with the root slash.
  19. * Node names must be alphanumeric, underscored, hyphenated.
  20. * Example of a valid path: /foo_bar/my-module
  21. */
  22. class POTHOS_API PluginPath
  23. {
  24. public:
  25. /*!
  26. * Create a PluginPath at the root ("/")
  27. */
  28. PluginPath(void);
  29. /*!
  30. * Create a PluginPath from a path string.
  31. * A PluginPathError will be thrown on bad format.
  32. * \param path a plugin path in string representation
  33. */
  34. PluginPath(const std::string &path);
  35. /*!
  36. * Create a PluginPath by concatenating two paths.
  37. * The resulting path with be a valid /path0/path1
  38. */
  39. PluginPath(const PluginPath &path0, const PluginPath &path1);
  40. /*!
  41. * Create a PluginPath from a path string.
  42. * \throws PluginPathError if bad format.
  43. * \param path a plugin path in string representation
  44. */
  45. PluginPath(const char *path);
  46. /*!
  47. * Copy constructor for PluginPath.
  48. * \param path the PluginPath to copy
  49. */
  50. PluginPath(const PluginPath &path);
  51. /*!
  52. * Destructor for PluginPath.
  53. */
  54. ~PluginPath(void);
  55. /*!
  56. * Assignment operator for PluginPath.
  57. * \param path the PluginPath to assign to this
  58. */
  59. PluginPath &operator=(const PluginPath &path);
  60. /*!
  61. * Join a subpath with the path in this PluginPath.
  62. * \throws PluginPathError if bad format.
  63. * \param subPath the path to append to the end
  64. * \return a newly constructed PluginPath
  65. */
  66. PluginPath join(const std::string &subPath) const;
  67. /*!
  68. * List the nodes that make up the path.
  69. * Basically, this splits the path at the slashes.
  70. * \return a vector of strings between each slash
  71. */
  72. std::vector<std::string> listNodes(void) const;
  73. /*!
  74. * Get the PluginPath as a string representation.
  75. * \return the path as a string with slashes
  76. */
  77. std::string toString(void) const;
  78. private:
  79. std::string _path;
  80. };
  81. /*!
  82. * Compare two plugin paths for equality.
  83. * \return true if the paths are identical
  84. */
  85. POTHOS_API bool operator==(const PluginPath &lhs, const PluginPath &rhs);
  86. /*!
  87. * Compare two plugin paths for inequality.
  88. * \return true if the paths are not identical
  89. */
  90. inline bool operator!=(const PluginPath &lhs, const PluginPath &rhs)
  91. {
  92. return !(lhs == rhs);
  93. }
  94. } //namespace Pothos