Home | History | Annotate | Download | only in include
      1 /* -*- c++ -*- */
      2 /*
      3  * Copyright (C) 2010 The Android Open Source Project
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  *  * Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  *  * Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in
     13  *    the documentation and/or other materials provided with the
     14  *    distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     20  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     23  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #ifndef ANDROID_ASTL_OSTREAM__
     31 #define ANDROID_ASTL_OSTREAM__
     32 
     33 #include <ios_base.h>
     34 #include <basic_ios.h>
     35 #include <ios_pos_types.h>
     36 #include <char_traits.h>
     37 
     38 namespace std {
     39 
     40 /**
     41  * Basic implementation of ostream. The STL standard defines a
     42  * basic_ostream template that gets specialized for char and
     43  * wchar. Since Android supports only char, we don't use a template
     44  * here.
     45  */
     46 class streambuf;
     47 class ostream: public basic_ios
     48 {
     49   public:
     50     typedef char                             char_type;
     51     typedef char_traits<char_type>::int_type int_type;
     52     typedef char_traits<char_type>::pos_type pos_type;
     53     typedef char_traits<char_type>::off_type off_type;
     54 
     55   protected:
     56     ostream();
     57 
     58   public:
     59     explicit ostream(streambuf *sb) { this->init(sb); }
     60     virtual ~ostream();
     61 
     62     // Synchronize the stream buffer.
     63     ostream& flush();
     64 
     65     // Formatted output.
     66     /**
     67      * Interface for manipulators (e.g std::endl, std::hex in
     68      * expression like "std::cout << std::endl"). See iomanip header.
     69      */
     70     ostream& operator<<(ostream& (*manip)(ostream&)) { return manip(*this); }
     71     ostream& operator<<(ios_base& (*manip)(ios_base&)) {
     72         manip(*this);
     73         return *this;
     74     }
     75 
     76     ostream& operator<<(unsigned long int val);
     77     ostream& operator<<(long int val);
     78     ostream& operator<<(unsigned int val);
     79     ostream& operator<<(int val);
     80     ostream& operator<<(unsigned long long int val);
     81     ostream& operator<<(long long int val);
     82 
     83     ostream& operator<<(double val);
     84     ostream& operator<<(float val);
     85 
     86     ostream& operator<<(char_type c);
     87     ostream& operator<<(const char_type *str);
     88     ostream& operator<<(bool val);
     89 
     90     // '(nil)' if p == 0
     91     ostream& operator<<(const void *p);
     92 
     93     // This is non standard, used by string.
     94     ostream& write_formatted(const char_type *str, streamsize num);
     95 
     96     // Unformatted output.
     97     ostream& put(char_type c);
     98     ostream& write(const char_type *str, streamsize num);
     99 };
    100 
    101 /**
    102  * Flushes the output stream.
    103  */
    104 inline ostream& flush(ostream& os) { return os.flush(); }
    105 
    106 /**
    107  * Write a newline and flush the stream.
    108  */
    109 inline ostream& endl(ostream& os) { return flush(os.put('\n')); }
    110 
    111 /**
    112  * Write a null character into the output sequence.
    113  */
    114 inline ostream& ends(ostream& os) { return os.put(char()); }
    115 
    116 }  // namespace std
    117 
    118 #endif
    119