BlockImpl.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ///
  2. /// \file Framework/BlockImpl.hpp
  3. ///
  4. /// This file contains inline definitions for Block members.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2014-2016 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Framework/Block.hpp>
  12. #include <Pothos/Framework/ConnectableImpl.hpp>
  13. #include <Pothos/Framework/Exception.hpp>
  14. #include <Pothos/Object/Containers.hpp>
  15. #include <utility> //std::forward
  16. inline const Pothos::WorkInfo &Pothos::Block::workInfo(void) const
  17. {
  18. return _workInfo;
  19. }
  20. inline Pothos::InputPort *Pothos::Block::input(const std::string &name) const
  21. {
  22. auto it = _namedInputs.find(name);
  23. if (it == _namedInputs.end()) throw PortAccessError(
  24. "Pothos::Block::input("+name+")", "input port name does not exist");
  25. return it->second;
  26. }
  27. inline Pothos::InputPort *Pothos::Block::input(const size_t index) const
  28. {
  29. if (index >= _indexedInputs.size()) throw PortAccessError(
  30. "Pothos::Block::input("+std::to_string(index)+")", "input port index does not exist");
  31. return _indexedInputs[index];
  32. }
  33. inline Pothos::OutputPort *Pothos::Block::output(const std::string &name) const
  34. {
  35. auto it = _namedOutputs.find(name);
  36. if (it == _namedOutputs.end()) throw PortAccessError(
  37. "Pothos::Block::output("+name+")", "output port name does not exist");
  38. return it->second;
  39. }
  40. inline Pothos::OutputPort *Pothos::Block::output(const size_t index) const
  41. {
  42. if (index >= _indexedOutputs.size()) throw PortAccessError(
  43. "Pothos::Block::output("+std::to_string(index)+")", "output port index does not exist");
  44. return _indexedOutputs[index];
  45. }
  46. inline const std::vector<Pothos::InputPort*> &Pothos::Block::inputs(void) const
  47. {
  48. return _indexedInputs;
  49. }
  50. inline const std::vector<Pothos::OutputPort*> &Pothos::Block::outputs(void) const
  51. {
  52. return _indexedOutputs;
  53. }
  54. inline const std::map<std::string, Pothos::InputPort*> &Pothos::Block::allInputs(void) const
  55. {
  56. return _namedInputs;
  57. }
  58. inline const std::map<std::string, Pothos::OutputPort*> &Pothos::Block::allOutputs(void) const
  59. {
  60. return _namedOutputs;
  61. }
  62. template <typename... ArgsType>
  63. void Pothos::Block::emitSignal(const std::string &name, ArgsType&&... args)
  64. {
  65. const auto it = _namedOutputs.find(name);
  66. if (it == _namedOutputs.end() or not it->second->isSignal()) throw PortAccessError(
  67. "Pothos::Block::emitSignal("+name+")", "signal port does not exist");
  68. const ObjectVector objArgs{{Object(std::forward<ArgsType>(args))...}};
  69. it->second->postMessage(std::move(objArgs));
  70. }