/////////////////////////////////////////////////////////////////////////////// // 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_AGGR_INSTANCE_H_ #define _DAI_AGGR_INSTANCE_H_ #include "daiAggr/daiAggr.h" #include "daiUntypedInstanceLogic.hpp" #include "TD_PackPush.h" //DOM-IGNORE-BEGIN namespace OdDAI { class DAI_EXPORT AggrInstance { public: virtual ~AggrInstance() {}; virtual IteratorPtr createIterator(Aggr& aggrHolder) = 0; virtual ConstIteratorPtr createConstIterator(const Aggr& aggrHolder) const = 0; virtual const OdRxValueType& type() const = 0; virtual void onBeforeRead() = 0; virtual void onAfterRead(bool readSucceeded) = 0; virtual void copyFrom(const AggrInstance* from) = 0; virtual bool compareTo(const AggrInstance* to) const= 0; virtual Aggr* cloneAndCreateAggrFrom(bool withItems = true) const = 0; virtual int getMemberCount() const = 0; virtual bool isMember(const OdRxValue& itemToCheck) const = 0; virtual AggrInstance* createEmpty() const = 0; virtual AggrInstance* defaultInstance() const = 0; virtual OrderedLogic* orderedLogic() = 0; virtual UnorderedLogic* unorderedLogic() = 0; virtual AggrType aggrType() const = 0; virtual const OdDAI::AggregationType* extractInternalAggrType() const = 0; virtual bool checkValuesUniqueness () const = 0; virtual int hasValue(int startIndex, const OdRxValue& itemToFound) const = 0; static AggrInstance* create(const AggrInstance* createFrom); static bool remove(AggrInstance*& instanceToRemove, bool resetToDefault = true); static bool resetToDefault(AggrInstance*& instanceToRemove, bool removeCurrent = true); static bool isDefault(const AggrInstance* aggrToTest); static bool isTheSameInstanceType(const AggrInstance* left, const AggrInstance* right); private: void freeItself() {// can not use smartptr(to avoid increase size of AggrInstance in Aggr). if (!isDefault(this)) { delete this; } } }; } namespace OdDAI { template class AggrInstanceDefaultBase : public AggrInstance , public OrderedLogic , public UnorderedLogic { public: IteratorPtr createIterator(Aggr& /*aggrHolder*/) override { return NULL; } ConstIteratorPtr createConstIterator(const Aggr& /*aggrHolder*/) const override { return NULL; } const OdRxValueType& type() const override { return OdRxValueType::Desc::value(); } AggrType aggrType() const override { return TWorkInstance::type_aggr; } void onBeforeRead() override {} void onAfterRead(bool /*readSucceeded*/) override {} void copyFrom(const AggrInstance*) override {} bool compareTo(const AggrInstance* to) const override { return to == this; } Aggr* cloneAndCreateAggrFrom(bool /*withItems*/) const override { return new typename TWorkInstance::container_type(); } OrderedLogic* orderedLogic() override { return this; } UnorderedLogic* unorderedLogic() override { return this; } protected: AggrInstanceDefaultBase() {} AggrInstanceDefaultBase(const AggrInstanceDefaultBase&) {} virtual ~AggrInstanceDefaultBase() {} AggrInstanceDefaultBase& operator=(const AggrInstanceDefaultBase&) { return *this; } OdRxValue getOdRxValueByIndex(int /*index*/) const override { return OdRxValue(); } void putOdRxValueByIndex(int /*index*/, const OdRxValue& /*element*/) override {} void insertOdRxValueByIndex(int /*index*/, const OdRxValue& /*element*/)override {} int getValueBoundByIndex(int /*index*/) override { return 0; } void createAggrInstanceByIndex(int /*index*/, Aggr*& /*newAggr*/) override {} ArrayLogic* arrayLogic() override { return nullptr; } ListLogic* listLogic() override { return nullptr; } bool AddOdRxValue(const OdRxValue& /*element*/) override { return false; } bool RemoveOdRxValue(const OdRxValue& /*anItem*/) override { return false; } int getMemberCount() const override { return 0; } int getLowerBound() const override { return 0; } int getUpperBound() const override { return 0; } bool isMember(const OdRxValue& /*itemToCheck*/) const override { return false; } bool checkValuesUniqueness () const override { return true; } int hasValue(int /*startIndex*/, const OdRxValue& /*itemToFound*/) const override { return -1; } const OdDAI::AggregationType* extractInternalAggrType() const override { return nullptr; } }; template class AggrInstanceDefault : public AggrInstanceDefaultBase { public: static AggrInstance& instance() { static AggrInstanceDefault aggr_instance; return aggr_instance; } AggrInstance* createEmpty() const override { return new TWorkInstance(); } AggrInstance* defaultInstance() const override { return &instance(); } protected: AggrInstanceDefault() {} AggrInstanceDefault(const AggrInstanceDefault&) {} virtual ~AggrInstanceDefault() {} }; template class TypedAggrInstanceDefault : public AggrInstanceDefaultBase { public: TypedAggrInstanceDefault() {} virtual ~TypedAggrInstanceDefault() {} AggrInstance* defaultInstance() const override { return this; } AggrInstance* createEmpty() const override { auto newInstance = new TWorkInstance(this); return newInstance; } }; } // namespace //DOM-IGNORE-END #include "TD_PackPop.h" #endif // _DAI_AGGR_INSTANCE_H_