| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "types_internal.hpp" |
| 21 |
|
| 22 |
#include "proton/type_id.hpp" |
| 23 |
|
| 24 |
#include <ostream> |
| 25 |
|
| 26 |
namespace proton { |
| 27 |
|
| 28 |
std::string type_name(type_id t) { |
| 29 |
switch (t) { |
| 30 |
case NULL_TYPE: return "null"; |
| 31 |
case BOOLEAN: return "boolean"; |
| 32 |
case UBYTE: return "ubyte"; |
| 33 |
case BYTE: return "byte"; |
| 34 |
case USHORT: return "ushort"; |
| 35 |
case SHORT: return "short"; |
| 36 |
case UINT: return "uint"; |
| 37 |
case INT: return "int"; |
| 38 |
case CHAR: return "char"; |
| 39 |
case ULONG: return "ulong"; |
| 40 |
case LONG: return "long"; |
| 41 |
case TIMESTAMP: return "timestamp"; |
| 42 |
case FLOAT: return "float"; |
| 43 |
case DOUBLE: return "double"; |
| 44 |
case DECIMAL32: return "decimal32"; |
| 45 |
case DECIMAL64: return "decimal64"; |
| 46 |
case DECIMAL128: return "decimal128"; |
| 47 |
case UUID: return "uuid"; |
| 48 |
case BINARY: return "binary"; |
| 49 |
case STRING: return "string"; |
| 50 |
case SYMBOL: return "symbol"; |
| 51 |
case DESCRIBED: return "described"; |
| 52 |
case ARRAY: return "array"; |
| 53 |
case LIST: return "list"; |
| 54 |
case MAP: return "map"; |
| 55 |
} |
| 56 |
// Avoid unreached diagnostic from clang |
| 57 |
#if defined(__clang__) |
| 58 |
#pragma GCC diagnostic push |
| 59 |
#pragma GCC diagnostic ignored "-Wunreachable-code" |
| 60 |
#endif |
| 61 |
return "unknown"; |
| 62 |
#if defined(__clang__) |
| 63 |
#pragma GCC diagnostic pop |
| 64 |
#endif |
| 65 |
} |
| 66 |
|
| 67 |
std::ostream& operator<<(std::ostream& o, type_id t) { return o << type_name(t); } |
| 68 |
|
| 69 |
void assert_type_equal(type_id want, type_id got) { |
| 70 |
if (want != got) throw make_conversion_error(want, got); |
| 71 |
} |
| 72 |
|
| 73 |
} // proton |