OR-Tools  8.2
integral_types.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_BASE_INTEGRAL_TYPES_H_
15 #define OR_TOOLS_BASE_INTEGRAL_TYPES_H_
16 
17 #include <cinttypes>
18 #include <cstdint>
19 #include <iostream> // NOLINT
20 
21 // Detect 64 bit.
22 #undef ARCH_K8
23 #if defined(_MSC_VER) && defined(_WIN64)
24 #define ARCH_K8
25 #elif defined(__APPLE__) && defined(__GNUC__)
26 #define ARCH_K8 // We only support 64 bit on Mac OS X.
27 #elif defined(__GNUC__) && defined(__LP64__) && !defined(__aarch64__)
28 #define ARCH_K8 // Linux x86_64
29 #endif
30 
31 typedef signed char int8;
32 typedef short int16; // NOLINT
33 typedef int int32;
34 typedef int64_t int64;
35 
36 typedef unsigned char uint8;
37 typedef unsigned short uint16; // NOLINT
38 typedef unsigned int uint32;
39 typedef uint64_t uint64;
40 
41 static const uint8 kuint8max = UINT8_MAX;
42 static const uint16 kuint16max = UINT16_MAX;
43 static const uint32 kuint32max = UINT32_MAX;
44 static const uint64 kuint64max = UINT64_MAX;
45 
46 static const int8 kint8min = INT8_MIN;
47 static const int8 kint8max = INT8_MAX;
48 static const int16 kint16min = INT16_MIN;
49 static const int16 kint16max = INT16_MAX;
50 static const int32 kint32min = INT32_MIN;
51 static const int32 kint32max = INT32_MAX;
52 static const int64 kint64min = INT64_MIN;
53 static const int64 kint64max = INT64_MAX;
54 
55 #ifdef STLPORT
56 #include <cstdio>
57 // int64 output not present in STL port.
58 inline std::ostream& operator<<(std::ostream& os, int64 i) {
59  char buffer[20];
60  snprintf(buffer, sizeof(buffer), "%" PRId64, i);
61  os << buffer;
62  return os;
63 }
64 
65 inline std::ostream& operator<<(std::ostream& os, uint64 i) {
66  char buffer[20];
67  snprintf(buffer, sizeof(buffer), "%llu", i);
68  os << buffer;
69  return os;
70 }
71 #endif // STLPORT
72 
73 #endif // OR_TOOLS_BASE_INTEGRAL_TYPES_H_
unsigned short uint16
static const int16 kint16max
unsigned int uint32
signed char int8
static const int16 kint16min
short int16
static const int8 kint8min
int int32
static const int8 kint8max
static const int64 kint64max
int64_t int64
static const uint16 kuint16max
static const uint64 kuint64max
static const uint32 kuint32max
static const int32 kint32max
static const int32 kint32min
uint64_t uint64
unsigned char uint8
static const uint8 kuint8max
static const int64 kint64min
std::ostream & operator<<(std::ostream &os, IntType< IntTypeName, ValueType > arg)
Definition: int_type.h:283
#define INT32_MAX
Definition: parser.yy.cc:310
#define UINT16_MAX
Definition: parser.yy.cc:316
#define INT32_MIN
Definition: parser.yy.cc:301
#define INT8_MIN
Definition: parser.yy.cc:295
#define INT8_MAX
Definition: parser.yy.cc:304
#define UINT32_MAX
Definition: parser.yy.cc:319
#define INT16_MAX
Definition: parser.yy.cc:307
#define INT16_MIN
Definition: parser.yy.cc:298
#define UINT8_MAX
Definition: parser.yy.cc:313