diff --git a/PTN_Engine/ImportExport/ActionsThreadOptionConversions.cpp b/PTN_Engine/ImportExport/ActionsThreadOptionConversions.cpp new file mode 100755 index 0000000..5af2d84 --- /dev/null +++ b/PTN_Engine/ImportExport/ActionsThreadOptionConversions.cpp @@ -0,0 +1,85 @@ +/* + * This file is part of PTN Engine + * + * Copyright (c) 2024 Eduardo Valgôde + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "PTN_Engine/ImportExport/ActionsThreadOptionConversions.h" +#include "PTN_Engine/PTN_Exception.h" + +namespace ptne +{ +using namespace std; + +const string ActionsThreadOptionConversions::ACTIONS_THREAD_OPTION_SINGLE_THREAD = "SINGLE_THREAD"; +const string ActionsThreadOptionConversions::ACTIONS_THREAD_OPTION_EVENT_LOOP = "EVENT_LOOP"; +const string ActionsThreadOptionConversions::ACTIONS_THREAD_OPTION_DETACHED = "DETACHED"; +const string ActionsThreadOptionConversions::ACTIONS_THREAD_OPTION_JOB_QUEUE = "JOB_QUEUE"; + +PTN_Engine::ACTIONS_THREAD_OPTION +ActionsThreadOptionConversions::toACTIONS_THREAD_OPTION(const string &actionsThreadOptionStr) +{ + using enum PTN_Engine::ACTIONS_THREAD_OPTION; + if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_SINGLE_THREAD) + { + return SINGLE_THREAD; + } + else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_EVENT_LOOP) + { + return EVENT_LOOP; + } + else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_DETACHED) + { + return DETACHED; + } + else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_JOB_QUEUE) + { + return JOB_QUEUE; + } + else + { + throw PTN_Exception("Could not convert " + actionsThreadOptionStr + " to ACTIONS_THREAD_OPTION"); + } +} + +string ActionsThreadOptionConversions::toString(PTN_Engine::ACTIONS_THREAD_OPTION actionsThreadOption) +{ + using enum PTN_Engine::ACTIONS_THREAD_OPTION; + switch (actionsThreadOption) + { + default: + { + throw PTN_Exception("Could not convert to string"); + } + case DETACHED: + { + return ACTIONS_THREAD_OPTION_DETACHED; + } + case SINGLE_THREAD: + { + return ACTIONS_THREAD_OPTION_SINGLE_THREAD; + } + case EVENT_LOOP: + { + return ACTIONS_THREAD_OPTION_EVENT_LOOP; + } + case JOB_QUEUE: + { + return ACTIONS_THREAD_OPTION_JOB_QUEUE; + } + } +} + +} // namespace ptne diff --git a/PTN_Engine/ImportExport/ActionsThreadOptionConversions.h b/PTN_Engine/ImportExport/ActionsThreadOptionConversions.h new file mode 100755 index 0000000..124b32c --- /dev/null +++ b/PTN_Engine/ImportExport/ActionsThreadOptionConversions.h @@ -0,0 +1,36 @@ +/* + * This file is part of PTN Engine + * + * Copyright (c) 2024 Eduardo Valgôde + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "PTN_Engine/PTN_Engine.h" +namespace ptne +{ + +class ActionsThreadOptionConversions +{ +public: + static PTN_Engine::ACTIONS_THREAD_OPTION toACTIONS_THREAD_OPTION(const std::string &actionsThreadOptionStr); + static std::string toString(PTN_Engine::ACTIONS_THREAD_OPTION actionsThreadOption); + +private: + static const std::string ACTIONS_THREAD_OPTION_SINGLE_THREAD; + static const std::string ACTIONS_THREAD_OPTION_EVENT_LOOP; + static const std::string ACTIONS_THREAD_OPTION_DETACHED; + static const std::string ACTIONS_THREAD_OPTION_JOB_QUEUE; +}; + +} // namespace ptne diff --git a/PTN_Engine/ImportExport/IExporter.cpp b/PTN_Engine/ImportExport/IFileExporter.cpp similarity index 85% rename from PTN_Engine/ImportExport/IExporter.cpp rename to PTN_Engine/ImportExport/IFileExporter.cpp index 7e5a009..7575464 100755 --- a/PTN_Engine/ImportExport/IExporter.cpp +++ b/PTN_Engine/ImportExport/IFileExporter.cpp @@ -17,6 +17,8 @@ */ #include "PTN_Engine/ImportExport/IFileExporter.h" +#include "PTN_Engine/ImportExport/ActionsThreadOptionConversions.h" +#include "PTN_Engine/PTN_Engine.h" #include "PTN_Engine/PTN_Exception.h" namespace ptne @@ -30,7 +32,7 @@ void IFileExporter::_export(const PTN_Engine &ptnEngine) throw PTN_Exception("Cannot change actions thread option while the event loop is running."); } - exportActionsThreadOption(PTN_Engine::toString(ptnEngine.getActionsThreadOption())); + exportActionsThreadOption(ActionsThreadOptionConversions::toString(ptnEngine.getActionsThreadOption())); for (const auto &placeProperties : ptnEngine.getPlacesProperties()) { diff --git a/PTN_Engine/ImportExport/IImporter.cpp b/PTN_Engine/ImportExport/IFileImporter.cpp similarity index 84% rename from PTN_Engine/ImportExport/IImporter.cpp rename to PTN_Engine/ImportExport/IFileImporter.cpp index a510437..1e8d250 100755 --- a/PTN_Engine/ImportExport/IImporter.cpp +++ b/PTN_Engine/ImportExport/IFileImporter.cpp @@ -17,6 +17,8 @@ */ #include "PTN_Engine/ImportExport/IFileImporter.h" +#include "PTN_Engine/ImportExport/ActionsThreadOptionConversions.h" +#include "PTN_Engine/PTN_Engine.h" namespace ptne { @@ -30,7 +32,8 @@ void IFileImporter::_import(PTN_Engine &ptnEngine) const } string actionsThreadOptionStr = importActionsThreadOption(); - ptnEngine.setActionsThreadOption(std::move(PTN_Engine::toACTIONS_THREAD_OPTION(actionsThreadOptionStr))); + ptnEngine.setActionsThreadOption( + std::move(ActionsThreadOptionConversions::toACTIONS_THREAD_OPTION(actionsThreadOptionStr))); for (const auto &placeProperties : importPlaces()) { diff --git a/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileExporter.h b/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileExporter.h index db4e0e3..81a57de 100755 --- a/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileExporter.h +++ b/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileExporter.h @@ -18,13 +18,15 @@ #pragma once -#include "PTN_Engine/PTN_Engine.h" #include "PTN_Engine/Utilities/Explicit.h" +#include namespace ptne { class PTN_Engine; +class PlaceProperties; +class TransitionProperties; //! //! \brief The IFileExporter class is an interface for all PTN_Engine file exporters. diff --git a/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileImporter.h b/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileImporter.h index 7f92fcd..982283f 100755 --- a/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileImporter.h +++ b/PTN_Engine/ImportExport/include/PTN_Engine/ImportExport/IFileImporter.h @@ -18,14 +18,17 @@ #pragma once -#include "PTN_Engine/PTN_Engine.h" #include "PTN_Engine/Utilities/Explicit.h" +#include #include namespace ptne { +class ArcProperties; class PTN_Engine; +class PlaceProperties; +class TransitionProperties; //! //! \brief The IFileImporter class is an interface class for all PTN_Engine file importers. diff --git a/PTN_Engine/PTN_Engine.cpp b/PTN_Engine/PTN_Engine.cpp index 7596050..7155e80 100755 --- a/PTN_Engine/PTN_Engine.cpp +++ b/PTN_Engine/PTN_Engine.cpp @@ -125,66 +125,4 @@ void PTN_Engine::stop() m_impProxy->stop(); } -namespace -{ - const string ACTIONS_THREAD_OPTION_SINGLE_THREAD{ "SINGLE_THREAD" }; - const string ACTIONS_THREAD_OPTION_EVENT_LOOP{ "EVENT_LOOP" }; - const string ACTIONS_THREAD_OPTION_DETACHED{ "DETACHED" }; - const string ACTIONS_THREAD_OPTION_JOB_QUEUE{ "JOB_QUEUE" }; -} - -PTN_Engine::ACTIONS_THREAD_OPTION -PTN_Engine::toACTIONS_THREAD_OPTION(const string &actionsThreadOptionStr) -{ - using enum ACTIONS_THREAD_OPTION; - if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_SINGLE_THREAD) - { - return SINGLE_THREAD; - } - else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_EVENT_LOOP) - { - return EVENT_LOOP; - } - else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_DETACHED) - { - return DETACHED; - } - else if (actionsThreadOptionStr == ACTIONS_THREAD_OPTION_JOB_QUEUE) - { - return JOB_QUEUE; - } - else - { - throw PTN_Exception("Could not convert " + actionsThreadOptionStr + " to ACTIONS_THREAD_OPTION"); - } -} - -string PTN_Engine::toString(ACTIONS_THREAD_OPTION actionsThreadOption) -{ - using enum ACTIONS_THREAD_OPTION; - switch (actionsThreadOption) - { - default: - { - throw PTN_Exception("Could not convert to string"); - } - case DETACHED: - { - return ACTIONS_THREAD_OPTION_DETACHED; - } - case SINGLE_THREAD: - { - return ACTIONS_THREAD_OPTION_SINGLE_THREAD; - } - case EVENT_LOOP: - { - return ACTIONS_THREAD_OPTION_EVENT_LOOP; - } - case JOB_QUEUE: - { - return ACTIONS_THREAD_OPTION_JOB_QUEUE; - } - } -} - } // namespace ptne diff --git a/PTN_Engine/include/PTN_Engine/PTN_Engine.h b/PTN_Engine/include/PTN_Engine/PTN_Engine.h index 2d5f23b..01c2b00 100755 --- a/PTN_Engine/include/PTN_Engine/PTN_Engine.h +++ b/PTN_Engine/include/PTN_Engine/PTN_Engine.h @@ -36,12 +36,13 @@ using ActionFunction = std::function; */ struct DLL_PUBLIC ArcProperties final { - enum class Type { + enum class Type + { ACTIVATION, DESTINATION, BIDIRECTIONAL, INHIBITOR, - //RESET, + // RESET, }; /*! @@ -164,20 +165,6 @@ class DLL_PUBLIC PTN_Engine JOB_QUEUE }; - /*! - * \brief toACTIONS_THREAD_OPTION - * \param actionsThreadOptionStr - * \return - */ - static ACTIONS_THREAD_OPTION toACTIONS_THREAD_OPTION(const std::string &actionsThreadOptionStr); - - /*! - * \brief toString - * \param actionsThreadOption - * \return - */ - static std::string toString(ACTIONS_THREAD_OPTION actionsThreadOption); - using EventLoopSleepDuration = std::chrono::duration>; virtual ~PTN_Engine(); @@ -276,13 +263,13 @@ class DLL_PUBLIC PTN_Engine * \brief addArc * \param arcProperties */ - void addArc(const ArcProperties& arcProperties); + void addArc(const ArcProperties &arcProperties); /*! * \brief addArc * \param arcProperties */ - void removeArc(const ArcProperties& arcProperties); + void removeArc(const ArcProperties &arcProperties); /*! * \brief clearNet