1 // Copyright 2016 The Draco Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 #include "draco/core/draco_types.h"
16 
17 namespace draco {
18 
DataTypeLength(DataType dt)19 int32_t DataTypeLength(DataType dt) {
20   switch (dt) {
21     case DT_INT8:
22     case DT_UINT8:
23       return 1;
24     case DT_INT16:
25     case DT_UINT16:
26       return 2;
27     case DT_INT32:
28     case DT_UINT32:
29       return 4;
30     case DT_INT64:
31     case DT_UINT64:
32       return 8;
33     case DT_FLOAT32:
34       return 4;
35     case DT_FLOAT64:
36       return 8;
37     case DT_BOOL:
38       return 1;
39     default:
40       return -1;
41   }
42 }
43 
IsDataTypeIntegral(DataType dt)44 bool IsDataTypeIntegral(DataType dt) {
45   switch (dt) {
46     case DT_INT8:
47     case DT_UINT8:
48     case DT_INT16:
49     case DT_UINT16:
50     case DT_INT32:
51     case DT_UINT32:
52     case DT_INT64:
53     case DT_UINT64:
54     case DT_BOOL:
55       return true;
56     default:
57       return false;
58   }
59 }
60 
61 }  // namespace draco
62