2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include "androidfw/StringPiece.h"
25 #include "util/Maybe.h"
30 * Represents a file on disk. Used for logging and
39 inline Source(const android::StringPiece& path) : path(path.to_string()) { // NOLINT(implicit)
42 inline Source(const android::StringPiece& path, size_t line)
43 : path(path.to_string()), line(line) {}
45 inline Source WithLine(size_t line) const { return Source(path, line); }
52 inline ::std::ostream& operator<<(::std::ostream& out, const Source& source) {
55 out << ":" << source.line.value();
60 inline bool operator==(const Source& lhs, const Source& rhs) {
61 return lhs.path == rhs.path && lhs.line == rhs.line;
64 inline bool operator<(const Source& lhs, const Source& rhs) {
65 int cmp = lhs.path.compare(rhs.path);
66 if (cmp < 0) return true;
67 if (cmp > 0) return false;
70 return lhs.line.value() < rhs.line.value();
74 return bool(rhs.line);
79 #endif // AAPT_SOURCE_H