/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _DAI_REDECLARED_ATTRIBUTE_H_ #define _DAI_REDECLARED_ATTRIBUTE_H_ #include "daiBuildOptions.h" #include "daiSpfFiler.h" #include "daiUtils/daiUnset.h" #include "daiAggr/daiAggr.h" #include "daiPrimitive.h" #include "daiSelect.h" #include "daiEnum.h" #include #include #include "TD_PackPush.h" //DOM-IGNORE-BEGIN // for internal using namespace OdDAI { class DAI_EXPORT RedeclaredAttribute { public: RedeclaredAttribute(); RedeclaredAttribute(const RedeclaredAttribute& t); RedeclaredAttribute(RedeclaredAttribute&& t) noexcept; template explicit RedeclaredAttribute(const T& t); ~RedeclaredAttribute(); RedeclaredAttribute& operator=(const RedeclaredAttribute& right); template TCasted& cast(); template const TCasted& cast() const; template TCasted* cast_ptr(); template const TCasted* cast_ptr() const; bool compare(const RedeclaredAttribute& right) const; OdRxValue getAttr() const; void inField(OdDAI::OdSpfFilerBase* rdFiler, bool needComma = true); void outField(OdDAI::OdSpfFilerBase* wrFiler, bool needComma = true); bool putAttr(const OdRxValue& val); bool testAttr() const; void unsetAttr(); private: struct redeclared_holder_base; template struct redeclared_holder; private: std::unique_ptr m_held; }; struct RedeclaredAttribute::redeclared_holder_base { virtual ~redeclared_holder_base() {}; virtual const std::type_info& type() const = 0; virtual std::unique_ptr clone() = 0; virtual bool compare(const redeclared_holder_base& right) const = 0; virtual OdRxValue getAttr() const = 0; virtual void inField(OdDAI::OdSpfFilerBase* rdFiler, bool needComma) = 0; virtual void outField(OdDAI::OdSpfFilerBase* wrFiler, bool needComma) = 0; virtual bool putAttr(const OdRxValue& val) = 0; virtual bool testAttr() const = 0; virtual void unsetAttr() = 0; }; namespace Utils { namespace redeclared { namespace get_attr { template class Aggr, class TItem> inline OdRxValue getImpl(Aggr& what) { return OdRxValue((Aggr*) & what); } template inline OdRxValue getImpl(T& what) { return OdRxValue(what); } template inline OdRxValue impl(T& what) { return getImpl(what); } template<> inline OdRxValue impl(OdDAI::Select& what) { return OdRxValue(&what); } } } namespace redeclared { namespace in_field { template inline void inFieldImpl(OdDAI::OdSpfFilerBase* rdFiler, T& what, bool needComma) { rdFiler->read(what, needComma); } template class TAggr, class TItem> inline void inFieldImpl(OdDAI::OdSpfFilerBase* rdFiler, TAggr& what, bool needComma) { rdFiler->read(what, needComma); } template inline void impl(OdDAI::OdSpfFilerBase* rdFiler, T& what, bool needComma) { inFieldImpl(rdFiler, what, needComma); } template<> inline void impl(OdDAI::OdSpfFilerBase* rdFiler, OdDAI::Boolean& what, bool needComma) { rdFiler->read(what, needComma); } template<> inline void impl(OdDAI::OdSpfFilerBase* rdFiler, OdDAI::Enum& what, bool needComma) { what.setTextValueCaseInsensitive(rdFiler->rdEnumerationToStr(needComma)); } } } namespace redeclared { namespace out_field { template class TAggr, class TItem> inline void implOut(OdDAI::OdSpfFilerBase* wrFiler, const TAggr& what, bool needComma) { wrFiler->wrAggr(what, needComma); } template inline void implOut(OdDAI::OdSpfFilerBase* wrFiler, const TItem& what, bool needComma) { if (needComma) { wrFiler->wrKeyword(","); } wrFiler->wrPrimitive(what); } template inline void impl(OdDAI::OdSpfFilerBase* wrFiler, const T& what, bool needComma) { implOut(wrFiler, what, needComma); } } } namespace redeclared { namespace put_attr { template inline bool impl(const OdRxValue& val, TType& putValue) { return val >> putValue; } template<> inline bool impl(const OdRxValue& val, OdDAI::Boolean& putValue) { bool transitValue = false; if ((val >> transitValue) == false) { return false; } putValue = transitValue; return true; } } } namespace redeclared { namespace test_attr { template class TAggr, class TItem> inline bool implTest(const TAggr& checkValue) { return checkValue.isNil(); } template inline bool implTest(const TItem& checkValue) { return Utils::isUnset(checkValue) == false; } template inline bool impl(const TType& checkValue) { return implTest(checkValue); } template<> inline bool impl(const OdDAI::Boolean& checkValue) { return checkValue != OdDAI::Boolean::Unset; } } } namespace redeclared { namespace unset_attr { template class TAggr, class TItem> inline void implUnset(TAggr& valueToUnset) { valueToUnset.nullify(); } template inline void implUnset(TType& valueToUnset) { valueToUnset = OdDAI::Utils::getUnset(); } template inline void impl(TType& valueToUnset) { implUnset(valueToUnset); } } } } template struct RedeclaredAttribute::redeclared_holder : public redeclared_holder_base { redeclared_holder(const T& t) : m_t(t) {} virtual const std::type_info& type() const { return typeid(m_t); } std::unique_ptr clone() override { return std::unique_ptr(new redeclared_holder(m_t)); } bool compare(const redeclared_holder_base& right) const override { auto casted_right = dynamic_cast*>(&right); return casted_right != nullptr && OdDAI::compare::isEqual(m_t, casted_right->m_t); } OdRxValue getAttr() const override { return Utils::redeclared::get_attr::impl(*const_cast(&m_t)); } void inField(OdDAI::OdSpfFilerBase* rdFiler, bool needComma) override { return Utils::redeclared::in_field::impl(rdFiler, m_t, needComma); } void outField(OdDAI::OdSpfFilerBase* wrFiler, bool needComma) override { Utils::redeclared::out_field::impl(wrFiler, m_t, needComma); } bool putAttr(const OdRxValue& val) override { return Utils::redeclared::put_attr::impl(val, m_t); } bool testAttr() const override { return Utils::redeclared::test_attr::impl(m_t); } void unsetAttr() override { Utils::redeclared::unset_attr::impl(m_t); // } T m_t; }; inline RedeclaredAttribute::RedeclaredAttribute() {} template inline RedeclaredAttribute::RedeclaredAttribute(const T& t) : m_held(new redeclared_holder(t)) {}; inline RedeclaredAttribute::~RedeclaredAttribute() { m_held = nullptr; } inline RedeclaredAttribute::RedeclaredAttribute(const RedeclaredAttribute& t) : m_held(nullptr) { m_held = t.m_held->clone(); } inline RedeclaredAttribute::RedeclaredAttribute(RedeclaredAttribute&& t) noexcept { m_held = std::move(t.m_held); } inline RedeclaredAttribute& RedeclaredAttribute::operator=(const RedeclaredAttribute& right) { if (&right == this) { return *this; } m_held = right.m_held->clone(); return *this; } template inline TCasted& RedeclaredAttribute::cast() { if (m_held->type() != typeid(TCasted)) { throw OdError(eNotApplicable); } return static_cast*>(m_held.get())->m_t; } template inline const TCasted& RedeclaredAttribute::cast() const { return const_cast(this)->cast(); } template inline TCasted* RedeclaredAttribute::cast_ptr() { if (m_held->type() != typeid(TCasted)) { return nullptr; } return &static_cast*>(m_held.get())->m_t; } template inline const TCasted* RedeclaredAttribute::cast_ptr() const { if (m_held->type() != typeid(TCasted)) { return nullptr; } return &static_cast*>(m_held.get())->m_t; } inline bool RedeclaredAttribute::compare(const RedeclaredAttribute& right) const { if (right.m_held == m_held) { return true; } return m_held->compare(*right.m_held); } inline OdRxValue RedeclaredAttribute::getAttr() const { return m_held->getAttr(); } inline void RedeclaredAttribute::inField(OdDAI::OdSpfFilerBase* rdFiler, bool needComma /*= true*/) { m_held->inField(rdFiler, needComma); } inline void RedeclaredAttribute::outField(OdDAI::OdSpfFilerBase* wrFiler, bool needComma /*= true*/) { m_held->outField(wrFiler, needComma); } inline bool RedeclaredAttribute::putAttr(const OdRxValue& val) { return m_held->putAttr(val); } inline bool RedeclaredAttribute::testAttr() const { return m_held->testAttr(); } inline void RedeclaredAttribute::unsetAttr() { m_held->unsetAttr(); } } //DOM-IGNORE-END #include "TD_PackPop.h" #endif // _DAI_VALIDATION_COMMON_H_