set.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 477 行 · 第 1/2 页

H
477
字号
    
    virtual void operator-= (const CL_Set<BaseType>& o);
    // Remove from this set the elements in common with o.

    virtual bool IncludesAll (const CL_Set<BaseType>& s) const;
    // Return true if this set contains all elements of the given set. The
    // algorithm performs as many comparisons as the sum of the sizes of
    // this set and the given set.
    
    //
    // ---------------------- 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
        {return new CL_Set<BaseType> (*this);};
    // Override the method inherited from {\small\tt CL_Object}.
    
    const char* ClassName() const {return "CL_Set";};
    // Override the method inherited from {\small\tt CL_Object}.
    
    CL_ClassId ClassId() const
        { return _CL_Set_CLASSID;};
    // Override the method inherited from {\small\tt CL_Object}.



    // -------------------- End public protocol ---------------------------

    
protected:

    // ---------------------- Friend declarations -----------------------
    
    friend CL_SetIterator<BaseType>;

    
    // ----------------------- Instance variables -----------------------
    
    void*              _idata;   // Representation of the Set
    CL_ObjectIOFilter* _filter;
    BaseType           _null;    // I wish this could be a static instance
                                 // var, but GCC doesn't implement static
                                 // template inst vars :-(

    
    // ------------------------ Protected methods ----------------------
    
    CL_Set (void* p);
    // Protected constructor, for use by derived classes. This constructor
    // assumes that its parameter p is the data representation, and sets
    // _idata to p.

    virtual bool       _ReadElement (const CL_Stream& s, BaseType& e);
    // Read an element e of the set 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, const BaseType& e) const;
    // Write an element e of the set 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}.
    
    
private:
    
    bool _OpEqual (const CL_Set<BaseType>&) const;
    // To sidestep the GCC bug.

    void _Destructor ();

    bool _ReadFrom (const CL_Stream&);

    bool _WriteTo  (CL_Stream&) const;

};




template <class BaseType>
class __CLASSTYPE CL_SetIterator: public CL_Object {

public:

    CL_SetIterator (const CL_Set<BaseType>& s);
    // Constructor. The parameter specifies the set to be inspected.

    CL_SetIterator (const CL_SetIterator<BaseType>& itr);
    // Copy constructor. The copy inspects the same set as {\tt itr}, and
    // (unless reset) begins  its iteration at the same object that itr is
    // currently positioned.
    
    virtual void Reset();

    virtual void BeginFromRank (long i);
    // Start the iteration so that the first call to {\tt Next} returns the
    // element of rank i. Thus {\tt BeginFromRank(0)} is equivalent to {\tt
    // Reset()}.
    
    virtual bool More() const;

    virtual const BaseType& Next();

    virtual const char* ClassName () const {return "CL_SetIterator";};
    
//     bool operator== (const CL_SetIterator<BaseType>&) const;
//     virtual bool operator== (const CL_Object& o) const
//        { return *this == ((const CL_SetIterator<BaseType>&) o);};


protected:
    const CL_Set<BaseType>& _set;
    long                    _index;

private:

    // These added to work around the GNU bug

    //    bool _OpEqual (const CL_SetIterator<BaseType>&) const;
  
};





// template <class BaseType>
// inline CL_Set<BaseType>::CL_Set  (const CL_Sequence<BaseType>& seq)
// {
//     *this = seq;
// }


template <class BaseType>
inline bool CL_Set<BaseType>::operator== (const CL_Set<BaseType>& o) const
{
    return _OpEqual (o);
}




template <class BaseType>
inline long CL_Set<BaseType>::StorableFormWidth () const
{
    return sizeof (CL_ClassId) +
        (*(CL_Sequence<BaseType> *)_idata).StorableFormWidth ();
}


template <class BaseType>
inline bool CL_Set<BaseType>::ReadFrom (const CL_Stream& s)
{
    return _ReadFrom (s);
}

template <class BaseType>
inline bool CL_Set<BaseType>::WriteTo  (CL_Stream& s) const
{
    return _WriteTo (s);
}


template <class BaseType>
inline CL_Set<BaseType>::~CL_Set  ()
{
    _Destructor ();
}


// template <class T>
// inline bool CL_SetIterator<T>::operator==
//     (const CL_SetIterator<T>& o) const
// {
//     return _OpEqual (o);
// }


template <class BaseType>
inline long CL_Set<BaseType>::Size () const
{
    return (*(CL_Sequence<BaseType>*)_idata).Size();
}



template <class BaseType>
inline CL_Set<BaseType>::operator CL_Sequence<BaseType>  () const
{
    return AsSequence ();
}


template <class BaseType>
inline bool CL_Set<BaseType>::operator== (const CL_Object& o) const
{
    return ClassId() == o.ClassId() && *this == ((const CL_Set<BaseType>&) o);
}

template <class BaseType>
inline void CL_Set<BaseType>::operator= (const CL_Object& o)
{
    if (CheckClassType (o, "CL_Set::op="))
        *this = ((const CL_Set<BaseType>&) o);
}


template <class BaseType>
inline CL_Sequence<BaseType> CL_Set<BaseType>::AsSequence () const
{
    return *(CL_Sequence<BaseType>*)_idata;
}

#ifndef _no_cl_set_typedefs_
// #include "base/setdef.h"
#endif /* _no_cl_set_typedefs_ */


#endif /* _set_h_ */


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?