/*
 * The OpenSAML License, Version 1.
 * Copyright (c) 2002
 * University Corporation for Advanced Internet Development, Inc.
 * All rights reserved
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution, if any, must include
 * the following acknowledgment: "This product includes software developed by
 * the University Corporation for Advanced Internet Development
 * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
 * may appear in the software itself, if and wherever such third-party
 * acknowledgments normally appear.
 *
 * Neither the name of OpenSAML nor the names of its contributors, nor
 * Internet2, nor the University Corporation for Advanced Internet Development,
 * Inc., nor UCAID may be used to endorse or promote products derived from this
 * software without specific prior written permission. For written permission,
 * please contact opensaml@opensaml.org
 *
 * Products derived from this software may not be called OpenSAML, Internet2,
 * UCAID, or the University Corporation for Advanced Internet Development, nor
 * may OpenSAML appear in their name, without prior written permission of the
 * University Corporation for Advanced Internet Development.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
 * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
 * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/* iterator.cpp - implements a template class for iterating over a vector

   Scott Cantor
   2/13/02

   $History:$
*/

#define SAML_INSTANTIATE
#include "internal.h"

using namespace saml;

#define SIMPLECLONE(T) \
    template<> SAML_EXPORTS std::vector<T> Iterator<T>::clone() const { return m_vector; }

#define SAMLCLONE(T) \
    template<> SAML_EXPORTS std::vector<T> Iterator<T>::clone() const \
    { \
        std::vector<T> copy; \
        for (std::vector<T>::const_iterator i=m_vector.begin(); i!=m_vector.end(); i++) \
            copy.push_back(static_cast<T>((*i)->clone())); \
        return copy; \
    } \

SIMPLECLONE(xstring)
SIMPLECLONE(std::string)
SIMPLECLONE(QName)
SIMPLECLONE(const XMLCh*)
SAMLCLONE(SAMLAttribute*)
SAMLCLONE(SAMLStatement*)
SAMLCLONE(SAMLAssertion*)
SAMLCLONE(SAMLCondition*)
SAMLCLONE(SAMLAuthorityBinding*)

#define GCC_VERSION (__GNUC__ * 10000 \
                     + __GNUC_MINOR__ * 100 \
                     + __GNUC_PATCHLEVEL__)
/* Test for GCC >= 3.2.0 */
#if GCC_VERSION >= 30200
// Provide std::char_traits specializations
namespace std
{
    void 
    char_traits<XMLCh>::assign(char_type& __c1, const char_type& __c2)
    { __c1 = __c2; }

    bool
    char_traits<XMLCh>::eq(const char_type& __c1, const char_type& __c2)
    { return __c1 == __c2; }

    bool
    char_traits<XMLCh>::lt(const char_type& __c1, const char_type& __c2)
    { return __c1 < __c2; }

    int
    char_traits<XMLCh>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
    {
        for (size_t __i = 0; __i < __n; ++__i)
            if (!eq(__s1[__i], __s2[__i]))
                return lt(__s1[__i], __s2[__i]) ? -1 : 1;
        return 0;
    }

    size_t
    char_traits<XMLCh>::length(const char_type* __s)
    {
        const char_type* __p = __s;
        while (*__p) ++__p;
            return (__p - __s);
    }

    const char_traits<XMLCh>::char_type*
    char_traits<XMLCh>::find(const char_type* __s, size_t __n, const char_type& __a)
    {
        for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
            if (*__p == __a) return __p;
        return 0;
    }

    char_traits<XMLCh>::char_type*
    char_traits<XMLCh>::move(char_type* __s1, const char_type* __s2, size_t __n)
    { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }

    char_traits<XMLCh>::char_type*
    char_traits<XMLCh>::copy(char_type* __s1, const char_type* __s2, size_t __n)
    { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }

    char_traits<XMLCh>::char_type*
    char_traits<XMLCh>::assign(char_type* __s, size_t __n, char_type __a)
    {
        for (char_type* __p = __s; __p < __s + __n; ++__p)
            assign(*__p, __a);
        return __s;
    }

    char_traits<XMLCh>::char_type
    char_traits<XMLCh>::to_char_type(const int_type& __c)
    { return char_type(__c); }

    char_traits<XMLCh>::int_type
    char_traits<XMLCh>::to_int_type(const char_type& __c)
    { return int_type(__c); }

    bool
    char_traits<XMLCh>::eq_int_type(const int_type& __c1, const int_type& __c2)
    { return __c1 == __c2; }

    char_traits<XMLCh>::int_type
    char_traits<XMLCh>::eof() { return static_cast<int_type>(-1); }

    char_traits<XMLCh>::int_type
    char_traits<XMLCh>::not_eof(const int_type& __c)
    { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
}
#endif

