SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
console.cpp
Go to the documentation of this file.
00001 
00002 // Console Output
00003 TCon::TCon() {
00004 #if defined (GLib_CreateConsole)
00005   Ok = (AllocConsole() != 0);
00006   HStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
00007   IAssert(HStdOut != INVALID_HANDLE_VALUE);
00008 #endif
00009 }
00010 
00011 TCon::~TCon() {
00012 #if defined (GLib_CreateConsole)
00013   if (Ok) IAssert(FreeConsole());
00014 #endif
00015 }
00016 
00017 void TCon::PutBf(const void *LBf, const int& LBfL) {
00018 #if defined (GLib_Console)
00019   #if defined (GLib_CreateConsole)
00020     DWORD ChsWritten;
00021     WriteConsole(HStdOut, LBf, LBfL, &ChsWritten, 0);
00022     IAssert(ChsWritten == static_cast<DWORD>(LBfL));
00023   #else
00024     fwrite(LBf, sizeof(char), LBfL, stdout);
00025   #endif
00026 #endif
00027 }
00028 
00029 TCon& TCon::operator << (const int& Int) {
00030   char Bf[255];
00031   sprintf(Bf, "%d", Int);
00032   PutBf((void *) Bf, int(strlen(Bf)));
00033   return *this;
00034 }
00035 
00036 TCon& TCon::operator << (const uint& UInt) {
00037   char Bf[255];
00038   sprintf(Bf, "%u", UInt);
00039   PutBf((void *) Bf, int(strlen(Bf)));
00040   return *this;
00041 }
00042 
00043 TCon& TCon::operator << (const float& Flt) {
00044   char Bf[255];
00045   sprintf(Bf, "%g", Flt);
00046   PutBf((void *) Bf, int(strlen(Bf)));
00047   return *this;
00048 
00049 }
00050 
00051 TCon& TCon::operator << (const double& Double) {
00052   char Bf[255];
00053   sprintf(Bf, "%g", Double);
00054   PutBf((void *) Bf, int(strlen(Bf)));
00055   return *this;
00056 }
00057 
00058 TCon& TCon::operator << (const long double& LDouble) {
00059   char Bf[255];
00060   sprintf(Bf, "%Lg", LDouble);
00061   PutBf((void *) Bf, int(strlen(Bf)));
00062   return *this;
00063 }
00064 
00065 void TCon::operator () (const char * FmtStr, ...) {
00066   static char Bf [2048];
00067   va_list valist;  va_start(valist, FmtStr);
00068   int BfL=vsnprintf(Bf, 2048, FmtStr, valist); va_end(valist);
00069   if (BfL!=-1){PutBf((void *) Bf, BfL);}
00070   else {PutBf((void *) Bf, 2048);}
00071 }
00072 
00073 TCon& Eol(TCon& Con) {
00074   Con.PutCh('\n'); return Con;
00075 }
00076 
00077 TCon& Tab(TCon& Con) {
00078   Con.PutCh('\t');  return Con;
00079 }
00080 
00081 TCon& Spc(TCon& Con) {
00082   Con.PutCh(' ');  return Con;
00083 }
00084 
00085 #if defined (GLib_Console)
00086   TCon Con;
00087 #endif