GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Status.cxx
Go to the documentation of this file.
1 // $Id: TGo4Status.cxx 2737 2020-04-15 16:41:11Z linev $
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  TGo4Status* localthis= const_cast<TGo4Status*>(this);
50  localthis->PrintStatus();
51 }
52 
53 Int_t TGo4Status::PrintStatus(Text_t* buffer, Int_t buflen)
54 {
55  GO4TRACE((12,"TGo4Status::PrintStatus()",__LINE__, __FILE__));
56 
57  if(buflen<=0 && buffer!=0) return 0;
58 
59  Int_t size = 0;
60  TString localbuf = TString::Format("G-OOOO-> Status Class %s, name: %s <-OOOO-G\n", ClassName(), GetName());
61 
62  if(buffer==0) {
63  std::cout << localbuf << std::endl;
64  } else {
65  size = localbuf.Length();
66  if(size>buflen-1) size = buflen-1;
67  strncpy(buffer,localbuf.Data(), size);
68  }
69  return size;
70 }
71 
72 Text_t* TGo4Status::PrintIndent(Text_t* buffer, Int_t& buflen)
73 {
74  if(buflen<0 && buffer!=0) return 0;
75  Int_t restlen=buflen;
76  Text_t *cursor = buffer;
77  for (int i = 0; (i < TROOT::GetDirLevel()) && (i < buflen); i++) {
78  cursor = PrintBuffer(cursor, restlen, " ");
79  }
80  buflen=restlen;
81  return cursor;
82 }
83 
84 Text_t* TGo4Status::PrintBuffer(char* buffer, Int_t& buflen, const char* text,...)
85 {
86  if(buffer==0 || buflen<0) return 0;
87  va_list args;
88  va_start(args, text);
89  Int_t size=vsnprintf(buffer, buflen, text, args);
90  va_end(args);
91  if(size>buflen || size<0) return 0;
92  char* current= buffer + size;
93  buflen-=size;
94  return current;
95 }
virtual void Print(Option_t *dummy="") const
Definition: TGo4Status.cxx:46
virtual Int_t PrintStatus(Text_t *buffer=0, Int_t buflen=0)
Definition: TGo4Status.cxx:53
static Text_t * PrintIndent(Text_t *buffer, Int_t &buflen)
Definition: TGo4Status.cxx:72
#define GO4TRACE(X)
Definition: TGo4Log.h:26
static Text_t * PrintBuffer(char *buffer, Int_t &buflen, const char *text,...)
Definition: TGo4Status.cxx:84
virtual ~TGo4Status()
Definition: TGo4Status.cxx:41