SNAP Library 2.3, User Reference  2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
console.cpp
Go to the documentation of this file.
1 // Console Output
4 #if defined (GLib_CreateConsole)
5  Ok = (AllocConsole() != 0);
6  HStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
7  IAssert(HStdOut != INVALID_HANDLE_VALUE);
8 #endif
9 }
10 
12 #if defined (GLib_CreateConsole)
13  if (Ok) IAssert(FreeConsole());
14 #endif
15 }
16 
17 void TCon::PutBf(const void *LBf, const int& LBfL) {
18 #if defined (GLib_Console)
19  #if defined (GLib_CreateConsole)
20  DWORD ChsWritten;
21  WriteConsole(HStdOut, LBf, LBfL, &ChsWritten, 0);
22  IAssert(ChsWritten == static_cast<DWORD>(LBfL));
23  #else
24  fwrite(LBf, sizeof(char), LBfL, stdout);
25  #endif
26 #endif
27 }
28 
29 TCon& TCon::operator << (const int& Int) {
30  char Bf[255];
31  sprintf(Bf, "%d", Int);
32  PutBf((void *) Bf, int(strlen(Bf)));
33  return *this;
34 }
35 
36 TCon& TCon::operator << (const uint& UInt) {
37  char Bf[255];
38  sprintf(Bf, "%u", UInt);
39  PutBf((void *) Bf, int(strlen(Bf)));
40  return *this;
41 }
42 
43 TCon& TCon::operator << (const float& Flt) {
44  char Bf[255];
45  sprintf(Bf, "%g", Flt);
46  PutBf((void *) Bf, int(strlen(Bf)));
47  return *this;
48 
49 }
50 
51 TCon& TCon::operator << (const double& Double) {
52  char Bf[255];
53  sprintf(Bf, "%g", Double);
54  PutBf((void *) Bf, int(strlen(Bf)));
55  return *this;
56 }
57 
58 TCon& TCon::operator << (const long double& LDouble) {
59  char Bf[255];
60  sprintf(Bf, "%Lg", LDouble);
61  PutBf((void *) Bf, int(strlen(Bf)));
62  return *this;
63 }
64 
65 void TCon::operator () (const char * FmtStr, ...) {
66  static char Bf [2048];
67  va_list valist; va_start(valist, FmtStr);
68  int BfL=vsnprintf(Bf, 2048, FmtStr, valist); va_end(valist);
69  if (BfL!=-1){PutBf((void *) Bf, BfL);}
70  else {PutBf((void *) Bf, 2048);}
71 }
72 
73 TCon& Eol(TCon& Con) {
74  Con.PutCh('\n'); return Con;
75 }
76 
77 TCon& Tab(TCon& Con) {
78  Con.PutCh('\t'); return Con;
79 }
80 
81 TCon& Spc(TCon& Con) {
82  Con.PutCh(' '); return Con;
83 }
84 
85 #if defined (GLib_Console)
86  TCon Con;
87 #endif
#define IAssert(Cond)
Definition: bd.h:262
TCon & Eol(TCon &Con)
Definition: console.cpp:73
Definition: console.h:19
TCon & Tab(TCon &Con)
Definition: console.cpp:77
unsigned int uint
Definition: bd.h:11
TCon & Spc(TCon &Con)
Definition: console.cpp:81
int PutCh(const int &Ch)
Definition: console.h:33
~TCon()
Definition: console.cpp:11
TCon & operator<<(const bool &Bool)
Definition: console.h:37
void PutBf(const void *LBf, const int &LBfL)
Definition: console.cpp:17
TCon()
Definition: console.cpp:3
void operator()(const char *FmtStr,...)
Definition: console.cpp:65