mapiter.h

来自「Data Replication Prototype Using ADO」· C头文件 代码 · 共 856 行 · 第 1/3 页

H
856
字号
// _iterator definition/implementation
// ISA _const_iterator (which is a stdc++lib forward iterator).  Allows 
// modification of the VALUE member through the proxy class _modifiable_value.
// KEY is not modifiable because mutable_value_tp has a const KEY type for
// the first parameter.
    class _iterator : public _const_iterator
        {
    public:
        typedef _const_iterator _baseclass;

    public:
            // CREATORS
        _iterator() 
            {}
        explicit _iterator(const collection_tp &col) : 
            _baseclass(col) 
            {}
        _iterator(const _iterator &other) : 
            _baseclass(other)       // don't need to copy m_mutRet member
            {}

    public:
            // MODIFIERS
        _iterator &operator=(const _iterator &other) 
            { 
            _baseclass::operator=(other); 
            return *this; 
            }

        _iterator &operator++() 
            { 
            _baseclass::operator++(); 
            return *this; 
            }
        const _iterator operator++(int) 
            { 
            const _iterator ret(*this); 
            operator++(); 
            return ret; 
            }

    public:
            // ACCESSORS
            // Allows the VALUE parameter to be modified.
            // (both of these are const functions because const-ness means immobile with iterators)
        mutable_value_tp &operator*() const
            {
                // ASSERT:cannot access a value referred to by an iterator unless
                // we have a valid container and are not already pointing to the end
                // of that sequence.
            ASSERT(reinterpret_cast<index_tp>(end_of_sequence) != m_pos);
            ASSERT(AfxIsValidAddress(m_col, sizeof(*m_col), FALSE));

                // Use placement delete and then placement new to change the value in m_mutRet.
                // We cannot use assignment because the returned pair<> has a const KEY field.
                // Without the const KEY field, the caller could modify the KEY member of the return field
            m_mutRet.~mutable_value_tp();
            new (&m_mutRet) 
                mutable_value_tp(
                    _const_iterator::operator*().first, 
                              _modifiable_value(*m_col, _const_iterator::operator*().first )
                                  );
            return m_mutRet;
            }
        mutable_value_tp *operator->() const
            {
            return &operator*();
            }

            // operators == and != are "inherited" from baseclass _const_iterator
    private:
        mutable mutable_value_tp m_mutRet;          // Return value from operator*() and operator->() to allow VALUE modification
                                                    // mutable to allow modification in const member function.
        };

private:
        // don't call
    base_map();     
    };

/*
    // freestanding support operators
template<class KEY, class VALUE, class MAP> 
bool operator==(const base_map<KEY,VALUE,MAP>::_const_iterator &i1, const base_map<KEY,VALUE,MAP>::_const_iterator &i2) 
    {
        // return true if both iterators are at the end of a sequence or both have
        // the same value for contained collection and position.
    return 
        (reinterpret_cast<base_map<KEY,VALUE,MAP>::index_tp>(base_map<KEY,VALUE,MAP>::end_of_sequence)==i1.m_pos &&       
         reinterpret_cast<base_map<KEY,VALUE,MAP>::index_tp>(base_map<KEY,VALUE,MAP>::end_of_sequence)==i2.m_pos) ||               
        (i1.m_col==i2.m_col && i1.m_pos==i2.m_pos);
    }
*/
/*
template<class KEY, class VALUE, class MAP> 
bool operator!=(typename const base_map<KEY,VALUE,MAP>::_const_iterator &i1, typename const base_map<KEY,VALUE,MAP>::_const_iterator &i2)
    {
    return !(i1 == i2);
    }
*/
////////////////////////////////////////////////////////////////////////////////
// cmap definition/implementation
// iterator containing struct used with MFC's CMap<> template 
template<class KEY,class VALUE,class ARG_KEY=KEY, class ARG_VALUE=VALUE>
struct cmap : public base_map<KEY, VALUE, CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> >
    {
private:
    cmap();     // not constructable
    };

    // cmap<> returning freestanding functions
template<class KEY,class VALUE, class ARG_KEY,class ARG_VALUE>
typename cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::const_iterator
	begin(const CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &mp) 
    {
    return cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::const_iterator(mp);
    }
template<class KEY,class VALUE, class ARG_KEY,class ARG_VALUE>
typename cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::iterator
    begin(CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &mp)
    {
    return cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::iterator(mp);
    }
template<class KEY,class VALUE, class ARG_KEY,class ARG_VALUE>
typename cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::const_iterator
    end(const CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &)
    {
    return cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::const_iterator();   
    }
template<class KEY,class VALUE, class ARG_KEY,class ARG_VALUE>
typename cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::iterator
    end(CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &)
    {
    return cmap<KEY,VALUE,ARG_KEY,ARG_VALUE>::iterator();   
    }


////////////////////////////////////////////////////////////////////////////////
// tppmap definition/implementation
// iterator containing struct used with MFC's CTypedPtrMap<CMapPtrToPtr> template.
// The accessor functions are all named tpp_[function] to deal with an internal
// compiler error discussed in the comments at the top of the file.
template<class KEY, class VALUE>
struct tppmap : public base_map<KEY, VALUE, CTypedPtrMap<CMapPtrToPtr, KEY, VALUE> >
    {
private:
    tppmap();   // not constructable
    };

    // tppmap<> returning freestanding functions
template<class KEY,class VALUE>
typename tppmap<KEY,VALUE>::const_iterator
    tpp_begin(const CTypedPtrMap<CMapPtrToPtr,KEY,VALUE> &mp) 
    {
    return tppmap<KEY,VALUE>::const_iterator(mp);
    }
