Classes | Namespaces | Defines | Typedefs | Variables

_src_base_types.hh File Reference

Basic types. More...

Go to the source code of this file.

Classes

class  base::Void
 Void that can be instantiated (useful with templates). More...
class  base::bool0
 Fundamental type auto-initialized as zero. More...
class  base::int0
 Fundamental type auto-initialized as zero. More...
class  base::uint0
 Fundamental type auto-initialized as zero. More...

Namespaces

namespace  base
 

Library of base code.


Defines

#define virtual   VIRTUAL_METHODS_IN_BASIC_TYPES_IS_TOO_SLOW
#define UINT_CAST(U)   (static_cast<unsigned int>((U)))
#define ULONG_CAST(U)   (static_cast<unsigned long>((U)))
#define DECLARE_DISTINCT_TYPE(CLASS, T, CONV_FUNC)
 Macro to turn a fundamental type into a distinct class.
#define DECLARE_DISTINCT_TYPE_STRICT(CLASS, T, CONV_FUNC)

Typedefs

typedef unsigned char Bool
 byte-sized bool
typedef unsigned char uchar
typedef unsigned int uint
typedef unsigned long ulong
typedef float fp
typedef double fpx
typedef int8_t base::int8
typedef uint8_t base::uint8
typedef int16_t base::int16
typedef uint16_t base::uint16
typedef int32_t base::int32
typedef uint32_t base::uint32
typedef int64_t base::int64
typedef uint64_t base::uint64

Variables

const uint base::INT_BITS = sizeof(int) * 8
const uint base::LONG_BITS = sizeof(long) * 8
const uint base::POINTER_BITS = sizeof(void*) * 8

Detailed Description

Basic types.

LastChangedDate:
2009-12-18 16:29:35 -0500 (Fri, 18 Dec 2009)
Author:
Jim E. Brooks http://www.palomino3d.org

Define Documentation

#define DECLARE_DISTINCT_TYPE (   CLASS,
  T,
  CONV_FUNC 
)
Value:
class CLASS                                                                                 \
{                                                                                           \
public:                                                                                     \
    typedef T value_type;                                                                   \
                CLASS( void ) : mVal(0) { }  /* clients depends on zero */                  \
                CLASS( T val ) : mVal(val) { }                                              \
    T           CONV_FUNC( void ) const { return mVal; }  /* explicit conversion */         \
                operator T() const { return mVal; }                                         \
    CLASS&      operator=( const T& val ) { mVal = val; return *this; }                     \
    friend bool operator==( const CLASS a, const CLASS b ) { return a.mVal == b.mVal; }     \
    friend bool operator!=( const CLASS a, const CLASS b ) { return a.mVal != b.mVal; }     \
    /* Arithmetic operators are omitted because of ambiguity. */                            \
    /* Rather, cast to fundamental type then do the math. */                                \
private:                                                                                    \
    T   mVal;                                                                               \
};

Macro to turn a fundamental type into a distinct class.

/// For example:
/// DECLARE_DISTINCT_TYPE( Radian, fp )
/// DECLARE_DISTINCT_TYPE( Degree, fp )
/// BTW, this can't done using a template class and typedefs
/// as the typedefs would still be the same type eg:
/// typedef Distinct<fp> Radian;
/// typedef Distinct<fp> Degree;
/// 

---------------------------------------------------------------------------- NOTE: DECLARE_DISTINCT_TYPE() MIGHT CAUSE BUGS IF NOT CAREFUL! !!!!! DECLARE_DISTINCT_TYPE() allows implied conversion to fundamental type! Instead use DECLARE_DISTINCT_TYPE_STRICT() to force explicit conversion. ----------------------------------------------------------------------------

#define DECLARE_DISTINCT_TYPE_STRICT (   CLASS,
  T,
  CONV_FUNC 
)
Value:
class CLASS                                                                                 \
{                                                                                           \
public:                                                                                     \
    typedef T value_type;                                                                   \
                 CLASS( void ) : mVal(0) { }  /* clients depends on zero */                 \
    explicit     CLASS( T val ) : mVal(val) { }  /* explicit conversion */                  \
              /* operator T() const { return mVal; } [wrong] */                             \
    T            CONV_FUNC( void ) const { return mVal; }  /* explicit conversion */        \
  /*CLASS&       operator=( const T& val ) { mVal = val; return *this; } [circumvents] */   \
    CLASS&       operator=(  const CLASS src ) { mVal =  src.mVal; return *this; }          \
    CLASS&       operator+=( const CLASS src ) { mVal += src.mVal; return *this; }          \
    CLASS&       operator-=( const CLASS src ) { mVal -= src.mVal; return *this; }          \
    CLASS&       operator*=( const CLASS src ) { mVal *= src.mVal; return *this; }          \
    CLASS&       operator/=( const CLASS src ) { mVal /= src.mVal; return *this; }          \
    friend CLASS operator+( CLASS a, CLASS b ) { return CLASS(a.mVal + b.mVal); }           \
    friend CLASS operator-( CLASS a, CLASS b ) { return CLASS(a.mVal - b.mVal); }           \
    friend CLASS operator*( CLASS a, CLASS b ) { return CLASS(a.mVal * b.mVal); }           \
    friend CLASS operator/( CLASS a, CLASS b ) { return CLASS(a.mVal / b.mVal); }           \
    friend CLASS operator-( CLASS a )          { return CLASS(-a.mVal); }                   \
    friend bool  operator==( const CLASS a, const CLASS b ) { return a.mVal == b.mVal; }    \
    friend bool  operator!=( const CLASS a, const CLASS b ) { return a.mVal != b.mVal; }    \
    friend bool  operator>( CLASS a, CLASS b ) { return a.mVal > b.mVal; }                  \
    friend bool  operator<( CLASS a, CLASS b ) { return a.mVal < b.mVal; }                  \
    friend bool  operator>=( CLASS a, CLASS b ) { return a.mVal >= b.mVal; }                \
    friend bool  operator<=( CLASS a, CLASS b ) { return a.mVal <= b.mVal; }                \
private:                                                                                    \
    T   mVal;                                                                               \
};
#define UINT_CAST (   U  )     (static_cast<unsigned int>((U)))
#define ULONG_CAST (   U  )     (static_cast<unsigned long>((U)))
#define virtual   VIRTUAL_METHODS_IN_BASIC_TYPES_IS_TOO_SLOW

Typedef Documentation

typedef unsigned char Bool

byte-sized bool

typedef float fp
typedef double fpx
typedef unsigned char uchar
typedef unsigned int uint
typedef unsigned long ulong
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Palomino Flight Simulator documents generated by doxygen 1.7.1 on Tue May 15 2012 22:40:10