0028832: MMgt_TShared can be replaced by Standard_Transient
[occt.git] / src / Interface / Interface_GeneralModule.hxx
1 // Created on: 1993-02-02
2 // Created by: Christian CAILLET
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Interface_GeneralModule_HeaderFile
18 #define _Interface_GeneralModule_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Transient.hxx>
24 #include <Standard_Integer.hxx>
25 #include <Standard_Boolean.hxx>
26 class Interface_InterfaceModel;
27 class Standard_Transient;
28 class Interface_EntityIterator;
29 class Interface_ShareTool;
30 class Interface_Check;
31 class Interface_CopyTool;
32 class TCollection_HAsciiString;
33
34
35 class Interface_GeneralModule;
36 DEFINE_STANDARD_HANDLE(Interface_GeneralModule, Standard_Transient)
37
38 //! This class defines general services, which must be provided
39 //! for each type of Entity (i.e. of Transient Object processed
40 //! by an Interface) : Shared List, Check, Copy, Delete, Category
41 //!
42 //! To optimise processing (e.g. firstly bind an Entity to a Module
43 //! then calls  Module), each recognized Entity Type corresponds
44 //! to a Case Number, determined by the Protocol each class of
45 //! GeneralModule belongs to.
46 class Interface_GeneralModule : public Standard_Transient
47 {
48
49 public:
50
51   
52   //! Specific filling of the list of Entities shared by an Entity
53   //! <ent>, according a Case Number <CN> (formerly computed by
54   //! CaseNum), considered in the context of a Model <model>
55   //! Default calls FillSharedCase (i.e., ignores the model)
56   //! Can be redefined to use the model for working
57   Standard_EXPORT virtual void FillShared (const Handle(Interface_InterfaceModel)& model, const Standard_Integer CN, const Handle(Standard_Transient)& ent, Interface_EntityIterator& iter) const;
58   
59   //! Specific filling of the list of Entities shared by an Entity
60   //! <ent>, according a Case Number <CN> (formerly computed by
61   //! CaseNum). Can use the internal utility method Share, below
62   Standard_EXPORT virtual void FillSharedCase (const Standard_Integer CN, const Handle(Standard_Transient)& ent, Interface_EntityIterator& iter) const = 0;
63   
64   //! Adds an Entity to a Shared List (uses GetOneItem on <iter>)
65   Standard_EXPORT void Share (Interface_EntityIterator& iter, const Handle(Standard_Transient)& shared) const;
66   
67   //! List the Implied References of <ent> considered in the context
68   //! of a Model <model> : i.e. the Entities which are Referenced
69   //! while not considered as Shared (not copied if <ent> is,
70   //! references not renewed by CopyCase but by ImpliedCase, only
71   //! if referenced Entities have been Copied too)
72   //! FillShared + ListImplied give the complete list of References
73   //! Default calls ListImpliedCase (i.e. ignores the model)
74   //! Can be redefined to use the model for working
75   Standard_EXPORT virtual void ListImplied (const Handle(Interface_InterfaceModel)& model, const Standard_Integer CN, const Handle(Standard_Transient)& ent, Interface_EntityIterator& iter) const;
76   
77   //! List the Implied References of <ent> (see above)
78   //! are Referenced while not considered as Shared (not copied if
79   //! <ent> is, references not renewed by CopyCase but by
80   //! ImpliedCase, only if referenced Entities have been Copied too)
81   //! FillSharedCase + ListImpliedCase give the complete list of
82   //! Referenced Entities
83   //! The provided default method does nothing (Implied References
84   //! are specific of a little amount of Entity Classes).
85   Standard_EXPORT virtual void ListImpliedCase (const Standard_Integer CN, const Handle(Standard_Transient)& ent, Interface_EntityIterator& iter) const;
86   
87   //! Specific Checking of an Entity <ent>
88   //! Can check context queried through a ShareTool, as required
89   Standard_EXPORT virtual void CheckCase (const Standard_Integer CN, const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares, Handle(Interface_Check)& ach) const = 0;
90   
91   //! Specific answer to the question "is Copy properly implemented"
92   //! Remark that it should be in phase with the implementation of
93   //! NewVoid+CopyCase/NewCopyCase
94   //! Default returns always False, can be redefined
95   Standard_EXPORT virtual Standard_Boolean CanCopy (const Standard_Integer CN, const Handle(Standard_Transient)& ent) const;
96   
97   //! Dispatches an entity
98   //! Returns True if it works by copy, False if it just duplicates
99   //! the starting Handle
100   //!
101   //! Dispatching means producing a new entity, image of the
102   //! starting one, in order to be put into a new Model, this Model
103   //! being itself the result of a dispatch from an original Model
104   //!
105   //! According to the cases, dispatch can either
106   //! * just return <entto> as equating <entfrom>
107   //! -> the new model designates the starting entity : it is
108   //! lighter, but the dispatched entity being shared might not be
109   //! modified for dispatch
110   //! * copy <entfrom> to <entto>
111   //! by calling NewVoid+CopyCase (two steps) or NewCopiedCase (1)
112   //! -> the dispatched entity is a COPY, hence it can be modified
113   //!
114   //! The provided default just duplicates the handle without
115   //! copying, then returns False. Can be redefined
116   Standard_EXPORT virtual Standard_Boolean Dispatch (const Standard_Integer CN, const Handle(Standard_Transient)& entfrom, Handle(Standard_Transient)& entto, Interface_CopyTool& TC) const;
117   
118   //! Creates a new void entity <entto> according to a Case Number
119   //! This entity remains to be filled, by reading from a file or
120   //! by copying from another entity of same type (see CopyCase)
121   Standard_EXPORT virtual Standard_Boolean NewVoid (const Standard_Integer CN, Handle(Standard_Transient)& entto) const = 0;
122   
123   //! Specific Copy ("Deep") from <entfrom> to <entto> (same type)
124   //! by using a CopyTool which provides its working Map.
125   //! Use method Transferred from CopyTool to work
126   Standard_EXPORT virtual void CopyCase (const Standard_Integer CN, const Handle(Standard_Transient)& entfrom, const Handle(Standard_Transient)& entto, Interface_CopyTool& TC) const = 0;
127   
128   //! Specific operator (create+copy) defaulted to do nothing.
129   //! It can be redefined : When it is not possible to work in two
130   //! steps (NewVoid then CopyCase). This can occur when there is
131   //! no default constructor : hence the result <entto> must be
132   //! created with an effective definition.
133   //! Remark : if NewCopiedCase is defined, CopyCase has nothing to do
134   //! Returns True if it has produced something, false else
135   Standard_EXPORT virtual Standard_Boolean NewCopiedCase (const Standard_Integer CN, const Handle(Standard_Transient)& entfrom, Handle(Standard_Transient)& entto, Interface_CopyTool& TC) const;
136   
137   //! Specific Copying of Implied References
138   //! A Default is provided which does nothing (must current case !)
139   //! Already copied references (by CopyFrom) must remain unchanged
140   //! Use method Search from CopyTool to work
141   Standard_EXPORT virtual void RenewImpliedCase (const Standard_Integer CN, const Handle(Standard_Transient)& entfrom, const Handle(Standard_Transient)& entto, const Interface_CopyTool& TC) const;
142   
143   //! Prepares an entity to be deleted. What does it mean :
144   //! Basically, any class of entity may define its own destructor
145   //! By default, it does nothing but calling destructors on fields
146   //! With the Memory Manager, it is useless to call destructor,
147   //! it is done automatically when the Handle is nullified(cleared)
148   //! BUT this is ineffective in looping structures (whatever these
149   //! are "Implied" references or not).
150   //!
151   //! THUS : if no loop may appear in definitions, a class which
152   //! inherits from TShared is correctly managed by automatic way
153   //! BUT if there can be loops (or simply back pointers), they must
154   //! be broken, for instance by clearing fields of one of the nodes
155   //! The default does nothing, to be redefined if a loop can occur
156   //! (Implied generally requires WhenDelete, but other cases can
157   //! occur)
158   //!
159   //! Warning : <dispatched> tells if the entity to be deleted has been
160   //! produced by Dispatch or not. Hence WhenDelete must be in
161   //! coherence with Dispatch
162   //! Dispatch can either copy or not.
163   //! If it copies the entity, this one should be deleted
164   //! If it doesnt (i.e. duplicates the handle) nothing to do
165   //!
166   //! If <dispatch> is False, normal deletion is to be performed
167   Standard_EXPORT virtual void WhenDeleteCase (const Standard_Integer CN, const Handle(Standard_Transient)& ent, const Standard_Boolean dispatched) const;
168   
169   //! Returns a category number which characterizes an entity
170   //! Category Numbers are managed by the class Category
171   //! <shares> can be used to evaluate this number in the context
172   //! Default returns 0 which means "unspecified"
173   Standard_EXPORT virtual Standard_Integer CategoryNumber (const Standard_Integer CN, const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares) const;
174   
175   //! Determines if an entity brings a Name (or widerly, if a Name
176   //! can be attached to it, through the ShareTool
177   //! By default, returns a Null Handle (no name can be produced)
178   //! Can be redefined
179   //!
180   //! Warning : While this string may be edited on the spot, if it is a read
181   //! field, the returned value must be copied before.
182   Standard_EXPORT virtual Handle(TCollection_HAsciiString) Name (const Standard_Integer CN, const Handle(Standard_Transient)& ent, const Interface_ShareTool& shares) const;
183
184
185
186
187   DEFINE_STANDARD_RTTIEXT(Interface_GeneralModule,Standard_Transient)
188
189 protected:
190
191
192
193
194 private:
195
196
197
198
199 };
200
201
202
203
204
205
206
207 #endif // _Interface_GeneralModule_HeaderFile