2
* Copyright (C) 2006 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.
17
#ifndef ANDROID_TEXTOUTPUT_H
18
#define ANDROID_TEXTOUTPUT_H
20
#include <androidfw/Platform.h>
22
#include ANDROIDFW_UTILS(Errors.h)
27
// ---------------------------------------------------------------------------
34
virtual ~TextOutput();
36
virtual status_t print(const char* txt, size_t len) = 0;
37
virtual void moveIndent(int delta) = 0;
41
inline Bundle(TextOutput& to) : mTO(to) { to.pushBundle(); }
42
inline ~Bundle() { mTO.popBundle(); }
47
virtual void pushBundle() = 0;
48
virtual void popBundle() = 0;
51
// ---------------------------------------------------------------------------
53
// Text output stream for printing to the log (via utils/Log.h).
54
extern TextOutput& alog;
56
// Text output stream for printing to stdout.
57
extern TextOutput& aout;
59
// Text output stream for printing to stderr.
60
extern TextOutput& aerr;
62
typedef TextOutput& (*TextOutputManipFunc)(TextOutput&);
64
TextOutput& endl(TextOutput& to);
65
TextOutput& indent(TextOutput& to);
66
TextOutput& dedent(TextOutput& to);
68
TextOutput& operator<<(TextOutput& to, const char* str);
69
TextOutput& operator<<(TextOutput& to, char); // writes raw character
70
TextOutput& operator<<(TextOutput& to, bool);
71
TextOutput& operator<<(TextOutput& to, int);
72
TextOutput& operator<<(TextOutput& to, long);
73
TextOutput& operator<<(TextOutput& to, unsigned int);
74
TextOutput& operator<<(TextOutput& to, unsigned long);
75
TextOutput& operator<<(TextOutput& to, long long);
76
TextOutput& operator<<(TextOutput& to, unsigned long long);
77
TextOutput& operator<<(TextOutput& to, float);
78
TextOutput& operator<<(TextOutput& to, double);
79
TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func);
80
TextOutput& operator<<(TextOutput& to, const void*);
85
inline TypeCode(uint32_t code);
88
inline uint32_t typeCode() const;
94
TextOutput& operator<<(TextOutput& to, const TypeCode& val);
99
HexDump(const void *buf, size_t size, size_t bytesPerLine=16);
102
inline HexDump& setBytesPerLine(size_t bytesPerLine);
103
inline HexDump& setSingleLineCutoff(int32_t bytes);
104
inline HexDump& setAlignment(size_t alignment);
105
inline HexDump& setCArrayStyle(bool enabled);
107
inline const void* buffer() const;
108
inline size_t size() const;
109
inline size_t bytesPerLine() const;
110
inline int32_t singleLineCutoff() const;
111
inline size_t alignment() const;
112
inline bool carrayStyle() const;
117
size_t mBytesPerLine;
118
int32_t mSingleLineCutoff;
123
TextOutput& operator<<(TextOutput& to, const HexDump& val);
125
// ---------------------------------------------------------------------------
126
// No user servicable parts below.
128
inline TextOutput& endl(TextOutput& to)
134
inline TextOutput& indent(TextOutput& to)
140
inline TextOutput& dedent(TextOutput& to)
146
inline TextOutput& operator<<(TextOutput& to, const char* str)
148
to.print(str, strlen(str));
152
inline TextOutput& operator<<(TextOutput& to, char c)
158
inline TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func)
163
inline TypeCode::TypeCode(uint32_t code) : mCode(code) { }
164
inline TypeCode::~TypeCode() { }
165
inline uint32_t TypeCode::typeCode() const { return mCode; }
167
inline HexDump::~HexDump() { }
169
inline HexDump& HexDump::setBytesPerLine(size_t bytesPerLine) {
170
mBytesPerLine = bytesPerLine; return *this;
172
inline HexDump& HexDump::setSingleLineCutoff(int32_t bytes) {
173
mSingleLineCutoff = bytes; return *this;
175
inline HexDump& HexDump::setAlignment(size_t alignment) {
176
mAlignment = alignment; return *this;
178
inline HexDump& HexDump::setCArrayStyle(bool enabled) {
179
mCArrayStyle = enabled; return *this;
182
inline const void* HexDump::buffer() const { return mBuffer; }
183
inline size_t HexDump::size() const { return mSize; }
184
inline size_t HexDump::bytesPerLine() const { return mBytesPerLine; }
185
inline int32_t HexDump::singleLineCutoff() const { return mSingleLineCutoff; }
186
inline size_t HexDump::alignment() const { return mAlignment; }
187
inline bool HexDump::carrayStyle() const { return mCArrayStyle; }
189
// ---------------------------------------------------------------------------
190
}; // namespace android
192
#endif // ANDROID_TEXTOUTPUT_H