gecko/xpcom/string/public/nsAlgorithm.h
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

96 lines
2.0 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsAlgorithm_h___
#define nsAlgorithm_h___
#ifndef nsCharTraits_h___
#include "nsCharTraits.h"
// for |nsCharSourceTraits|, |nsCharSinkTraits|
#endif
#ifndef prtypes_h___
#include "prtypes.h"
// for |uint32_t|...
#endif
#ifndef nsDebug_h___
#include "nsDebug.h"
// for NS_ASSERTION
#endif
template <class T>
inline
T
NS_ROUNDUP( const T& a, const T& b )
{
return ((a + (b - 1)) / b) * b;
}
template <class T>
inline
const T&
NS_MIN( const T& a, const T& b )
{
return b < a ? b : a;
}
// Must return b when a == b in case a is -0
template <class T>
inline
const T&
NS_MAX( const T& a, const T& b )
{
return a > b ? a : b;
}
namespace mozilla {
template <class T>
inline
const T&
clamped( const T& a, const T& min, const T& max )
{
NS_ABORT_IF_FALSE(max >= min, "clamped(): max must be greater than or equal to min");
return NS_MIN(NS_MAX(a, min), max);
}
}
template <class T>
inline
T
NS_ABS( const T& a )
{
return a < 0 ? -a : a;
}
template <class InputIterator, class T>
inline
uint32_t
NS_COUNT( InputIterator& first, const InputIterator& last, const T& value )
{
uint32_t result = 0;
for ( ; first != last; ++first )
if ( *first == value )
++result;
return result;
}
template <class InputIterator, class OutputIterator>
inline
OutputIterator&
copy_string( const InputIterator& first, const InputIterator& last, OutputIterator& result )
{
typedef nsCharSourceTraits<InputIterator> source_traits;
typedef nsCharSinkTraits<OutputIterator> sink_traits;
sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last));
return result;
}
#endif // !defined(nsAlgorithm_h___)