Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsAlgorithm.h File Reference
#include "nsCharTraits.h"
#include "prtypes.h"
#include "nsDebug.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<class T >
const TNS_MIN (const T &a, const T &b)
template<class T >
const TNS_MAX (const T &a, const T &b)
template<class InputIterator , class T >
PRUint32 NS_COUNT (InputIterator &first, const InputIterator &last, const T &value)
template<class InputIterator , class OutputIterator >
OutputIterator & copy_string (InputIterator &first, const InputIterator &last, OutputIterator &result)
template<class InputIterator , class OutputIterator >
OutputIterator & copy_string_backward (const InputIterator &first, InputIterator &last, OutputIterator &result)

Function Documentation

template<class InputIterator , class OutputIterator >
OutputIterator& copy_string ( InputIterator &  first,
const InputIterator &  last,
OutputIterator &  result 
) [inline]

Definition at line 88 of file nsAlgorithm.h.

  {
    typedef nsCharSourceTraits<InputIterator> source_traits;
    typedef nsCharSinkTraits<OutputIterator>  sink_traits;

    while ( first != last )
      {
        PRInt32 count_copied = PRInt32(sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last)));
        NS_ASSERTION(count_copied > 0, "|copy_string| will never terminate");
        source_traits::advance(first, count_copied);
      }

    return result;
  }

Here is the caller graph for this function:

template<class InputIterator , class OutputIterator >
OutputIterator& copy_string_backward ( const InputIterator &  first,
InputIterator &  last,
OutputIterator &  result 
)

Definition at line 105 of file nsAlgorithm.h.

  {
    while ( first != last )
      {
        last.normalize_backward();
        result.normalize_backward();
        PRUint32 lengthToCopy = PRUint32( NS_MIN(last.size_backward(), result.size_backward()) );
        if ( first.fragment().mStart == last.fragment().mStart )
          lengthToCopy = NS_MIN(lengthToCopy, PRUint32(last.get() - first.get()));

        NS_ASSERTION(lengthToCopy, "|copy_string_backward| will never terminate");

#ifdef _MSC_VER
        // XXX Visual C++ can't stomach 'typename' where it rightfully should
        nsCharTraits<OutputIterator::value_type>::move(result.get()-lengthToCopy, last.get()-lengthToCopy, lengthToCopy);
#else
        nsCharTraits<typename OutputIterator::value_type>::move(result.get()-lengthToCopy, last.get()-lengthToCopy, lengthToCopy);
#endif

        last.advance( -PRInt32(lengthToCopy) );
        result.advance( -PRInt32(lengthToCopy) );
      }

    return result;
  }

Here is the call graph for this function:

template<class InputIterator , class T >
PRUint32 NS_COUNT ( InputIterator &  first,
const InputIterator &  last,
const T value 
) [inline]

Definition at line 76 of file nsAlgorithm.h.

  {
    PRUint32 result = 0;
    for ( ; first != last; ++first )
      if ( *first == value )
        ++result;
    return result;
  }

Here is the caller graph for this function:

template<class T >
const T& NS_MAX ( const T a,
const T b 
) [inline]

Definition at line 68 of file nsAlgorithm.h.

  {
    return a > b ? a : b;
  }

Here is the caller graph for this function:

template<class T >
const T& NS_MIN ( const T a,
const T b 
) [inline]

Definition at line 60 of file nsAlgorithm.h.

  {
    return b < a ? b : a;
  }

Here is the caller graph for this function: