|
||||
File indexing completed on 2025-01-18 10:04:37
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 PCDM_ReaderFilter; 0024 DEFINE_STANDARD_HANDLE (PCDM_ReaderFilter, Standard_Transient) 0025 0026 0027 //! Class represents a document reading filter. 0028 //! 0029 //! It allows to set attributes (by class names) that must be skipped during the document reading 0030 //! or attributes that must be retrieved only. 0031 //! In addition it is possible to define one or several subtrees (by entry) which must be 0032 //! retrieved during the reading. Other labels are created, but no one attribute on them. 0033 class PCDM_ReaderFilter : public Standard_Transient 0034 { 0035 public: 0036 0037 //! Supported modes of appending the file content into existing document 0038 enum AppendMode 0039 { 0040 AppendMode_Forbid = 0, //!< do not allow append, default mode 0041 AppendMode_Protect = 1, //!< keeps existing attributes, reads only new ones 0042 AppendMode_Overwrite = 2, //!< overwrites the existing attributes by the loaded ones 0043 }; 0044 0045 0046 //! Creates an empty filter, so, all will be retrieved if nothing else is defined. 0047 inline PCDM_ReaderFilter() : myAppend(AppendMode_Forbid) {} 0048 0049 //! Creates a filter to skip only one type of attributes. 0050 Standard_EXPORT PCDM_ReaderFilter (const Handle(Standard_Type)& theSkipped); 0051 0052 //! Creates a filter to read only sub-labels of a label-path. 0053 //! Like, for "0:2" it will read all attributes for labels "0:2", "0:2:1", etc. 0054 Standard_EXPORT PCDM_ReaderFilter (const TCollection_AsciiString& theEntryToRead); 0055 0056 //! Creates a filter to append the content of file to open to existing document. 0057 Standard_EXPORT PCDM_ReaderFilter (const AppendMode theAppend); 0058 0059 //! Destructor for the filter content 0060 Standard_EXPORT ~PCDM_ReaderFilter(); 0061 0062 //! Adds skipped attribute by type. 0063 Standard_EXPORT void AddSkipped (const Handle(Standard_Type)& theSkipped) { mySkip.Add(theSkipped->Name()); } 0064 //! Adds skipped attribute by type name. 0065 Standard_EXPORT void AddSkipped (const TCollection_AsciiString& theSkipped) { mySkip.Add (theSkipped); } 0066 0067 //! Adds attribute to read by type. Disables the skipped attributes added. 0068 Standard_EXPORT void AddRead (const Handle(Standard_Type)& theRead) { myRead.Add(theRead->Name()); } 0069 //! Adds attribute to read by type name. Disables the skipped attributes added. 0070 Standard_EXPORT void AddRead (const TCollection_AsciiString& theRead) { myRead.Add (theRead); } 0071 0072 //! Adds sub-tree path (like "0:2"). 0073 Standard_EXPORT void AddPath (const TCollection_AsciiString& theEntryToRead) { mySubTrees.Append (theEntryToRead); } 0074 0075 //! Makes filter pass all data. 0076 Standard_EXPORT void Clear(); 0077 0078 //! Returns true if attribute must be read. 0079 Standard_EXPORT virtual Standard_Boolean IsPassed (const Handle(Standard_Type)& theAttributeID) const; 0080 //! Returns true if attribute must be read. 0081 Standard_EXPORT virtual Standard_Boolean IsPassedAttr (const TCollection_AsciiString& theAttributeType) const; 0082 //! Returns true if content of the label must be read. 0083 Standard_EXPORT virtual Standard_Boolean IsPassed (const TCollection_AsciiString& theEntry) const; 0084 //! Returns true if some sub-label of the given label is passed. 0085 Standard_EXPORT virtual Standard_Boolean IsSubPassed (const TCollection_AsciiString& theEntry) const; 0086 //! Returns true if only part of the document tree will be retrieved. 0087 Standard_EXPORT virtual Standard_Boolean IsPartTree(); 0088 0089 //! Returns the append mode. 0090 Standard_EXPORT AppendMode& Mode() { return myAppend; } 0091 //! Returns true if appending to the document is performed. 0092 Standard_EXPORT Standard_Boolean IsAppendMode() { return myAppend != PCDM_ReaderFilter::AppendMode_Forbid; } 0093 0094 //! Starts the tree iterator. It is used for fast searching of passed labels if the whole tree of labels 0095 //! is parsed. So, on each iteration step the methods Up and Down must be called after the iteration start. 0096 Standard_EXPORT virtual void StartIteration(); 0097 //! Iteration to the child label. 0098 Standard_EXPORT virtual void Up(); 0099 //! Iteration to the child with defined tag. 0100 Standard_EXPORT virtual void Down (const int& theTag); 0101 //! Returns true if content of the currently iterated label must be read. 0102 Standard_EXPORT virtual Standard_Boolean IsPassed() const; 0103 //! Returns true if some sub-label of the currently iterated label is passed. 0104 Standard_EXPORT virtual Standard_Boolean IsSubPassed() const; 0105 0106 DEFINE_STANDARD_RTTIEXT (PCDM_ReaderFilter, Standard_Transient) 0107 0108 private: 0109 //! Clears the iteration tree 0110 Standard_EXPORT void ClearTree(); 0111 //! Clears the iteration sub-tree 0112 Standard_EXPORT static void ClearSubTree (const Standard_Address theMap); 0113 0114 protected: 0115 //! Append mode for reading files into existing document 0116 AppendMode myAppend; 0117 //! Class names of attributes that must be skipped during the read 0118 NCollection_Map<TCollection_AsciiString> mySkip; 0119 //! Class names of only attributes to read (if it is not empty, mySkip is unused) 0120 NCollection_Map<TCollection_AsciiString> myRead; 0121 //! Paths to the labels that must be read. If it is empty, read all. 0122 NCollection_List<TCollection_AsciiString> mySubTrees; 0123 0124 //! Map from tag of a label to sub-tree of this tag. Used for fast browsing the tree 0125 //! and compare with entities that must be read. 0126 typedef NCollection_DataMap<Standard_Integer, Standard_Address> TagTree; 0127 //! Whole tree that correspond to retrieved document. 0128 TagTree myTree; 0129 //! Pointer to the current node of the iterator. 0130 TagTree* myCurrent; 0131 //! If a node does not described in the read-entries, the iterator goes inside of this subtree just by 0132 //! keeping the depth of iteration. 0133 Standard_Integer myCurrentDepth; 0134 }; 0135 0136 #endif // _PCDM_ReaderFilter_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |