media/omx-plugin/include/froyo/utils/TextOutput.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/omx-plugin/include/froyo/utils/TextOutput.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,190 @@
     1.4 +/*
     1.5 + * Copyright (C) 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef ANDROID_TEXTOUTPUT_H
    1.21 +#define ANDROID_TEXTOUTPUT_H
    1.22 +
    1.23 +#include <utils/Errors.h>
    1.24 +
    1.25 +#include <stdint.h>
    1.26 +#include <string.h>
    1.27 +
    1.28 +// ---------------------------------------------------------------------------
    1.29 +namespace android {
    1.30 +
    1.31 +class TextOutput
    1.32 +{
    1.33 +public:
    1.34 +                        TextOutput();
    1.35 +    virtual             ~TextOutput();
    1.36 +    
    1.37 +    virtual status_t    print(const char* txt, size_t len) = 0;
    1.38 +    virtual void        moveIndent(int delta) = 0;
    1.39 +    
    1.40 +    class Bundle {
    1.41 +    public:
    1.42 +        inline Bundle(TextOutput& to) : mTO(to) { to.pushBundle(); }
    1.43 +        inline ~Bundle() { mTO.popBundle(); }
    1.44 +    private:
    1.45 +        TextOutput&     mTO;
    1.46 +    };
    1.47 +    
    1.48 +    virtual void        pushBundle() = 0;
    1.49 +    virtual void        popBundle() = 0;
    1.50 +};
    1.51 +
    1.52 +// ---------------------------------------------------------------------------
    1.53 +
    1.54 +// Text output stream for printing to the log (via utils/Log.h).
    1.55 +extern TextOutput& alog;
    1.56 +
    1.57 +// Text output stream for printing to stdout.
    1.58 +extern TextOutput& aout;
    1.59 +
    1.60 +// Text output stream for printing to stderr.
    1.61 +extern TextOutput& aerr;
    1.62 +
    1.63 +typedef TextOutput& (*TextOutputManipFunc)(TextOutput&);
    1.64 +
    1.65 +TextOutput& endl(TextOutput& to);
    1.66 +TextOutput& indent(TextOutput& to);
    1.67 +TextOutput& dedent(TextOutput& to);
    1.68 +
    1.69 +TextOutput& operator<<(TextOutput& to, const char* str);
    1.70 +TextOutput& operator<<(TextOutput& to, char);     // writes raw character
    1.71 +TextOutput& operator<<(TextOutput& to, bool);
    1.72 +TextOutput& operator<<(TextOutput& to, int);
    1.73 +TextOutput& operator<<(TextOutput& to, long);
    1.74 +TextOutput& operator<<(TextOutput& to, unsigned int);
    1.75 +TextOutput& operator<<(TextOutput& to, unsigned long);
    1.76 +TextOutput& operator<<(TextOutput& to, long long);
    1.77 +TextOutput& operator<<(TextOutput& to, unsigned long long);
    1.78 +TextOutput& operator<<(TextOutput& to, float);
    1.79 +TextOutput& operator<<(TextOutput& to, double);
    1.80 +TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func);
    1.81 +TextOutput& operator<<(TextOutput& to, const void*);
    1.82 +
    1.83 +class TypeCode 
    1.84 +{
    1.85 +public:
    1.86 +    inline TypeCode(uint32_t code);
    1.87 +    inline ~TypeCode();
    1.88 +
    1.89 +    inline uint32_t typeCode() const;
    1.90 +    
    1.91 +private:
    1.92 +    uint32_t mCode;
    1.93 +};
    1.94 +
    1.95 +TextOutput& operator<<(TextOutput& to, const TypeCode& val);
    1.96 +
    1.97 +class HexDump
    1.98 +{
    1.99 +public:
   1.100 +    HexDump(const void *buf, size_t size, size_t bytesPerLine=16);
   1.101 +    inline ~HexDump();
   1.102 +    
   1.103 +    inline HexDump& setBytesPerLine(size_t bytesPerLine);
   1.104 +    inline HexDump& setSingleLineCutoff(int32_t bytes);
   1.105 +    inline HexDump& setAlignment(size_t alignment);
   1.106 +    inline HexDump& setCArrayStyle(bool enabled);
   1.107 +    
   1.108 +    inline const void* buffer() const;
   1.109 +    inline size_t size() const;
   1.110 +    inline size_t bytesPerLine() const;
   1.111 +    inline int32_t singleLineCutoff() const;
   1.112 +    inline size_t alignment() const;
   1.113 +    inline bool carrayStyle() const;
   1.114 +
   1.115 +private:
   1.116 +    const void* mBuffer;
   1.117 +    size_t mSize;
   1.118 +    size_t mBytesPerLine;
   1.119 +    int32_t mSingleLineCutoff;
   1.120 +    size_t mAlignment;
   1.121 +    bool mCArrayStyle;
   1.122 +};
   1.123 +
   1.124 +TextOutput& operator<<(TextOutput& to, const HexDump& val);
   1.125 +
   1.126 +// ---------------------------------------------------------------------------
   1.127 +// No user servicable parts below.
   1.128 +
   1.129 +inline TextOutput& endl(TextOutput& to)
   1.130 +{
   1.131 +    to.print("\n", 1);
   1.132 +    return to;
   1.133 +}
   1.134 +
   1.135 +inline TextOutput& indent(TextOutput& to)
   1.136 +{
   1.137 +    to.moveIndent(1);
   1.138 +    return to;
   1.139 +}
   1.140 +
   1.141 +inline TextOutput& dedent(TextOutput& to)
   1.142 +{
   1.143 +    to.moveIndent(-1);
   1.144 +    return to;
   1.145 +}
   1.146 +
   1.147 +inline TextOutput& operator<<(TextOutput& to, const char* str)
   1.148 +{
   1.149 +    to.print(str, strlen(str));
   1.150 +    return to;
   1.151 +}
   1.152 +
   1.153 +inline TextOutput& operator<<(TextOutput& to, char c)
   1.154 +{
   1.155 +    to.print(&c, 1);
   1.156 +    return to;
   1.157 +}
   1.158 +
   1.159 +inline TextOutput& operator<<(TextOutput& to, TextOutputManipFunc func)
   1.160 +{
   1.161 +    return (*func)(to);
   1.162 +}
   1.163 +
   1.164 +inline TypeCode::TypeCode(uint32_t code) : mCode(code) { }
   1.165 +inline TypeCode::~TypeCode() { }
   1.166 +inline uint32_t TypeCode::typeCode() const { return mCode; }
   1.167 +
   1.168 +inline HexDump::~HexDump() { }
   1.169 +
   1.170 +inline HexDump& HexDump::setBytesPerLine(size_t bytesPerLine) {
   1.171 +    mBytesPerLine = bytesPerLine; return *this;
   1.172 +}
   1.173 +inline HexDump& HexDump::setSingleLineCutoff(int32_t bytes) {
   1.174 +    mSingleLineCutoff = bytes; return *this;
   1.175 +}
   1.176 +inline HexDump& HexDump::setAlignment(size_t alignment) {
   1.177 +    mAlignment = alignment; return *this;
   1.178 +}
   1.179 +inline HexDump& HexDump::setCArrayStyle(bool enabled) {
   1.180 +    mCArrayStyle = enabled; return *this;
   1.181 +}
   1.182 +
   1.183 +inline const void* HexDump::buffer() const { return mBuffer; }
   1.184 +inline size_t HexDump::size() const { return mSize; }
   1.185 +inline size_t HexDump::bytesPerLine() const { return mBytesPerLine; }
   1.186 +inline int32_t HexDump::singleLineCutoff() const { return mSingleLineCutoff; }
   1.187 +inline size_t HexDump::alignment() const { return mAlignment; }
   1.188 +inline bool HexDump::carrayStyle() const { return mCArrayStyle; }
   1.189 +
   1.190 +// ---------------------------------------------------------------------------
   1.191 +}; // namespace android
   1.192 +
   1.193 +#endif // ANDROID_TEXTOUTPUT_H

mercurial