types.h 2.4 KB

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