Generated on: Thu Mar 29 07:46:58 PDT 2012 for custom file set
// doxy/ or-tools/ src/ base/

or-tools/src/base/int-type.h File Reference

#include <stddef.h>
#include "base/hash.h"
#include <iosfwd>
#include <ostream>
#include "base/macros.h"

Go to the source code of this file.

Namespaces

namespace  __gnu_cxx

Classes

class  IntType< IntTypeName, _ValueType >
 Holds a integral value (of type ValueType) and behaves as a ValueType by exposing assignment, unary, comparison, and arithmetic operators. More...
struct  __gnu_cxx::hash< IntType< IntTypeName, ValueType > >

Defines

#define DEFINE_INT_TYPE(int_type_name, value_type)
 Defines the IntType using value_type and typedefs it to int_type_name.
#define INT_TYPE_ASSIGNMENT_OP(op)
 -- ASSIGNMENT OPERATORS --------------------------------------------------- We support the following assignment operators: =, +=, -=, *=, /=, <<=, >>= and = for both ThisType and ValueType.
#define INT_TYPE_ARITHMETIC_OP(op)
 -- NON-MEMBER ARITHMETIC OPERATORS ------------------------------------------ We support only the +, -, *, and / operators with the same IntType and ValueType types.
#define INT_TYPE_COMPARISON_OP(op)
 -- NON-MEMBER COMPARISON OPERATORS ------------------------------------------ Static inline comparison operators.

Functions

template<typename IntTypeName, typename ValueType>
std::ostream & operator<< (std::ostream &os, IntType< IntTypeName, ValueType > arg)
 -- NON-MEMBER STREAM OPERATORS ---------------------------------------------- We provide the << operator, primarily for logging purposes.
 INT_TYPE_ARITHMETIC_OP (+)
 INT_TYPE_ARITHMETIC_OP (-)
INT_TYPE_ARITHMETIC_OP * INT_TYPE_ARITHMETIC_OP (/);INT_TYPE_ARITHMETIC_OP(<<
 NOLINT.
 INT_TYPE_ARITHMETIC_OP (>>)
 NOLINT.
 INT_TYPE_ARITHMETIC_OP (%)
 INT_TYPE_COMPARISON_OP (==)
 NOLINT.
 INT_TYPE_COMPARISON_OP (!=)
 NOLINT.
 INT_TYPE_COMPARISON_OP (<=)
 NOLINT.
 INT_TYPE_COMPARISON_OP (>=)
 NOLINT.


Define Documentation

#define DEFINE_INT_TYPE ( int_type_name,
value_type   ) 

Value:

struct int_type_name ## _tag_ {};                                         \
  typedef IntType<int_type_name ## _tag_, value_type> int_type_name;
Defines the IntType using value_type and typedefs it to int_type_name.

The struct int_type_name ## _tag_ trickery is needed to ensure that a new type is created per int_type_name.

Definition at line 160 of file int-type.h.

#define INT_TYPE_ARITHMETIC_OP ( op   ) 

Value:

template <typename IntTypeName, typename ValueType>                          \
  static inline IntType<IntTypeName, ValueType>                                \
  operator op(IntType<IntTypeName, ValueType> id_1,                            \
              IntType<IntTypeName, ValueType> id_2) {                          \
    id_1 op ## = id_2.value();                                                 \
    return id_1;                                                               \
  }                                                                            \
  template <typename IntTypeName, typename ValueType>                          \
  static inline IntType<IntTypeName, ValueType>                                \
  operator op(IntType<IntTypeName, ValueType> id,                              \
              typename IntType<IntTypeName, ValueType>::ValueType arg_val) {   \
    id op ## = arg_val;                                                        \
    return id;                                                                 \
  }                                                                            \
  template <typename IntTypeName, typename ValueType>                          \
  static inline IntType<IntTypeName, ValueType>                                \
  operator op(typename IntType<IntTypeName, ValueType>::ValueType arg_val,     \
              IntType<IntTypeName, ValueType> id) {                            \
    IntType<IntTypeName, ValueType> obj(arg_val);                              \
    obj op ## = id.value();                                                    \
    return obj;                                                                \
  }
-- NON-MEMBER ARITHMETIC OPERATORS ------------------------------------------ We support only the +, -, *, and / operators with the same IntType and ValueType types.

The reason is to allow simple manipulation on these IDs when used as indices in vectors and arrays.

NB: Although it is possible to do IntType * IntType and IntType / IntType, it is probably non-sensical from a dimensionality analysis perspective.

Definition at line 264 of file int-type.h.

#define INT_TYPE_ASSIGNMENT_OP ( op   ) 

Value:

ThisType& operator op(const ThisType& arg_value) {                           \
    value_ op arg_value.value();                                               \
    return *this;                                                              \
  }                                                                            \
  ThisType& operator op(ValueType arg_value) {                                 \
    value_ op arg_value;                                                       \
    return *this;                                                              \
  }
-- ASSIGNMENT OPERATORS --------------------------------------------------- We support the following assignment operators: =, +=, -=, *=, /=, <<=, >>= and = for both ThisType and ValueType.

Definition at line 224 of file int-type.h.

#define INT_TYPE_COMPARISON_OP ( op   ) 

Value:

template <typename IntTypeName, typename ValueType>                          \
  static inline bool operator op(IntType<IntTypeName, ValueType> id_1,         \
                                 IntType<IntTypeName, ValueType> id_2) {       \
    return id_1.value() op id_2.value();                                       \
  }                                                                            \
  template <typename IntTypeName, typename ValueType>                          \
  static inline bool operator op(                                              \
      IntType<IntTypeName, ValueType> id,                                      \
      typename IntType<IntTypeName, ValueType>::ValueType val) {               \
    return id.value() op val;                                                  \
  }                                                                            \
  template <typename IntTypeName, typename ValueType>                          \
  static inline bool operator op(                                              \
      typename IntType<IntTypeName, ValueType>::ValueType val,                 \
      IntType<IntTypeName, ValueType> id) {                                    \
    return val op id.value();                                                  \
  }
-- NON-MEMBER COMPARISON OPERATORS ------------------------------------------ Static inline comparison operators.

We allow all comparison operators among the following types (OP [==, !=, <, <=, >, >=]: IntType<IntTypeName, ValueType> OP IntType<IntTypeName, ValueType> IntType<IntTypeName, ValueType> OP ValueType ValueType OP IntType<IntTypeName, ValueType>

Definition at line 302 of file int-type.h.


Function Documentation

INT_TYPE_ARITHMETIC_OP (  ) 

INT_TYPE_ARITHMETIC_OP ( >>   ) 

NOLINT.

INT_TYPE_ARITHMETIC_OP* INT_TYPE_ARITHMETIC_OP (  ) 

NOLINT.

INT_TYPE_ARITHMETIC_OP (  ) 

INT_TYPE_ARITHMETIC_OP (  ) 

INT_TYPE_COMPARISON_OP ( >=   ) 

NOLINT.

INT_TYPE_COMPARISON_OP ( <=   ) 

NOLINT.

INT_TYPE_COMPARISON_OP (  ) 

NOLINT.

INT_TYPE_COMPARISON_OP (  ) 

NOLINT.

template<typename IntTypeName, typename ValueType>
std::ostream& operator<< ( std::ostream &  os,
IntType< IntTypeName, ValueType >  arg 
) [inline]

-- NON-MEMBER STREAM OPERATORS ---------------------------------------------- We provide the << operator, primarily for logging purposes.

Currently, there seems to be no need for an >> operator.

Parameters:
os  NOLINT

Definition at line 252 of file int-type.h.