69706ffc40ad511dbbdae47270bf85682a714d5d
[occt.git] / src / Poly / Poly_CoherentTriPtr.hxx
1 // File:      Poly_CoherentTriPtr.hxx
2 // Created:   08.12.07 11:52
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2007
5
6
7 #ifndef Poly_CoherentTriPtr_HeaderFile
8 #define Poly_CoherentTriPtr_HeaderFile
9
10 #include <NCollection_BaseAllocator.hxx>
11
12 class Poly_CoherentTriangle;
13
14 #ifdef WNT
15 #pragma warning (push)
16 #pragma warning(disable:4355 4291) //'this' : used in base member initializer list
17 #endif
18
19 /**
20  * Implementation of both list node for Poly_CoherentTriangle type and
21  * round double-linked list of these nodes. 
22  */
23
24 class Poly_CoherentTriPtr
25 {
26  public:
27   /**
28    * Iterator class for this list of triangles. Because the list is round,
29    * an iteration can be started from any member and it finishes before taking
30    * this member again. The iteration sense is always forward (Next).
31    */  
32   class Iterator {
33   public:
34     //! Empty constructor
35     inline Iterator ()
36       : myFirst         (0L),
37         myCurrent       (0L)
38     {}
39     //! Constructor
40     inline Iterator (const Poly_CoherentTriPtr& thePtr)
41       : myFirst         (&thePtr),
42         myCurrent       (&thePtr)
43     {}
44     //! Query the triangle that started the current iteration.
45     inline const Poly_CoherentTriangle * First  () const
46     { return myFirst ? &myFirst->GetTriangle() : 0L; }
47     //! Query if there is available triangle pointer on this iteration
48     inline Standard_Boolean             More    () const
49     { return myCurrent != 0L; }
50     //! Go to the next iteration.
51     Standard_EXPORT void                Next    ();
52     //! Get the current iterated triangle
53     inline const Poly_CoherentTriangle& Value   () const
54     { return myCurrent->GetTriangle(); }
55     //! Get the current iterated triangle (mutable)
56     inline Poly_CoherentTriangle&       ChangeValue   () const
57     { return const_cast<Poly_CoherentTriangle&>(myCurrent->GetTriangle()); }
58     //! Get the current iterated pointer to triangle
59     inline const Poly_CoherentTriPtr&   PtrValue() const
60     { return * myCurrent; }
61   private:
62     const Poly_CoherentTriPtr * myFirst;
63     const Poly_CoherentTriPtr * myCurrent;
64   };
65
66   // ---------- PUBLIC METHODS ----------
67
68
69   /**
70    * Constructor.
71    */
72   inline Poly_CoherentTriPtr (const Poly_CoherentTriangle& theTri)
73     : mypTriangle (&theTri),
74       myNext      (this),
75       myPrevious  (this)
76   {}
77
78   /**
79    * Operator new for dynamic allocations
80    */
81   void* operator new    (Standard_Size theSize,
82                          const Handle(NCollection_BaseAllocator)& theAllocator)
83   {
84     return theAllocator->Allocate(theSize);
85   }
86
87   /**
88    * Query the stored pointer to Triangle.
89    */
90   inline const Poly_CoherentTriangle&
91                         GetTriangle () const
92   { return * mypTriangle; }
93
94   /**
95    * Initialize this instance with a pointer to triangle.
96    */
97   inline void          SetTriangle (const Poly_CoherentTriangle * pTri)
98   { mypTriangle = pTri; }
99   
100   /**
101    * Query the next pointer in the list.
102    */
103   inline Poly_CoherentTriPtr&
104                        Next     () const
105   { return * myNext; }
106
107   /**
108    * Query the previous pointer in the list.
109    */
110   inline Poly_CoherentTriPtr&
111                        Previous () const
112   { return * myPrevious; }
113
114   /**
115    * Append a pointer to triangle into the list after the current instance.
116    * @param pTri
117    *   Triangle that is to be included in the list after this one.
118    * @param theA
119    *   Allocator where the new pointer instance is created.
120    */
121   Standard_EXPORT void Append   (const Poly_CoherentTriangle *           pTri,
122                                  const Handle_NCollection_BaseAllocator& theA);
123
124   /**
125    * Prepend a pointer to triangle into the list before the current instance.
126    * @param pTri
127    *   Triangle that is to be included in the list before this one.
128    * @param theA
129    *   Allocator where the new pointer instance is created.
130    */
131   Standard_EXPORT void Prepend  (const Poly_CoherentTriangle *           pTri,
132                                  const Handle_NCollection_BaseAllocator& theA);
133
134   /**
135    * Remove a pointer to triangle from its list.
136    * @param thePtr
137    *   This class instance that should be removed from its list.
138    * @param theA
139    *   Allocator where the current pointer instance was created.
140    */
141   Standard_EXPORT static void
142                        Remove   (Poly_CoherentTriPtr *                   thePtr,
143                                  const Handle_NCollection_BaseAllocator& theA);
144
145   /**
146    * Remove the list containing the given pointer to triangle.
147    */
148   Standard_EXPORT static void
149                        RemoveList (Poly_CoherentTriPtr *                 thePtr,
150                                    const Handle_NCollection_BaseAllocator&);
151
152  protected:
153   // ---------- PROTECTED METHODS ----------
154
155   /**
156    * Constructor.
157    */
158   inline Poly_CoherentTriPtr (const Poly_CoherentTriangle * pTri)
159     : mypTriangle (pTri),
160       myNext      (this),
161       myPrevious  (this)
162   {}
163
164  private:
165   // ---------- PRIVATE FIELDS ----------
166
167   const Poly_CoherentTriangle * mypTriangle;
168   Poly_CoherentTriPtr         * myNext;
169   Poly_CoherentTriPtr         * myPrevious;
170
171   friend class Iterator;
172 };
173
174 #ifdef WNT
175 #pragma warning (pop)
176 #endif
177
178 #endif