blob: 1d437ebe6492e5051f88b782cda2ef37b36b4425 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
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_LOGGER_H
18#define AAPT_LOGGER_H
19
20#include "Source.h"
21
22#include <memory>
23#include <ostream>
24#include <string>
25#include <utils/String8.h>
26
27namespace aapt {
28
29struct Log {
30 Log(std::ostream& out, std::ostream& err);
31 Log(const Log& rhs) = delete;
32
33 std::ostream& out;
34 std::ostream& err;
35};
36
37class Logger {
38public:
39 static void setLog(const std::shared_ptr<Log>& log);
40
41 static std::ostream& error();
42 static std::ostream& error(const Source& source);
43 static std::ostream& error(const SourceLine& sourceLine);
44
45 static std::ostream& warn();
46 static std::ostream& warn(const Source& source);
47 static std::ostream& warn(const SourceLine& sourceLine);
48
49 static std::ostream& note();
50 static std::ostream& note(const Source& source);
51 static std::ostream& note(const SourceLine& sourceLine);
52
53private:
54 static std::shared_ptr<Log> sLog;
55};
56
57class SourceLogger {
58public:
59 SourceLogger(const Source& source);
60
61 std::ostream& error();
62 std::ostream& error(size_t line);
63
64 std::ostream& warn();
65 std::ostream& warn(size_t line);
66
67 std::ostream& note();
68 std::ostream& note(size_t line);
69
70private:
71 Source mSource;
72};
73
74inline ::std::ostream& operator<<(::std::ostream& out, const std::u16string& str) {
75 android::String8 utf8(str.data(), str.size());
76 return out.write(utf8.string(), utf8.size());
77}
78
79} // namespace aapt
80
81#endif // AAPT_LOGGER_H