diff options
author | Kenji Hosokawa <khosokawa@jp.adit-jv.com> | 2020-08-24 21:58:42 +0900 |
---|---|---|
committer | Kenji Hosokawa <khosokawa@jp.adit-jv.com> | 2020-08-24 21:58:42 +0900 |
commit | 2b4ae7fde370bc3316ab30cc38b74d23e785b360 (patch) | |
tree | 41b6eb70b3419c2fbd192ed133c5890a985eddec /src/core/model | |
parent | 6694a4d2952ebd171564932200cac00d6e5792f4 (diff) |
First commitjellyfish_9.99.4jellyfish/9.99.49.99.4
Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Change-Id: I381abb0a6521f5349768a76ef7ceecbce4b2d701
Diffstat (limited to 'src/core/model')
59 files changed, 5298 insertions, 0 deletions
diff --git a/src/core/model/RBAAbstractAllocatable.cpp b/src/core/model/RBAAbstractAllocatable.cpp new file mode 100644 index 0000000..c0dfb4f --- /dev/null +++ b/src/core/model/RBAAbstractAllocatable.cpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AbstractAllocatable class implementation + */ + +#include "RBAAbstractAllocatable.hpp" + +#include "RBAModelElementType.hpp" +#include "RBAContent.hpp" +#include "RBAContentSet.hpp" +#include "RBAViewContentSet.hpp" +#include "RBASoundContentSet.hpp" + +namespace rba +{ + +RBAAbstractAllocatable::RBAAbstractAllocatable(const std::string& name) + : RBARuleObject{name}, + contentSet_{std::make_unique<RBAContentSet>()} +{ +} + +const std::list<const RBAContent*>& +RBAAbstractAllocatable::getInternalContents() const +{ + return contentSet_->getLeafContent(); +} + +void +RBAAbstractAllocatable::addContent(const RBAContent* const content) +{ + contentSet_->addTarget(content); +} + +const RBAContentSet* +RBAAbstractAllocatable::getContentSet() const +{ + return contentSet_.get(); +} + +} diff --git a/src/core/model/RBAAbstractAllocatable.hpp b/src/core/model/RBAAbstractAllocatable.hpp new file mode 100644 index 0000000..b8b7acb --- /dev/null +++ b/src/core/model/RBAAbstractAllocatable.hpp @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AbstractAllocatable class header + */ + +#ifndef RBAABSTRACTALLOCATABLE_HPP +#define RBAABSTRACTALLOCATABLE_HPP + +#include <memory> +#include <list> +#include "RBARuleObject.hpp" +#include "RBAContentSet.hpp" + +namespace rba +{ + +class RBAContent; + +class DLL_EXPORT RBAAbstractAllocatable : virtual public RBARuleObject +{ +protected: + explicit RBAAbstractAllocatable(const std::string& name=""); + RBAAbstractAllocatable(const RBAAbstractAllocatable&)=delete; + RBAAbstractAllocatable(const RBAAbstractAllocatable&&)=delete; + RBAAbstractAllocatable& operator=(const RBAAbstractAllocatable&)=delete; + RBAAbstractAllocatable& operator=(const RBAAbstractAllocatable&&)=delete; + +public: + virtual ~RBAAbstractAllocatable()=default; + +public: + const std::list<const RBAContent*>& getInternalContents() const; + void addContent(const RBAContent* const content); + const RBAContentSet* getContentSet() const; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::unique_ptr<RBAContentSet> contentSet_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractAllocatableMaker.cpp b/src/core/model/RBAAbstractAllocatableMaker.cpp new file mode 100644 index 0000000..793336a --- /dev/null +++ b/src/core/model/RBAAbstractAllocatableMaker.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractAllocatableMaker.cpp +/// @brief AbstractAllocatable generator class implementation + +#include "RBAAbstractAllocatableMaker.hpp" +#include "RBAAbstractAllocatable.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAAbstractAllocatableMaker::RBAAbstractAllocatableMaker(const std::string& label) + : RBARuleObjectMaker{label} +{ +} + +RBAModelElement* +RBAAbstractAllocatableMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBARuleObjectMaker::setProperty(element, jsonElem, model, owner)); + + const auto abstAllo = dynamic_cast<RBAAbstractAllocatable*>(element); + + // Currently, there is no member set by RBAAbstractAllocatableMaker + // as model information, but this process is implemented + // because it may be added in the future. + + return abstAllo; +} + +} diff --git a/src/core/model/RBAAbstractAllocatableMaker.hpp b/src/core/model/RBAAbstractAllocatableMaker.hpp new file mode 100644 index 0000000..845acd2 --- /dev/null +++ b/src/core/model/RBAAbstractAllocatableMaker.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractAllocatableMaker.hpp +/// @brief AbstractAllocatable generator class header + +#ifndef RBAABSTRACTALLOCATABLEMAKER_HPP +#define RBAABSTRACTALLOCATABLEMAKER_HPP + +#include "RBARuleObjectMaker.hpp" + +namespace rba +{ + +/// @brief AbstractAllocatable generator class +class DLL_EXPORT RBAAbstractAllocatableMaker : virtual public RBARuleObjectMaker +{ +public: + explicit RBAAbstractAllocatableMaker(const std::string& label=""); + RBAAbstractAllocatableMaker(const RBAAbstractAllocatableMaker&)=delete; + RBAAbstractAllocatableMaker(const RBAAbstractAllocatableMaker&&)=delete; + RBAAbstractAllocatableMaker& operator=(const RBAAbstractAllocatableMaker&)=delete; + RBAAbstractAllocatableMaker& operator=(const RBAAbstractAllocatableMaker&&)=delete; + virtual ~RBAAbstractAllocatableMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractConstraint.cpp b/src/core/model/RBAAbstractConstraint.cpp new file mode 100644 index 0000000..3c8ba73 --- /dev/null +++ b/src/core/model/RBAAbstractConstraint.cpp @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AbstractConstraint class implementation + */ + +#include "RBAAbstractConstraint.hpp" + +#include "RBAExpression.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +RBAAbstractConstraint::RBAAbstractConstraint(const std::string& name) + : RBANamedElement{name} +{ +} + +bool +RBAAbstractConstraint::isConstraint() const +{ + return false; +} + +bool +RBAAbstractConstraint::isRule() const +{ + return false; +} + +void +RBAAbstractConstraint::clearInfo() +{ + info_->clear(); +} + +void +RBAAbstractConstraint::setExpression(RBAExpression* newExpr) +{ + expression_ = newExpr; +} + +RBAExpression* const +RBAAbstractConstraint::getExpression() const +{ + return expression_; +} + +RBAConstraintInfo* +RBAAbstractConstraint::getInfo() const +{ + return info_.get(); +} + +#ifdef RBA_USE_LOG +void +RBAAbstractConstraint::createHierarchy() +{ + LOG_initConstraintHierarchy(); + LOG_coverageHierarchyOfConstraintStartLog(this); + getExpression()->createHierarchy(); + LOG_coverageHierarchyOfConstraintEndLog(this); +} +#endif + +} diff --git a/src/core/model/RBAAbstractConstraint.hpp b/src/core/model/RBAAbstractConstraint.hpp new file mode 100644 index 0000000..d19bba5 --- /dev/null +++ b/src/core/model/RBAAbstractConstraint.hpp @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AbstractConstraint class header + */ + +#ifndef RBAABSTRACTCONSTRAINT_HPP +#define RBAABSTRACTCONSTRAINT_HPP + +#include <memory> +#include "RBANamedElement.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +class RBAExpression; + +class DLL_EXPORT RBAAbstractConstraint : public RBANamedElement +{ +protected: + explicit RBAAbstractConstraint(const std::string& name); + RBAAbstractConstraint(const RBAAbstractConstraint&)=delete; + RBAAbstractConstraint(const RBAAbstractConstraint&&)=delete; + RBAAbstractConstraint& operator=(const RBAAbstractConstraint&)=delete; + RBAAbstractConstraint& operator=(const RBAAbstractConstraint&&)=delete; + void clearInfo(); + +public: + virtual ~RBAAbstractConstraint()=default; + virtual bool isConstraint() const; + virtual bool isRule() const; + virtual void setExpression(RBAExpression*); + virtual RBAExpression* const getExpression() const; + RBAConstraintInfo* getInfo() const; + + // Log +#ifdef RBA_USE_LOG + virtual void createHierarchy(); +#endif + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::unique_ptr<RBAConstraintInfo> info_ {std::make_unique<RBAConstraintInfo>()}; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + RBAExpression* expression_ {nullptr}; + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractConstraintMaker.cpp b/src/core/model/RBAAbstractConstraintMaker.cpp new file mode 100644 index 0000000..5de0ae3 --- /dev/null +++ b/src/core/model/RBAAbstractConstraintMaker.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractConstraintMaker.cpp +/// @brief Abstract Constraint expresion generator class + +#include "RBAAbstractConstraintMaker.hpp" +#include "RBAAbstractConstraint.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAAbstractConstraintMaker::RBAAbstractConstraintMaker(const std::string& label) + : RBAModelElementMaker{label} +{ +} + +RBAModelElement* +RBAAbstractConstraintMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + const auto abstConstraint = dynamic_cast<RBAAbstractConstraint*>(element); + + // Set expression + const RBAJsonElement* const childElem {jsonElem->findChildren("expression")}; + RBAModelElement* const expr {getFactory()->createElement(childElem->getClassName(), + childElem)}; + abstConstraint->setExpression(dynamic_cast<RBAExpression*>(expr)); + + return abstConstraint; +} + +} diff --git a/src/core/model/RBAAbstractConstraintMaker.hpp b/src/core/model/RBAAbstractConstraintMaker.hpp new file mode 100644 index 0000000..916408e --- /dev/null +++ b/src/core/model/RBAAbstractConstraintMaker.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractConstraintMaker.hpp +/// @brief Abstract Constraint expresion generator class header + +#ifndef RBAABSTRACTCONSTRAINTMAKER_HPP +#define RBAABSTRACTCONSTRAINTMAKER_HPP + +#include "RBAModelElementMaker.hpp" + +namespace rba +{ + +/// @brief Abstract Constraint expresion generator class +class DLL_EXPORT RBAAbstractConstraintMaker + : public RBAModelElementMaker +{ +public: + explicit RBAAbstractConstraintMaker(const std::string& label); + RBAAbstractConstraintMaker(const RBAAbstractConstraintMaker&)=delete; + RBAAbstractConstraintMaker(const RBAAbstractConstraintMaker&&)=delete; + RBAAbstractConstraintMaker& operator=(const RBAAbstractConstraintMaker&)=delete; + RBAAbstractConstraintMaker& operator=(const RBAAbstractConstraintMaker&&)=delete; + virtual ~RBAAbstractConstraintMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractContent.cpp b/src/core/model/RBAAbstractContent.cpp new file mode 100644 index 0000000..d8f025f --- /dev/null +++ b/src/core/model/RBAAbstractContent.cpp @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Abstract Content class implementation + */ + +#include "RBAAbstractContent.hpp" + +namespace rba +{ + +RBAAbstractContent::RBAAbstractContent(const std::string& name) + : RBARuleObject{name} +{ +} + +} diff --git a/src/core/model/RBAAbstractContent.hpp b/src/core/model/RBAAbstractContent.hpp new file mode 100644 index 0000000..c2d72b1 --- /dev/null +++ b/src/core/model/RBAAbstractContent.hpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Abstract Content class header + */ + +#ifndef RBAABSTRACTCONTENT_HPP +#define RBAABSTRACTCONTENT_HPP + +#include "RBARuleObject.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAAbstractContent : virtual public RBARuleObject +{ +protected: + explicit RBAAbstractContent(const std::string& name=""); + RBAAbstractContent(const RBAAbstractContent&)=delete; + RBAAbstractContent(const RBAAbstractContent&&)=delete; + RBAAbstractContent& operator=(const RBAAbstractContent&)=delete; + RBAAbstractContent& operator=(const RBAAbstractContent&&)=delete; + +public: + virtual ~RBAAbstractContent()=default; + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractContentMaker.cpp b/src/core/model/RBAAbstractContentMaker.cpp new file mode 100644 index 0000000..b0ff0be --- /dev/null +++ b/src/core/model/RBAAbstractContentMaker.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractContentMaker.cpp +/// @brief Abstract Content generator class implementation + +#include "RBAAbstractContentMaker.hpp" +#include "RBAAbstractContent.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAAbstractContentMaker::RBAAbstractContentMaker(const std::string& label) + : RBARuleObjectMaker{label} +{ +} + +RBAModelElement* +RBAAbstractContentMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBARuleObjectMaker::setProperty( element, jsonElem, + model, owner)); + + const auto abstContent = dynamic_cast<RBAAbstractContent*>(element); + + // Currently, there is no member set by RBAAbstractContentMaker + // as model information, but this process is implemented + // because it may be added in the future. + + return abstContent; +} + +} diff --git a/src/core/model/RBAAbstractContentMaker.hpp b/src/core/model/RBAAbstractContentMaker.hpp new file mode 100644 index 0000000..df311a8 --- /dev/null +++ b/src/core/model/RBAAbstractContentMaker.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAbstractContentMaker.cpp +/// @brief Abstract Content generator class header + +#ifndef RBAABSTRACTCONTENTMAKER_HPP +#define RBAABSTRACTCONTENTMAKER_HPP + +#include "RBARuleObjectMaker.hpp" + +namespace rba +{ + +/// @brief Abstract Content generator class +class DLL_EXPORT RBAAbstractContentMaker : virtual public RBARuleObjectMaker +{ +public: + explicit RBAAbstractContentMaker(const std::string& label=""); + RBAAbstractContentMaker(const RBAAbstractContentMaker&)=delete; + RBAAbstractContentMaker(const RBAAbstractContentMaker&&)=delete; + RBAAbstractContentMaker& operator=(const RBAAbstractContentMaker&)=delete; + RBAAbstractContentMaker& operator=(const RBAAbstractContentMaker&&)=delete; + virtual ~RBAAbstractContentMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAAbstractProperty.cpp b/src/core/model/RBAAbstractProperty.cpp new file mode 100644 index 0000000..a90fa4d --- /dev/null +++ b/src/core/model/RBAAbstractProperty.cpp @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Abstract property class implementation + */ + +#include "RBAAbstractProperty.hpp" +#include "RBASceneImpl.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +RBAAbstractProperty::RBAAbstractProperty(const RBASceneImpl* const scene, const std::string& name) + : RBARuleObject{name}, + scene_{scene} +{ +} + +RBAModelElementType +RBAAbstractProperty::getModelElementType() const +{ + return RBAModelElementType::Property; +} + +const RBASceneImpl* +RBAAbstractProperty::getScene() const +{ + return scene_; +} + +} diff --git a/src/core/model/RBAAbstractProperty.hpp b/src/core/model/RBAAbstractProperty.hpp new file mode 100644 index 0000000..15ecc2d --- /dev/null +++ b/src/core/model/RBAAbstractProperty.hpp @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Abstract property class header + */ + +#ifndef RBAABSTRACTPROPERTY_HPP +#define RBAABSTRACTPROPERTY_HPP + +#include <cstdint> +#include "RBARuleObject.hpp" + +namespace rba +{ + +class RBASceneImpl; + +class RBAAbstractProperty : public RBARuleObject +{ +protected: + RBAAbstractProperty(const RBASceneImpl* const scene, const std::string& name); + RBAAbstractProperty(const RBAAbstractProperty&)=delete; + RBAAbstractProperty(const RBAAbstractProperty&&)=delete; + RBAAbstractProperty& operator=(const RBAAbstractProperty&)=delete; + RBAAbstractProperty& operator=(const RBAAbstractProperty&&)=delete; + +public: + virtual ~RBAAbstractProperty()=default; + +public: + RBAModelElementType getModelElementType() const override; + virtual std::int32_t getValue() const=0; + virtual const RBASceneImpl* getScene() const; + + // Log +#ifdef RBA_USE_LOG + virtual const std::string getExpressionText() const=0; +#endif + +private: + const RBASceneImpl* scene_; + +}; + +} + +#endif diff --git a/src/core/model/RBAAllocatable.cpp b/src/core/model/RBAAllocatable.cpp new file mode 100644 index 0000000..aac639b --- /dev/null +++ b/src/core/model/RBAAllocatable.cpp @@ -0,0 +1,387 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Allocatable class implementation + */ + +#include <algorithm> + +#include "RBAAllocatable.hpp" +#include "RBAModelElementType.hpp" +#include "RBAViewContent.hpp" +#include "RBAAreaImpl.hpp" +#include "RBAConstraintImpl.hpp" +#include "RBAConstraintInfo.hpp" +#include "RBAConstraintMap.hpp" + +namespace rba +{ + +RBAAllocatable::RBAAllocatable(const std::string& name) + : RBARuleObject{name}, + RBAAbstractAllocatable{name} +{ +} + +void RBAAllocatable::clearStatus() +{ + allocatablesAffectedByThisAllocatable_.clear(); + state_ = nullptr; + hiddenChecked_ = false; + checked_ = false; + attenuateChecked_ = false; + hidden_ = false; + attenuated_ = false; +} + +bool +RBAAllocatable::isArea() const +{ + return isModelElementType(RBAModelElementType::Area); +} + +bool +RBAAllocatable::isZone() const +{ + return isModelElementType(RBAModelElementType::Zone); +} + +RBAArbitrationPolicy +RBAAllocatable::getAllocatableArbitrationPolicy() const +{ + return arbitrationPolicy_; +} + +void +RBAAllocatable::setArbitrationPolicy(const RBAArbitrationPolicy newPolicy) +{ + arbitrationPolicy_ = newPolicy; +} + +std::int32_t +RBAAllocatable::getVisibility() const +{ + return visibility_; +} + +void +RBAAllocatable::setVisibility(const std::int32_t newVisibility) +{ + visibility_ = newVisibility; +} + +const std::list<const RBAAllocatable*>& +RBAAllocatable::getAllocatablesAffectedByYou() const +{ + return allocatablesAffectedByThisAllocatable_; +} + +void +RBAAllocatable::clearAllocatablesAffectedByYou() +{ + return allocatablesAffectedByThisAllocatable_.clear(); +} + +void +RBAAllocatable::addAllocatableWhichHasBeenAffectedByYou(const RBAAllocatable* const allocatable) +{ + allocatablesAffectedByThisAllocatable_.push_back(allocatable); +} + +void +RBAAllocatable::removeAffectAllocatable(const RBAAllocatable* const allocatable) +{ + const auto it = std::find(allocatablesAffectedByThisAllocatable_.begin(), + allocatablesAffectedByThisAllocatable_.end(), allocatable); + if(it != allocatablesAffectedByThisAllocatable_.end()) { + static_cast<void>(allocatablesAffectedByThisAllocatable_.erase(it)); + } +} + +void +RBAAllocatable::clearAffectAllocatable() +{ + allocatablesAffectedByThisAllocatable_.clear(); +} + +void +RBAAllocatable::clearChecked() +{ + hiddenChecked_ = false; + checked_ = false; + attenuateChecked_ =false; + hidden_ = false; + attenuated_ = false; +} + +std::int32_t +RBAAllocatable::getIndex() const +{ + return index_; +} + +void +RBAAllocatable::setIndex(const std::int32_t newIndex) +{ + index_ = newIndex; +} + +bool +RBAAllocatable::compare(const RBAAllocatable* const arg0, + const RBAAllocatable* const arg1) +{ + const std::int32_t visibility0 {arg0->getVisibility()}; + const std::int32_t visibility1 {arg1->getVisibility()}; + // Do not swap because the front element is more visible than the rear element + if(visibility0 > visibility1) { + return true; + } + // Compare the Z orders because the front element and the rear element + // have the same visibility. + else if(visibility0 == visibility1) { + std::int32_t zorder0{0}; + std::int32_t zorder1{0}; + if(arg0->isModelElementType(RBAModelElementType::Area)) { + zorder0 = (dynamic_cast<const RBAAreaImpl*>(arg0))->getZorder(); + zorder1 = (dynamic_cast<const RBAAreaImpl*>(arg1))->getZorder(); + } + else { + zorder0 = ZONE_ZORDER; + zorder1 = ZONE_ZORDER; + } + // Do not swap because the front element has a larger Z order than + // the rear element. + if(zorder0 > zorder1) { + return true; + } + // Do not swap because the Z order of the front element and the rear element + // is the same + else if(zorder0 == zorder1) { + return false; + } + // Swap because the front element has a smaller Z order than + // the rear element. + else { + return false; + } + } + // Replace because the front element is less visible than + // the rear element. + else { + return false; + } +} + +bool +RBAAllocatable::compareIndex(const RBAAllocatable* const arg0, + const RBAAllocatable* const arg1) +{ + return arg0->getIndex() < arg1->getIndex(); +} + +void +RBAAllocatable::addConstraint(RBAConstraintImpl* const constraint, + const RBAConstraintMap& kind) +{ + if (kind == RBAConstraintMap::CONTENT_ALLOCATE_CONSTRAINTS) { + addConstraintImpl(constraint, constraints_); + } else if (kind == RBAConstraintMap::HIDDEN_TRUE_CHECK_CONSTRAINTS) { + addConstraintImpl(constraint, hiddenTrueCheckConstraints_); + } else if (kind == RBAConstraintMap::HIDDEN_FALSE_CHECK_CONSTRAINTS) { + addConstraintImpl(constraint, hiddenFalseCheckConstraints_); + } else if (kind == RBAConstraintMap::ATTENUATE_TRUE_CHECK_CONSTRAINTS) { + addConstraintImpl(constraint, attenuateTrueCheckConstraints_); + } else { + addConstraintImpl(constraint, attenuateFalseCheckConstraints_); + } +} + +std::list<RBAConstraintImpl*>& +RBAAllocatable::getConstraints() +{ + return constraints_; +} +std::list<RBAConstraintImpl*>& RBAAllocatable::getHiddenTrueCheckConstraints() +{ + return hiddenTrueCheckConstraints_; +} +std::list<RBAConstraintImpl*>& RBAAllocatable::getHiddenFalseCheckConstraints() +{ + return hiddenFalseCheckConstraints_; +} +std::list<RBAConstraintImpl*>& RBAAllocatable::getAttenuateTrueCheckConstraints() +{ + return attenuateTrueCheckConstraints_; +} +std::list<RBAConstraintImpl*>& RBAAllocatable::getAttenuateFalseCheckConstraints() +{ + return attenuateFalseCheckConstraints_; +} + +bool RBAAllocatable::hasConstraint(const RBAConstraintImpl* const constraint) const +{ + if ((std::find(constraints_.begin(), constraints_.end(), constraint) + != constraints_.end()) + || (std::find(hiddenTrueCheckConstraints_.begin(), + hiddenTrueCheckConstraints_.end(), constraint) + != hiddenTrueCheckConstraints_.end()) + || (std::find(hiddenFalseCheckConstraints_.begin(), + hiddenFalseCheckConstraints_.end(), constraint) + != hiddenFalseCheckConstraints_.end()) + || (std::find(attenuateTrueCheckConstraints_.begin(), + attenuateTrueCheckConstraints_.end(), constraint) + != attenuateTrueCheckConstraints_.end()) + || (std::find(attenuateFalseCheckConstraints_.begin(), + attenuateFalseCheckConstraints_.end(), constraint) + != attenuateFalseCheckConstraints_.end())) { + return true; + } + return false; +} + +bool +RBAAllocatable::isChecked() const +{ + return checked_; +} + +void +RBAAllocatable::setChecked(const bool checked) +{ + checked_ = checked; +} + +bool +RBAAllocatable::isHiddenChecked() const +{ + return hiddenChecked_; +} + +void +RBAAllocatable::setHiddenChecked(const bool hiddenChecked) +{ + hiddenChecked_ = hiddenChecked; +} + +bool +RBAAllocatable::isAttenuateChecked() const +{ + return attenuateChecked_; +} + +void +RBAAllocatable::setAttenuateChecked(const bool attenuateChecked) +{ + this->attenuateChecked_ = attenuateChecked; +} + +bool +RBAAllocatable::isAttenuated() const +{ + return attenuated_; +} + +void +RBAAllocatable::setAttenuated(const bool attenuated) +{ + this->attenuated_ = attenuated; +} + +bool +RBAAllocatable::isHidden() const +{ + return hidden_; +} + +void +RBAAllocatable::setHidden(const bool hidden) +{ + hidden_ = hidden; +} + +const RBAContentState* +RBAAllocatable::getState() const +{ + return state_; +} + +void +RBAAllocatable::setState(const RBAContentState* const state) +{ + state_ = state; +} + +#ifdef RBA_USE_LOG +std::string +RBAAllocatable::getSymbol() const +{ + // This function is never called because the function of the derived class + // is called. + return "Allocatable"; +} + +std::string +RBAAllocatable::getHiddenSymbol() const +{ + // This function is never called because the function of the derived class + // is called. + return "Allocatable: Unsuppored operation exception"; +} + +std::string +RBAAllocatable::getArbitrationPolicyString() const +{ + std::string res; + switch(arbitrationPolicy_) { + case RBAArbitrationPolicy::FIRST_COME_FIRST: + res = "FIRST_COME_FIRST"; + break; + case RBAArbitrationPolicy::LAST_COME_FIRST: + res = "LAST_COME_FIRST"; + break; + case RBAArbitrationPolicy::PRIORITY_FIRST_COME_FIRST: + res = "PRIORITY_FIRST_COME_FIRST"; + break; + case RBAArbitrationPolicy::PRIORITY_LAST_COME_FIRST: + res = "PRIORITY_LAST_COME_FIRST"; + break; + default: + res = "DEFAULT"; + break; + } + + return res; +} + +std::string +RBAAllocatable::getVisibilityString() const +{ + return std::to_string(visibility_); +} +#endif + +void +RBAAllocatable::addConstraintImpl(RBAConstraintImpl* const constraint, + std::list<RBAConstraintImpl*>& constraints) +{ + if (std::find(constraints.begin(), constraints.end(), constraint) + == constraints.end()) { + constraints.push_back(constraint); + } +} + +} diff --git a/src/core/model/RBAAllocatable.hpp b/src/core/model/RBAAllocatable.hpp new file mode 100644 index 0000000..c44d643 --- /dev/null +++ b/src/core/model/RBAAllocatable.hpp @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Allocatable class header + */ + +#ifndef RBAALLOCATABLE_HPP +#define RBAALLOCATABLE_HPP + +#include "RBAAbstractAllocatable.hpp" +#include "RBAArbitrationPolicy.hpp" + +namespace rba +{ + +class RBAViewContent; +class RBANotificationChain; +class RBAContentState; +class RBAConstraintImpl; +enum class RBAConstraintMap : std::uint8_t; + +class DLL_EXPORT RBAAllocatable : public RBAAbstractAllocatable +{ +public: + explicit RBAAllocatable(const std::string& name=""); + RBAAllocatable(const RBAAllocatable&)=delete; + RBAAllocatable(const RBAAllocatable&&)=delete; + RBAAllocatable& operator=(const RBAAllocatable&)=delete; + RBAAllocatable& operator=(const RBAAllocatable&&)=delete; + virtual ~RBAAllocatable()=default; + +public: + void clearStatus() override; + virtual bool isArea() const; + virtual bool isZone() const; + RBAArbitrationPolicy getAllocatableArbitrationPolicy() const; + void setArbitrationPolicy(const RBAArbitrationPolicy newPolicy); + std::int32_t getVisibility() const; + void setVisibility(const std::int32_t newVisibility); + const std::list<const RBAAllocatable*>& getAllocatablesAffectedByYou() const; + void clearAllocatablesAffectedByYou(); + void addAllocatableWhichHasBeenAffectedByYou(const RBAAllocatable* const allocatable); + void removeAffectAllocatable(const RBAAllocatable* const allocatable); + void clearAffectAllocatable(); + virtual void clearChecked(); + std::int32_t getIndex() const; + void setIndex(const std::int32_t newIndex); + + static bool compare(const RBAAllocatable* const arg0, const RBAAllocatable* const arg1); + static bool compareIndex(const RBAAllocatable* const arg0, const RBAAllocatable* const arg1); + const static RBAArbitrationPolicy ARBITRATION_POLICY_EDEFAULT = + RBAArbitrationPolicy::DEFAULT; + void addConstraint(RBAConstraintImpl* const constraint, const RBAConstraintMap& kind); + std::list<RBAConstraintImpl*>& getConstraints(); + std::list<RBAConstraintImpl*>& getHiddenTrueCheckConstraints(); + std::list<RBAConstraintImpl*>& getHiddenFalseCheckConstraints(); + std::list<RBAConstraintImpl*>& getAttenuateTrueCheckConstraints(); + std::list<RBAConstraintImpl*>& getAttenuateFalseCheckConstraints(); + bool hasConstraint(const RBAConstraintImpl* const constraint) const; + + bool isChecked() const; + void setChecked(const bool checked); + bool isHiddenChecked() const; + void setHiddenChecked(const bool hiddenChecked); + bool isAttenuateChecked() const; + void setAttenuateChecked(const bool attenuateChecked=false); + bool isAttenuated() const; + void setAttenuated(const bool attenuated=false); + bool isHidden() const; + void setHidden(const bool hidden=false); + const RBAContentState* getState() const; + void setState(const RBAContentState* const state); + + // Log +#ifdef RBA_USE_LOG + virtual std::string getSymbol() const; + virtual std::string getHiddenSymbol() const; + std::string getArbitrationPolicyString() const; + std::string getVisibilityString() const; +#endif + + private: + void addConstraintImpl(RBAConstraintImpl* const constraint, + std::list<RBAConstraintImpl*>& constraints); + +protected: + // Zone should be a Z-order below the minimum Area + const static std::int32_t ZONE_ZORDER = -2; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::list<const RBAAllocatable*> allocatablesAffectedByThisAllocatable_; + std::list<RBAConstraintImpl*> constraints_; + std::list<RBAConstraintImpl*> hiddenTrueCheckConstraints_; + std::list<RBAConstraintImpl*> hiddenFalseCheckConstraints_; + std::list<RBAConstraintImpl*> attenuateTrueCheckConstraints_; + std::list<RBAConstraintImpl*> attenuateFalseCheckConstraints_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + RBAArbitrationPolicy arbitrationPolicy_{ARBITRATION_POLICY_EDEFAULT}; + std::int32_t visibility_ {0}; + std::int32_t index_ {0}; + const RBAContentState * state_ {nullptr}; + bool hiddenChecked_ {false}; + bool checked_ {false}; + bool attenuateChecked_ {false}; + bool hidden_ {false}; + bool attenuated_ {false}; +}; + +} + +#endif diff --git a/src/core/model/RBAAllocatableMaker.cpp b/src/core/model/RBAAllocatableMaker.cpp new file mode 100644 index 0000000..f59813b --- /dev/null +++ b/src/core/model/RBAAllocatableMaker.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAllocatableMaker.cpp +/// @brief Allocatable object generator abstract class implementation + +#include <iostream> +#include "RBAAllocatableMaker.hpp" +#include "RBAAllocatable.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAAllocatableMaker::RBAAllocatableMaker(const std::string& label) + : RBARuleObjectMaker{label}, + RBAAbstractAllocatableMaker{label} +{ +} + +RBAModelElement* +RBAAllocatableMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBAAbstractAllocatableMaker::setProperty(element, jsonElem, model, owner)); + + const auto alloc = dynamic_cast<RBAAllocatable*>(element); + + // Set policy + const RBAJsonElement* const policy {jsonElem->findChildren("arbitrationPolicy")}; + if(policy == nullptr) { + std::cerr << alloc->getElementName() + << ": arbitrationPolicy not found" << &std::endl; + return nullptr; + } + alloc->setArbitrationPolicy(policy->getArbitrationPolicy()); + + // Set visibility or priority + if (alloc->isArea()) { + const RBAJsonElement* const visibility {jsonElem->findChildren("visibility")}; + if(visibility == nullptr) { + std::cerr << alloc->getElementName() + << ": visibility not found" << &std::endl; + return nullptr; + } + alloc->setVisibility(visibility->getInt()); + } else if (alloc->isZone()) { + const RBAJsonElement* const priority {jsonElem->findChildren("priority")}; + if(priority == nullptr) { + std::cerr << alloc->getElementName() + << ": priority not found" << &std::endl; + return nullptr; + } + alloc->setVisibility(priority->getInt()); + } else { + ; + } + + model->addAllocatable(alloc); + + return alloc; +} + +} diff --git a/src/core/model/RBAAllocatableMaker.hpp b/src/core/model/RBAAllocatableMaker.hpp new file mode 100644 index 0000000..f4393cb --- /dev/null +++ b/src/core/model/RBAAllocatableMaker.hpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAllocatableMaker.cpp +/// @brief Allocatable object generator abstract class header + +#ifndef RBAALLOCATABLEMAKER_HPP +#define RBAALLOCATABLEMAKER_HPP + +#include "RBAAbstractAllocatableMaker.hpp" + +namespace rba +{ + +/// @brief Allocatable object generator abstract class +class DLL_EXPORT RBAAllocatableMaker + : public RBAAbstractAllocatableMaker +{ +public: + explicit RBAAllocatableMaker(const std::string& label=""); + RBAAllocatableMaker(const RBAAllocatableMaker&)=delete; + RBAAllocatableMaker(const RBAAllocatableMaker&&)=delete; + RBAAllocatableMaker& operator=(const RBAAllocatableMaker&)=delete; + RBAAllocatableMaker& operator=(const RBAAllocatableMaker&&)=delete; + virtual ~RBAAllocatableMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAAllocatableSet.cpp b/src/core/model/RBAAllocatableSet.cpp new file mode 100644 index 0000000..c545417 --- /dev/null +++ b/src/core/model/RBAAllocatableSet.cpp @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AllocatableSet class implementation + */ + +#include "RBAAllocatableSet.hpp" +#include "RBAAllocatable.hpp" + +namespace rba +{ + +RBAAllocatableSet::RBAAllocatableSet(const std::string& name) + : RBARuleObject{name}, + RBAAbstractAllocatable{name} +{ +} + +void +RBAAllocatableSet::addTarget(const RBAAllocatable* alloc) +{ + leafAllocatable_.push_back(alloc); +#ifdef RBA_USE_LOG + std::string newName = "["; + for (auto& a : leafAllocatable_) { + newName += a->getElementName() + ","; + } + if (newName.size() != 1U) { + newName.erase(newName.end() - 1); // Remove the trailing ",". + } + newName += "]"; + setDynamicName(newName); +#endif +} + +void +RBAAllocatableSet::clear() +{ + leafAllocatable_.clear(); +#ifdef RBA_USE_LOG + setDynamicName("[]"); +#endif +} + +const std::list<const RBAAllocatable*>& +RBAAllocatableSet::getLeafAllocatable() const +{ + return leafAllocatable_; +} + +} diff --git a/src/core/model/RBAAllocatableSet.hpp b/src/core/model/RBAAllocatableSet.hpp new file mode 100644 index 0000000..1c02155 --- /dev/null +++ b/src/core/model/RBAAllocatableSet.hpp @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * AllocatableSet class header + */ + +#ifndef RBAALLOCATABLESET_HPP +#define RBAALLOCATABLESET_HPP + +#include "RBAAbstractAllocatable.hpp" + +namespace rba +{ + +class RBAAllocatable; + +class DLL_EXPORT RBAAllocatableSet : public RBAAbstractAllocatable +{ +public: + explicit RBAAllocatableSet(const std::string& name=""); + RBAAllocatableSet(const RBAAllocatableSet&)=delete; + RBAAllocatableSet(const RBAAllocatableSet&&)=delete; + RBAAllocatableSet& operator=(const RBAAllocatableSet&)=delete; + RBAAllocatableSet& operator=(const RBAAllocatableSet&&)=delete; + virtual ~RBAAllocatableSet()=default; + +public: + virtual void addTarget(const RBAAllocatable* alloc); + virtual void clear(); + const std::list<const RBAAllocatable*>& getLeafAllocatable() const; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::list<const RBAAllocatable*> leafAllocatable_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} +#endif diff --git a/src/core/model/RBAAllocatableSetMaker.cpp b/src/core/model/RBAAllocatableSetMaker.cpp new file mode 100644 index 0000000..9b9922a --- /dev/null +++ b/src/core/model/RBAAllocatableSetMaker.cpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAllocatableSetMaker.cpp +/// @brief AllocatableSet object genartor abstract class implementation + +#include <iostream> +#include "RBAAllocatableSetMaker.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAAllocatableSetMaker::RBAAllocatableSetMaker(const std::string& label) + : RBARuleObjectMaker{label}, + RBAAbstractAllocatableMaker{label} +{ +} + +RBAModelElement* +RBAAllocatableSetMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBAAbstractAllocatableMaker::setProperty(element, jsonElem, model, owner)); + + const auto allocSet = dynamic_cast<RBAAllocatableSet*>(element); + + // Set target + const RBAJsonElement* const target {jsonElem->findChildren("target")}; + for(const auto& targetElem : target->getChildren()) { + const auto alloc = model->findAllocatable(targetElem->getName()); + allocSet->addTarget(alloc); + } + + return allocSet; +} + +} diff --git a/src/core/model/RBAAllocatableSetMaker.hpp b/src/core/model/RBAAllocatableSetMaker.hpp new file mode 100644 index 0000000..619d220 --- /dev/null +++ b/src/core/model/RBAAllocatableSetMaker.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAAllocatableSetMaker.cpp +/// @brief AllocatableSet object genartor abstract class header + +#ifndef RBAALLOCATABLESETMAKER_HPP +#define RBAALLOCATABLESETMAKER_HPP + +#include "RBAAbstractAllocatableMaker.hpp" + +namespace rba +{ + +/// @brief AllocatableSet object genartor abstract class +class RBAAllocatableSetMaker : public RBAAbstractAllocatableMaker +{ +public: + explicit RBAAllocatableSetMaker(const std::string& label=""); + RBAAllocatableSetMaker(const RBAAllocatableSetMaker&)=delete; + RBAAllocatableSetMaker(const RBAAllocatableSetMaker&&)=delete; + RBAAllocatableSetMaker& operator=(const RBAAllocatableSetMaker&)=delete; + RBAAllocatableSetMaker& operator=(const RBAAllocatableSetMaker&&)=delete; + virtual ~RBAAllocatableSetMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAConstraint.hpp b/src/core/model/RBAConstraint.hpp new file mode 100644 index 0000000..312bedc --- /dev/null +++ b/src/core/model/RBAConstraint.hpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Constraint class + */ + +#ifndef RBACONSTRAINT_HPP +#define RBACONSTRAINT_HPP + +#include <string> +#include "RBADllExport.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAConstraint +{ + public: + RBAConstraint()=default; + RBAConstraint(const RBAConstraint&)=delete; + RBAConstraint(const RBAConstraint&&)=delete; + RBAConstraint& operator=(const RBAConstraint&)=delete; + RBAConstraint& operator=(const RBAConstraint&&)=delete; + virtual ~RBAConstraint() = default; + virtual std::string getName() const =0; + const static bool RUNTIME_EDEFAULT = true; +}; + +} + +#endif diff --git a/src/core/model/RBAConstraintImpl.cpp b/src/core/model/RBAConstraintImpl.cpp new file mode 100644 index 0000000..a634621 --- /dev/null +++ b/src/core/model/RBAConstraintImpl.cpp @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Constraint Implementation class + */ + +#include "RBAConstraintImpl.hpp" + +#include "RBAExpression.hpp" +#include "RBALogManager.hpp" + +namespace rba +{ + +RBAConstraintImpl::RBAConstraintImpl(const std::string& name) + : RBAConstraint(), + RBAAbstractConstraint{name} +{ +} + +void +RBAConstraintImpl::setRuntime(const bool newRuntime) +{ + runtime_ = newRuntime; +} + +std::string +RBAConstraintImpl::getName() const +{ + return RBANamedElement::getElementName(); +} + +bool +RBAConstraintImpl::isConstraint() const +{ + return true; +} + +bool +RBAConstraintImpl::isRuntime() const +{ + return runtime_; +} + +bool +RBAConstraintImpl::execute(RBAArbitrator* const arb) +{ + LOG_arbitrateConstraintLogicLogLine(" constraint expression[" + + getExpression()->LOG_getExpressionText() + + "] check start"); + LOG_initConstraintHierarchy(); + LOG_coverageConstraintStartLog(this); + + clearInfo(); + + bool res {getExpression()->execute(getInfo(), arb)}; +#ifdef RBA_USE_LOG + std::string log = " constraint expression[" + getExpression()->getExpressionText(); + + if (res == true) { + log += "] true"; + } else { +#endif + if (getInfo()->isExceptionBeforeArbitrate() == true) { +#ifdef RBA_USE_LOG + log += "] before arbitrate skip"; +#endif + res = true; +#ifdef RBA_USE_LOG + } else { + log += "] false"; + } +#endif + } + LOG_arbitrateConstraintLogicLogLine(log + "\n"); + + LOG_coverageConstraintEndLog(this); + + return res; +} + +} diff --git a/src/core/model/RBAConstraintImpl.hpp b/src/core/model/RBAConstraintImpl.hpp new file mode 100644 index 0000000..eb4d6ab --- /dev/null +++ b/src/core/model/RBAConstraintImpl.hpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Constraint Implementation class header + */ + +#ifndef RBACONSTRAINTIMPL_HPP +#define RBACONSTRAINTIMPL_HPP + +#include "RBAConstraint.hpp" +#include "RBAAbstractConstraint.hpp" + +namespace rba +{ + +class RBAArbitrator; + +class DLL_EXPORT RBAConstraintImpl : public RBAConstraint, + public RBAAbstractConstraint +{ +public: + explicit RBAConstraintImpl(const std::string& name=""); + RBAConstraintImpl(const RBAConstraintImpl&)=delete; + RBAConstraintImpl(const RBAConstraintImpl&&)=delete; + RBAConstraintImpl& operator=(const RBAConstraintImpl&)=delete; + RBAConstraintImpl& operator=(const RBAConstraintImpl&&)=delete; + virtual ~RBAConstraintImpl()=default; + +public: + void setRuntime(const bool newRuntime); + std::string getName() const override; + bool isConstraint() const override; + bool isRuntime() const; + bool execute(RBAArbitrator* const arb); + +private: + bool runtime_ {RUNTIME_EDEFAULT}; +}; + +} + +#endif diff --git a/src/core/model/RBAConstraintMaker.cpp b/src/core/model/RBAConstraintMaker.cpp new file mode 100644 index 0000000..7363c16 --- /dev/null +++ b/src/core/model/RBAConstraintMaker.cpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAConstraintMaker.cpp +/// @brief Constraint object genartor class implementation + +#include "RBAConstraintMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAConstraintImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAConstraintMaker::RBAConstraintMaker() + : RBAAbstractConstraintMaker{"constraints"} +{ +} + +std::unique_ptr<RBAModelElement> +RBAConstraintMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBAConstraintImpl>(name); +} + +RBAModelElement* +RBAConstraintMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBAAbstractConstraintMaker::setProperty(element, jsonElem, model, owner)); + + const auto constraint = dynamic_cast<RBAConstraintImpl*>(element); + + // Set runtime + bool runtime {false}; + if(jsonElem->findChildren("runtime")->getString() == "true") { + runtime = true; + } + constraint->setRuntime(runtime); + + model->addConstraint(constraint); + + return constraint; +} + +} diff --git a/src/core/model/RBAConstraintMaker.hpp b/src/core/model/RBAConstraintMaker.hpp new file mode 100644 index 0000000..4bcb250 --- /dev/null +++ b/src/core/model/RBAConstraintMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAConstraintMaker.jhp +/// @brief Constraint object generator class header + +#ifndef RBACONSTRAINTMAKER_HPP +#define RBACONSTRAINTMAKER_HPP + +#include "RBAAbstractConstraintMaker.hpp" + +namespace rba +{ + +/// @brief Constraint object generator class +class RBAConstraintMaker : public RBAAbstractConstraintMaker +{ +public: + RBAConstraintMaker(); + RBAConstraintMaker(const RBAConstraintMaker&)=delete; + RBAConstraintMaker(const RBAConstraintMaker&&)=delete; + RBAConstraintMaker& operator=(const RBAConstraintMaker&)=delete; + RBAConstraintMaker& operator=(const RBAConstraintMaker&&)=delete; + virtual ~RBAConstraintMaker()=default; + +protected: + /// @brief Create an empty instance + /// @details Create an empty class of unique_ptr in derived class + /// @return unique_ptr for instance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAContent.cpp b/src/core/model/RBAContent.cpp new file mode 100644 index 0000000..e2e3c9f --- /dev/null +++ b/src/core/model/RBAContent.cpp @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Content class + */ + +#include "RBAContent.hpp" +#include "RBAResultImpl.hpp" +#include "RBAResultSet.hpp" +#include "RBAExpression.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBAContent::RBAContent(const std::string& name) + : RBARuleObject{name}, + RBAAbstractContent{name} +{ +} + +bool +RBAContent::isViewContent() const +{ + return false; +} + +bool +RBAContent::isSoundContent() const +{ + return false; +} + +const std::list<const RBAContentState*>& +RBAContent::getStates() const +{ + return states_; +} + +void +RBAContent::addState(const RBAContentState* const state) +{ + states_.push_back(state); +} + +const std::list<const RBAAllocatable*>& +RBAContent::getAllocatables() const +{ + return allocatableSet_->getLeafAllocatable(); +} + +void +RBAContent::addAllocatable(const RBAAllocatable* const alloc) +{ + allocatableSet_->addTarget(alloc); +} + +RBAContentLoserType +RBAContent::getContentLoserType() const +{ + return loserType_; +} + +void +RBAContent::setLoserType(const RBAContentLoserType newLoserType) +{ + loserType_ = newLoserType; +} + +const RBAAllocatableSet* +RBAContent::getAllocatableSet() const +{ + return allocatableSet_.get(); +} + +void RBAContent::updateRequestStatus(RBAResultSet* const resultset, const bool isOnRequest) +{ + resultset->updateRequestStatus(this, isOnRequest); +} + +void RBAContent::updateStatus(RBAResultImpl* const result) +{ + result->updateStatus(this); +} + +const std::list<const RBASize*>& +RBAContent::getSizes() const +{ + static const std::list<const RBASize*> sizes; + return sizes; +} + +} diff --git a/src/core/model/RBAContent.hpp b/src/core/model/RBAContent.hpp new file mode 100644 index 0000000..17e912c --- /dev/null +++ b/src/core/model/RBAContent.hpp @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * Content class header + */ + +#ifndef RBACONTENT_HPP +#define RBACONTENT_HPP + +#include <memory> +#include <set> +#include "RBAAbstractContent.hpp" +#include "RBAAllocatableSet.hpp" +#include "RBAContentLoserType.hpp" + +namespace rba +{ + +class RBAArbitrator; +class RBAAllocatable; +class RBAContentState; +class RBAResultImpl; +class RBAResultSet; +class RBAExpression; +class RBASize; + +class DLL_EXPORT RBAContent : public RBAAbstractContent +{ +public: + explicit RBAContent(const std::string& name=""); + RBAContent(const RBAContent&)=delete; + RBAContent(const RBAContent&&)=delete; + RBAContent& operator=(const RBAContent&)=delete; + RBAContent& operator=(const RBAContent&&)=delete; + virtual ~RBAContent()=default; + +public: + virtual bool isViewContent() const; + virtual bool isSoundContent() const; + + const std::list<const RBAContentState*>& getStates() const; + void addState(const RBAContentState* const state); + const std::list<const RBAAllocatable*>& getAllocatables() const; + void addAllocatable(const RBAAllocatable* const alloc); + RBAContentLoserType getContentLoserType() const; + void setLoserType(const RBAContentLoserType newLoserType); + const RBAAllocatableSet* getAllocatableSet() const; + void updateRequestStatus(RBAResultSet* const resultset, const bool isOnRequest); + void updateStatus(RBAResultImpl* const result); + virtual const std::list<const RBASize*>& getSizes() const; + +#ifdef RBA_USE_LOG + virtual std::string getSymbol() const = 0; + virtual std::string getVisibleSymbol() const = 0; +#endif + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::list<const RBAContentState*> states_; + std::unique_ptr<RBAAllocatableSet> allocatableSet_ {std::make_unique<RBAAllocatableSet>()}; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + RBAContentLoserType loserType_ {RBAContentLoserType::DO_NOT_GIVEUP_UNTIL_WIN}; + +}; + +} + +#endif diff --git a/src/core/model/RBAContentMaker.cpp b/src/core/model/RBAContentMaker.cpp new file mode 100644 index 0000000..a9828ba --- /dev/null +++ b/src/core/model/RBAContentMaker.cpp @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAContentMaker.cpp +/// @brief Content obecjt generator abstract class + +#include <iostream> +#include "RBAContentMaker.hpp" +#include "RBAContent.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBAViewContentStateMaker.hpp" +#include "RBASoundContentStateMaker.hpp" + +namespace rba +{ + +RBAContentMaker::RBAContentMaker(const std::string& label) + : RBARuleObjectMaker{label}, + RBAAbstractContentMaker{label} +{ +} + +RBAModelElement* +RBAContentMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBAAbstractContentMaker::setProperty(element, jsonElem, model, owner)); + + RBAContent* const content {dynamic_cast<RBAContent*>(element)}; + + // loserType + const RBAJsonElement* const loserTypeElem {jsonElem->findChildren("loserType")}; + if(loserTypeElem == nullptr) { + std::cerr << content->getElementName() + << ": loserType not found" << &std::endl; + return nullptr; + } + content->setLoserType(loserTypeElem->getLoserType()); + + // allocatable + for(auto& allocElem : jsonElem->findChildren("allocatable")->getChildren()) { + const auto str = allocElem->getName(); + std::string allocName {""}; + std::string className {""}; + if (str.find(':') != std::string::npos) { + allocName = str.substr(0U, str.find(':')); + className = str.substr(str.find(':') + 1U); + } else { + allocName = str; + } + + auto alloc = model->findAllocatable(allocName); + if (alloc == nullptr) { + alloc = dynamic_cast<RBAAllocatable*>(getMaker(className)->getInstance(model, allocName)); + } + const_cast<RBAAllocatable*>(alloc)->addContent(content); + content->addAllocatable(alloc); + } + + // state + if (content->isViewContent()) { + RBAViewContentStateMaker csMaker; + for(const auto& state : jsonElem->findChildren("states")->getChildren()) { + RBAModelElement* const s {csMaker.create(state.get(), model, content)}; + content->addMember(dynamic_cast<RBARuleObject*>(s)); + content->addState(dynamic_cast<RBAContentState*>(s)); + } + } + else if (content->isSoundContent()) { + RBASoundContentStateMaker csMaker; + for(const auto& state : jsonElem->findChildren("states")->getChildren()) { + RBAModelElement* const s {csMaker.create(state.get(), model, content)}; + content->addMember(dynamic_cast<RBARuleObject*>(s)); + content->addState(dynamic_cast<RBAContentState*>(s)); + } + } + // Expand Content + else { + auto alloc = content->getAllocatables().front(); + // Seek until it becomes an Area or Zone + while (!alloc->isArea() && !alloc->isZone()) { + alloc = dynamic_cast<const RBAContent*>(alloc)->getAllocatables().front(); + } + if (alloc->isArea()) { + RBAViewContentStateMaker csMaker; + for(const auto& state : jsonElem->findChildren("states")->getChildren()) { + RBAModelElement* const s {csMaker.create(state.get(), model, content)}; + content->addMember(dynamic_cast<RBARuleObject*>(s)); + content->addState(dynamic_cast<RBAContentState*>(s)); + } + } else if (alloc->isZone()) { + RBASoundContentStateMaker csMaker; + for(const auto& state : jsonElem->findChildren("states")->getChildren()) { + RBAModelElement* const s {csMaker.create(state.get(), model, content)}; + content->addMember(dynamic_cast<RBARuleObject*>(s)); + content->addState(dynamic_cast<RBAContentState*>(s)); + } + } else { + ; + } + } + + model->addContent(content); + + return content; +} + +} diff --git a/src/core/model/RBAContentMaker.hpp b/src/core/model/RBAContentMaker.hpp new file mode 100644 index 0000000..5564fc1 --- /dev/null +++ b/src/core/model/RBAContentMaker.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAContentMaker.hpp +/// @brief Content obecjt generator class header + +#ifndef RBACONTENTMAKER_HPP +#define RBACONTENTMAKER_HPP + +#include "RBAAbstractContentMaker.hpp" + +namespace rba +{ + +/// @brief Content obecjt generator class +class DLL_EXPORT RBAContentMaker : public RBAAbstractContentMaker +{ +public: + explicit RBAContentMaker(const std::string& label=""); + RBAContentMaker(const RBAContentMaker&)=delete; + RBAContentMaker(const RBAContentMaker&&)=delete; + RBAContentMaker& operator=(const RBAContentMaker&)=delete; + RBAContentMaker& operator=(const RBAContentMaker&&)=delete; + virtual ~RBAContentMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAContentSet.cpp b/src/core/model/RBAContentSet.cpp new file mode 100644 index 0000000..00da62e --- /dev/null +++ b/src/core/model/RBAContentSet.cpp @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + + /** + * ContentSet class + */ + +#include <string> +#include "RBAContentSet.hpp" +#include "RBAContent.hpp" + +namespace rba +{ + +RBAContentSet::RBAContentSet(const std::string& name) + : RBARuleObject{name}, + RBAAbstractContent{name} +{ +} + +void +RBAContentSet::addTarget(const RBAContent* content) +{ + leafContent_.push_back(content); +#ifdef RBA_USE_LOG + std::string newName = "["; + for (auto& c : leafContent_) { + newName += c->getElementName() + ","; + } + if (newName.size() != 1U) { + newName.erase(newName.end() - 1); // Remove the trailing "," + } + newName += "]"; + setDynamicName(newName); +#endif +} + +void +RBAContentSet::clear() +{ + leafContent_.clear(); +#ifdef RBA_USE_LOG + setDynamicName("[]"); +#endif +} + +const std::list<const RBAContent*>& +RBAContentSet::getLeafContent() const +{ + return leafContent_; +} + +} diff --git a/src/core/model/RBAContentSet.hpp b/src/core/model/RBAContentSet.hpp new file mode 100644 index 0000000..3997f07 --- /dev/null +++ b/src/core/model/RBAContentSet.hpp @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * ContentSet class header + */ + +#ifndef RBACONTENTSET_HPP +#define RBACONTENTSET_HPP + +#include <list> +#include "RBAAbstractContent.hpp" + +namespace rba +{ + +class RBAContent; + +class DLL_EXPORT RBAContentSet : public RBAAbstractContent +{ +public: + explicit RBAContentSet(const std::string& name=""); + RBAContentSet(const RBAContentSet&)=delete; + RBAContentSet(const RBAContentSet&&)=delete; + RBAContentSet& operator=(const RBAContentSet&)=delete; + RBAContentSet& operator=(const RBAContentSet&&)=delete; + virtual ~RBAContentSet()=default; + +public: + virtual void addTarget(const RBAContent* content); + virtual void clear(); + const std::list<const RBAContent*>& getLeafContent() const; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::list<const RBAContent*> leafContent_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBAContentSetMaker.cpp b/src/core/model/RBAContentSetMaker.cpp new file mode 100644 index 0000000..cbc8db9 --- /dev/null +++ b/src/core/model/RBAContentSetMaker.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/// @file RBAContentSetMaker.cpp +/// @brief ContentSet object generator class + +#include "RBAContentSetMaker.hpp" +#include "RBAContentSet.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBAContentSetMaker::RBAContentSetMaker(const std::string& label) + : RBARuleObjectMaker{label}, + RBAAbstractContentMaker{label} +{ +} + +RBAModelElement* +RBAContentSetMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBAAbstractContentMaker::setProperty(element, jsonElem, model, owner)); + + const auto contentSet = dynamic_cast<RBAContentSet*>(element); + + // content + for(const auto& content : jsonElem->findChildren("target")->getChildren()) { + const auto cont = model->findContent(content->getName()); + contentSet->addTarget(cont); + } + + return contentSet; +} + +} diff --git a/src/core/model/RBAContentSetMaker.hpp b/src/core/model/RBAContentSetMaker.hpp new file mode 100644 index 0000000..182764c --- /dev/null +++ b/src/core/model/RBAContentSetMaker.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAContentSetMaker.hpp +/// @brief ContentSet object generator class header + +#ifndef RBACONTENTSETMAKER_HPP +#define RBACONTENTSETMAKER_HPP + +#include "RBAAbstractContentMaker.hpp" + +namespace rba +{ + +/// @brief ContentSet object generator class +class RBAContentSetMaker : public RBAAbstractContentMaker +{ +public: + explicit RBAContentSetMaker(const std::string& label=""); + RBAContentSetMaker(const RBAContentSetMaker&)=delete; + RBAContentSetMaker(const RBAContentSetMaker&&)=delete; + RBAContentSetMaker& operator=(const RBAContentSetMaker&)=delete; + RBAContentSetMaker& operator=(const RBAContentSetMaker&&)=delete; + virtual ~RBAContentSetMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAContentState.cpp b/src/core/model/RBAContentState.cpp new file mode 100644 index 0000000..f149129 --- /dev/null +++ b/src/core/model/RBAContentState.cpp @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +] +/** + * ContentState class + */ + +#include <string> + +#include "RBAViewContentState.hpp" +#include "RBAContent.hpp" +#include "RBAContentState.hpp" + +namespace rba +{ + +RBAContentState::RBAContentState(const std::string& name) + : RBARuleObject{name} +{ +} + +void +RBAContentState::clearStatus() +{ + order_ = 0; +} + +bool +RBAContentState::isViewContentState() const +{ + return false; +} + +bool +RBAContentState::isSoundContentState() const +{ + return false; +} + +std::string +RBAContentState::getUniqueName() const +{ + return getOwner()->getElementName() + RBAViewContentState::CONTEXT_SEPARATER + getElementName(); +} + +std::int32_t +RBAContentState::getContentStatePriority() const +{ + return priority_; +} + +void +RBAContentState::setPriority(const std::int32_t newPriority) +{ + priority_ = newPriority; +} + +std::int32_t +RBAContentState::getContentStateOrder() const +{ + return order_; +} + +void +RBAContentState::setOrder(const std::int32_t newOrder) +{ + order_ = newOrder; +} + +bool +RBAContentState::compareFirstComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs) +{ + return lhs->getContentStateOrder() < rhs->getContentStateOrder(); +} + +bool +RBAContentState::compareLastComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs) +{ + return lhs->getContentStateOrder() > rhs->getContentStateOrder(); +} + +bool +RBAContentState::comparePriorityFirstComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs) +{ + if(lhs->getContentStatePriority() == rhs->getContentStatePriority()) { + return compareFirstComeFirst(lhs, rhs); + } + else { + return lhs->getContentStatePriority() > rhs->getContentStatePriority(); + } +} + +bool +RBAContentState::comparePriorityLastComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs) +{ + if(lhs->getContentStatePriority() == rhs->getContentStatePriority()) { + return compareLastComeFirst(lhs, rhs); + } + else { + return lhs->getContentStatePriority() > rhs->getContentStatePriority(); + } +} + +const std::string +RBAContentState::getPriorityString() const +{ + return std::to_string(priority_); +} + +const std::string +RBAContentState::getOrderString() const +{ + return std::to_string(order_); +} + +} diff --git a/src/core/model/RBAContentState.hpp b/src/core/model/RBAContentState.hpp new file mode 100644 index 0000000..7d4a81f --- /dev/null +++ b/src/core/model/RBAContentState.hpp @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + +/** + * ContentState class header + */ + +#ifndef RBACONTENTSTATE_HPP +#define RBACONTENTSTATE_HPP + +#include <cstdint> +#include "RBARuleObject.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAContentState : public RBARuleObject +{ +protected: + explicit RBAContentState(const std::string& name); + RBAContentState(const RBAContentState&)=delete; + RBAContentState(const RBAContentState&&)=delete; + RBAContentState& operator=(const RBAContentState&)=delete; + RBAContentState& operator=(const RBAContentState&&)=delete; + +public: + virtual ~RBAContentState()=default; + +public: + void clearStatus() final; + virtual bool isViewContentState() const; + virtual bool isSoundContentState() const; + + std::string getUniqueName() const override; + std::int32_t getContentStatePriority() const; + void setPriority(const std::int32_t newPriority); + std::int32_t getContentStateOrder() const; + void setOrder(const std::int32_t newOrder); + + static bool compareFirstComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs); + static bool compareLastComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs); + static bool comparePriorityFirstComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs); + static bool comparePriorityLastComeFirst(const RBAContentState* const lhs, + const RBAContentState* const rhs); + + // Log + const std::string getPriorityString() const; + const std::string getOrderString() const; + +private: + std::int32_t priority_ {0}; + std::int32_t order_ {0}; + +}; + +} + +#endif diff --git a/src/core/model/RBAContentStateMaker.cpp b/src/core/model/RBAContentStateMaker.cpp new file mode 100644 index 0000000..92129ef --- /dev/null +++ b/src/core/model/RBAContentStateMaker.cpp @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAContentStateMaker.cpp +/// @brief ContentState object generator abstract class + +#include "RBAContentStateMaker.hpp" +#include "RBAContentState.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +RBAContentStateMaker::RBAContentStateMaker(const std::string& label) + : RBARuleObjectMaker{label} +{ +} + +RBAModelElement* +RBAContentStateMaker::getInstance(RBAModelImpl* model, + const std::string& name, + RBAModelElement* owner) +{ + RBAModelElement* ret {nullptr}; + + const auto content = dynamic_cast<RBAContent*>(owner); + const auto uniqueName = content->getUniqueName() + "/" + name; + + const auto element = model->findModelElement(uniqueName); + // exists in model + if(element != nullptr) { + ret = const_cast<RBAModelElement*>(element); + } + // not exists in modelmodel + else { + std::unique_ptr<RBAModelElement> inst {createInstance(name)}; + const auto contentState = dynamic_cast<RBAContentState*>(inst.get()); + contentState->setOwner(content); + ret = model->addNamedElement(std::move(inst)); + } + + return ret; +} + +RBAModelElement* +RBAContentStateMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBARuleObjectMaker::setProperty(element, jsonElem, model, owner)); + + RBAContentState* const state {dynamic_cast<RBAContentState*>(element)}; + + // Set priority + state->setPriority(jsonElem->findChildren("priority")->getInt()); + + model->addContentState(state); + + return state; +} + +} diff --git a/src/core/model/RBAContentStateMaker.hpp b/src/core/model/RBAContentStateMaker.hpp new file mode 100644 index 0000000..4082739 --- /dev/null +++ b/src/core/model/RBAContentStateMaker.hpp @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAContentStateMaker.hpp +/// @brief ContentState object generator abstract class header + +#ifndef RBACONTENTSTATEMAKER_HPP +#define RBACONTENTSTATEMAKER_HPP + +#include "RBARuleObjectMaker.hpp" + +namespace rba +{ + +/// @brief ContentState object generator abstract class +class RBAContentStateMaker : public RBARuleObjectMaker +{ +public: + explicit RBAContentStateMaker(const std::string& label); + RBAContentStateMaker(const RBAContentStateMaker&)=delete; + RBAContentStateMaker(const RBAContentStateMaker&&)=delete; + RBAContentStateMaker& operator=(const RBAContentStateMaker&)=delete; + RBAContentStateMaker& operator=(const RBAContentStateMaker&&)=delete; + virtual ~RBAContentStateMaker()=default; + +public: + + RBAModelElement* getInstance(RBAModelImpl* model, + const std::string& name="", + RBAModelElement* owner=nullptr) override; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBAContentStatusType.hpp b/src/core/model/RBAContentStatusType.hpp new file mode 100644 index 0000000..d6cd161 --- /dev/null +++ b/src/core/model/RBAContentStatusType.hpp @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +// +// State transition type of content +// + +#ifndef RBACONTENTSTATUSTYPE_HPP +#define RBACONTENTSTATUSTYPE_HPP + +namespace rba +{ + +enum class RBAContentStatusType : std::uint8_t +{ + NoRequest, + Undisplayed, + Displayed, + StandBy, + Canceled +}; +} + +#endif /* RBACONTENTSTATUSTYPE_HPP */ diff --git a/src/core/model/RBAIntegerProperty.cpp b/src/core/model/RBAIntegerProperty.cpp new file mode 100644 index 0000000..aeee3b0 --- /dev/null +++ b/src/core/model/RBAIntegerProperty.cpp @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + /** + * Integer property class + */ + +#include "RBAIntegerProperty.hpp" +#include "RBASceneImpl.hpp" + +namespace rba +{ + +RBAIntegerProperty::RBAIntegerProperty(const RBASceneImpl* const scene, + const std::string& newName, + const std::int32_t newValue) + : RBAAbstractProperty{scene, newName}, + value_{newValue} +{ +} + +std::int32_t +RBAIntegerProperty::getValue() const +{ + return value_; +} + +#ifdef RBA_USE_LOG +const std::string +RBAIntegerProperty::getExpressionText() const +{ + return getScene()->getElementName() + "." + getElementName(); +} +#endif + +} diff --git a/src/core/model/RBAIntegerProperty.hpp b/src/core/model/RBAIntegerProperty.hpp new file mode 100644 index 0000000..f174f0a --- /dev/null +++ b/src/core/model/RBAIntegerProperty.hpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ + /** + * Integer property class header + */ + +#ifndef RBAINTEGERPROPERTY_HPP +#define RBAINTEGERPROPERTY_HPP + +#include "RBAAbstractProperty.hpp" + +namespace rba +{ + +class RBAIntegerProperty : public RBAAbstractProperty +{ +public: + RBAIntegerProperty(const RBASceneImpl* const scene, + const std::string& newName, const std::int32_t newValue); + RBAIntegerProperty(const RBAIntegerProperty&)=delete; + RBAIntegerProperty(const RBAIntegerProperty&&)=delete; + RBAIntegerProperty& operator=(const RBAIntegerProperty&)=delete; + RBAIntegerProperty& operator=(const RBAIntegerProperty&&)=delete; + +public: + std::int32_t getValue() const override; + + // Log +#ifdef RBA_USE_LOG + const std::string getExpressionText() const override; +#endif + +private: + std::int32_t value_; + +}; + +} + +#endif diff --git a/src/core/model/RBAModelElement.cpp b/src/core/model/RBAModelElement.cpp new file mode 100644 index 0000000..b4308e5 --- /dev/null +++ b/src/core/model/RBAModelElement.cpp @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * ModelElment class + */ + +#include "RBAModelElement.hpp" +#include "RBAModelElementType.hpp" + +namespace rba +{ + +void RBAModelElement::clearStatus() +{ + // This function is called from a ModelElement that has no internal state + // to clear. + // The overridden function is called from the ModelElement + // that has the internal state to clear. +} +RBAModelElementType +RBAModelElement::getModelElementType() const +{ + // This function is never called because the function of + // the derived class is called. + return RBAModelElementType::None; +} + +bool +RBAModelElement::isModelElementType(const RBAModelElementType elemType) const +{ + return (elemType == getModelElementType()); +} + +} diff --git a/src/core/model/RBAModelElement.hpp b/src/core/model/RBAModelElement.hpp new file mode 100644 index 0000000..7ee7557 --- /dev/null +++ b/src/core/model/RBAModelElement.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * ModelElment class header + */ + +#ifndef RBAMODELELEMENT_HPP +#define RBAMODELELEMENT_HPP + +#include <cstdint> +#include "RBADllExport.hpp" + +namespace rba +{ + +enum class RBAModelElementType : std::uint8_t; + +class DLL_EXPORT RBAModelElement +{ +protected: + RBAModelElement()=default; + RBAModelElement(const RBAModelElement&)=delete; + RBAModelElement(const RBAModelElement&&)=delete; + RBAModelElement& operator=(const RBAModelElement&)=delete; + RBAModelElement& operator=(const RBAModelElement&&)=delete; + +public: + virtual ~RBAModelElement()=default; + +public: + virtual void clearStatus(); + virtual RBAModelElementType getModelElementType() const; + bool isModelElementType(const RBAModelElementType elemType) const; + +}; + +} + +#endif diff --git a/src/core/model/RBAModelElementMaker.cpp b/src/core/model/RBAModelElementMaker.cpp new file mode 100644 index 0000000..9d750c0 --- /dev/null +++ b/src/core/model/RBAModelElementMaker.cpp @@ -0,0 +1,122 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAModelElementMaker.cpp +/// @brief ModelElement object genartor abstract class + +#include "RBAModelElementMaker.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelFactory.hpp" +#include "RBAModelImpl.hpp" + +namespace rba +{ + +std::unordered_map<std::string, std::unique_ptr<RBAModelElementMaker>> RBAModelElementMaker::makerMap_; + +RBAModelElementMaker::RBAModelElementMaker(const std::string& label) + : factory_{nullptr}, + label_{label} +{ +} + +void +RBAModelElementMaker::setFactory(RBAModelFactory* const factory) +{ + factory_ = factory; +} + +RBAModelFactory* RBAModelElementMaker::getFactory() const +{ + return factory_; +} + +const std::string& +RBAModelElementMaker::getLabel() const +{ + return label_; +} + +RBAModelElement* +RBAModelElementMaker::create(const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + const auto nameElement = jsonElem->findChildren("name"); + + RBAModelElement* element {nullptr}; + if (nameElement != nullptr) { + element = getInstance(model, nameElement->getString(), owner); + } else { + element = getInstance(model, "", owner); + } + + return setProperty(element, jsonElem, model, owner); +} + +RBAModelElement* +RBAModelElementMaker::getInstance(RBAModelImpl* model, + const std::string& name, + RBAModelElement* owner) +{ + RBAModelElement* ret {nullptr}; + + // If there is a class name, delete the class name + std::string fullName {name}; + while (fullName.find(':') != std::string::npos) { + const auto start = fullName.find(':'); + const auto end = fullName.find('/', start); + static_cast<void>(fullName.erase(start, end - start)); + } + + // In case of Elemetn with name + if(fullName != "") { + const auto elem = model->findModelElement(fullName); + // exists in model + if(elem != nullptr) { + ret = const_cast<RBAModelElement*>(elem); + } + // not exists in model + else { + std::unique_ptr<RBAModelElement> inst {createInstance(fullName)}; + ret = model->addNamedElement(std::move(inst)); + } + } + // In case of Elemetn without name + else { + std::unique_ptr<RBAModelElement> inst {createInstance()}; + ret = model->addModelElement(std::move(inst)); + } + + return ret; +} + +void +RBAModelElementMaker::addMaker(const std::string& typeName, std::unique_ptr<RBAModelElementMaker> maker) +{ + makerMap_[typeName] = std::move(maker); +} + +RBAModelElementMaker* +RBAModelElementMaker::getMaker(const std::string& typeName) +{ + if (makerMap_.find(typeName) == makerMap_.end()) { + return nullptr; + } + return makerMap_[typeName].get(); +} + +} diff --git a/src/core/model/RBAModelElementMaker.hpp b/src/core/model/RBAModelElementMaker.hpp new file mode 100644 index 0000000..c038f5a --- /dev/null +++ b/src/core/model/RBAModelElementMaker.hpp @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAModelElementMaker.hpp +/// @brief ModelElement object genartor abstract class header + +#ifndef RBAMODELELEMENTMAKER_HPP +#define RBAMODELELEMENTMAKER_HPP + +#include <memory> +#include <string> +#include "RBADllExport.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +class RBAModelElement; +class RBAJsonElement; +class RBAModelImpl; + +/// @brief ModelElement object genartor abstract class +class DLL_EXPORT RBAModelElementMaker +{ +public: + /// @brief Constructor that specifies the label + /// @details Set label and generate + /// @param[in] label labe to set + RBAModelElementMaker()=default; + explicit RBAModelElementMaker(const std::string& label); + virtual ~RBAModelElementMaker()=default; + +protected: + RBAModelElementMaker(const RBAModelElementMaker& maker)=delete; + RBAModelElementMaker& operator=(const RBAModelElementMaker& maker)=delete; + // Use "move" in RBAAbstractModelTable::addMaker() + RBAModelElementMaker(RBAModelElementMaker&&)=default; + RBAModelElementMaker& operator=(RBAModelElementMaker&&)=default; + +public: + /// @brief Set model factory + /// @param[in] factory model factory + void setFactory(RBAModelFactory* const factory); + + /// @brief Get label + /// @details Returns the label of the corresponding JSON element + /// @return Label string + const std::string& getLabel() const; + + /// @brief Create ModelElement object + /// @details create ModelElement object and register unique_ptr to model + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The moder to store created object + /// @param[in,out] owner Parent object (Not in use) + /// @return ModelElement object + virtual RBAModelElement* create(const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr); + + /// @brief Get instance + /// @details Get the element corresponding to name from model. + /// If there is no name or it is not in model, + /// create an instance and register it in model. + /// @return ModelElement object + virtual RBAModelElement* getInstance(RBAModelImpl* model, + const std::string& name="", + RBAModelElement* owner=nullptr); + + /// @brief Register Maker + /// @details Register the Maker corresponding to the class name + /// used in JSON in the map + /// @return void + static void addMaker(const std::string& typeName, + std::unique_ptr<RBAModelElementMaker> maker); + + /// @brief Get Maker + /// @details Get the Maker corresponding to the class name from the map + /// @return Corresponding Maker. If it doesn't exist, return null. + static RBAModelElementMaker* getMaker(const std::string& typeName); + +protected: + /// @brief Create an empty instance + /// @details Create an empty instance of unique_ptr in derived class + /// @return unique_ptr for instance + virtual std::unique_ptr<RBAModelElement> createInstance(const std::string& name="")=0; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + virtual RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr)=0; + + /// @brief Get model factory + /// @details Get model factory + /// @return model factory + RBAModelFactory* getFactory() const; + +private: + /// @brief Factory for recursively generating objects + RBAModelFactory* factory_; + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + /// @brief Label of corresponding JSON element + const std::string label_; + + /// @brief Correspondence map of each Maker and the character string that + /// represents the class used in JSON + static std::unordered_map<std::string, std::unique_ptr<RBAModelElementMaker>> makerMap_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBAModelElementType.hpp b/src/core/model/RBAModelElementType.hpp new file mode 100644 index 0000000..756f22b --- /dev/null +++ b/src/core/model/RBAModelElementType.hpp @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * ModelElementType class header + */ + +#ifndef RBAMODELELEMENTTYPE_HPP +#define RBAMODELELEMENTTYPE_HPP + +namespace rba +{ + +enum class RBAModelElementType : std::uint8_t +{ + AllInstanceOfArea, + AllInstanceOfViewContent, + AllInstanceOfZone, + AllInstanceOfSoundContent, + Allocatable, + AllocatedContent, + AndOperator, + Area, + AreaSet, + ArithmeticOperator, + Constraint, + ViewContent, + ViewContentSet, + ViewContentState, + ContentValue, + DisplayingContent, + ExistsOperator, + ForAllOperator, + GetAllocatables, + ActiveState, + ActiveContents, + GetContentsList, + IfStatement, + IfActionOperator, + ImpliesOperator, + IntegerValue, + IsActive, + IsDisplayed, + IsEqualToOperator, + IsGreaterThanEqualOperator, + IsGreaterThanOperator, + IsHidden, + IsLowerThanEqualOperator, + IsLowerThanOperator, + IsVisible, + LambdaContext, + LambdaExpression, + LetStatement, + NotOperator, + ObjectCompare, + ObjectReference, + MemberFeatureReference, + OrOperator, + PlusOperator, + PreviousModifier, + RuleObject, + Scene, + Property, + SetExpression, + SetOfOperator, + SetOperator, + ValueExpression, + Variable, + IsOn, + Zone, + ZoneSet, + SoundContent, + SoundContentSet, + SoundContentState, + IsAttenuated, + IsOutputted, + IsMuted, + IsSounding, + Rule, + OnScene, + OffScene, + GetProperty, + SetProperty, + IntegerProperty, + OutputtingSound, + StateValue, + HasBeenCanceled, + HasBeenDisplayed, + HasComeEarlier, + HasComeLater, + EventProcessing, + MaxOperator, + MinOperator, + SelectOperator, + SizeOperator, + Undisplayed, + IsTypeOfOperator, + Displayed, + None +}; + +} + +#endif diff --git a/src/core/model/RBAModelImpl.cpp b/src/core/model/RBAModelImpl.cpp new file mode 100644 index 0000000..081607c --- /dev/null +++ b/src/core/model/RBAModelImpl.cpp @@ -0,0 +1,823 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAModelmpl.cpp +/// @brief Model implementation class + +#include "RBAModelImpl.hpp" +#include "RBAConstraintImpl.hpp" + +namespace rba +{ + +const RBAContentState* +RBAModelImpl::findContentState(const std::string& stateName) +{ + const auto elem = findModelElementImpl(stateName); + auto contentState = dynamic_cast<const RBAContentState*>(elem); + if (contentState == nullptr) { + const auto content = dynamic_cast<const RBAContent*>(elem); + if (content != nullptr) { + contentState = content->getStates().front(); + } + } + return contentState; +} + +const RBAArea* +RBAModelImpl::findArea(const std::string& areaName) const +{ + return findAreaImpl(areaName); +} + +const RBAViewContent* +RBAModelImpl::findViewContent(const std::string& contName) const +{ + return findViewContentImpl(contName); +} + +const RBAViewContentState* +RBAModelImpl::findViewContentState(const std::string& stateName) const +{ + return findViewContentStateImpl(stateName); +} + +const RBASize* +RBAModelImpl::findSize(const std::string& sizeName) const +{ + return findSizeImpl(sizeName); +} + +const RBAZone* +RBAModelImpl::findZone(const std::string& zoneName) const +{ + return findZoneImpl(zoneName); +} + +const RBASoundContent* +RBAModelImpl::findSoundContent(const std::string& contName) const +{ + return findSoundContentImpl(contName); +} + +const RBASoundContentState* +RBAModelImpl::findSoundContentState(const std::string& stateName) const +{ + return findSoundContentStateImpl(stateName); +} + +const RBAScene* +RBAModelImpl::findScene(const std::string& sceneName) const +{ + return findSceneImpl(sceneName); +} + +const RBADisplay* +RBAModelImpl::findDisplay(const std::string& displayName) const +{ + return findDisplayImpl(displayName); +} + +const RBAModelElement* +RBAModelImpl::findModelElement(const std::string& elementName) const +{ + return findModelElementImpl(elementName); +} + +const std::list<const RBAArea*>& +RBAModelImpl::getAreas() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAArea is the base class of RBAAreaImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAArea*>&>(getAreaImpls()); +} + +const std::list<const RBAViewContent*>& +RBAModelImpl::getViewContents() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAViewContent is the base class of + // RBAViewContentImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAViewContent*>&>(getViewContentImpls()); +} + +const std::list<const RBAViewContentState*>& +RBAModelImpl::getViewContentStates() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAViewContentState is the base class of + // RBAViewContentStateImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAViewContentState*>&>(getViewContentStateImpls()); +} + +const std::list<const RBASize*>& +RBAModelImpl::getSizes() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBASize is the base class of RBASizeImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBASize*>&>(getSizeImpls()); +} + +const std::list<const RBAZone*>& +RBAModelImpl::getZones() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAZone is the base class of RBAZoneImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAZone*>&>(getZoneImpls()); +} + +const std::list<const RBASoundContent*>& +RBAModelImpl::getSoundContents() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBASoundContent is the base class of + // RBASoundContentImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBASoundContent*>&>(getSoundContentImpls()); +} + +const std::list<const RBASoundContentState*>& +RBAModelImpl::getSoundContentStates() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBASoundContentState is the base class of + // RBASoundContentStateImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBASoundContentState*>&>(getSoundContentStateImpls()); +} + +const std::list<const RBAScene*>& +RBAModelImpl::getScenes() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAScene is the base class of + // RBASceneImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAScene*>&>(getSceneImpls()); +} + +const std::list<const RBAAreaSet*>& +RBAModelImpl::getAreaSets() const +{ + return getAreaSetImpls(); +} + +const std::list<const RBAViewContentSet*>& +RBAModelImpl::getViewContentSets() const +{ + return getViewContentSetImpls(); +} + +const std::list<const RBAZoneSet*>& +RBAModelImpl::getZoneSets() const +{ + return getZoneSetImpls(); +} + +const std::list<const RBASoundContentSet*>& +RBAModelImpl::getSoundContentSets() const +{ + return getSoundContentSetImpls(); +} + +const std::list<const RBAPositionContainer*>& +RBAModelImpl::getPositionContainers() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAPositionContainer is the base class of + // RBAPositionContainerImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBAPositionContainer*>&>(getPositionContainerImpls()); +} + +const std::list<const RBADisplay*>& +RBAModelImpl::getDisplays() const +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBADisplay is the base class of RBADisplayImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<const std::list<const RBADisplay*>&>(getDisplayImpls()); +} + +std::list<RBAConstraint*>& +RBAModelImpl::getConstraints() +{ + // @Deviation (A5-2-4) + // [Contents that deviate from the rules] + // reinterpret_cast shall not be used. + // [Reason that there is no problem if the rule is deviated] + // There is no problem because RBAConstraint is the base class of + // RBAConstraintImpl. + // Since the conversion process is costly, it deviates because it hides + // the internal structure. + return reinterpret_cast<std::list<RBAConstraint*>&>(getConstraintImpls()); +} + +void RBAModelImpl::clearElementsStatus() +{ + for (auto& o : unnamedObjects_) { + o->clearStatus(); + } + for (auto& o : nameToObject_) { + o.second->clearStatus(); + } +} + +const RBAAllocatable* +RBAModelImpl::findAllocatable(const std::string& allocatableName) const +{ + auto it = nameToObject_.find(allocatableName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAAllocatable*>(it->second.get()); + } + + return nullptr; +} + +const RBAContent* +RBAModelImpl::findContent(const std::string& contentName) const +{ + auto it = nameToObject_.find(contentName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAContent*>(it->second.get()); + } + + return nullptr; +} + +const RBAAreaImpl* +RBAModelImpl::findAreaImpl(const std::string& areaName) const +{ + auto it = nameToObject_.find(areaName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAAreaImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBAViewContentImpl* +RBAModelImpl::findViewContentImpl(const std::string& contName) const +{ + auto it = nameToObject_.find(contName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAViewContentImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBAViewContentStateImpl* +RBAModelImpl::findViewContentStateImpl(const std::string& stateName) const +{ + const RBAViewContentStateImpl* ret {nullptr}; + if(RBAViewContentState::isUniqueName(stateName)) { + auto it = nameToObject_.find(stateName); + if(it != nameToObject_.end()) { + ret = dynamic_cast<const RBAViewContentStateImpl*>(it->second.get()); + } + } + else { + const RBAViewContentImpl* const content {findViewContentImpl(stateName)}; + if(content != nullptr) { + const RBAContentState* const state {content->getStates().front()}; + ret = dynamic_cast<const RBAViewContentStateImpl*>(state); + } + } + + return ret; +} + +const RBASizeImpl* +RBAModelImpl::findSizeImpl(const std::string& sizeName) const +{ + auto it = nameToObject_.find(sizeName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBASizeImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBAZoneImpl* +RBAModelImpl::findZoneImpl(const std::string& zoneName) const +{ + auto it = nameToObject_.find(zoneName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAZoneImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBASoundContentImpl* +RBAModelImpl::findSoundContentImpl(const std::string& contName) const +{ + auto it = nameToObject_.find(contName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBASoundContentImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBASoundContentStateImpl* +RBAModelImpl::findSoundContentStateImpl(const std::string& stateName) const +{ + const RBASoundContentStateImpl* ret {nullptr}; + if(RBASoundContentState::isUniqueName(stateName)) { + auto it = nameToObject_.find(stateName); + if(it != nameToObject_.end()) { + ret = dynamic_cast<const RBASoundContentStateImpl*>(it->second.get()); + } + } + else { + const RBASoundContentImpl* const content {findSoundContentImpl(stateName)}; + if(content != nullptr) { + const RBAContentState* const state {content->getStates().front()}; + ret = dynamic_cast<const RBASoundContentStateImpl*>(state); + } + } + + return ret; +} + +const RBASceneImpl* +RBAModelImpl::findSceneImpl(const std::string& sceneName) const +{ + auto it = nameToObject_.find(sceneName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBASceneImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBADisplayImpl* +RBAModelImpl::findDisplayImpl(const std::string& displayName) const +{ + auto it = nameToObject_.find(displayName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBADisplayImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBAModelElement* +RBAModelImpl::findModelElementImpl(const std::string& elementName) const +{ + auto it = nameToObject_.find(elementName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAModelElement*>(it->second.get()); + } + + return nullptr; +} + +const std::list<const RBAAllocatable*>& +RBAModelImpl::getAllocatables() const +{ + return allocatables_; +} + +const std::list<const RBAContent*>& +RBAModelImpl::getContents() const +{ + return contents_; +} + +const std::list<const RBAContentState*>& +RBAModelImpl::getContentStates() const +{ + return contentStates_; +} + +const std::list<const RBAAreaImpl*>& +RBAModelImpl::getAreaImpls() const +{ + return areas_; +} + +const std::list<const RBAViewContentImpl*>& +RBAModelImpl::getViewContentImpls() const +{ + return viewContents_; +} + +const std::list<const RBAViewContentStateImpl*>& +RBAModelImpl::getViewContentStateImpls() const +{ + return viewContentStates_; +} + +const std::list<const RBASizeImpl*>& +RBAModelImpl::getSizeImpls() const +{ + return sizes_; +} + +const std::list<const RBAZoneImpl*>& +RBAModelImpl::getZoneImpls() const +{ + return zones_; +} + +const std::list<const RBASoundContentImpl*>& +RBAModelImpl::getSoundContentImpls() const +{ + return soundContents_; +} + +const std::list<const RBASoundContentStateImpl*>& +RBAModelImpl::getSoundContentStateImpls() const +{ + return soundContentStates_; +} + +const std::list<const RBASceneImpl*>& +RBAModelImpl::getSceneImpls() const +{ + return scenes_; +} + +const std::list<const RBAPositionContainerImpl*>& +RBAModelImpl::getPositionContainerImpls() const +{ + return positionContainers_; +} + +const std::list<const RBADisplayImpl*>& +RBAModelImpl::getDisplayImpls() const +{ + return displays_; +} + +void +RBAModelImpl::createSortedAllocatables() +{ + if(!(sortedAllocatables_.empty())) { + sortedAllocatables_.clear(); + } + + for(auto& alloc : allocatables_) { + sortedAllocatables_.push_back(const_cast<RBAAllocatable*>(alloc)); + } + sortedAllocatables_.sort(&RBAAllocatable::compare); + + std::int32_t index{0}; + for(RBAAllocatable* const allocatable : sortedAllocatables_) { + allocatable->setIndex(index); + index++; + } +} + +std::list<RBAAllocatable*>& +RBAModelImpl::getSortedAllocatables() +{ + return sortedAllocatables_; +} + +RBAConstraintImpl* +RBAModelImpl::findConstraintImpl(const std::string& consName) const +{ + auto it = nameToObject_.find(consName); + if(it != nameToObject_.end()) { + return dynamic_cast<RBAConstraintImpl*>(it->second.get()); + } + + return nullptr; +} + +const RBAAreaSet* +RBAModelImpl::findAreaSetImpl(const std::string& areaSetName) const +{ + auto it = nameToObject_.find(areaSetName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAAreaSet*>(it->second.get()); + } + + return nullptr; +} + +const RBAZoneSet* +RBAModelImpl::findZoneSetImpl(const std::string& zoneSetName) const +{ + auto it = nameToObject_.find(zoneSetName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAZoneSet*>(it->second.get()); + } + + return nullptr; +} + +const RBAViewContentSet* +RBAModelImpl::findViewContentSetImpl(const std::string& contSetName) const +{ + auto it = nameToObject_.find(contSetName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBAViewContentSet*>(it->second.get()); + } + + return nullptr; +} + +const RBASoundContentSet* +RBAModelImpl::findSoundContentSetImpl(const std::string& contSetName) const +{ + auto it = nameToObject_.find(contSetName); + if(it != nameToObject_.end()) { + return dynamic_cast<const RBASoundContentSet*>(it->second.get()); + } + + return nullptr; +} + +const RBAPositionContainerImpl* +RBAModelImpl::findPositionContainerImpl(const std::string& areaName) const +{ + auto it = areaNameToPositionContainer_.find(areaName); + if(it != areaNameToPositionContainer_.end()) { + return dynamic_cast<const RBAPositionContainerImpl*>(it->second); + } + + return nullptr; +} + +/* + * get list functions + */ + +std::list<const RBAConstraintImpl*>& +RBAModelImpl::getConstraintImpls() +{ + return constraints_; +} + +const std::list<const RBAAreaSet*>& +RBAModelImpl::getAreaSetImpls() const +{ + return areaSets_; +} + +const std::list<const RBAZoneSet*>& +RBAModelImpl::getZoneSetImpls() const +{ + return zoneSets_; +} + +const std::list<const RBAViewContentSet*>& +RBAModelImpl::getViewContentSetImpls() const +{ + return viewContentSets_; +} + +const std::list<const RBASoundContentSet*>& +RBAModelImpl::getSoundContentSetImpls() const +{ + return soundContentSets_; +} + +RBAModelElement* +RBAModelImpl::addModelElement(std::unique_ptr<RBAModelElement> newElement) +{ + RBAModelElement* const element {newElement.get()}; + unnamedObjects_.push_back(std::move(newElement)); + return element; +} + +RBANamedElement* +RBAModelImpl::addNamedElement(std::unique_ptr<RBAModelElement> newElement) +{ + RBANamedElement* const element {dynamic_cast<RBANamedElement*>(newElement.get())}; + nameToObject_[element->getUniqueName()] = std::move(newElement); + return element; +} + +void +RBAModelImpl::addAllocatable(const RBAAllocatable* newAlloc) +{ + allocatables_.push_back(newAlloc); + if(newAlloc->isArea()) { + areas_.push_back(dynamic_cast<const RBAAreaImpl*>(newAlloc)); + } + else if (newAlloc->isZone()) { + zones_.push_back(dynamic_cast<const RBAZoneImpl*>(newAlloc)); + } else { + ; + } +} + +void +RBAModelImpl::addContent(const RBAContent* newContent) +{ + contents_.push_back(newContent); + if(newContent->isViewContent()) { + viewContents_.push_back(dynamic_cast<const RBAViewContentImpl*>(newContent)); + } + else if (newContent->isSoundContent()) { + soundContents_.push_back(dynamic_cast<const RBASoundContentImpl*>(newContent)); + } else { + ; + } +} + +void +RBAModelImpl::addContentState(const RBAContentState* newState) +{ + contentStates_.push_back(newState); + if(newState->isViewContentState()) { + viewContentStates_.push_back(dynamic_cast<const RBAViewContentStateImpl*>(newState)); + } + else { + soundContentStates_.push_back(dynamic_cast<const RBASoundContentStateImpl*>(newState)); + } +} + +void +RBAModelImpl::addAreaSet(const RBAAreaSet* newAreaSet) +{ + areaSets_.push_back(newAreaSet); +} + +void +RBAModelImpl::addZoneSet(const RBAZoneSet* newZoneSet) +{ + zoneSets_.push_back(newZoneSet); +} + +void +RBAModelImpl::addConstraint(const RBAConstraintImpl* newConstraint) +{ + constraints_.push_back(newConstraint); +} + +void +RBAModelImpl::addViewContentSet(const RBAViewContentSet* newContentSet) +{ + viewContentSets_.push_back(newContentSet); +} + +void +RBAModelImpl::addSoundContentSet(const RBASoundContentSet* newContentSet) +{ + soundContentSets_.push_back(newContentSet); +} + +void +RBAModelImpl::addScene(const RBASceneImpl* newScene) +{ + scenes_.push_back(newScene); +} + +RBASizeImpl* +RBAModelImpl::addSizeInstance(const std::string& ownerName, + std::unique_ptr<RBAModelElement> newSize) +{ + RBASizeImpl* sizeImpl {dynamic_cast<RBASizeImpl*>(newSize.get())}; + sizes_.push_back(sizeImpl); + nameToObject_[ownerName+std::string("/")+sizeImpl->getName()] + = std::move(newSize); + return sizeImpl; +} + +void +RBAModelImpl::addPositionContainer(const RBAPositionContainerImpl* newPositionContainer) +{ + positionContainers_.push_back(newPositionContainer); + areaNameToPositionContainer_[newPositionContainer->getArea()->getName()] + = newPositionContainer; +} + +void +RBAModelImpl::addDisplay(const RBADisplayImpl* newDisplay) +{ + displays_.push_back(newDisplay); +} + +void +RBAModelImpl::addLabeledElement(const std::string& label, + RBAModelElement* element) +{ + labelToElements_[label].push_back(element); +} + +void +RBAModelImpl::addLabeledConstraint(const std::string& label, + RBAAbstractConstraint* constraint) +{ + labelToConstraints_[label].push_back(constraint); +} + +const std::list<const RBAModelElement*> +RBAModelImpl::getLabeledElements(const std::string& label) const +{ + auto it = labelToElements_.find(label); + if(it != labelToElements_.end()) { + return it->second; + } + + const std::list<const RBAModelElement*> emp; + return emp; +} + +const std::list<RBAAbstractConstraint*> +RBAModelImpl::getLabeledConstraints(const std::string& label) const +{ + auto it = labelToConstraints_.find(label); + if(it != labelToConstraints_.end()) { + return it->second; + } + + const std::list<RBAAbstractConstraint*> emp; + return emp; +} + +const RBAModelElement* +RBAModelImpl::findLabeledElement(const std::string& label, + const std::string& name) const +{ + const std::list<const RBAModelElement*> elems {getLabeledElements(label)}; + for(const RBAModelElement* const elem : elems) { + if(dynamic_cast<const RBANamedElement*>(elem)->getElementName() == name) { + return elem; + } + } + + return nullptr; +} + +void +RBAModelImpl::addAffectedAllocsMap(const RBAModelElement* const owner, RBAAllocatable* const alloc) +{ + affectedAllocsMap_[owner].push_back(alloc); +} + +const std::list<RBAAllocatable*>* +RBAModelImpl::getAffectedAllocs(const RBAModelElement* const owner) +{ + auto itr = affectedAllocsMap_.find(owner); + if (itr != affectedAllocsMap_.end()) { + return &itr->second; + } + return nullptr; +} + +} diff --git a/src/core/model/RBAModelImpl.hpp b/src/core/model/RBAModelImpl.hpp new file mode 100644 index 0000000..5773506 --- /dev/null +++ b/src/core/model/RBAModelImpl.hpp @@ -0,0 +1,221 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBAModelImplhpp +/// @brief Model implementaion class header + +#ifndef RBAMODELIMPL_HPP +#define RBAMODELIMPL_HPP + +#include <memory> +#include <string> +#include <unordered_map> + +#include "RBAAreaImpl.hpp" +#include "RBAConstraintImpl.hpp" +#include "RBADisplayImpl.hpp" +#include "RBAExpression.hpp" +#include "RBAModel.hpp" +#include "RBAModelElement.hpp" +#include "RBAPositionContainerImpl.hpp" +#include "RBASceneImpl.hpp" +#include "RBASizeImpl.hpp" +#include "RBASoundContentImpl.hpp" +#include "RBASoundContentStateImpl.hpp" +#include "RBAVariable.hpp" +#include "RBAViewContentImpl.hpp" +#include "RBAViewContentStateImpl.hpp" +#include "RBAZoneImpl.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAModelImpl : public RBAModel +{ +public: + RBAModelImpl()=default; + RBAModelImpl(const RBAModelImpl&)=delete; + RBAModelImpl(const RBAModelImpl&&)=delete; + RBAModelImpl& operator=(const RBAModelImpl&)=delete; + RBAModelImpl& operator=(const RBAModelImpl&&)=delete; + virtual ~RBAModelImpl()=default; + +public: + const RBAArea* findArea(const std::string& areaName) const override; + const RBAViewContent* findViewContent(const std::string& contName) const override; + const RBAViewContentState* findViewContentState(const std::string& stateName) const override; + const RBASize* findSize(const std::string& sizeName) const override; + const RBAZone* findZone(const std::string& zoneName) const override; + const RBASoundContent* findSoundContent(const std::string& contName) const override; + const RBASoundContentState* findSoundContentState(const std::string& stateName) const override; + const RBAScene* findScene(const std::string& sceneName) const override; + const RBADisplay* findDisplay(const std::string& displayName) const override; + const RBAModelElement* findModelElement(const std::string& elementName) const override; + + const std::list<const RBAArea*>& getAreas() const override; + const std::list<const RBAViewContent*>& getViewContents() const override; + const std::list<const RBAViewContentState*>& getViewContentStates() const override; + const std::list<const RBASize*>& getSizes() const override; + const std::list<const RBAZone*>& getZones() const override; + const std::list<const RBASoundContent*>& getSoundContents() const override; + const std::list<const RBASoundContentState*>& getSoundContentStates() const override; + const std::list<const RBAScene*>& getScenes() const override; + const std::list<const RBAAreaSet*>& getAreaSets() const override; + const std::list<const RBAViewContentSet*>& getViewContentSets() const override; + virtual const std::list<const RBAZoneSet*>& getZoneSets() const; + virtual const std::list<const RBASoundContentSet*>& getSoundContentSets() const; + const std::list<const RBAPositionContainer*>& getPositionContainers() const override; + const std::list<const RBADisplay*>& getDisplays() const override; + std::list<RBAConstraint*>& getConstraints() override; + + virtual void clearElementsStatus(); + virtual const RBAContentState* findContentState(const std::string& stateName); + const RBAAllocatable* findAllocatable(const std::string& allocatableName) const; + const RBAContent* findContent(const std::string& contentName) const; + virtual const RBAAreaImpl* findAreaImpl(const std::string& areaName) const; + virtual const RBAViewContentImpl* findViewContentImpl(const std::string& contName) const; + virtual const RBAViewContentStateImpl* findViewContentStateImpl(const std::string& stateName) const; + virtual const RBASizeImpl* findSizeImpl(const std::string& sizeName) const; + virtual const RBAZoneImpl* findZoneImpl(const std::string& zoneName) const; + virtual const RBASoundContentImpl* findSoundContentImpl(const std::string& contName) const; + virtual const RBASoundContentStateImpl* findSoundContentStateImpl(const std::string& stateName) const; + virtual const RBASceneImpl* findSceneImpl(const std::string& sceneName) const; + virtual const RBADisplayImpl* findDisplayImpl(const std::string& displayName) const; + virtual const RBAModelElement* findModelElementImpl(const std::string& elementName) const; + + virtual const std::list<const RBAAllocatable*>& getAllocatables() const; + virtual const std::list<const RBAContent*>& getContents() const; + virtual const std::list<const RBAContentState*>& getContentStates() const; + + virtual const std::list<const RBAAreaImpl*>& getAreaImpls() const; + virtual const std::list<const RBAViewContentImpl*>& getViewContentImpls() const; + virtual const std::list<const RBAViewContentStateImpl*>& getViewContentStateImpls() const; + virtual const std::list<const RBASizeImpl*>& getSizeImpls() const; + virtual const std::list<const RBAZoneImpl*>& getZoneImpls() const; + virtual const std::list<const RBASoundContentImpl*>& getSoundContentImpls() const; + virtual const std::list<const RBASoundContentStateImpl*>& getSoundContentStateImpls() const; + virtual const std::list<const RBASceneImpl*>& getSceneImpls() const; + virtual const std::list<const RBAPositionContainerImpl*>& getPositionContainerImpls() const; + virtual const std::list<const RBADisplayImpl*>& getDisplayImpls() const; + + virtual void createSortedAllocatables(); + + virtual RBAConstraintImpl* findConstraintImpl(const std::string& consName) const; + virtual const RBAAreaSet* findAreaSetImpl(const std::string& areaSetName) const; + virtual const RBAZoneSet* findZoneSetImpl(const std::string& zoneSetName) const; + virtual const RBAViewContentSet* findViewContentSetImpl(const std::string& contSetName) const; + virtual const RBASoundContentSet* findSoundContentSetImpl(const std::string& contSetName) const; + virtual const RBAPositionContainerImpl* findPositionContainerImpl(const std::string& areaName) const; + + virtual std::list<const RBAConstraintImpl*>& getConstraintImpls(); + virtual const std::list<const RBAAreaSet*>& getAreaSetImpls() const; + virtual const std::list<const RBAZoneSet*>& getZoneSetImpls() const; + virtual const std::list<const RBAViewContentSet*>& getViewContentSetImpls() const; + virtual const std::list<const RBASoundContentSet*>& getSoundContentSetImpls() const; + // Do not set to const because the internal state is changed by arbitration + // processing + virtual std::list<RBAAllocatable*>& getSortedAllocatables(); + + virtual RBAModelElement* addModelElement(std::unique_ptr<RBAModelElement> newElement); + virtual RBANamedElement* addNamedElement(std::unique_ptr<RBAModelElement> newElement); + virtual RBASizeImpl* addSizeInstance(const std::string& ownerName, + std::unique_ptr<RBAModelElement> newSize); + + virtual void addAllocatable(const RBAAllocatable* newAlloc); + virtual void addContent(const RBAContent* newContent); + virtual void addContentState(const RBAContentState* newState); + virtual void addAreaSet(const RBAAreaSet* newAreaSet); + virtual void addZoneSet(const RBAZoneSet* newZoneSet); + virtual void addConstraint(const RBAConstraintImpl* newConstraint); + virtual void addViewContentSet(const RBAViewContentSet* newContentSet); + virtual void addSoundContentSet(const RBASoundContentSet* newContentSet); + virtual void addScene(const RBASceneImpl* newScene); + virtual void addPositionContainer(const RBAPositionContainerImpl* newPositionContainer); + virtual void addDisplay(const RBADisplayImpl* newDisplay); + /// Add element with label + virtual void addLabeledElement(const std::string& label, + RBAModelElement* element); + /// Add constraint expression with label + virtual void addLabeledConstraint(const std::string& label, + RBAAbstractConstraint* constraint); + + /// Add element list with label + virtual const std::list<const RBAModelElement*> getLabeledElements(const std::string& label) const; + /// Add constraint expression list with label + virtual const std::list<RBAAbstractConstraint*> getLabeledConstraints(const std::string& label) const; + /// Search element with label + virtual const RBAModelElement* findLabeledElement(const std::string& label, + const std::string& name) const; + + // Add to Allcatable map + void addAffectedAllocsMap(const RBAModelElement* const owner, RBAAllocatable* const alloc); + // Get affected Allocatable list + const std::list<RBAAllocatable*>* getAffectedAllocs(const RBAModelElement* const owner); + + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::list<const RBAAllocatable*> allocatables_; + std::list<const RBAContent*> contents_; + std::list<const RBAContentState*> contentStates_; + std::list<const RBAAreaImpl*> areas_; + std::list<const RBAViewContentImpl*> viewContents_; + std::list<const RBAViewContentStateImpl*> viewContentStates_; + std::list<const RBASizeImpl*> sizes_; + std::list<const RBAZoneImpl*> zones_; + std::list<const RBASoundContentImpl*> soundContents_; + std::list<const RBASoundContentStateImpl*> soundContentStates_; + std::list<const RBAConstraintImpl*> constraints_; + std::list<const RBAAreaSet*> areaSets_; + std::list<const RBAZoneSet*> zoneSets_; + std::list<const RBASceneImpl*> scenes_; + std::list<const RBAViewContentSet*> viewContentSets_; + std::list<const RBASoundContentSet*> soundContentSets_; + std::list<const RBAPositionContainerImpl*> positionContainers_; + std::list<const RBADisplayImpl*> displays_; + + // Do not set to const because the internal state is changed by arbitration + // processing + std::list<RBAAllocatable*> sortedAllocatables_; + + // For storing objects not managed by name + // expression, variable are applicable. + std::list<std::unique_ptr<RBAModelElement>> unnamedObjects_; + + // Managing RBARuleObject and RBASize + std::unordered_map<std::string, std::unique_ptr<RBAModelElement>> nameToObject_; + // Position container is managed by map paired with Area name + std::unordered_map<std::string, const RBAPositionContainerImpl*> areaNameToPositionContainer_; + + // Managing Labeled element model for extensions + std::unordered_map<std::string, std::list<const RBAModelElement*>> labelToElements_; + // Managing Labeled Constraint Expressions for extensions + std::unordered_map<std::string, std::list<RBAAbstractConstraint*>> labelToConstraints_; + + // Allocatable map + std::unordered_map<const RBAModelElement*, std::list<RBAAllocatable*>> affectedAllocsMap_; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBANamedElement.cpp b/src/core/model/RBANamedElement.cpp new file mode 100644 index 0000000..9bfd1c0 --- /dev/null +++ b/src/core/model/RBANamedElement.cpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * NamedElement clsass + */ + +#include "RBANamedElement.hpp" + +namespace rba +{ + +RBANamedElement::RBANamedElement(const std::string& newName) + : RBAModelElement(), + name_(newName) +{ +} + +std::string +RBANamedElement::getUniqueName() const +{ + return getElementName(); +} + +const std::string& +RBANamedElement::getElementName() const +{ + return name_; +} + +const std::string& +RBANamedElement::getDynamicName() const +{ + return dynamic_name_; +} + +void +RBANamedElement::setDynamicName(const std::string& newName) +{ + dynamic_name_ = newName; +} +} diff --git a/src/core/model/RBANamedElement.hpp b/src/core/model/RBANamedElement.hpp new file mode 100644 index 0000000..81db36d --- /dev/null +++ b/src/core/model/RBANamedElement.hpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * NamedElement clsass header + */ + +#ifndef RBANAMEDELEMENT_HPP +#define RBANAMEDELEMENT_HPP + +#include <string> +#include "RBAModelElement.hpp" + +namespace rba +{ + +class DLL_EXPORT RBANamedElement : public RBAModelElement +{ +protected: + explicit RBANamedElement(const std::string& newName = ""); + RBANamedElement(const RBANamedElement&)=delete; + RBANamedElement(const RBANamedElement&&)=delete; + RBANamedElement& operator=(const RBANamedElement&)=delete; + RBANamedElement& operator=(const RBANamedElement&&)=delete; + +public: + virtual ~RBANamedElement()=default; + virtual std::string getUniqueName() const; + const std::string& getElementName() const; + const std::string& getDynamicName() const; + void setDynamicName(const std::string& newName); + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + const std::string name_; + std::string dynamic_name_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBARuleObject.cpp b/src/core/model/RBARuleObject.cpp new file mode 100644 index 0000000..62aa1a5 --- /dev/null +++ b/src/core/model/RBARuleObject.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * RuleObject class + */ + +#include <string> +#include <unordered_map> +#include "RBARuleObject.hpp" + +namespace rba +{ + +RBARuleObject::RBARuleObject(const std::string& name) + : RBANamedElement{name} +{ +} + +bool +RBARuleObject::isPrevious() const +{ + return false; +} + +const RBARuleObject* +RBARuleObject::getRawObject() const +{ + return this; +} + +void RBARuleObject::addTag(const std::string& tag) +{ + static_cast<void>(tags_.insert(tag)); +} + +bool RBARuleObject::containsTag(const std::string& tag) const +{ + return (tags_.find(tag) != tags_.end()); +} + +void RBARuleObject::addMember(RBARuleObject* member) +{ + members_[member->getElementName()] = member; +} + +const RBARuleObject* RBARuleObject::getMember(const std::string& memberName) const +{ + if (members_.find(memberName) != members_.end()) { + return (members_.at(memberName)); + } else { + return nullptr; + } +} + +void RBARuleObject::addMember(const std::string& memberName, RBARuleObject* const val) +{ + members_[memberName] = val; +} + +RBARuleObject* +RBARuleObject::getOwner() const +{ + return owner_; +} + +void +RBARuleObject::setOwner(RBARuleObject* owner) +{ + owner_ = owner; +} + +std::string +RBARuleObject::getUniqueName() const +{ + if (owner_ != nullptr) { + // @Deviation (MEM05-CPP,Rule-7_5_4,A7-5-2) + // [Contents that deviate from the rules] + // Calling getUniqueName() recursively. + // [Reason that there is no problem if the rule is deviated] + // Since the number of elements in the rule model is finite and + // there is no cyclic relationship, stack overflow does not occur. + return owner_->getUniqueName() + "/" + getElementName(); + } + return getElementName(); +} + +const std::unordered_map<std::string, RBARuleObject*>& RBARuleObject::getMembers() const +{ + return members_; +} + +} diff --git a/src/core/model/RBARuleObject.hpp b/src/core/model/RBARuleObject.hpp new file mode 100644 index 0000000..3f03ddc --- /dev/null +++ b/src/core/model/RBARuleObject.hpp @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * RuleObject class header + */ + +#ifndef RBARULEOBJECT_HPP +#define RBARULEOBJECT_HPP + +#include <unordered_map> +#include <unordered_set> +#include <string> + +#include "RBANamedElement.hpp" + +namespace rba +{ + +class DLL_EXPORT RBARuleObject : public RBANamedElement +{ +protected: + explicit RBARuleObject(const std::string& name=""); + RBARuleObject(const RBARuleObject&)=delete; + RBARuleObject(const RBARuleObject&&)=delete; + RBARuleObject& operator=(const RBARuleObject&)=delete; + RBARuleObject& operator=(const RBARuleObject&&)=delete; + +public: + virtual ~RBARuleObject()=default; + virtual bool isPrevious() const; + virtual const RBARuleObject* getRawObject() const; + bool containsTag(const std::string& tag) const; + void addTag(const std::string& tag); + virtual void addMember(RBARuleObject* member); + virtual const RBARuleObject* getMember(const std::string& memberName) const; + RBARuleObject* getOwner() const; + virtual void setOwner(RBARuleObject* owner); + std::string getUniqueName() const override; + +protected: + void addMember(const std::string& memberName, RBARuleObject* const val); + const std::unordered_map<std::string, RBARuleObject*>& getMembers() const; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::unordered_set<std::string> tags_; + std::unordered_map<std::string, RBARuleObject*> members_; + RBARuleObject* owner_ {nullptr}; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; + +} + +#endif diff --git a/src/core/model/RBARuleObjectMaker.cpp b/src/core/model/RBARuleObjectMaker.cpp new file mode 100644 index 0000000..7b384e1 --- /dev/null +++ b/src/core/model/RBARuleObjectMaker.cpp @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBARuleObjectMaker.cpp +/// @brief RuleObject generator class + +#include "RBARuleObjectMaker.hpp" +#include "RBARuleObject.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAModelFactory.hpp" + +namespace rba +{ + +RBARuleObjectMaker::RBARuleObjectMaker(const std::string& label) + : RBAModelElementMaker{label} +{ +} + +RBAModelElement* +RBARuleObjectMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + const auto ruleObj = dynamic_cast<RBARuleObject*>(element); + + // Tag + const RBAJsonElement* const tags {jsonElem->findChildren("tags")}; + if (tags != nullptr) { + for (const auto& tag : tags->getChildren()) { + const RBAJsonElement* const tagName {tag->findChildren("name")}; + if (tagName != nullptr) { + ruleObj->addTag(tagName->getString()); + } + } + } + + // owner + const auto ownerRuleObj = dynamic_cast<RBARuleObject*>(owner); + if (ownerRuleObj != nullptr) { + ruleObj->setOwner(ownerRuleObj); + } + + return ruleObj; +} + +} diff --git a/src/core/model/RBARuleObjectMaker.hpp b/src/core/model/RBARuleObjectMaker.hpp new file mode 100644 index 0000000..661b0b7 --- /dev/null +++ b/src/core/model/RBARuleObjectMaker.hpp @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBARuleObjectMaker.cpp +/// @brief RuleObject generator class header + +#ifndef RBARULEOBJECTMAKER_HPP +#define RBARULEOBJECTMAKER_HPP + +#include "RBAModelElementMaker.hpp" + +namespace rba +{ + +/// @brief RuleObject generator class header +class DLL_EXPORT RBARuleObjectMaker : public RBAModelElementMaker +{ +public: + explicit RBARuleObjectMaker(const std::string& label=""); + RBARuleObjectMaker(const RBARuleObjectMaker&)=delete; + RBARuleObjectMaker(const RBARuleObjectMaker&&)=delete; + RBARuleObjectMaker& operator=(const RBARuleObjectMaker&)=delete; + RBARuleObjectMaker& operator=(const RBARuleObjectMaker&&)=delete; + virtual ~RBARuleObjectMaker()=default; + +protected: + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif diff --git a/src/core/model/RBASceneImpl.cpp b/src/core/model/RBASceneImpl.cpp new file mode 100644 index 0000000..82ecab2 --- /dev/null +++ b/src/core/model/RBASceneImpl.cpp @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * Scene implementation class + */ + +#include "RBASceneImpl.hpp" +#include "RBAModelElementType.hpp" +#include "RBAAbstractProperty.hpp" +#include "RBAIntegerProperty.hpp" + +namespace rba +{ + +RBASceneImpl::RBASceneImpl(const std::string& name) + : RBAScene(), + RBARuleObject{name} +{ +} + +std::string +RBASceneImpl::getName() const +{ + return RBARuleObject::getElementName(); +} + +RBAModelElementType +RBASceneImpl::getModelElementType() const +{ + return RBAModelElementType::Scene; +} + +bool +RBASceneImpl::isGlobal() const +{ + return global_; +} + +const std::list<std::string>& +RBASceneImpl::getPropertyNames() const +{ + return propertyNames_; +} + +std::int32_t +RBASceneImpl::getPropertyValue(const std::string& propertyName) const +{ + const RBAAbstractProperty* const prop {getProperty(propertyName)}; + if(prop == nullptr) { + // Returns "-1" if the property is not registered + return -1; + } + + // Returns default value + return prop->getValue(); +} + +const RBARuleObject* RBASceneImpl::getMember(const std::string& memberName) const +{ + return getProperty(memberName); +} + +const RBAAbstractProperty* +RBASceneImpl::getProperty(const std::string& propertyName) const +{ + auto p = nameToProperty_.find(propertyName); + if(p == nameToProperty_.end()) { + // Returns nullptr if the property is not registered + return nullptr; + } + + return p->second; +} + +void +RBASceneImpl::setGlobal(const bool newGlobal) +{ + global_ = newGlobal; +} + +const RBAAbstractProperty* +RBASceneImpl::addProperty(const std::string& newName, std::int32_t newValue) +{ + auto p = nameToProperty_.find(newName); + if(p != nameToProperty_.end()) { + // No operation if the property is registered + return p->second; + } + + // Registration + properties_.push_back(std::make_unique<RBAIntegerProperty>(this, + newName, + newValue)); + propertyNames_.push_back(newName); + nameToProperty_[newName] = properties_.back().get(); + + return properties_.back().get(); +} + +} diff --git a/src/core/model/RBASceneImpl.hpp b/src/core/model/RBASceneImpl.hpp new file mode 100644 index 0000000..dd1fe3a --- /dev/null +++ b/src/core/model/RBASceneImpl.hpp @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/** + * Scene implementation class header + */ + +#ifndef RBASCENEIMPL_HPP +#define RBASCENEIMPL_HPP + +#include <memory> +#include "RBAScene.hpp" +#include "RBARuleObject.hpp" + +namespace rba +{ + +class RBAAbstractProperty; + +class RBASceneImpl : public RBAScene, public RBARuleObject +{ +public: + explicit RBASceneImpl(const std::string& name=""); + RBASceneImpl(const RBASceneImpl&)=delete; + RBASceneImpl(const RBASceneImpl&&)=delete; + RBASceneImpl& operator=(const RBASceneImpl&)=delete; + RBASceneImpl& operator=(const RBASceneImpl&&)=delete; + virtual ~RBASceneImpl()=default; + +public: + std::string getName() const override; + RBAModelElementType getModelElementType() const override; + bool isGlobal() const override; + const std::list<std::string>& getPropertyNames() const override; + std::int32_t getPropertyValue(const std::string& propertyName) const override; + const RBARuleObject* getMember(const std::string& memberName) const override; + const RBAAbstractProperty* getProperty(const std::string& propertyName) const; + + void setGlobal(const bool newGlobal); + const RBAAbstractProperty* addProperty(const std::string& newName, + std::int32_t newValue); + +private: + bool global_ {false}; + // Used to get property name in RBAScene + std::list<std::string> propertyNames_; + std::list<std::unique_ptr<RBAAbstractProperty>> properties_; + std::unordered_map<std::string, RBAAbstractProperty*> nameToProperty_; +}; + +} + +#endif diff --git a/src/core/model/RBASceneMaker.cpp b/src/core/model/RBASceneMaker.cpp new file mode 100644 index 0000000..9c55f84 --- /dev/null +++ b/src/core/model/RBASceneMaker.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBASceneMaker.cpp +/// @brief Scene object generator class + +#include "RBASceneMaker.hpp" +#include "RBASceneImpl.hpp" +#include "RBAJsonElement.hpp" +#include "RBAModelElement.hpp" +#include "RBAModelImpl.hpp" +#include "RBAAbstractProperty.hpp" + +namespace rba +{ + +RBASceneMaker::RBASceneMaker() + : RBARuleObjectMaker{"scenes"} +{ +} + +std::unique_ptr<RBAModelElement> +RBASceneMaker::createInstance(const std::string& name) +{ + return std::make_unique<RBASceneImpl>(name); +} + +RBAModelElement* +RBASceneMaker::setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner) +{ + static_cast<void>(RBARuleObjectMaker::setProperty(element, jsonElem, model, owner)); + + RBASceneImpl* const scene {dynamic_cast<RBASceneImpl*>(element)}; + + // Set global + const std::string global {jsonElem->findChildren("global")->getString()}; + if(global == "true") { + scene->setGlobal(true); + } + else { + scene->setGlobal(false); + } + + // Set property + const RBAJsonElement* const properties {jsonElem->findChildren("property")}; + if(properties != nullptr) { + for(const auto& property : properties->getChildren()) { + const std::string propertyName {property->findChildren("name")->getString()}; + const std::int32_t value {property->findChildren("value")->getInt()}; + static_cast<void>(scene->addProperty(propertyName, value)); + } + } + + model->addScene(scene); + + return scene; +} + +} diff --git a/src/core/model/RBASceneMaker.hpp b/src/core/model/RBASceneMaker.hpp new file mode 100644 index 0000000..6d2ea5e --- /dev/null +++ b/src/core/model/RBASceneMaker.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2019 DENSO CORPORATION. + * + * 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. + */ +/// @file RBASceneMaker.hpp +/// @brief Scene object generator class header + +#ifndef RBASCENEMAKER_HPP +#define RBASCENEMAKER_HPP + +#include "RBARuleObjectMaker.hpp" + +namespace rba +{ + +/// @brief Scene object generator class +class RBASceneMaker : public RBARuleObjectMaker +{ +public: + RBASceneMaker(); + RBASceneMaker(const RBASceneMaker&)=delete; + RBASceneMaker(const RBASceneMaker&&)=delete; + RBASceneMaker& operator=(const RBASceneMaker&)=delete; + RBASceneMaker& operator=(const RBASceneMaker&&)=delete; + virtual ~RBASceneMaker()=default; + +protected: + /// @brief Create an empty instance + /// @details Create an empty instance of unique_ptr in derived class + /// @return unique_ptr for insitance + std::unique_ptr<RBAModelElement> createInstance(const std::string& name="") override; + + /// @brief Set model element attributes for each derived class + /// @param[in] jsonElem JSON element of ModelElement + /// @param[in] model The model to store generated RBARuleObjectMaker + /// @param[in,out] owner Parent object (Not in use) + RBAModelElement* setProperty(RBAModelElement* element, + const RBAJsonElement* jsonElem, + RBAModelImpl* model, + RBAModelElement* owner=nullptr) override; + +}; + +} + +#endif |