diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ios_base.h | 27 | ||||
-rw-r--r-- | include/iostream | 64 | ||||
-rw-r--r-- | include/ostream | 8 |
3 files changed, 95 insertions, 4 deletions
diff --git a/include/ios_base.h b/include/ios_base.h index 858bb96..18b0ef8 100644 --- a/include/ios_base.h +++ b/include/ios_base.h @@ -27,8 +27,8 @@ * SUCH DAMAGE. */ -#ifndef ANDROID_ASTL_IOS_BASE__ -#define ANDROID_ASTL_IOS_BASE__ +#ifndef ANDROID_ASTL_IOS_BASE_H__ +#define ANDROID_ASTL_IOS_BASE_H__ #include <ios_pos_types.h> @@ -38,6 +38,11 @@ namespace std { * Root of the streams inheritance. * The STL defines ios_base as a template with 2 params char types and * traits. We support only char and no traits. + * ios_base defines flags, types and fields to hold these values. + * ios_base is extended by basic_ios which wraps a streambuf and + * provides common methods for all streams. + * The only mode supported for the standards streams (cout, cerr, cin) + * is synced with stdio. */ class ios_base @@ -80,7 +85,23 @@ class ios_base */ streamsize width(streamsize width); -private: + // Helper class to initialize the standard streams. Its + // construction ensures the initialization of the stdio + // streams (cout, cerr,...) declared in iostream. + // The destruction of the last instance of this class will flush + // the streams. + class Init { + public: + Init(); + ~Init(); + + static bool done() { return sDone; } + private: + static int sGuard; + static bool sDone; + }; + + private: streamsize mPrecision; streamsize mWidth; }; diff --git a/include/iostream b/include/iostream new file mode 100644 index 0000000..abfc6b2 --- /dev/null +++ b/include/iostream @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef ANDROID_ASTL_IOSTREAM__ +#define ANDROID_ASTL_IOSTREAM__ + +#include <ios_base.h> +#include <ostream> + +/** + * Declaration of the standard stream objects. + * + * The inclusion of this header will guarantee the initialization of + * the std streams. Since it uses statics (see ioinit below) to + * initialize the cout/cerr streams and that statics are initialized + * in their declaration order, it is best to include this file first + * just in case another included one uses cout/cerr in a static + * instance constructor. + * + * The storage for cout and cerr is in ios_globals.cpp. + */ + +namespace std { +// cin and clog are not supported. +// No wchar support either. +extern ostream cout; // Linked to standard output +extern ostream cerr; // Linked to standard error (unbuffered) + +// Each translation unit that includes this file will get a copy of +// this static variable. Its construction ensures that the standard +// streams (cout, cerr, etc...) have been initialized. +// The destruction of each instance of ioinit will flush the +// streams (e.g on unload). +static ios_base::Init ioinit; + +} // namespace std + +#endif diff --git a/include/ostream b/include/ostream index ef31b34..2bfb722 100644 --- a/include/ostream +++ b/include/ostream @@ -41,7 +41,7 @@ namespace std { * wchar. Since Android supports only char, we don't use a template * here. */ - +class streambuf; class ostream: public ios_base { public: @@ -54,8 +54,14 @@ class ostream: public ios_base ostream(); public: + // TODO: implement. + ostream(streambuf *sb) {} virtual ~ostream(); + // Synchronize the stream buffer. + // TODO: implement. + ostream& flush() { return *this; } + /** * Interface for manipulators (e.g std::endl, std::hex in * expression like "std::cout << std::endl"). See iomanip header. |