template<class KEY,class VALUE>
typename tppmap<KEY,VALUE>::iterator
    tpp_begin(CTypedPtrMap<CMapPtrToPtr,KEY,VALUE> &mp) 
    {
    return tppmap<KEY,VALUE>::iterator(mp);
    }
template<class KEY,class VALUE>
typename tppmap<KEY,VALUE>::const_iterator
    tpp_end(const CTypedPtrMap<CMapPtrToPtr,KEY,VALUE> &) 
    {
    return tppmap<KEY,VALUE>::const_iterator();
    }
template<class KEY,class VALUE>
typename tppmap<KEY,VALUE>::iterator
    tpp_end(CTypedPtrMap<CMapPtrToPtr,KEY,VALUE> &) 
    {
    return tppmap<KEY,VALUE>::iterator();
    }


////////////////////////////////////////////////////////////////////////////////
// tpwmap definition/implementation
// iterator containing struct used with MFC's CTypedPtrMap<CMapPtrToWord> template.
// The accessor functions are all named tpw_[function] to deal with an internal
// compiler error discussed in the comments at the top of the file.
template<class KEY, class VALUE>
struct tpwmap : public base_map<KEY, VALUE, CTypedPtrMap<CMapPtrToWord, KEY, VALUE> >
    {
private:
    tpwmap();   // not constructable
    };

    // tpwmap<> returning freestanding functions
template<class KEY,class VALUE>
typename tpwmap<KEY,VALUE>::const_iterator
    tpw_begin(const CTypedPtrMap<CMapPtrToWord,KEY,VALUE> &mp) 
    {
    return tpwmap<KEY,VALUE>::const_iterator(mp);
    }
template<class KEY,class VALUE>
typename tpwmap<KEY,VALUE>::iterator
    tpw_begin(CTypedPtrMap<CMapPtrToWord,KEY,VALUE> &mp) 
    {
    return tpwmap<KEY,VALUE>::iterator(mp);
    }
template<class KEY,class VALUE>
typename tpwmap<KEY,VALUE>::const_iterator
    tpw_end(const CTypedPtrMap<CMapPtrToWord,KEY,VALUE> &) 
    {
    return tpwmap<KEY,VALUE>::const_iterator();
    }
template<class KEY,class VALUE>
typename tpwmap<KEY,VALUE>::iterator
    tpw_end(CTypedPtrMap<CMapPtrToWord,KEY,VALUE> &) 
    {
    return tpwmap<KEY,VALUE>::iterator();
    }


////////////////////////////////////////////////////////////////////////////////
// tsomap definition/implementation
// iterator containing struct used with MFC's CTypedPtrMap<CMapStringToOb> template.
// The accessor functions are all named tso_[function] to deal with an internal
// compiler error discussed in the comments at the top of the file.
template<class KEY, class VALUE>
struct tsomap : public base_map<KEY, VALUE, CTypedPtrMap<CMapStringToOb, KEY, VALUE> >
    {
private:
    tsomap();   // not constructable
    };

    // tsomap<> returning freestanding functions
template<class KEY,class VALUE>
typename tsomap<KEY,VALUE>::const_iterator
    tso_begin(const CTypedPtrMap<CMapStringToOb,KEY,VALUE> &mp) 
    {
    return tsomap<KEY,VALUE>::const_iterator(mp);
    }
template<class KEY,class VALUE>
typename tsomap<KEY,VALUE>::iterator
    tso_begin(CTypedPtrMap<CMapStringToOb,KEY,VALUE> &mp) 
    {
    return tsomap<KEY,VALUE>::iterator(mp);
    }
template<class KEY,class VALUE>
typename tsomap<KEY,VALUE>::const_iterator
    tso_end(const CTypedPtrMap<CMapStringToOb,KEY,VALUE> &) 
    {
    return tsomap<KEY,VALUE>::const_iterator();
    }
template<class KEY,class VALUE>
typename tsomap<KEY,VALUE>::iterator
    tso_end(CTypedPtrMap<CMapStringToOb,KEY,VALUE> &) 
    {
    return tsomap<KEY,VALUE>::iterator();
    }


////////////////////////////////////////////////////////////////////////////////
// tspmap definition/implementation
// iterator containing struct used with MFC's CTypedPtrMap<CMapStringToPtr> template.
// The accessor functions are all named tsp_[function] to deal with an internal
// compiler error discussed in the comments at the top of the file.
template<class KEY, class VALUE>
struct tspmap : public base_map<KEY, VALUE, CTypedPtrMap<CMapStringToPtr, KEY, VALUE> >
    {
private:
    tspmap();   // not constructable
    };

    // tspmap<> returning freestanding functions
template<class KEY,class VALUE>
typename tspmap<KEY,VALUE>::const_iterator
    tsp_begin(const CTypedPtrMap<CMapStringToPtr,KEY,VALUE> &mp) 
    {
    return tspmap<KEY,VALUE>::const_iterator(mp);
    }
template<class KEY,class VALUE>
typename tspmap<KEY,VALUE>::iterator
    tsp_begin(CTypedPtrMap<CMapStringToPtr,KEY,VALUE> &mp) 
    {
    return tspmap<KEY,VALUE>::iterator(mp);
    }
template<class KEY,class VALUE>
typename tspmap<KEY,VALUE>::const_iterator
    tsp_end(const CTypedPtrMap<CMapStringToPtr,KEY,VALUE> &) 
    {
    return tspmap<KEY,VALUE>::const_iterator();
    }
template<class KEY,class VALUE>

⌨️ 快捷键说明

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