/* Interpreted-only <iostream> shim for the CINT-based C++ engine.
 *
 * CINT's own compiled iostream binding (the "gcc4strm" dictionary) reaches into libstdc++'s
 * private internal typedefs (__streambuf_type etc.) from a ~2005-2010 GCC ABI that no modern
 * standard library (libc++ included, which is what Android and this NDK use) still exposes --
 * it cannot be fixed without hand-writing new ABI glue, and CINT's own bundled include/iostream
 * points at that same broken binding. This header sidesteps it entirely: it's CINT SOURCE CODE,
 * parsed and executed by the interpreter itself rather than bound to a real compiled std::cout,
 * so it never touches libstdc++/libc++ internals -- cout/cin syntax comes through, backed by
 * plain printf/scanf (already known to work: CINT calls already-linked libc functions directly,
 * no compiled dictionary needed for extern "C" functions). No STL container/string support here
 * -- that would need its own compiled dictionary (stlport4strm et al.), out of scope for now.
 */
#ifndef G__PYLEARN_IOSTREAM_SHIM
#define G__PYLEARN_IOSTREAM_SHIM

#include <stdio.h>

class ostream_shim {
public:
  ostream_shim& operator<<(const char* s) { printf("%s", s); return *this; }
  ostream_shim& operator<<(char c) { printf("%c", c); return *this; }
  ostream_shim& operator<<(int i) { printf("%d", i); return *this; }
  ostream_shim& operator<<(unsigned int i) { printf("%u", i); return *this; }
  ostream_shim& operator<<(long i) { printf("%ld", i); return *this; }
  ostream_shim& operator<<(unsigned long i) { printf("%lu", i); return *this; }
  ostream_shim& operator<<(double d) { printf("%g", d); return *this; }
  ostream_shim& operator<<(float d) { printf("%g", d); return *this; }
  ostream_shim& operator<<(bool b) { printf("%s", b ? "1" : "0"); return *this; }
  ostream_shim& operator<<(const void* p) { printf("%p", p); return *this; }
};

class istream_shim {
public:
  istream_shim& operator>>(int& i) { scanf("%d", &i); return *this; }
  istream_shim& operator>>(long& i) { scanf("%ld", &i); return *this; }
  istream_shim& operator>>(double& d) { scanf("%lf", &d); return *this; }
  istream_shim& operator>>(float& d) { scanf("%f", &d); return *this; }
  istream_shim& operator>>(char& c) { scanf(" %c", &c); return *this; }
};

static ostream_shim cout;
static ostream_shim cerr;
static istream_shim cin;
static const char* endl = "\n";

#endif
