PothosUtilModuleInfo.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2018-2018 Josh Blum
  2. // SPDX-License-Identifier: BSL-1.0
  3. #include "PothosUtil.hpp"
  4. #include <Pothos/Plugin.hpp>
  5. #include <map>
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <iomanip>
  9. static std::map<std::string, std::vector<std::string>> modMap;
  10. static std::map<std::string, std::string> modVers;
  11. static void traverseDump(const std::string &modulePath, const Pothos::PluginRegistryInfoDump &dump)
  12. {
  13. const bool isBuiltin = modulePath == "builtin" and dump.modulePath.empty();
  14. const bool filterPass = modulePath.empty() or modulePath == dump.modulePath;
  15. if (not dump.objectType.empty() and (isBuiltin or filterPass))
  16. {
  17. modMap[dump.modulePath].push_back(dump.pluginPath);
  18. modVers[dump.modulePath] = dump.moduleVersion;
  19. }
  20. for (const auto &subInfo : dump.subInfo)
  21. {
  22. traverseDump(modulePath, subInfo);
  23. }
  24. }
  25. static const std::string stringifyName(const std::string &modulePath)
  26. {
  27. return modulePath.empty()?"Builtin":modulePath;
  28. }
  29. void PothosUtilBase::printModuleInfo(const std::string &, const std::string &modulePath)
  30. {
  31. Pothos::ScopedInit init;
  32. traverseDump(modulePath, Pothos::PluginRegistry::dump());
  33. size_t maxPathLength(0);
  34. for (const auto &module : modMap)
  35. {
  36. const auto displayName = stringifyName(module.first);
  37. maxPathLength = std::max(maxPathLength, displayName.size());
  38. }
  39. for (const auto &module : modMap)
  40. {
  41. const auto displayName = stringifyName(module.first);
  42. const auto paddedName = displayName + std::string(maxPathLength-displayName.size()+1, ' ');
  43. std::cout << paddedName << "(" << std::setw(2) << module.second.size() << " plugins)";
  44. const auto modVer = modVers.at(module.first);
  45. if (not modVer.empty()) std::cout << " [" << modVer << "]";
  46. std::cout << std::endl;
  47. if (not modulePath.empty())
  48. {
  49. for (const auto &pluginPath : module.second)
  50. {
  51. std::cout << " " << pluginPath << std::endl;
  52. }
  53. }
  54. }
  55. std::cout << std::endl;
  56. }