TextOutput.cpp
Go to the documentation of this file.
1 #include "TextOutput.hpp"
2 #include <iostream>
3 #include <ivorium_config.hpp>
4 
5 #if IV_ENABLE_ANDROID_JNI
6  #include <android/log.h>
7 #endif
8 
9 namespace iv
10 {
11 
13 
15 {
16 }
17 
18 std::streambuf::int_type TextOutput_streambuf::overflow( std::streambuf::int_type value )
19 {
20  if( value == traits_type::eof() )
21  {
22  this->flush_as_line();
23  }
24  else
25  {
26  auto c = traits_type::to_char_type( value );
27  if( c == '\n' )
28  this->flush_as_line();
29  else
30  this->buffer.push_back( c );
31  }
32 
33  return traits_type::not_eof( value );
34 }
35 
36 void TextOutput_streambuf::flush_as_line()
37 {
38  // print line
39  #if IV_TEXTOUT_COUT
40  std::cout << this->buffer << std::endl;
41  #endif
42 
43  #if IV_ENABLE_ANDROID_JNI
44  __android_log_write( ANDROID_LOG_INFO, "ivorium", this->buffer.c_str() );
45  #endif
46 
47  //for( auto listener : this->listeners )
48  // listener->AddLine( this->buffer );
49 
50  // clear buffer for next line
51  this->buffer.clear();
52 }
53 
55  std::ostream( new TextOutput_streambuf() )
56 {
57 }
58 
60 {
61  delete this->rdbuf();
62 }
63 
64 }