summaryrefslogtreecommitdiff
path: root/inc/Poly_CoherentTriPtr.hxx
blob: d67b4eeb6f52968a92a6aced411beb16941ce54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// File:      Poly_CoherentTriPtr.hxx
// Created:   08.12.07 11:52
// Author:    Alexander GRIGORIEV
// Copyright: Open Cascade 2007


#ifndef Poly_CoherentTriPtr_HeaderFile
#define Poly_CoherentTriPtr_HeaderFile

#include <NCollection_BaseAllocator.hxx>

class Poly_CoherentTriangle;

#ifdef WNT
#pragma warning (push)
#pragma warning(disable:4355 4291) //'this' : used in base member initializer list
#endif

/**
 * Implementation of both list node for Poly_CoherentTriangle type and
 * round double-linked list of these nodes. 
 */

class Poly_CoherentTriPtr
{
 public:
  /**
   * Iterator class for this list of triangles. Because the list is round,
   * an iteration can be started from any member and it finishes before taking
   * this member again. The iteration sense is always forward (Next).
   */  
  class Iterator {
  public:
    //! Empty constructor
    inline Iterator ()
      : myFirst         (0L),
        myCurrent       (0L)
    {}
    //! Constructor
    inline Iterator (const Poly_CoherentTriPtr& thePtr)
      : myFirst         (&thePtr),
        myCurrent       (&thePtr)
    {}
    //! Query the triangle that started the current iteration.
    inline const Poly_CoherentTriangle * First  () const
    { return myFirst ? &myFirst->GetTriangle() : 0L; }
    //! Query if there is available triangle pointer on this iteration
    inline Standard_Boolean             More    () const
    { return myCurrent != 0L; }
    //! Go to the next iteration.
    Standard_EXPORT void                Next    ();
    //! Get the current iterated triangle
    inline const Poly_CoherentTriangle& Value   () const
    { return myCurrent->GetTriangle(); }
    //! Get the current iterated triangle (mutable)
    inline Poly_CoherentTriangle&       ChangeValue   () const
    { return const_cast<Poly_CoherentTriangle&>(myCurrent->GetTriangle()); }
    //! Get the current iterated pointer to triangle
    inline const Poly_CoherentTriPtr&   PtrValue() const
    { return * myCurrent; }
  private:
    const Poly_CoherentTriPtr * myFirst;
    const Poly_CoherentTriPtr * myCurrent;
  };

  // ---------- PUBLIC METHODS ----------


  /**
   * Constructor.
   */
  inline Poly_CoherentTriPtr (const Poly_CoherentTriangle& theTri)
    : mypTriangle (&theTri),
      myNext      (this),
      myPrevious  (this)
  {}

  /**
   * Operator new for dynamic allocations
   */
  void* operator new    (Standard_Size theSize,
                         const Handle(NCollection_BaseAllocator)& theAllocator)
  {
    return theAllocator->Allocate(theSize);
  }

  void operator delete (void * aBuffer, const Handle(NCollection_BaseAllocator)& theAllocator) 
  {
    theAllocator->Free(aBuffer);
  };

  /**
   * Query the stored pointer to Triangle.
   */
  inline const Poly_CoherentTriangle&
                        GetTriangle () const
  { return * mypTriangle; }

  /**
   * Initialize this instance with a pointer to triangle.
   */
  inline void          SetTriangle (const Poly_CoherentTriangle * pTri)
  { mypTriangle = pTri; }
  
  /**
   * Query the next pointer in the list.
   */
  inline Poly_CoherentTriPtr&
                       Next     () const
  { return * myNext; }

  /**
   * Query the previous pointer in the list.
   */
  inline Poly_CoherentTriPtr&
                       Previous () const
  { return * myPrevious; }

  /**
   * Append a pointer to triangle into the list after the current instance.
   * @param pTri
   *   Triangle that is to be included in the list after this one.
   * @param theA
   *   Allocator where the new pointer instance is created.
   */
  Standard_EXPORT void Append   (const Poly_CoherentTriangle *           pTri,
                                 const Handle_NCollection_BaseAllocator& theA);

  /**
   * Prepend a pointer to triangle into the list before the current instance.
   * @param pTri
   *   Triangle that is to be included in the list before this one.
   * @param theA
   *   Allocator where the new pointer instance is created.
   */
  Standard_EXPORT void Prepend  (const Poly_CoherentTriangle *           pTri,
                                 const Handle_NCollection_BaseAllocator& theA);

  /**
   * Remove a pointer to triangle from its list.
   * @param thePtr
   *   This class instance that should be removed from its list.
   * @param theA
   *   Allocator where the current pointer instance was created.
   */
  Standard_EXPORT static void
                       Remove   (Poly_CoherentTriPtr *                   thePtr,
                                 const Handle_NCollection_BaseAllocator& theA);

  /**
   * Remove the list containing the given pointer to triangle.
   */
  Standard_EXPORT static void
                       RemoveList (Poly_CoherentTriPtr *                 thePtr,
                                   const Handle_NCollection_BaseAllocator&);

 protected:
  // ---------- PROTECTED METHODS ----------

  /**
   * Constructor.
   */
  inline Poly_CoherentTriPtr (const Poly_CoherentTriangle * pTri)
    : mypTriangle (pTri),
      myNext      (this),
      myPrevious  (this)
  {}

 private:
  // ---------- PRIVATE FIELDS ----------

  const Poly_CoherentTriangle * mypTriangle;
  Poly_CoherentTriPtr         * myNext;
  Poly_CoherentTriPtr         * myPrevious;

  friend class Iterator;
};

#ifdef WNT
#pragma warning (pop)
#endif

#endif