From ae2294a392d51f10e945f23eda38c227e61e549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fre=CC=81de=CC=81ric=20Py?= Date: Tue, 16 Jun 2015 15:16:48 +0100 Subject: [PATCH] Moved domain conversion classes to europa core Moved the utilities allowing conversion from/to TREX domains to/from their europa counterpart to europa_core instead of the plugin so they can be used externally --- extra/europa/CMakeLists.txt | 4 - extra/europa/EuropaReactor.cc | 2 +- extra/europa/core/CMakeLists.txt | 9 +- extra/europa/{ => core}/EuropaDomain.cc | 4 +- extra/europa/{ => core}/europa_convert.cc | 4 +- .../europa/{ => core}/private/EuropaDomain.hh | 0 .../europa/{ => trex/europa}/EuropaEntity.hh | 0 .../{ => trex/europa}/bits/europa_convert.hh | 254 +++++++++--------- 8 files changed, 139 insertions(+), 138 deletions(-) rename extra/europa/{ => core}/EuropaDomain.cc (98%) rename extra/europa/{ => core}/europa_convert.cc (99%) rename extra/europa/{ => core}/private/EuropaDomain.hh (100%) rename extra/europa/{ => trex/europa}/EuropaEntity.hh (100%) rename extra/europa/{ => trex/europa}/bits/europa_convert.hh (50%) diff --git a/extra/europa/CMakeLists.txt b/extra/europa/CMakeLists.txt index 795ef16ea..ae166ce16 100644 --- a/extra/europa/CMakeLists.txt +++ b/extra/europa/CMakeLists.txt @@ -88,8 +88,6 @@ if(WITH_EUROPA) trex_plugin(europa europa_plugin.cc EuropaReactor.cc - europa_convert.cc - EuropaDomain.cc extensions/Bind.cc extensions/DoNotMatchFilter.cc extensions/extensions.cc @@ -99,8 +97,6 @@ if(WITH_EUROPA) extensions/Trigonometry.cc # headers EuropaReactor.hh - bits/europa_convert.hh - EuropaEntity.hh extensions/Bind.hh extensions/DoNotMatchFilter.hh extensions/EarliestFirstFlawManager.hh diff --git a/extra/europa/EuropaReactor.cc b/extra/europa/EuropaReactor.cc index 92b06d98b..33e14e21e 100644 --- a/extra/europa/EuropaReactor.cc +++ b/extra/europa/EuropaReactor.cc @@ -33,7 +33,7 @@ */ #include "EuropaReactor.hh" -#include "bits/europa_convert.hh" +#include #include "core/private/CurrentState.hh" #include diff --git a/extra/europa/core/CMakeLists.txt b/extra/europa/core/CMakeLists.txt index e2ca1654e..d10792536 100644 --- a/extra/europa/core/CMakeLists.txt +++ b/extra/europa/core/CMakeLists.txt @@ -45,17 +45,21 @@ add_library(TREXeuropa_core SHARED Assembly.cc core.cc CurrentState.cc + EuropaDomain.cc TrexThreatDecisionPoint.cc DeliberationFilter.cc + europa_convert.cc europa_helpers.cc ModeConstraints.cc ReactorConstraints.cc Schema.cc SynchronizationManager.cc TimeConstraints.cc - # headers + # headers + private/EuropaDomain.hh ../trex/europa/Assembly.hh ../trex/europa/DeliberationFilter.hh + ../trex/europa/EuropaEntity.hh ../trex/europa/EuropaException.hh ../trex/europa/EuropaPlugin.hh ../trex/europa/ModeConstraints.hh @@ -64,6 +68,7 @@ add_library(TREXeuropa_core SHARED ../trex/europa/SynchronizationManager.hh ../trex/europa/TimeConstraints.hh ../trex/europa/TrexThreatDecisionPoint.hh + ../trex/europa/bits/europa_convert.hh ../trex/europa/bits/europa_helpers.hh ../trex/europa/config.hh ) @@ -72,7 +77,7 @@ source_group("Header\ Files\\bits" FILES ../trex/europa/bits/europa_helpers.hh ) -target_link_libraries(TREXeuropa_core ${EUROPA_LIBRARIES} TREXutils +target_link_libraries(TREXeuropa_core ${EUROPA_LIBRARIES} TREXdomain ${Boost_REGEX_LIBRARY}) trex_lib(TREXeuropa_core extra) diff --git a/extra/europa/EuropaDomain.cc b/extra/europa/core/EuropaDomain.cc similarity index 98% rename from extra/europa/EuropaDomain.cc rename to extra/europa/core/EuropaDomain.cc index a15b8a75d..74a25dbb0 100644 --- a/extra/europa/EuropaDomain.cc +++ b/extra/europa/core/EuropaDomain.cc @@ -32,9 +32,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "EuropaEntity.hh" +#include #include "private/EuropaDomain.hh" -#include "bits/europa_convert.hh" +#include using namespace TREX::europa; using namespace TREX; diff --git a/extra/europa/europa_convert.cc b/extra/europa/core/europa_convert.cc similarity index 99% rename from extra/europa/europa_convert.cc rename to extra/europa/core/europa_convert.cc index 2b28ba365..11dbb2edb 100644 --- a/extra/europa/europa_convert.cc +++ b/extra/europa/core/europa_convert.cc @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "bits/europa_convert.hh" +#include #include -#include "EuropaEntity.hh" +#include #include "private/EuropaDomain.hh" #include diff --git a/extra/europa/private/EuropaDomain.hh b/extra/europa/core/private/EuropaDomain.hh similarity index 100% rename from extra/europa/private/EuropaDomain.hh rename to extra/europa/core/private/EuropaDomain.hh diff --git a/extra/europa/EuropaEntity.hh b/extra/europa/trex/europa/EuropaEntity.hh similarity index 100% rename from extra/europa/EuropaEntity.hh rename to extra/europa/trex/europa/EuropaEntity.hh diff --git a/extra/europa/bits/europa_convert.hh b/extra/europa/trex/europa/bits/europa_convert.hh similarity index 50% rename from extra/europa/bits/europa_convert.hh rename to extra/europa/trex/europa/bits/europa_convert.hh index da8c4a8c0..c62cda1a0 100644 --- a/extra/europa/bits/europa_convert.hh +++ b/extra/europa/trex/europa/bits/europa_convert.hh @@ -1,13 +1,13 @@ /********************************************************************* * Software License Agreement (BSD License) - * + * * Copyright (c) 2011, MBARI. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditeions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -17,7 +17,7 @@ * * Neither the name of the TREX Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -48,15 +48,15 @@ namespace TREX { namespace europa { namespace details { /** @brief Europa to TREX domain conversion - * + * * @param[in] dom A europa domain - * + * * Converts the europa domain @p dom into the equivalent TREX domain - * + * * @pre @p dom is a domain tyope supported by TREX - * + * * @return The TREX representation of @p dom - * + * * @throw EuropaException Unable to matrch the type of @p dom with a * TREX domain type * @@ -65,14 +65,14 @@ namespace TREX { * @ingroup europa */ TREX::transaction::DomainBase *trex_domain(EUROPA::Domain const &dom); - + /** @brief TREX to Europa domain conversion * * This isitor class allows to convert a TREX domain into the equivalent * Europa representation. * * More accurately it restricts a europa domain using a TREX domain. The - * Europa domain to be restircted can be either a new instance, the copy + * Europa domain to be restircted can be either a new instance, the copy * of an already existing domain, or the exisitng domain itself. * * @author Frederic Py @@ -81,79 +81,79 @@ namespace TREX { */ class europa_domain :public TREX::transaction::DomainVisitor { public: - /** @brief Constructor - * - * @param[in] type An europa type - * - * Create a new instance starting with the base domain of @p type - * The base domain corresponding to the mpost relaxed domain for - * @p type, an instance created with this constructor is often used - * to do a simple conversion for a TREX domain to its europa counterpart. - * - * @post The new instance is temporary which means that the europa domain - * will be deleted with this instance - */ - explicit europa_domain(EUROPA::DataTypeId const &type) - :m_temporary(true), m_dom(type->baseDomain().copy()), m_type(type) {} - /** @brief Constructor - * - * @param[in] dom An europa domain - * - * Create a new instance starting with a copy of @p dom. As this instsnce - * manipulates a copy @p dom won't be modified even though this instaance - * visits domains. - * - * @post The new instance is temporary which means that the europa domain - * will be deleted with this instance - */ - explicit europa_domain(EUROPA::Domain const &dom) - :m_temporary(true), m_dom(dom.copy()), m_type(dom.getDataType()) {} - /** @brief Constructor - * - * @param[in] dom A pointer to en europa domain - * - * @pre dom is a valid pointer to an existing europa domain instance - * - * Create a new instance that will modify directly the domain pointed by - * @p dom. As a result any trex domain visited will directly modifies this - * domain. Such instance is usefull when a trex domain is used to restrict - * the domain of a varaiable already exisiting in the plan database (such - * as for example a token attribute). - * - * @post The new insatnce is @e not temporary and the referred domain will - * not be deleted on destruction - */ - explicit europa_domain(EUROPA::Domain *dom) - :m_temporary(false), m_dom(dom), m_type(dom->getDataType()) {} - /** @brief Copy constructor - * - * @param[in] other Another instance - * - * Create a new insatnce that duplicates other - * - * @note If @p other is temporary this constructor will crreate a copy of - * the domain managed by @p other. This is required in order to avoid - * memory access issues. As a result the copy a temporary instance won't - * alter the same domain but just a copy. - * - * @post the temporary state of the new instance is the same oas @p other - */ - europa_domain(europa_domain const &other) - :m_temporary(other.m_temporary), m_dom(other.m_dom), - m_type(other.m_type) { - if( m_temporary ) - // Create a copy of temporary domains to avoid double delete - m_dom = m_dom->copy(); - } - /** @brief destructor - * - * If the instance was temporary theb n the asscited domain is deleted. - */ - ~europa_domain() { - if( m_temporary ) - delete m_dom; - } - + /** @brief Constructor + * + * @param[in] type An europa type + * + * Create a new instance starting with the base domain of @p type + * The base domain corresponding to the mpost relaxed domain for + * @p type, an instance created with this constructor is often used + * to do a simple conversion for a TREX domain to its europa counterpart. + * + * @post The new instance is temporary which means that the europa domain + * will be deleted with this instance + */ + explicit europa_domain(EUROPA::DataTypeId const &type) + :m_temporary(true), m_dom(type->baseDomain().copy()), m_type(type) {} + /** @brief Constructor + * + * @param[in] dom An europa domain + * + * Create a new instance starting with a copy of @p dom. As this instsnce + * manipulates a copy @p dom won't be modified even though this instaance + * visits domains. + * + * @post The new instance is temporary which means that the europa domain + * will be deleted with this instance + */ + explicit europa_domain(EUROPA::Domain const &dom) + :m_temporary(true), m_dom(dom.copy()), m_type(dom.getDataType()) {} + /** @brief Constructor + * + * @param[in] dom A pointer to en europa domain + * + * @pre dom is a valid pointer to an existing europa domain instance + * + * Create a new instance that will modify directly the domain pointed by + * @p dom. As a result any trex domain visited will directly modifies this + * domain. Such instance is usefull when a trex domain is used to restrict + * the domain of a varaiable already exisiting in the plan database (such + * as for example a token attribute). + * + * @post The new insatnce is @e not temporary and the referred domain will + * not be deleted on destruction + */ + explicit europa_domain(EUROPA::Domain *dom) + :m_temporary(false), m_dom(dom), m_type(dom->getDataType()) {} + /** @brief Copy constructor + * + * @param[in] other Another instance + * + * Create a new insatnce that duplicates other + * + * @note If @p other is temporary this constructor will crreate a copy of + * the domain managed by @p other. This is required in order to avoid + * memory access issues. As a result the copy a temporary instance won't + * alter the same domain but just a copy. + * + * @post the temporary state of the new instance is the same oas @p other + */ + europa_domain(europa_domain const &other) + :m_temporary(other.m_temporary), m_dom(other.m_dom), + m_type(other.m_type) { + if( m_temporary ) + // Create a copy of temporary domains to avoid double delete + m_dom = m_dom->copy(); + } + /** @brief destructor + * + * If the instance was temporary theb n the asscited domain is deleted. + */ + ~europa_domain() { + if( m_temporary ) + delete m_dom; + } + /** @brief Conversion visitors * @param[in] dom A T-REX domain * @@ -161,52 +161,52 @@ namespace TREX { * * @pre @p dom type is compatible with the type of the europa domain * - * @throw TREX::transaction::DomainAccess The types of @p dom is not + * @throw TREX::transaction::DomainAccess The types of @p dom is not * compatible with the type of the europa domain - * @throw TREX::transaction::EmptyDomain The intersection of @p dom and + * @throw TREX::transaction::EmptyDomain The intersection of @p dom and * the europa domain is empty * @{ */ - void visit(TREX::transaction::BasicEnumerated const *dom); - void visit(TREX::transaction::BasicInterval const *dom); - void visit(TREX::transaction::DomainBase const *dom, bool); + void visit(TREX::transaction::BasicEnumerated const *dom); + void visit(TREX::transaction::BasicInterval const *dom); + void visit(TREX::transaction::DomainBase const *dom, bool); /** @} */ - /** @brief Get europa domain - * - * @return the reuropa domain amnipulated by this visitor - * @{ - */ - EUROPA::Domain const &domain() const { - return *m_dom; - } - EUROPA::Domain &domain() { - return *m_dom; - } - /** @} */ + /** @brief Get europa domain + * + * @return the reuropa domain amnipulated by this visitor + * @{ + */ + EUROPA::Domain const &domain() const { + return *m_dom; + } + EUROPA::Domain &domain() { + return *m_dom; + } + /** @} */ private: - /** @brief temporary flag - * - * This flag is used in order to identify if the asoacited domain - * should be deleted on detsruction or not. - */ - bool m_temporary; - /** @brief Europa domain - * - * The pointer to the domain to be restricted every time this instance - * visits a TREX domain - */ - EUROPA::Domain *m_dom; - /** @brief Europa type of the domain - * - * The type of the domain manipulated by this visitor - */ - EUROPA::DataTypeId m_type; - - // following methods have purposedly no code - europa_domain(); + /** @brief temporary flag + * + * This flag is used in order to identify if the asoacited domain + * should be deleted on detsruction or not. + */ + bool m_temporary; + /** @brief Europa domain + * + * The pointer to the domain to be restricted every time this instance + * visits a TREX domain + */ + EUROPA::Domain *m_dom; + /** @brief Europa type of the domain + * + * The type of the domain manipulated by this visitor + */ + EUROPA::DataTypeId m_type; + + // following methods have purposedly no code + europa_domain(); }; // TREX::europa::details::europa_domain - + /** @brief T-REX to europa domain * * @param[in] var A europa variable @@ -224,15 +224,15 @@ namespace TREX { * @ingroup europa */ inline void europa_restrict(EUROPA::ConstrainedVariableId &var, - TREX::transaction::DomainBase const &dom) { - europa_domain convert(var->lastDomain()); - dom.accept(convert); - var->restrictBaseDomain(convert.domain()); + TREX::transaction::DomainBase const &dom) { + europa_domain convert(var->lastDomain()); + dom.accept(convert); + var->restrictBaseDomain(convert.domain()); } } // TREX::europa::details - + } // TREX::europa } // TREX