sequence.h
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 438 行 · 第 1/2 页
H
438 行
void operator= (const CL_Object& o);
// Check that the given object has the same class id as the sequence,
// and then perform a sequence assignment after casting down.
virtual CL_Sequence<BaseType>& operator+= (const CL_Sequence<BaseType>& s);
// Concatenate the given sequence onto the end of this sequence. If
// the template parameter {\small\tt BaseType>}
// is a first-class object, the copy constructor of the {\small\tt
// BaseType} is used to copy each entry in the sequence {\small\tt s};
// if it's a pointer, just the pointer is copied.
#ifndef __GNUC__ // Temporarily disable these methods to work around
// the GCC bug
virtual CL_Sequence<BaseType> Subsequence (const CL_IntegerSet& s)
const;
// Return the subsequence of this sequence containing those
// elements whose positions are in the given set.
virtual CL_Sequence<BaseType> operator- (const CL_IntegerSet& s) const;
// Return the sequence obtained by removing from this sequence those
// elements whose indices are in the given set. If the {\small\tt
// BaseType} of this sequence is a pointer,
// the pointers are copied into the returned
// sequence; if the {\small\tt BaseType} is a first-class objects, the copy
// constructor of the {\small\tt BaseType} is used to copy the objects
// into the returned sequence.
virtual void operator-= (const CL_IntegerSet& s);
// Remove from this sequence those elements whose indices are in the
// given set. The implementation uses no more than n = Size() pointer
// movements, regardless of how big s is.
#endif // __GNUC__
virtual bool ChangeSize (long new_size);
// Expand ourselves to the given size. If new_size is less than
// the current size, this operation truncates the sequence, i.e. the
// elements with higher indices are lost. If the new sequence is
// longer, the additional elements are initialized with the null value
// of the {\small\tt BaseType} (i.e., the NULL pointer for pointer
// types, and the value returned by the default constructor for
// first-class objects).
// The method returns TRUE if successful, FALSE if no more memory.
virtual void MakeEmpty ();
// Delete all contained objects, and set our size to 0. If this is a
// sequence of Object pointers, the contained objects are {\it not\/}
// deleted.
virtual bool ShiftRightAt (long pos, long amount = 1);
// Shift all elements, beginning at position {\tt pos}, right by
// {\tt amount} cells; then set the cells {\tt pos} through {\tt
// pos+amount-1} to
// the null value of the base type. The new sequence will have its size
// increased by {\tt amount}. The value {\tt pos} must be in the range 0 to
// {\tt Size()-1}.
// This method returns TRUE on success, FALSE on failure (e.g., memory
// allocation failure).
//
// The implementation performs {\small\tt Size() - pos} pointer
// movements. These are pointer movements even when the {\small\tt
// BaseType} is a first-class object.
virtual bool ShiftLeftAt (long pos, long amount = 1);
// Shift all elements, beginning at position "pos" upto our last
// element, left by "amount" cells; this causes the sequence to lose the
// elements that were at positions pos-amount through pos-1.
// The new sequence will have its size decreased by "amount".
// Return TRUE on success, false on failure (e.g., memory
// allocation failure).
//
// The implementation performs {\small\tt Size() - pos} pointer
// movements. These are pointer movements even when the {\small\tt
// BaseType} is a first-class object.
virtual bool Sort ();
// Sort the elements into ascending order. Return FALSE if either the
// sequence was already sorted, memory allocation failed, or one of
// the pre-change dependents refused permission, and TRUE otherwise.
// The _Compare method is used for comparison. The implementation uses
// the _QuickSort method.
virtual bool IsSorted () const;
// Is this sequence sorted?
// -------------------- Storage and retrieval ---------------------
long StorableFormWidth () const;
// Override the method inherited from {\small\tt CL_Object}.
bool ReadFrom (const CL_Stream&);
// Override the method inherited from {\small\tt CL_Object}.
bool WriteTo (CL_Stream&) const;
// Override the method inherited from {\small\tt CL_Object}.
// -------------------- Basic methods --------------------
CL_Object* Clone () const;
// Override the method inherited from {\small\tt CL_Object}.
const char* ClassName() const {return "CL_Sequence";};
// Override the method inherited from {\small\tt CL_Object}.
CL_ClassId ClassId() const { return _CL_Sequence_CLASSID;};
// Override the method inherited from {\small\tt CL_Object}.
// -------------------- End public protocol ---------------------------
protected:
//
// Instance variables
//
void* _idata;
long _size;
CL_ObjectIOFilter* _builder;
virtual bool _QuickSort (long left, long right);
// Apply QuickSort on the segment of the sequence beginning at {\tt
// left} and ending at {\tt right}. Return FALSE if this segment was
// already sorted, and TRUE otherwise. This method does not perform
// notification.
virtual bool _ReadElement (const CL_Stream& s, long i);
// Read the i-th element of the sequence from the stream. This method
// is used by {\tt ReadFrom}. The return value is TRUE if the
// operation succeeds, and FALSE otherwise. The default implementation
// simply calls {\tt CL_RestoreFrom} in {\tt basicops.h}.
virtual bool _WriteElement (CL_Stream& s, long i) const;
// Write the i-th element of the sequence to the stream. This method
// is used by {\tt WriteTo}. The return value is TRUE if the
// operation succeeds, and FALSE otherwise. The default implementation
// simply calls {\tt CL_SaveTo} in {\tt basicops.h}.
virtual short _Compare (const BaseType&, const BaseType&) const;
// Compare two objects. All comparisons needed by all methods in the
// Sequence are done by this method. The default implementation uses
// the CL_Basics<BaseType>::Compare function.
private:
bool _SaveTo (CL_ObjectPtr&, CL_Stream&) const;
bool _ShiftRightAt (long pos, long amount);
// Do the ShiftRight without notifying clients.
bool _ShiftLeftAt (long pos, long amount);
// Do the ShiftLeft without notifying clients.
short _ChangeSize (long new_size);
// Do the ChangeSize without notifying clients.
short _DoInsert (const BaseType& o, long index);
// Do the Insert without notifying clients.
void _DoMakeEmpty ();
// Do the MakeEmpty without notifying clients.
// void _Destructor ();
// Added to sidestep the problems with gcc.
};
template <class BaseType>
inline long CL_Sequence<BaseType>::Size () const
{
return _size;
}
template <class BaseType>
inline void CL_Sequence<BaseType>::operator= (const CL_Object& o)
{
if (CheckClassType (o, "CL_Sequence::op="))
*this = ((const CL_Sequence<BaseType>&) o);
}
template <class BaseType>
inline long CL_Sequence<BaseType>::Add (const BaseType& o)
{
long pos = Size()-1;
return Insert (o, pos) ? pos+1 : -1;
}
template <class BaseType>
inline CL_Object* CL_Sequence<BaseType>::Clone () const
{
return new CL_Sequence<BaseType> (*this);
}
#endif /* _sequence_h_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?