type_ztf.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_ZUCCHINI_TYPE_ZTF_H_
  5. #define COMPONENTS_ZUCCHINI_TYPE_ZTF_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. namespace zucchini {
  9. namespace ztf {
  10. typedef int16_t dim_t;
  11. // A exclusive upper bound on number of lines and/or columns. Throughout the ZTF
  12. // code a dimension (dim) refers to a block of 1-3 digits which contain a line
  13. // or column number.
  14. enum : size_t { kMaxDimValue = 1000 };
  15. enum SignChar : uint8_t {
  16. kMinus = '-',
  17. kPlus = '+',
  18. };
  19. // Lines and columns are 1-based to follow the convention of most modern text
  20. // editing software. |line| and |col| should be positive, but int16_t is used to
  21. // limit ranges such that it matches DeltaLineCol.
  22. struct LineCol {
  23. dim_t line;
  24. dim_t col;
  25. };
  26. struct DeltaLineCol {
  27. dim_t line;
  28. dim_t col;
  29. };
  30. constexpr DeltaLineCol operator-(const LineCol& lhs, const LineCol& rhs) {
  31. return DeltaLineCol{static_cast<dim_t>(lhs.line - rhs.line),
  32. static_cast<dim_t>(lhs.col - rhs.col)};
  33. }
  34. constexpr LineCol operator+(const LineCol& lhs, const DeltaLineCol& rhs) {
  35. return LineCol{static_cast<dim_t>(lhs.line + rhs.line),
  36. static_cast<dim_t>(lhs.col + rhs.col)};
  37. }
  38. } // namespace ztf
  39. } // namespace zucchini
  40. #endif // COMPONENTS_ZUCCHINI_TYPE_ZTF_H_