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 5 #ifndef COMPONENTS_ZUCCHINI_TYPE_ZTF_H_ 6 #define COMPONENTS_ZUCCHINI_TYPE_ZTF_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 namespace zucchini { 12 13 namespace ztf { 14 15 typedef int16_t dim_t; 16 17 // A exclusive upper bound on number of lines and/or columns. Throughout the ZTF 18 // code a dimension (dim) refers to a block of 1-3 digits which contain a line 19 // or column number. 20 enum : size_t { kMaxDimValue = 1000 }; 21 22 enum SignChar : uint8_t { 23 kMinus = '-', 24 kPlus = '+', 25 }; 26 27 // Lines and columns are 1-based to follow the convention of most modern text 28 // editing software. |line| and |col| should be positive, but int16_t is used to 29 // limit ranges such that it matches DeltaLineCol. 30 struct LineCol { 31 dim_t line; 32 dim_t col; 33 }; 34 35 struct DeltaLineCol { 36 dim_t line; 37 dim_t col; 38 }; 39 40 constexpr DeltaLineCol operator-(const LineCol& lhs, const LineCol& rhs) { 41 return DeltaLineCol{static_cast<dim_t>(lhs.line - rhs.line), 42 static_cast<dim_t>(lhs.col - rhs.col)}; 43 } 44 45 constexpr LineCol operator+(const LineCol& lhs, const DeltaLineCol& rhs) { 46 return LineCol{static_cast<dim_t>(lhs.line + rhs.line), 47 static_cast<dim_t>(lhs.col + rhs.col)}; 48 } 49 50 } // namespace ztf 51 52 } // namespace zucchini 53 54 #endif // COMPONENTS_ZUCCHINI_TYPE_ZTF_H_ 55