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 <utils/Errors.h>
25 // ---------------------------------------------------------------------------
32 virtual ~TextOutput();
34 virtual status_t print(const char* txt, size_t len) = 0;
35 virtual void moveIndent(int delta) = 0;
39 inline Bundle(TextOutput& to) : mTO(to) { to.pushBundle(); }
40 inline ~Bundle() { mTO.popBundle(); }
45 virtual void pushBundle() = 0;
46 virtual void popBundle() = 0;
49 // ---------------------------------------------------------------------------
51 // Text output stream for printing to the log (via utils/Log.h).
52 extern TextOutput& alog;
54 // Text output stream for printing to stdout.
55 extern TextOutput& aout;
57 // Text output stream for printing to stderr.
58 extern TextOutput& aerr;
60 typedef TextOutput& (*TextOutputManipFunc)(TextOutput&);
62 TextOutput& endl(TextOutput& to);
63 TextOutput& indent(TextOutput& to);
64 TextOutput& dedent(TextOutput& to);
66 TextOutput& operator<<(TextOutput& to, const char* str);
67 TextOutput& operator<<(TextOutput& to, char); // writes raw character
68 TextOutput& operator<<(TextOutput& to, bool);
69 TextOutput& operator<<(TextOutput& to, int);
70 TextOutput& operator<<(TextOutput& to, long);
71 TextOutput& operator<<(TextOutput& to, unsigned int);
72 TextOutput& operator<<(TextOutput& to, unsigned long);
73 TextOutput& operator<<(TextOutput& to, long long);
74 TextOutput& operator<<(TextOutput& to, unsigned long long);
75 TextOutput& operator<<(TextOutput& to, float);
76 TextOutput& operator<<(TextOutput& to, double);
77 TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func);
78 TextOutput& operator<<(TextOutput& to, const void*);
83 inline TypeCode(uint32_t code);
86 inline uint32_t typeCode() const;
92 TextOutput& operator<<(TextOutput& to, const TypeCode& val);
97 HexDump(const void *buf, size_t size, size_t bytesPerLine=16);
100 inline HexDump& setBytesPerLine(size_t bytesPerLine);
101 inline HexDump& setSingleLineCutoff(int32_t bytes);
102 inline HexDump& setAlignment(size_t alignment);
103 inline HexDump& setCArrayStyle(bool enabled);
105 inline const void* buffer() const;
106 inline size_t size() const;
107 inline size_t bytesPerLine() const;
108 inline int32_t singleLineCutoff() const;
109 inline size_t alignment() const;
110 inline bool carrayStyle() const;
115 size_t mBytesPerLine;
116 int32_t mSingleLineCutoff;
121 TextOutput& operator<<(TextOutput& to, const HexDump& val);
123 // ---------------------------------------------------------------------------
124 // No user servicable parts below.
126 inline TextOutput& endl(TextOutput& to)
132 inline TextOutput& indent(TextOutput& to)
138 inline TextOutput& dedent(TextOutput& to)
144 inline TextOutput& operator<<(TextOutput& to, const char* str)
146 to.print(str, strlen(str));
150 inline TextOutput& operator<<(TextOutput& to, char c)
156 inline TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func)
161 inline TypeCode::TypeCode(uint32_t code) : mCode(code) { }
162 inline TypeCode::~TypeCode() { }
163 inline uint32_t TypeCode::typeCode() const { return mCode; }
165 inline HexDump::~HexDump() { }
167 inline HexDump& HexDump::setBytesPerLine(size_t bytesPerLine) {
168 mBytesPerLine = bytesPerLine; return *this;
170 inline HexDump& HexDump::setSingleLineCutoff(int32_t bytes) {
171 mSingleLineCutoff = bytes; return *this;
173 inline HexDump& HexDump::setAlignment(size_t alignment) {
174 mAlignment = alignment; return *this;
176 inline HexDump& HexDump::setCArrayStyle(bool enabled) {
177 mCArrayStyle = enabled; return *this;
180 inline const void* HexDump::buffer() const { return mBuffer; }
181 inline size_t HexDump::size() const { return mSize; }
182 inline size_t HexDump::bytesPerLine() const { return mBytesPerLine; }
183 inline int32_t HexDump::singleLineCutoff() const { return mSingleLineCutoff; }
184 inline size_t HexDump::alignment() const { return mAlignment; }
185 inline bool HexDump::carrayStyle() const { return mCArrayStyle; }
187 // ---------------------------------------------------------------------------
188 }; // namespace android
190 #endif // ANDROID_TEXTOUTPUT_H