123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /**
- * @file tests/pdevs/models.hpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef TESTS_PDEVS_MODELS_HPP
- #define TESTS_PDEVS_MODELS_HPP 1
- #include <common/Time.hpp>
- #include <common/Trace.hpp>
- #include <pdevs/Dynamics.hpp>
- #include <limits>
- namespace paradevs { namespace tests { namespace pdevs {
- template < typename T >
- struct Limits
- {
- static constexpr T negative_infinity =
- -std::numeric_limits < T >::infinity();
- static constexpr T positive_infinity =
- std::numeric_limits < T >::infinity();
- static constexpr T null = 0;
- };
- typedef paradevs::common::Time < double, Limits < double > > MyTime;
- class A : public paradevs::pdevs::Dynamics < MyTime >
- {
- public:
- A(const std::string& name, const common::NoParameters& parameters) :
- paradevs::pdevs::Dynamics < MyTime >(name, parameters)
- { }
- virtual ~A()
- { }
- void dint(typename MyTime::type t)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_INT);
- common::Trace < MyTime >::trace().flush();
- if (_phase == SEND) {
- _phase = WAIT;
- }
- }
- void dext(typename MyTime::type t, typename MyTime::type /* e */,
- const common::Bag < MyTime >& msgs)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_EXT)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- _phase = SEND;
- }
- void dconf(typename MyTime::type t, typename MyTime::type /* e */,
- const common::Bag < MyTime >& msgs)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_CONF)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- }
- typename MyTime::type start(typename MyTime::type t)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::START);
- common::Trace < MyTime >::trace().flush();
- _phase = WAIT;
- return 0;
- }
- typename MyTime::type ta(typename MyTime::type t) const
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::TA);
- common::Trace < MyTime >::trace().flush();
- if (_phase == WAIT) {
- return 1;
- } else {
- return 0;
- }
- }
- common::Bag < MyTime > lambda(typename MyTime::type t) const
- {
- common::Bag < MyTime > msgs;
- msgs.push_back(common::ExternalEvent < MyTime >("out", 0.));
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::LAMBDA)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- return msgs;
- }
- void observation(std::ostream& /* file */) const
- { }
- private:
- enum Phase { WAIT, SEND };
- Phase _phase;
- };
- class B : public paradevs::pdevs::Dynamics < MyTime >
- {
- public:
- B(const std::string& name, const common::NoParameters& parameters) :
- paradevs::pdevs::Dynamics < MyTime >(name, parameters)
- { }
- virtual ~B()
- { }
- void dint(typename MyTime::type t)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_INT);
- common::Trace < MyTime >::trace().flush();
- if (_phase == SEND) {
- _phase = WAIT;
- }
- }
- void dext(typename MyTime::type t, typename MyTime::type /* e */,
- const common::Bag < MyTime >& msgs)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_EXT)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- _phase = SEND;
- }
- void dconf(typename MyTime::type t, typename MyTime::type /* e */,
- const common::Bag < MyTime >& msgs)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::DELTA_CONF)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- }
- typename MyTime::type start(typename MyTime::type t)
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::START);
- common::Trace < MyTime >::trace().flush();
- _phase = WAIT;
- return std::numeric_limits < double >::max();
- }
- typename MyTime::type ta(typename MyTime::type t) const
- {
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::TA);
- common::Trace < MyTime >::trace().flush();
- if (_phase == WAIT) {
- return std::numeric_limits < double >::max();
- } else {
- return 0;
- }
- }
- common::Bag < MyTime > lambda(typename MyTime::type t) const
- {
- common::Bag < MyTime > msgs;
- msgs.push_back(common::ExternalEvent < MyTime >("out", 0.));
- common::Trace < MyTime >::trace()
- << common::TraceElement < MyTime >(get_name(), t,
- common::LAMBDA)
- << "messages = " << msgs.to_string();
- common::Trace < MyTime >::trace().flush();
- return msgs;
- }
- void observation(std::ostream& /* file */) const
- { }
- private:
- enum Phase { WAIT, SEND };
- Phase _phase;
- };
- } } } // namespace paradevs tests pdevs
- #endif
|