/////////////////////////////////////////////////////////////////////////////// // 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_COMMON_FILER_ERROR_PROCESSOR_H_ #define _DAI_COMMON_FILER_ERROR_PROCESSOR_H_ #include "OdaCommon.h" #include "daiFilerErrorProcessorPE.h" #include "TD_PackPush.h" /** \details Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format. */ namespace OdDAI { class Model; class Schema; class CommonFilerErrorProcessor; using SchemaPtr = OdSmartPtr; using CommonFilerErrorProcessorPtr = OdSmartPtr; /** \details A common default class that can be used or overrided for fix issues during read file error. */ class DAI_EXPORT CommonFilerErrorProcessor : public FilerErrorProcessorPE { public: /** \details Internal interface that is used to provide schema dependent error processor for read error handling. */ class IProcessorProvider { public: /** \details Virtual destructor. */ virtual ~IProcessorProvider() {} /** \details Checks provided schema and returns custom error processor for it. \param schema [in] Schema to check. returns Returns valid pointer FilerErrorProcessorPEPtr if schema check passed; otherwise it returns nullptr. */ virtual FilerErrorProcessorPEPtr check(const OdDAI::SchemaPtr& schema) = 0; }; /** \details A data type that represents a shared pointer to an object. */ using ProcessorProviderPtr = std::shared_ptr; public: ODRX_DECLARE_MEMBERS(CommonFilerErrorProcessor); /** \details Constructor. */ CommonFilerErrorProcessor(); /** \details Provides FilerErrorProcessorPEPtr for schema. Is used during the file reading. \param forSchema [in] Schema model. \returns a valid pointer to FilerErrorProcessorPEPtr for schema of currently reading model. */ static FilerErrorProcessorPEPtr instance(const OdDAI::Schema* forSchema); /** \details Register FilerErrorProcessorPEPtr for schema. \param forSchema [in] schema model. \param processorPtr[in] error processor which should be used during reading model. \returns previous registred error processor for the schema. */ static FilerErrorProcessorPEPtr registerCustomErrorProcessorForSchema(OdDAI::SchemaPtr, FilerErrorProcessorPEPtr processorPtr); /** \details Deletes FilerErrorProcessorPEPtr for schema. \param forSchema [in] schema model. \returns deleted registred error processor for schema. */ static FilerErrorProcessorPEPtr unregisterCustomProcessorForSchema(OdDAI::SchemaPtr); /** \details Registers custom error processor provider. \param provider [in] pointer to error processor provider. */ static void registerCustomProcessorProvider(ProcessorProviderPtr provider); /** \details Unregisters custom error processor provider. \param provider [in] Pointer to error processor provider. */ static void unregisterCustomProcessorProvider(ProcessorProviderPtr provider); /** \details This function should be called before the file reading. \param model [in] A model read to. */ void onStartReading(Model* model) override; /** \details This function should be called after the file reading. \param model [in] A model read to. \param executionResult [out] Receives the result code of the method execution. */ void onFinishReading(Model* model, OdResult executionResult) override; /** \details Handles unknown entity name state. \param entityTypeName [in] Abnormal entity name from read buffer. \param fixTool [in] Tools for fixing abnormal situation. \returns an enum HandleWorkOrder. */ HandleWorkOrder unknownTypeEntity(const char* entityTypeName, IWrongEntityFixTool& fixTool) override; /** \details Handles none instanctiable entity state. \param entityTypeName [in] None instantiable entity name from read buffer. \param fixTool [in] Tools for fixing this abnormal situation. \returns an enum HandleWorkOrder. */ HandleWorkOrder nonInstantiableEntity(const char* entityTypeName, IWrongEntityFixTool& fixTool) override; /** \details Provides a handler to process corrupted start parameters state. \param instanceToFill [in] Instance for what we can not read parameters. \param model [in] Model to get access to other created instances and schema objects. \param readOnlyFileBuffer [in] Read only buffer to try read manually or fix parameters reading. \returns an enum HandleWorkOrder. */ CorruptedParametersWorkOrder corruptedParametersCustomRead(OdDAI::ApplicationInstancePtr& instanceToFill, OdDAI::Model* model, IBufferDataProvider& readOnlyFileBuffer) override; /** \details Tries to process situation with duplicate instance. \param model [in] The filling model. \param handle [in] Not unique handle. \param alreadyAdded [in] The instance already added. \param instanceToAdd [in] The new instance with the same handle. \returns true if the file reading should be continued, and false otherwise. */ HandleWorkOrder duplicateHandle(OdDAI::Model* model, OdDbHandle& handle, OdDAI::ApplicationInstancePtr& alreadyAdded, OdDAI::ApplicationInstancePtr& instanceToAdd) override; /** \details Provides a handler to process syntax error state. \returns a handler to process error. If the function returns nullptr the handling does not run and exception occurs. */ HandleWorkOrder syntaxErrorAction(IBufferDataProvider& readOnlyFileBuffer) override; protected: HandleWorkOrder wrongTypeEntitySkipper(const char* entityTypeName, IWrongEntityFixTool& fixTool, const OdAnsiString& skipActionName); private: std::vector m_duplicateInstances; OdMutex m_duplicateInstancesMutex; std::map m_schemaToProcessorDictionary; std::set m_processorProviderCollection; }; } #include "TD_PackPop.h" #endif // _DAI_COMMON_FILER_ERROR_PROCESSOR_H_