*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)

*Fix a possible crash in Spell::DoAllEffectOnTarget

--HG--
branch : trunk
This commit is contained in:
maximius
2009-10-17 15:35:07 -07:00
parent f21f47005d
commit 26b5e033ff
2257 changed files with 750 additions and 103852 deletions
-128
View File
@@ -1,5 +1,4 @@
// -*- C++ -*-
//=============================================================================
/**
* @file Truncate.h
@@ -11,36 +10,25 @@
* @author Russell Mora <[email protected]>
*/
//=============================================================================
#ifndef ACE_TRUNCATE_H
#define ACE_TRUNCATE_H
#include /**/ "ace/pre.h"
#include "ace/config-all.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/Global_Macros.h"
#include "ace/If_Then_Else.h"
#include "ace/Numeric_Limits.h"
#if defined (ACE_LACKS_LONGLONG_T) \
|| defined (__BORLANDC__) && __BORLANDC__ < 0x590
# include "ace/Basic_Types.h"
#endif /* ACE_LACKS_LONGLONG_T || __BORLANDC__ < 0x590 */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
namespace ACE_Utils
{
#if !defined (__BORLANDC__) || __BORLANDC__ >= 0x590
template<typename T> struct Sign_Check;
// Specialize the unsigned signed cases.
template<> struct Sign_Check<unsigned char> { ACE_STATIC_CONSTANT (bool, is_signed = 0); };
template<> struct Sign_Check<unsigned short> { ACE_STATIC_CONSTANT (bool, is_signed = 0); };
@@ -56,7 +44,6 @@ namespace ACE_Utils
#else
template<> struct Sign_Check<ACE_U_LongLong> { ACE_STATIC_CONSTANT (bool, is_signed = 0); };
#endif /* !ACE_LACKS_LONGLONG_T */
// Specialize the signed cases.
template<> struct Sign_Check<signed char> { ACE_STATIC_CONSTANT (bool, is_signed = 1); };
template<> struct Sign_Check<signed short> { ACE_STATIC_CONSTANT (bool, is_signed = 1); };
@@ -70,9 +57,7 @@ namespace ACE_Utils
# endif /* __GNUC__ */
template<> struct Sign_Check<signed long long> { ACE_STATIC_CONSTANT (bool, is_signed = 1); };
#endif /* !ACE_LACKS_LONGLONG_T */
// -----------------------------------------------------
/**
* @struct To_Unsigned
*
@@ -81,39 +66,30 @@ namespace ACE_Utils
* Retrieve unsigned counterpart to given type or value.
*/
template<typename T> struct To_Unsigned;
template<>
struct To_Unsigned<unsigned char>
{
typedef unsigned char unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
template<>
struct To_Unsigned<unsigned short>
{
typedef unsigned short unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
template<>
struct To_Unsigned<unsigned int>
{
typedef unsigned int unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
template<>
struct To_Unsigned<unsigned long>
{
typedef unsigned long unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
#if !(defined(ACE_LACKS_LONGLONG_T) || defined(ACE_LACKS_UNSIGNEDLONGLONG_T))
# ifdef __GNUC__
// Silence g++ "-pedantic" warnings regarding use of "long long"
@@ -124,7 +100,6 @@ namespace ACE_Utils
struct To_Unsigned<unsigned long long>
{
typedef unsigned long long unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
#else
@@ -132,61 +107,50 @@ namespace ACE_Utils
struct To_Unsigned<ACE_U_LongLong>
{
typedef ACE_U_LongLong unsigned_type;
unsigned_type operator() (unsigned_type x) { return x; }
};
#endif /* !ACE_LACKS_LONGLONG_T */
// ----------------
template<>
struct To_Unsigned<signed char>
{
typedef signed char signed_type;
typedef unsigned char unsigned_type;
unsigned_type operator() (signed_type x)
{
return static_cast<unsigned_type> (x);
}
};
template<>
struct To_Unsigned<signed short>
{
typedef signed short signed_type;
typedef unsigned short unsigned_type;
unsigned_type operator() (signed_type x)
{
return static_cast<unsigned_type> (x);
}
};
template<>
struct To_Unsigned<signed int>
{
typedef signed int signed_type;
typedef unsigned int unsigned_type;
unsigned_type operator() (signed_type x)
{
return static_cast<unsigned_type> (x);
}
};
template<>
struct To_Unsigned<signed long>
{
typedef signed long signed_type;
typedef unsigned long unsigned_type;
unsigned_type operator() (signed_type x)
{
return static_cast<unsigned_type> (x);
}
};
#if !(defined(ACE_LACKS_LONGLONG_T) || defined(ACE_LACKS_UNSIGNEDLONGLONG_T))
# ifdef __GNUC__
// Silence g++ "-pedantic" warnings regarding use of "long long"
@@ -198,16 +162,13 @@ namespace ACE_Utils
{
typedef signed long long signed_type;
typedef unsigned long long unsigned_type;
unsigned_type operator() (signed_type x)
{
return static_cast<unsigned_type> (x);
}
};
#endif /* !ACE_LACKS_LONGLONG_T */
// -----------------------------------------------------
/**
* @struct Safe_Comparator
*
@@ -224,7 +185,6 @@ namespace ACE_Utils
typename RIGHT,
bool IS_LEFT_SIGNED,
bool IS_RIGHT_SIGNED> struct Safe_Comparator;
// LEFT: signed, RIGHT: unsigned
template<typename LEFT, typename RIGHT>
struct Safe_Comparator<LEFT, RIGHT, true, false>
@@ -241,7 +201,6 @@ namespace ACE_Utils
}
}
};
// LEFT: unsigned, RIGHT: signed
template<typename LEFT, typename RIGHT>
struct Safe_Comparator<LEFT, RIGHT, false, true>
@@ -258,7 +217,6 @@ namespace ACE_Utils
}
}
};
// LEFT: unsigned, RIGHT: unsigned
template<typename LEFT, typename RIGHT>
struct Safe_Comparator<LEFT, RIGHT, false, false>
@@ -269,7 +227,6 @@ namespace ACE_Utils
return lhs > rhs;
}
};
// LEFT: signed, RIGHT: signed
template<typename LEFT, typename RIGHT>
struct Safe_Comparator<LEFT, RIGHT, true, true>
@@ -280,9 +237,7 @@ namespace ACE_Utils
return lhs > rhs;
}
};
// -----------------------------------------------------
/**
* @struct Fast_Comparator
*
@@ -304,7 +259,6 @@ namespace ACE_Utils
USE_LEFT = ((sizeof (LEFT) > sizeof (RIGHT)
&& (Sign_Check<LEFT>::is_signed == 1
|| Sign_Check<RIGHT>::is_signed == 0))
// The following is basically the case where LEFT
// and RIGHT are the same integral type.
|| (sizeof (LEFT) == sizeof (RIGHT)
@@ -318,15 +272,12 @@ namespace ACE_Utils
&& Sign_Check<RIGHT>::is_signed == 1)
|| (Sign_Check<LEFT>::is_signed == 0
&& Sign_Check<RIGHT>::is_signed == 0)))));
ACE_STATIC_CONSTANT (
bool,
USE_RIGHT = (sizeof (RIGHT) > sizeof (LEFT)
&& (Sign_Check<RIGHT>::is_signed == 1
|| Sign_Check<LEFT>::is_signed == 0)));
ACE_STATIC_CONSTANT (bool, USABLE = (USE_LEFT || USE_RIGHT));
typedef typename ACE::If_Then_Else<
USE_LEFT,
LEFT,
@@ -334,7 +285,6 @@ namespace ACE_Utils
USE_RIGHT,
RIGHT,
void>::result_type>::result_type promote_type;
static bool greater_than (LEFT lhs, RIGHT rhs)
{
// The explicit cast is assumed to change the type of rhs without
@@ -342,11 +292,8 @@ namespace ACE_Utils
return
(static_cast<promote_type> (lhs) > static_cast<promote_type> (rhs));
}
};
// -----------------------------------------------------
/**
* @struct Comparator
*
@@ -384,9 +331,7 @@ namespace ACE_Utils
Sign_Check<LEFT>::is_signed,
Sign_Check<RIGHT>::is_signed> >::result_type comp_type;
};
// -----------------------------------------------------
/**
* @struct Truncator
*
@@ -404,12 +349,10 @@ namespace ACE_Utils
MAX_FROM_GT_MAX_TO = (sizeof(FROM) > sizeof (TO)
|| (sizeof(FROM) == sizeof (TO)
&& Sign_Check<FROM>::is_signed == 0)));
typedef typename ACE::If_Then_Else<
MAX_FROM_GT_MAX_TO,
FROM,
TO>::result_type comp_to_type;
// Take advantage of knowledge that we're casting a positive value
// to a type large enough to hold it so that we can bypass
// negative value checks at compile-time. Otherwise fallback on
@@ -418,7 +361,6 @@ namespace ACE_Utils
MAX_FROM_GT_MAX_TO,
Fast_Comparator<FROM, comp_to_type>,
typename Comparator<FROM, comp_to_type>::comp_type>::result_type comparator;
/// Truncate a value of type @c FROM to value of type @c TO, if
/// the value is larger than the maximum of value of type @c TO.
TO operator() (FROM val)
@@ -428,9 +370,7 @@ namespace ACE_Utils
? ACE_Numeric_Limits<TO>::max ()
: static_cast<TO> (val));
}
};
// Partial specialization for the case where the types are the same.
// No truncation is necessary.
template<typename T>
@@ -442,7 +382,6 @@ namespace ACE_Utils
}
};
#if defined (ACE_LACKS_LONGLONG_T) || defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
// Partial specialization for the case where we're casting from
// ACE_U_LongLong to a smaller integer. We assume that we're always
@@ -464,7 +403,6 @@ namespace ACE_Utils
}
};
#endif /* ACE_LACKS_LONGLONG_T || ACE_LACKS_UNSIGNEDLONGLONG_T */
// -----------------------------------------------------
/**
* @struct Noop_Truncator
@@ -484,7 +422,6 @@ namespace ACE_Utils
}
};
// -----------------------------------------------------
/**
* @class truncate_cast
*
@@ -508,27 +445,20 @@ namespace ACE_Utils
(sizeof (FROM) < sizeof (TO)),
Noop_Truncator<FROM, TO>,
Truncator<FROM, TO> >::result_type truncator;
return truncator() (val);
}
#else
// Borland can't handle the template meta-programming above so
// provide explicit specializations for a few types. More will be
// added if necessary.
/**
* @deprecated Borland ACE_Utils::Truncator<> specializations should
* be removed.
*/
template<typename FROM, typename TO> struct Truncator;
//----------------------------------------------------------
// sizeof(FROM) > sizeof(TO)
//----------------------------------------------------------
template<>
struct Truncator<ACE_INT32, ACE_INT8>
{
@@ -540,7 +470,6 @@ namespace ACE_Utils
: static_cast<ACE_INT8> (val));
}
};
template<>
struct Truncator<ACE_UINT32, ACE_UINT8>
{
@@ -552,7 +481,6 @@ namespace ACE_Utils
: static_cast<ACE_UINT8> (val));
}
};
template<>
struct Truncator<ACE_INT32, ACE_UINT8>
{
@@ -564,7 +492,6 @@ namespace ACE_Utils
: static_cast<ACE_UINT8> (val));
}
};
template<>
struct Truncator<ACE_UINT32, ACE_INT8>
{
@@ -576,7 +503,6 @@ namespace ACE_Utils
: static_cast<ACE_INT8> (val));
}
};
#if defined (ACE_SIZEOF_LONG) && ACE_SIZEOF_LONG < 8
template<>
struct Truncator<ACE_INT64, signed long>
@@ -589,7 +515,6 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
template<>
struct Truncator<ACE_INT64, unsigned long>
{
@@ -601,7 +526,6 @@ namespace ACE_Utils
: static_cast<unsigned long> (val));
}
};
template<>
struct Truncator<ACE_UINT64, unsigned long>
{
@@ -613,7 +537,6 @@ namespace ACE_Utils
: static_cast<unsigned long> (val));
}
};
template<>
struct Truncator<ACE_UINT64, signed long>
{
@@ -625,7 +548,6 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
template<>
struct Truncator<const ACE_UINT64, signed long>
{
@@ -637,9 +559,7 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
#endif /* ACE_SIZEOF_LONG < 8 */
#if defined (ACE_SIZEOF_INT) && ACE_SIZEOF_INT < 8
template<>
struct Truncator<ACE_INT64, signed int>
@@ -652,7 +572,6 @@ namespace ACE_Utils
: static_cast<signed int> (val));
}
};
template<>
struct Truncator<ACE_INT64, unsigned int>
{
@@ -664,7 +583,6 @@ namespace ACE_Utils
: static_cast<unsigned int> (val));
}
};
template<>
struct Truncator<ACE_UINT64, unsigned int>
{
@@ -676,7 +594,6 @@ namespace ACE_Utils
: static_cast<unsigned int> (val));
}
};
template<>
struct Truncator<ACE_UINT64, signed int>
{
@@ -688,13 +605,10 @@ namespace ACE_Utils
: static_cast<signed int> (val));
}
};
#endif /* ACE_SIZEOF_INT < 8 */
//----------------------------------------------------------
// sizeof(FROM) == sizeof(TO)
//----------------------------------------------------------
template<>
struct Truncator<unsigned int, char>
{
@@ -703,7 +617,6 @@ namespace ACE_Utils
return static_cast<char> (val);
}
};
template<>
struct Truncator<unsigned int, wchar_t>
{
@@ -712,7 +625,6 @@ namespace ACE_Utils
return static_cast<wchar_t> (val);
}
};
template<>
struct Truncator<signed int, unsigned int>
{
@@ -721,7 +633,6 @@ namespace ACE_Utils
return static_cast<unsigned int> (val);
}
};
template<>
struct Truncator<unsigned int, signed int>
{
@@ -733,7 +644,6 @@ namespace ACE_Utils
: static_cast<signed int> (val));
}
};
template<>
struct Truncator<const unsigned int, signed int>
{
@@ -745,7 +655,6 @@ namespace ACE_Utils
: static_cast<signed int> (val));
}
};
template<>
struct Truncator<signed long, unsigned long>
{
@@ -754,7 +663,6 @@ namespace ACE_Utils
return static_cast<unsigned long> (val);
}
};
template<>
struct Truncator<unsigned long, signed long>
{
@@ -766,10 +674,8 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
#if defined (ACE_SIZEOF_INT) && defined (ACE_SIZEOF_LONG) \
&& ACE_SIZEOF_INT == ACE_SIZEOF_LONG
template<>
struct Truncator<signed int, unsigned long>
{
@@ -778,7 +684,6 @@ namespace ACE_Utils
return static_cast<unsigned long> (val);
}
};
template<>
struct Truncator<signed int, signed long>
{
@@ -787,7 +692,6 @@ namespace ACE_Utils
return static_cast<signed long> (val);
}
};
template<>
struct Truncator<unsigned long, signed int>
{
@@ -799,7 +703,6 @@ namespace ACE_Utils
: static_cast<signed int> (val));
}
};
template<>
struct Truncator<signed long, signed int>
{
@@ -814,7 +717,6 @@ namespace ACE_Utils
// : static_cast<signed int> (val));
}
};
template<>
struct Truncator<signed long, unsigned int>
{
@@ -823,7 +725,6 @@ namespace ACE_Utils
return static_cast<unsigned int> (val);
}
};
template<>
struct Truncator<const signed long, unsigned int>
{
@@ -833,7 +734,6 @@ namespace ACE_Utils
}
};
template<>
struct Truncator<unsigned int, signed long>
{
@@ -845,9 +745,7 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
#endif /* ACE_SIZEOF_INT == ACE_SIZEOF_LONG */
template<>
struct Truncator<ACE_INT64, ACE_UINT64>
{
@@ -856,7 +754,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT64> (val);
}
};
template<>
struct Truncator<ACE_UINT64, ACE_INT64>
{
@@ -868,11 +765,9 @@ namespace ACE_Utils
: static_cast<ACE_INT64> (val));
}
};
//----------------------------------------------------------
// sizeof(FROM) < sizeof(TO)
//----------------------------------------------------------
template<>
struct Truncator<ACE_INT8, ACE_INT32>
{
@@ -881,7 +776,6 @@ namespace ACE_Utils
return static_cast<ACE_INT32> (val);
}
};
template<>
struct Truncator<ACE_UINT8, ACE_UINT32>
{
@@ -890,7 +784,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT32> (val);
}
};
template<>
struct Truncator<ACE_UINT8, ACE_INT32>
{
@@ -899,7 +792,6 @@ namespace ACE_Utils
return static_cast<ACE_INT32> (val);
}
};
template<>
struct Truncator<ACE_INT8, ACE_UINT32>
{
@@ -908,7 +800,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT32> (val);
}
};
#if defined (ACE_SIZEOF_LONG) && ACE_SIZEOF_LONG < 8
template<>
struct Truncator<signed long, ACE_INT64>
@@ -918,7 +809,6 @@ namespace ACE_Utils
return static_cast<ACE_INT64> (val);
}
};
template<>
struct Truncator<signed long, ACE_UINT64>
{
@@ -927,7 +817,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT64> (val);
}
};
template<>
struct Truncator<const signed long, ACE_UINT64>
{
@@ -939,7 +828,6 @@ namespace ACE_Utils
: static_cast<signed long> (val));
}
};
template<>
struct Truncator<unsigned long, ACE_UINT64>
{
@@ -948,7 +836,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT64> (val);
}
};
template<>
struct Truncator<unsigned long, ACE_INT64>
{
@@ -958,7 +845,6 @@ namespace ACE_Utils
}
};
#endif /* ACE_SIZEOF_LONG < 8 */
#if defined (ACE_SIZEOF_INT) && ACE_SIZEOF_INT < 8
template<>
struct Truncator<signed int, ACE_INT64>
@@ -968,7 +854,6 @@ namespace ACE_Utils
return static_cast<ACE_INT64> (val);
}
};
template<>
struct Truncator<signed int, ACE_UINT64>
{
@@ -977,7 +862,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT64> (val);
}
};
template<>
struct Truncator<unsigned int, ACE_UINT64>
{
@@ -986,7 +870,6 @@ namespace ACE_Utils
return static_cast<ACE_UINT64> (val);
}
};
template<>
struct Truncator<unsigned int, ACE_INT64>
{
@@ -996,7 +879,6 @@ namespace ACE_Utils
}
};
#endif /* ACE_SIZEOF_INT < 8 */
template<>
struct Truncator<size_t, unsigned long>
{
@@ -1008,7 +890,6 @@ namespace ACE_Utils
: static_cast<size_t> (val));
}
};
// Partial specialization for the case where the types are the same.
// No truncation is necessary.
template<typename T>
@@ -1019,7 +900,6 @@ namespace ACE_Utils
return val;
}
};
// Partial specialization for the case where the types are the same,
// but the from type is const. No truncation is necessary.
//
@@ -1033,24 +913,16 @@ namespace ACE_Utils
return val;
}
};
// -------------------------------------
template<typename TO, typename FROM>
inline TO truncate_cast (FROM val)
{
typedef Truncator<FROM, TO> truncator;
return truncator() (val);
}
#endif /* !__BORLANDC__ || __BORLANDC__ >= 0x590 */
} // namespace ACE_Utils
ACE_END_VERSIONED_NAMESPACE_DECL
#include /**/ "ace/post.h"
#endif /* ACE_TRUNCATE_H*/