Links.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @file Links.hpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef COMMON_LINKS
  26. #define COMMON_LINKS 1
  27. #include <common/Node.hpp>
  28. #include <map>
  29. #include <sstream>
  30. namespace paradevs { namespace common {
  31. template < class Time >
  32. class Node;
  33. template < class Time >
  34. class Links : public std::multimap < Node < Time >, Node < Time > >
  35. {
  36. public:
  37. typedef std::pair < typename Links < Time >::const_iterator,
  38. typename Links < Time >::const_iterator > Result;
  39. Links()
  40. { }
  41. virtual ~Links()
  42. { }
  43. void add(Model < Time >* out_model, const std::string& out_port_name,
  44. Model < Time >* in_model, const std::string& in_port_name)
  45. {
  46. std::multimap < Node < Time >, Node < Time > >::insert(
  47. std::pair < Node < Time >, Node <Time > >(
  48. Node < Time >(out_model, out_port_name),
  49. Node < Time >(in_model, in_port_name)));
  50. }
  51. Links::Result find(Model < Time >* out_model,
  52. const std::string& out_port_name) const
  53. {
  54. return std::multimap < Node < Time >, Node < Time > >::equal_range(
  55. common::Node < Time >(out_model, out_port_name));
  56. }
  57. std::string to_string() const
  58. {
  59. std::stringstream ss;
  60. ss << "Graph = { ";
  61. for (typename Node < Time >::const_iterator it = Node < Time >::begin();
  62. it != Node < Time >::end(); ++it) {
  63. ss << "(" << it->first.get_model()->get_name() << ":"
  64. << it->first.get_port_name()
  65. << " -> "
  66. << it->second.get_model()->get_name() << ":"
  67. << it->second.get_port_name()
  68. << ") ";
  69. }
  70. ss << "}";
  71. return ss.str();
  72. }
  73. };
  74. } } // namespace paradevs common
  75. #endif