d5c71e20 |
1 | // Copyright (c) 2021 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _PCDM_ReaderFilter_HeaderFile |
15 | #define _PCDM_ReaderFilter_HeaderFile |
16 | |
17 | #include <Standard_Type.hxx> |
18 | #include <Standard_Transient.hxx> |
19 | #include <TCollection_AsciiString.hxx> |
20 | #include <NCollection_Map.hxx> |
21 | #include <NCollection_List.hxx> |
22 | |
23 | class PCDM_ReaderFilter; |
24 | DEFINE_STANDARD_HANDLE (PCDM_ReaderFilter, Standard_Transient) |
25 | |
26 | |
27 | //! Class represents a document reading filter. |
28 | //! |
29 | //! It allows to set attributes (by class names) that must be skipped during the document reading |
30 | //! or attributes that must be retrieved only. |
31 | //! In addition it is possible to define one or several subtrees (by entry) which must be |
32 | //! retrieved during the reading. Other labels are created, but no one attribute on them. |
33 | class PCDM_ReaderFilter : public Standard_Transient |
34 | { |
35 | public: |
36 | |
37 | //! Supported modes of appending the file content into existing document |
38 | enum AppendMode |
39 | { |
40 | AppendMode_Forbid = 0, //!< do not allow append, default mode |
41 | AppendMode_Protect = 1, //!< keeps existing attributes, reads only new ones |
42 | AppendMode_Overwrite = 2, //!< overwrites the existing attributes by the loaded ones |
43 | }; |
44 | |
45 | |
46 | //! Creates an empty filter, so, all will be retrieved if nothing else is defined. |
47 | inline PCDM_ReaderFilter() : myAppend(AppendMode_Forbid) {} |
48 | |
49 | //! Creates a filter to skip only one type of attributes. |
50 | Standard_EXPORT PCDM_ReaderFilter (const Handle(Standard_Type)& theSkipped); |
51 | |
52 | //! Creates a filter to read only sub-labels of a label-path. |
53 | //! Like, for "0:2" it will read all attributes for labels "0:2", "0:2:1", etc. |
54 | Standard_EXPORT PCDM_ReaderFilter (const TCollection_AsciiString& theEntryToRead); |
55 | |
56 | //! Creates a filter to append the content of file to open to existing document. |
57 | Standard_EXPORT PCDM_ReaderFilter (const AppendMode theAppend); |
58 | |
59 | //! Destructor for the filter content |
60 | Standard_EXPORT ~PCDM_ReaderFilter(); |
61 | |
62 | //! Adds skipped attribute by type. |
63 | Standard_EXPORT void AddSkipped (const Handle(Standard_Type)& theSkipped) { mySkip.Add(theSkipped->Name()); } |
64 | //! Adds skipped attribute by type name. |
65 | Standard_EXPORT void AddSkipped (const TCollection_AsciiString& theSkipped) { mySkip.Add (theSkipped); } |
66 | |
67 | //! Adds attribute to read by type. Disables the skipped attributes added. |
68 | Standard_EXPORT void AddRead (const Handle(Standard_Type)& theRead) { myRead.Add(theRead->Name()); } |
69 | //! Adds attribute to read by type name. Disables the skipped attributes added. |
70 | Standard_EXPORT void AddRead (const TCollection_AsciiString& theRead) { myRead.Add (theRead); } |
71 | |
72 | //! Adds sub-tree path (like "0:2"). |
73 | Standard_EXPORT void AddPath (const TCollection_AsciiString& theEntryToRead) { mySubTrees.Append (theEntryToRead); } |
74 | |
75 | //! Makes filter pass all data. |
76 | Standard_EXPORT void Clear(); |
77 | |
78 | //! Returns true if attribute must be read. |
79 | Standard_EXPORT virtual Standard_Boolean IsPassed (const Handle(Standard_Type)& theAttributeID) const; |
80 | //! Returns true if attribute must be read. |
81 | Standard_EXPORT virtual Standard_Boolean IsPassedAttr (const TCollection_AsciiString& theAttributeType) const; |
82 | //! Returns true if content of the label must be read. |
83 | Standard_EXPORT virtual Standard_Boolean IsPassed (const TCollection_AsciiString& theEntry) const; |
84 | //! Returns true if some sub-label of the given label is passed. |
85 | Standard_EXPORT virtual Standard_Boolean IsSubPassed (const TCollection_AsciiString& theEntry) const; |
86 | //! Returns true if only part of the document tree will be retrieved. |
87 | Standard_EXPORT virtual Standard_Boolean IsPartTree(); |
88 | |
89 | //! Returns the append mode. |
90 | Standard_EXPORT AppendMode& Mode() { return myAppend; } |
91 | //! Returns true if appending to the document is performed. |
92 | Standard_EXPORT Standard_Boolean IsAppendMode() { return myAppend != PCDM_ReaderFilter::AppendMode_Forbid; } |
93 | |
94 | //! Starts the tree iterator. It is used for fast searching of passed labels if the whole tree of labels |
95 | //! is parsed. So, on each iteration step the methods Up and Down must be called after the iteration start. |
96 | Standard_EXPORT virtual void StartIteration(); |
97 | //! Iteration to the child label. |
98 | Standard_EXPORT virtual void Up(); |
99 | //! Iteration to the child with defined tag. |
100 | Standard_EXPORT virtual void Down (const int& theTag); |
101 | //! Returns true if content of the currently iterated label must be read. |
102 | Standard_EXPORT virtual Standard_Boolean IsPassed() const; |
103 | //! Returns true if some sub-label of the currently iterated label is passed. |
104 | Standard_EXPORT virtual Standard_Boolean IsSubPassed() const; |
105 | |
106 | DEFINE_STANDARD_RTTIEXT (PCDM_ReaderFilter, Standard_Transient) |
107 | |
108 | private: |
109 | //! Clears the iteration tree |
110 | Standard_EXPORT void ClearTree(); |
111 | //! Clears the iteration sub-tree |
112 | Standard_EXPORT static void ClearSubTree (const Standard_Address theMap); |
113 | |
114 | protected: |
115 | //! Append mode for reading files into existing document |
116 | AppendMode myAppend; |
117 | //! Class names of attributes that must be skipped during the read |
118 | NCollection_Map<TCollection_AsciiString> mySkip; |
119 | //! Class names of only attributes to read (if it is not empty, mySkip is unused) |
120 | NCollection_Map<TCollection_AsciiString> myRead; |
121 | //! Paths to the labels that must be read. If it is empty, read all. |
122 | NCollection_List<TCollection_AsciiString> mySubTrees; |
123 | |
124 | //! Map from tag of a label to sub-tree of this tag. Used for fast browsing the tree |
125 | //! and compare with entities that must be read. |
126 | typedef NCollection_DataMap<Standard_Integer, Standard_Address> TagTree; |
127 | //! Whole tree that correspond to retrieved document. |
128 | TagTree myTree; |
129 | //! Pointer to the current node of the iterator. |
130 | TagTree* myCurrent; |
131 | //! If a node does not described in the read-entries, the iterator goes inside of this subtree just by |
132 | //! keeping the depth of iteration. |
133 | Standard_Integer myCurrentDepth; |
134 | }; |
135 | |
136 | #endif // _PCDM_ReaderFilter_HeaderFile |