Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_SOURCE_H |
| 18 | #define AAPT_SOURCE_H |
| 19 | |
| 20 | #include <ostream> |
| 21 | #include <string> |
| 22 | |
| 23 | namespace aapt { |
| 24 | |
| 25 | struct SourceLineColumn; |
| 26 | struct SourceLine; |
| 27 | |
| 28 | /** |
| 29 | * Represents a file on disk. Used for logging and |
| 30 | * showing errors. |
| 31 | */ |
| 32 | struct Source { |
| 33 | std::string path; |
| 34 | |
| 35 | inline SourceLine line(size_t line) const; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * Represents a file on disk and a line number in that file. |
| 40 | * Used for logging and showing errors. |
| 41 | */ |
| 42 | struct SourceLine { |
| 43 | std::string path; |
| 44 | size_t line; |
| 45 | |
| 46 | inline SourceLineColumn column(size_t column) const; |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * Represents a file on disk and a line:column number in that file. |
| 51 | * Used for logging and showing errors. |
| 52 | */ |
| 53 | struct SourceLineColumn { |
| 54 | std::string path; |
| 55 | size_t line; |
| 56 | size_t column; |
| 57 | }; |
| 58 | |
| 59 | // |
| 60 | // Implementations |
| 61 | // |
| 62 | |
| 63 | SourceLine Source::line(size_t line) const { |
| 64 | return SourceLine{ path, line }; |
| 65 | } |
| 66 | |
| 67 | SourceLineColumn SourceLine::column(size_t column) const { |
| 68 | return SourceLineColumn{ path, line, column }; |
| 69 | } |
| 70 | |
| 71 | inline ::std::ostream& operator<<(::std::ostream& out, const Source& source) { |
| 72 | return out << source.path; |
| 73 | } |
| 74 | |
| 75 | inline ::std::ostream& operator<<(::std::ostream& out, const SourceLine& source) { |
| 76 | return out << source.path << ":" << source.line; |
| 77 | } |
| 78 | |
| 79 | inline ::std::ostream& operator<<(::std::ostream& out, const SourceLineColumn& source) { |
| 80 | return out << source.path << ":" << source.line << ":" << source.column; |
| 81 | } |
| 82 | |
| 83 | } // namespace aapt |
| 84 | |
| 85 | #endif // AAPT_SOURCE_H |