GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4Status.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4Status.h"
15 
16 #include <stdarg.h>
17 #include <iostream>
18 
19 #include "snprintf.h"
20 #include "TROOT.h"
21 
22 #include "TGo4Log.h"
23 
25  TNamed()
26 {
27 }
28 
29 TGo4Status::TGo4Status(const char *name) :
30  TNamed(name, "This is a Go4 Status Object")
31 {
32  GO4TRACE((12,"TGo4Status::TGo4Status(const char *)",__LINE__, __FILE__));
33 }
34 
35 TGo4Status::TGo4Status(const char *name, const char *title) :
36  TNamed(name, title)
37 {
38  GO4TRACE((12,"TGo4Status::TGo4Status(const char*, const char*)",__LINE__, __FILE__));
39 }
40 
42 {
43  GO4TRACE((12,"TGo4Status::~TGo4Status()",__LINE__, __FILE__));
44 }
45 
46 void TGo4Status::Print(Option_t *dummy) const
47 {
48  // this trick is needed since root defines Print as const function...
49  // keep code here to support by chance old objects with implemented PrintStatus
50  TGo4Status *localthis = const_cast<TGo4Status *>(this);
51  localthis->PrintStatus();
52 }
53 
54 Int_t TGo4Status::PrintStatus(Text_t *buffer, Int_t buflen)
55 {
56  GO4TRACE((12,"TGo4Status::PrintStatus()",__LINE__, __FILE__));
57 
58  if(buflen <= 0 && buffer) return 0;
59 
60  Int_t size = 0;
61  TString localbuf = TString::Format("G-OOOO-> Status Class %s, name: %s <-OOOO-G\n", ClassName(), GetName());
62 
63  if(!buffer) {
64  std::cout << localbuf << std::endl;
65  } else {
66  size = localbuf.Length();
67  if(size>buflen-1) size = buflen-1;
68  strncpy(buffer,localbuf.Data(), size);
69  }
70  return size;
71 }
72 
73 Text_t *TGo4Status::PrintIndent(Text_t *buffer, Int_t &buflen)
74 {
75  if(buflen < 0 && buffer)
76  return nullptr;
77  Int_t restlen = buflen;
78  Text_t *cursor = buffer;
79  for (int i = 0; (i < TROOT::GetDirLevel()) && (i < buflen); i++) {
80  cursor = PrintBuffer(cursor, restlen, " ");
81  }
82  buflen = restlen;
83  return cursor;
84 }
85 
86 Text_t *TGo4Status::PrintBuffer(char *buffer, Int_t &buflen, const char *text,...)
87 {
88  if(!buffer || buflen < 0)
89  return nullptr;
90  va_list args;
91  va_start(args, text);
92  Int_t size=vsnprintf(buffer, buflen, text, args);
93  va_end(args);
94  if(size>buflen || size<0)
95  return nullptr;
96  char *current = buffer + size;
97  buflen -= size;
98  return current;
99 }
100 
101 void TGo4Status::PrintLine(const char *text, ...)
102 {
103  const int bufsize = 2000;
104  char buffer[bufsize];
105  char *cursor = buffer;
106  int len = bufsize;
107 
108  for (int i = 0; (i < TROOT::GetDirLevel()) && (len > 10); i++) {
109  *cursor++ = ' ';
110  len--;
111  }
112 
113  va_list args;
114  va_start(args, text);
115  vsnprintf(cursor, len-1, text, args);
116  va_end(args);
117 
118  buffer[bufsize-1] = 0; // ensure null-terminated string
119 
120  std::cout << buffer << std::endl;
121 }
122 
void Print(Option_t *opt="") const override
Definition: TGo4Status.cxx:46
static Text_t * PrintIndent(Text_t *buffer, Int_t &buflen)
Definition: TGo4Status.cxx:73
#define GO4TRACE(X)
Definition: TGo4Log.h:25
static void PrintLine(const char *text,...)
Definition: TGo4Status.cxx:101
static Text_t * PrintBuffer(char *buffer, Int_t &buflen, const char *text,...)
Definition: TGo4Status.cxx:86
virtual Int_t PrintStatus(Text_t *buffer=nullptr, Int_t buflen=0)
Definition: TGo4Status.cxx:54
virtual ~TGo4Status()
Definition: TGo4Status.cxx:41