| 1 | // Copyright 2019 Google LLC |
| 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 | // https://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 | // This file holds the basic serializable types used by the debug adapter |
| 16 | // protocol. |
| 17 | |
| 18 | #ifndef dap_types_h |
| 19 | #define dap_types_h |
| 20 | |
| 21 | #include "any.h" |
| 22 | #include "optional.h" |
| 23 | #include "variant.h" |
| 24 | |
| 25 | #include <unordered_map> |
| 26 | #include <vector> |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | namespace dap { |
| 31 | |
| 32 | // string is a sequence of characters. |
| 33 | // string defaults to an empty string. |
| 34 | using string = std::string; |
| 35 | |
| 36 | // boolean holds a true or false value. |
| 37 | // boolean defaults to false. |
| 38 | class boolean { |
| 39 | public: |
| 40 | inline boolean() : val(false) {} |
| 41 | inline boolean(bool i) : val(i) {} |
| 42 | inline operator bool() const { return val; } |
| 43 | inline boolean& operator=(bool i) { |
| 44 | val = i; |
| 45 | return *this; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | bool val; |
| 50 | }; |
| 51 | |
| 52 | // integer holds a whole signed number. |
| 53 | // integer defaults to 0. |
| 54 | class integer { |
| 55 | public: |
| 56 | inline integer() : val(0) {} |
| 57 | inline integer(int64_t i) : val(i) {} |
| 58 | inline operator int64_t() const { return val; } |
| 59 | inline integer& operator=(int64_t i) { |
| 60 | val = i; |
| 61 | return *this; |
| 62 | } |
| 63 | inline integer operator++(int) { |
| 64 | auto copy = *this; |
| 65 | val++; |
| 66 | return copy; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | int64_t val; |
| 71 | }; |
| 72 | |
| 73 | // number holds a 64-bit floating point number. |
| 74 | // number defaults to 0. |
| 75 | class number { |
| 76 | public: |
| 77 | inline number() : val(0.0) {} |
| 78 | inline number(double i) : val(i) {} |
| 79 | inline operator double() const { return val; } |
| 80 | inline number& operator=(double i) { |
| 81 | val = i; |
| 82 | return *this; |
| 83 | } |
| 84 | |
| 85 | private: |
| 86 | double val; |
| 87 | }; |
| 88 | |
| 89 | // array is a list of items of type T. |
| 90 | // array defaults to an empty list. |
| 91 | template <typename T> |
| 92 | using array = std::vector<T>; |
| 93 | |
| 94 | // object is a map of string to any. |
| 95 | // object defaults to an empty map. |
| 96 | using object = std::unordered_map<string, any>; |
| 97 | |
| 98 | // null represents no value. |
| 99 | // null is used by any to check for no-value. |
| 100 | using null = std::nullptr_t; |
| 101 | |
| 102 | } // namespace dap |
| 103 | |
| 104 | #endif // dap_types_h |
| 105 | |