models.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @file tests/dtss/models.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 TESTS_DTSS_MODELS_HPP
  26. #define TESTS_DTSS_MODELS_HPP 1
  27. #include <dtss/Dynamics.hpp>
  28. #include <common/Time.hpp>
  29. namespace paradevs { namespace tests { namespace dtss {
  30. template < typename T >
  31. struct Limits
  32. {
  33. static constexpr T negative_infinity =
  34. -std::numeric_limits < T >::infinity();
  35. static constexpr T positive_infinity =
  36. std::numeric_limits < T >::infinity();
  37. static constexpr T null = 0;
  38. };
  39. typedef paradevs::common::Time < double, Limits < double > > MyTime;
  40. struct NoParameters
  41. {
  42. NoParameters()
  43. { }
  44. };
  45. class A : public paradevs::dtss::Dynamics < MyTime, NoParameters >
  46. {
  47. public:
  48. A(const std::string& name, const NoParameters& parameters) :
  49. paradevs::dtss::Dynamics < MyTime, NoParameters >(name, parameters)
  50. { }
  51. virtual ~A()
  52. { }
  53. void transition(const common::Bag < MyTime >& /* x */, MyTime::type t)
  54. {
  55. common::Trace < MyTime >::trace()
  56. << common::TraceElement < MyTime >(get_name(), t,
  57. common::DELTA_INT);
  58. common::Trace < MyTime >::trace().flush();
  59. }
  60. MyTime::type start(MyTime::type t)
  61. {
  62. common::Trace < MyTime >::trace()
  63. << common::TraceElement < MyTime >(get_name(), t,
  64. common::START);
  65. common::Trace < MyTime >::trace().flush();
  66. return 0;
  67. }
  68. common::Bag < MyTime > lambda(MyTime::type t) const
  69. {
  70. common::Bag < MyTime > msgs;
  71. msgs.push_back(common::ExternalEvent < MyTime >("out", 0.));
  72. common::Trace < MyTime >::trace()
  73. << common::TraceElement < MyTime >(get_name(), t,
  74. common::LAMBDA)
  75. << "messages = " << msgs.to_string();
  76. common::Trace < MyTime >::trace().flush();
  77. return msgs;
  78. }
  79. };
  80. class B : public paradevs::dtss::Dynamics < MyTime, NoParameters >
  81. {
  82. public:
  83. B(const std::string& name, const NoParameters& parameters) :
  84. paradevs::dtss::Dynamics < MyTime, NoParameters >(name, parameters)
  85. { }
  86. virtual ~B()
  87. { }
  88. void transition(const common::Bag < MyTime >& x, MyTime::type t)
  89. {
  90. common::Trace < MyTime >::trace()
  91. << common::TraceElement < MyTime >(get_name(), t,
  92. common::DELTA_INT)
  93. << "x = " << x.to_string();
  94. common::Trace < MyTime >::trace().flush();
  95. }
  96. MyTime::type start(MyTime::type t)
  97. {
  98. common::Trace < MyTime >::trace()
  99. << common::TraceElement < MyTime >(get_name(), t,
  100. common::START);
  101. common::Trace < MyTime >::trace().flush();
  102. return 0;
  103. }
  104. common::Bag < MyTime > lambda(MyTime::type t) const
  105. {
  106. common::Bag < MyTime > msgs;
  107. msgs.push_back(common::ExternalEvent < MyTime >("out", 0.));
  108. common::Trace < MyTime >::trace()
  109. << common::TraceElement < MyTime >(get_name(), t,
  110. common::LAMBDA)
  111. << "messages = " << msgs.to_string();
  112. common::Trace < MyTime >::trace().flush();
  113. return msgs;
  114. }
  115. };
  116. } } } // namespace paradevs tests dtss
  117. #endif