~mir-team/mir/in-process-egl+input-conglomeration

« back to all changes in this revision

Viewing changes to 3rd_party/android-input/android/frameworks/native/include/utils/TextOutput.h

Merged trunk and fixed issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2006 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 ANDROID_TEXTOUTPUT_H
18
 
#define ANDROID_TEXTOUTPUT_H
19
 
 
20
 
#include <androidfw/Platform.h>
21
 
 
22
 
#include ANDROIDFW_UTILS(Errors.h)
23
 
 
24
 
#include <stdint.h>
25
 
#include <string.h>
26
 
 
27
 
// ---------------------------------------------------------------------------
28
 
namespace android {
29
 
 
30
 
class TextOutput
31
 
{
32
 
public:
33
 
                        TextOutput();
34
 
    virtual             ~TextOutput();
35
 
    
36
 
    virtual status_t    print(const char* txt, size_t len) = 0;
37
 
    virtual void        moveIndent(int delta) = 0;
38
 
    
39
 
    class Bundle {
40
 
    public:
41
 
        inline Bundle(TextOutput& to) : mTO(to) { to.pushBundle(); }
42
 
        inline ~Bundle() { mTO.popBundle(); }
43
 
    private:
44
 
        TextOutput&     mTO;
45
 
    };
46
 
    
47
 
    virtual void        pushBundle() = 0;
48
 
    virtual void        popBundle() = 0;
49
 
};
50
 
 
51
 
// ---------------------------------------------------------------------------
52
 
 
53
 
// Text output stream for printing to the log (via utils/Log.h).
54
 
extern TextOutput& alog;
55
 
 
56
 
// Text output stream for printing to stdout.
57
 
extern TextOutput& aout;
58
 
 
59
 
// Text output stream for printing to stderr.
60
 
extern TextOutput& aerr;
61
 
 
62
 
typedef TextOutput& (*TextOutputManipFunc)(TextOutput&);
63
 
 
64
 
TextOutput& endl(TextOutput& to);
65
 
TextOutput& indent(TextOutput& to);
66
 
TextOutput& dedent(TextOutput& to);
67
 
 
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*);
81
 
 
82
 
class TypeCode 
83
 
{
84
 
public:
85
 
    inline TypeCode(uint32_t code);
86
 
    inline ~TypeCode();
87
 
 
88
 
    inline uint32_t typeCode() const;
89
 
    
90
 
private:
91
 
    uint32_t mCode;
92
 
};
93
 
 
94
 
TextOutput& operator<<(TextOutput& to, const TypeCode& val);
95
 
 
96
 
class HexDump
97
 
{
98
 
public:
99
 
    HexDump(const void *buf, size_t size, size_t bytesPerLine=16);
100
 
    inline ~HexDump();
101
 
    
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);
106
 
    
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;
113
 
 
114
 
private:
115
 
    const void* mBuffer;
116
 
    size_t mSize;
117
 
    size_t mBytesPerLine;
118
 
    int32_t mSingleLineCutoff;
119
 
    size_t mAlignment;
120
 
    bool mCArrayStyle;
121
 
};
122
 
 
123
 
TextOutput& operator<<(TextOutput& to, const HexDump& val);
124
 
 
125
 
// ---------------------------------------------------------------------------
126
 
// No user servicable parts below.
127
 
 
128
 
inline TextOutput& endl(TextOutput& to)
129
 
{
130
 
    to.print("\n", 1);
131
 
    return to;
132
 
}
133
 
 
134
 
inline TextOutput& indent(TextOutput& to)
135
 
{
136
 
    to.moveIndent(1);
137
 
    return to;
138
 
}
139
 
 
140
 
inline TextOutput& dedent(TextOutput& to)
141
 
{
142
 
    to.moveIndent(-1);
143
 
    return to;
144
 
}
145
 
 
146
 
inline TextOutput& operator<<(TextOutput& to, const char* str)
147
 
{
148
 
    to.print(str, strlen(str));
149
 
    return to;
150
 
}
151
 
 
152
 
inline TextOutput& operator<<(TextOutput& to, char c)
153
 
{
154
 
    to.print(&c, 1);
155
 
    return to;
156
 
}
157
 
 
158
 
inline TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func)
159
 
{
160
 
    return (*func)(to);
161
 
}
162
 
 
163
 
inline TypeCode::TypeCode(uint32_t code) : mCode(code) { }
164
 
inline TypeCode::~TypeCode() { }
165
 
inline uint32_t TypeCode::typeCode() const { return mCode; }
166
 
 
167
 
inline HexDump::~HexDump() { }
168
 
 
169
 
inline HexDump& HexDump::setBytesPerLine(size_t bytesPerLine) {
170
 
    mBytesPerLine = bytesPerLine; return *this;
171
 
}
172
 
inline HexDump& HexDump::setSingleLineCutoff(int32_t bytes) {
173
 
    mSingleLineCutoff = bytes; return *this;
174
 
}
175
 
inline HexDump& HexDump::setAlignment(size_t alignment) {
176
 
    mAlignment = alignment; return *this;
177
 
}
178
 
inline HexDump& HexDump::setCArrayStyle(bool enabled) {
179
 
    mCArrayStyle = enabled; return *this;
180
 
}
181
 
 
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; }
188
 
 
189
 
// ---------------------------------------------------------------------------
190
 
}; // namespace android
191
 
 
192
 
#endif // ANDROID_TEXTOUTPUT_H