Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:17:34

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _PCDM_ReaderFilter_HeaderFile
0015 #define _PCDM_ReaderFilter_HeaderFile
0016 
0017 #include <Standard_Transient.hxx>
0018 #include <TCollection_AsciiString.hxx>
0019 #include <NCollection_Map.hxx>
0020 #include <NCollection_DataMap.hxx>
0021 #include <NCollection_List.hxx>
0022 
0023 //! Class represents a document reading filter.
0024 //!
0025 //! It allows to set attributes (by class names) that must be skipped during the document reading
0026 //! or attributes that must be retrieved only.
0027 //! In addition it is possible to define one or several subtrees (by entry) which must be
0028 //! retrieved during the reading. Other labels are created, but no one attribute on them.
0029 class PCDM_ReaderFilter : public Standard_Transient
0030 {
0031 public:
0032   //! Supported modes of appending the file content into existing document
0033   enum AppendMode
0034   {
0035     AppendMode_Forbid    = 0, //!< do not allow append, default mode
0036     AppendMode_Protect   = 1, //!< keeps existing attributes, reads only new ones
0037     AppendMode_Overwrite = 2, //!< overwrites the existing attributes by the loaded ones
0038   };
0039 
0040   //! Creates an empty filter, so, all will be retrieved if nothing else is defined.
0041   inline PCDM_ReaderFilter()
0042       : myAppend(AppendMode_Forbid)
0043   {
0044   }
0045 
0046   //! Creates a filter to skip only one type of attributes.
0047   Standard_EXPORT PCDM_ReaderFilter(const occ::handle<Standard_Type>& theSkipped);
0048 
0049   //! Creates a filter to read only sub-labels of a label-path.
0050   //! Like, for "0:2" it will read all attributes for labels "0:2", "0:2:1", etc.
0051   Standard_EXPORT PCDM_ReaderFilter(const TCollection_AsciiString& theEntryToRead);
0052 
0053   //! Creates a filter to append the content of file to open to existing document.
0054   Standard_EXPORT PCDM_ReaderFilter(const AppendMode theAppend);
0055 
0056   //! Destructor for the filter content
0057   Standard_EXPORT ~PCDM_ReaderFilter() override;
0058 
0059   //! Adds skipped attribute by type.
0060   Standard_EXPORT void AddSkipped(const occ::handle<Standard_Type>& theSkipped)
0061   {
0062     mySkip.Add(theSkipped->Name());
0063   }
0064 
0065   //! Adds skipped attribute by type name.
0066   Standard_EXPORT void AddSkipped(const TCollection_AsciiString& theSkipped)
0067   {
0068     mySkip.Add(theSkipped);
0069   }
0070 
0071   //! Adds attribute to read by type. Disables the skipped attributes added.
0072   Standard_EXPORT void AddRead(const occ::handle<Standard_Type>& theRead)
0073   {
0074     myRead.Add(theRead->Name());
0075   }
0076 
0077   //! Adds attribute to read by type name. Disables the skipped attributes added.
0078   Standard_EXPORT void AddRead(const TCollection_AsciiString& theRead) { myRead.Add(theRead); }
0079 
0080   //! Adds sub-tree path (like "0:2").
0081   Standard_EXPORT void AddPath(const TCollection_AsciiString& theEntryToRead)
0082   {
0083     mySubTrees.Append(theEntryToRead);
0084   }
0085 
0086   //! Makes filter pass all data.
0087   Standard_EXPORT void Clear();
0088 
0089   //! Returns true if attribute must be read.
0090   Standard_EXPORT virtual bool IsPassed(const occ::handle<Standard_Type>& theAttributeID) const;
0091   //! Returns true if attribute must be read.
0092   Standard_EXPORT virtual bool IsPassedAttr(const TCollection_AsciiString& theAttributeType) const;
0093   //! Returns true if content of the label must be read.
0094   Standard_EXPORT virtual bool IsPassed(const TCollection_AsciiString& theEntry) const;
0095   //! Returns true if some sub-label of the given label is passed.
0096   Standard_EXPORT virtual bool IsSubPassed(const TCollection_AsciiString& theEntry) const;
0097   //! Returns true if only part of the document tree will be retrieved.
0098   Standard_EXPORT virtual bool IsPartTree();
0099 
0100   //! Returns the append mode.
0101   Standard_EXPORT AppendMode& Mode() { return myAppend; }
0102 
0103   //! Returns true if appending to the document is performed.
0104   Standard_EXPORT bool IsAppendMode() { return myAppend != PCDM_ReaderFilter::AppendMode_Forbid; }
0105 
0106   //! Starts the tree iterator. It is used for fast searching of passed labels if the whole tree of
0107   //! labels is parsed. So, on each iteration step the methods Up and Down must be called after the
0108   //! iteration start.
0109   Standard_EXPORT virtual void StartIteration();
0110   //! Iteration to the child label.
0111   Standard_EXPORT virtual void Up();
0112   //! Iteration to the child with defined tag.
0113   Standard_EXPORT virtual void Down(const int& theTag);
0114   //! Returns true if content of the currently iterated label must be read.
0115   Standard_EXPORT virtual bool IsPassed() const;
0116   //! Returns true if some sub-label of the currently iterated label is passed.
0117   Standard_EXPORT virtual bool IsSubPassed() const;
0118 
0119   DEFINE_STANDARD_RTTIEXT(PCDM_ReaderFilter, Standard_Transient)
0120 
0121 private:
0122   //! Clears the iteration tree
0123   Standard_EXPORT void ClearTree();
0124   //! Clears the iteration sub-tree
0125   Standard_EXPORT static void ClearSubTree(void* const theMap);
0126 
0127 protected:
0128   //! Append mode for reading files into existing document
0129   AppendMode myAppend;
0130   //! Class names of attributes that must be skipped during the read
0131   NCollection_Map<TCollection_AsciiString> mySkip;
0132   //! Class names of only attributes to read (if it is not empty, mySkip is unused)
0133   NCollection_Map<TCollection_AsciiString> myRead;
0134   //! Paths to the labels that must be read. If it is empty, read all.
0135   NCollection_List<TCollection_AsciiString> mySubTrees;
0136 
0137   //! Map from tag of a label to sub-tree of this tag. Used for fast browsing the tree
0138   //! and compare with entities that must be read.
0139   typedef NCollection_DataMap<int, void*> TagTree;
0140   //! Whole tree that correspond to retrieved document.
0141   TagTree myTree;
0142   //! Pointer to the current node of the iterator.
0143   TagTree* myCurrent;
0144   //! If a node does not described in the read-entries, the iterator goes inside of this subtree
0145   //! just by keeping the depth of iteration.
0146   int myCurrentDepth;
0147 };
0148 
0149 #endif // _PCDM_ReaderFilter_HeaderFile