File indexing completed on 2025-01-18 10:04:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef LDOM_DeclareSequence_HeaderFile
0017 #define LDOM_DeclareSequence_HeaderFile
0018
0019 #ifndef _Standard_Macro_HeaderFile
0020 #include <Standard_Macro.hxx>
0021 #endif
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #define DECLARE_SEQUENCE( ClassName, Type ) \
0040 \
0041 class ClassName { \
0042 public: \
0043 inline ClassName (); \
0044 inline ClassName (const ClassName& anOther); \
0045 inline ClassName& operator= (const ClassName& anOther); \
0046 inline Standard_Integer Length () const; \
0047 inline const Type& First () const; \
0048 inline const Type& Last () const; \
0049 inline const Type& Value (const Standard_Integer)const;\
0050 inline Type& ChangeValue (const Standard_Integer); \
0051 inline const Type& operator () (const Standard_Integer)const;\
0052 inline Type& operator () (const Standard_Integer); \
0053 \
0054 Standard_EXPORT virtual ~ClassName (); \
0055 Standard_EXPORT void Append (const Type& aVal); \
0056 Standard_EXPORT void Prepend (const Type& aVal); \
0057 Standard_EXPORT void InsertAt (const Standard_Integer, \
0058 const Type& aVal); \
0059 Standard_EXPORT void Clear (); \
0060 Standard_EXPORT void Remove (const Standard_Integer); \
0061 \
0062 private: \
0063 class Node { \
0064 private: \
0065 Type myValue; \
0066 Node * myPrev; \
0067 Node * myNext; \
0068 public: \
0069 Node (const Type& aValue, Node * aPrv, Node * aNxt) \
0070 : myValue (aValue), myPrev (aPrv), myNext (aNxt) {} \
0071 const Type& Value () const { return myValue; } \
0072 Type& ChangeValue () { return myValue; } \
0073 friend class ClassName; \
0074 }; \
0075 \
0076 Standard_EXPORT const void * FindItem (const Standard_Integer)const;\
0077 Standard_EXPORT void Assign (const ClassName& anOther); \
0078 \
0079 Node * myFirst; \
0080 Node * myLast; \
0081 Node * myCurrent; \
0082 Standard_Integer myICur; \
0083 Standard_Integer myLength; \
0084 }; \
0085 \
0086 inline ClassName::ClassName () : \
0087 myFirst (NULL), \
0088 myLast (NULL), \
0089 myCurrent (NULL), \
0090 myICur (0), \
0091 myLength (0) {} \
0092 \
0093 inline ClassName::ClassName (const ClassName& anOther) : \
0094 myFirst (NULL) \
0095 { \
0096 Assign (anOther); \
0097 } \
0098 \
0099 inline ClassName& ClassName::operator= (const ClassName& anOther) \
0100 { \
0101 Assign (anOther); \
0102 return * this; \
0103 } \
0104 \
0105 inline Standard_Integer ClassName::Length () const{ \
0106 return myLength; \
0107 } \
0108 \
0109 inline const Type& ClassName::First () const \
0110 { \
0111 return myFirst -> Value (); \
0112 } \
0113 \
0114 inline const Type& ClassName::Last () const \
0115 { \
0116 return myLast -> Value(); \
0117 } \
0118 \
0119 inline const Type& ClassName::Value (const Standard_Integer anI) const \
0120 { \
0121 const Node * anItem = (const Node *) FindItem (anI); \
0122 return anItem -> Value (); \
0123 } \
0124 \
0125 inline Type& ClassName::ChangeValue (const Standard_Integer anI) \
0126 { \
0127 Node * anItem = (Node *) FindItem (anI); \
0128 return anItem -> ChangeValue (); \
0129 } \
0130 \
0131 inline const Type& ClassName::operator() (const Standard_Integer anI) const \
0132 { \
0133 return Value (anI); \
0134 } \
0135 \
0136 inline Type& ClassName::operator() (const Standard_Integer anI) \
0137 { \
0138 return ChangeValue (anI); \
0139 } \
0140
0141
0142
0143
0144
0145 #define IMPLEMENT_SEQUENCE( ClassName, Type ) \
0146 const void * ClassName::FindItem (const Standard_Integer anI) const \
0147 { \
0148 if (anI < 1 || anI > myLength) return NULL; \
0149 Standard_Integer aCounter; \
0150 Node * aCurrent = (Node *) myCurrent; \
0151 Standard_Boolean aDir (Standard_False); \
0152 if (aCurrent == NULL) { \
0153 aCurrent = myFirst; \
0154 aCounter = anI - 1; \
0155 aDir = Standard_True; \
0156 }else{ \
0157 aCounter = Abs (anI - myICur); \
0158 if (anI <= aCounter) { \
0159 aCurrent = myFirst; \
0160 aCounter = anI - 1; \
0161 aDir = Standard_True; \
0162 }else if (myLength - anI < aCounter) { \
0163 aCurrent = myLast; \
0164 aCounter = myLength - anI; \
0165 }else if (anI > myICur) \
0166 aDir = Standard_True; \
0167 } \
0168 if (aDir) \
0169 while (aCounter--) aCurrent = aCurrent -> myNext; \
0170 else \
0171 while (aCounter--) aCurrent = aCurrent -> myPrev; \
0172 (Standard_Integer&) myICur = anI; \
0173 (Node *&) myCurrent = aCurrent; \
0174 return aCurrent; \
0175 } \
0176 \
0177 ClassName::~ClassName () \
0178 { \
0179 Clear (); \
0180 } \
0181 \
0182 void ClassName::Append (const Type& aVal) \
0183 { \
0184 Node * anItem = new Node (aVal, myLast, NULL); \
0185 if (myLength == 0) \
0186 myFirst = anItem; \
0187 else \
0188 myLast -> myNext = anItem; \
0189 myLast = anItem; \
0190 myLength++; \
0191 } \
0192 \
0193 void ClassName::Prepend (const Type& aVal) \
0194 { \
0195 Node * anItem = new Node (aVal, NULL, myFirst); \
0196 if (myLength == 0) \
0197 myLast = anItem; \
0198 else \
0199 myFirst -> myPrev = anItem; \
0200 myFirst = anItem; \
0201 myLength++; \
0202 if (myICur > 0) myICur++; \
0203 } \
0204 \
0205 void ClassName::InsertAt (const Standard_Integer anI, const Type& aVal) \
0206 { \
0207 if (anI <= 1) Prepend (aVal); \
0208 else if (anI > myLength) Append (aVal); \
0209 else if (FindItem(anI)) { \
0210 Node * anItem = new Node (aVal, myCurrent -> myPrev, myCurrent); \
0211 myCurrent -> myPrev = anItem; \
0212 if (anItem -> myPrev) anItem -> myPrev -> myNext = anItem; \
0213 myLength++; \
0214 myICur++; \
0215 } \
0216 } \
0217 \
0218 void ClassName::Clear () \
0219 { \
0220 while (myFirst) { \
0221 Node * aCurr = myFirst -> myNext; \
0222 delete myFirst; \
0223 myFirst = aCurr; \
0224 } \
0225 myFirst = myLast = myCurrent = NULL; \
0226 myLength = 0; \
0227 myICur = 0; \
0228 } \
0229 \
0230 void ClassName::Remove (const Standard_Integer anI) \
0231 { \
0232 Node * anItem = (Node *) FindItem (anI); \
0233 if (anItem) { \
0234 if (myCurrent -> myPrev) { \
0235 myCurrent -> myPrev -> myNext = myCurrent -> myNext; \
0236 } \
0237 if (myCurrent -> myNext) { \
0238 myCurrent -> myNext -> myPrev = myCurrent -> myPrev; \
0239 myCurrent = myCurrent -> myNext; \
0240 }else{ \
0241 myCurrent = myCurrent -> myPrev; \
0242 myICur--; \
0243 } \
0244 if (myFirst == anItem) myFirst = myFirst -> myNext; \
0245 if (myLast == anItem) myLast = myLast -> myPrev; \
0246 delete anItem; \
0247 myLength--; \
0248 } \
0249 } \
0250 \
0251 void ClassName::Assign (const ClassName& anOther) \
0252 { \
0253 Clear (); \
0254 if (anOther.Length () == 0) return; \
0255 myFirst = new Node (anOther.First(), NULL, NULL); \
0256 Node * aPrevious = myFirst; \
0257 myLength = 1; \
0258 while (myLength < anOther.Length()) { \
0259 myLength++; \
0260 Node * aCurrent = new Node (anOther.Value(myLength), aPrevious, NULL); \
0261 aPrevious = aPrevious -> myNext = aCurrent; \
0262 } \
0263 myLast = aPrevious; \
0264 } \
0265
0266 #endif