Logo ROOT   6.10/09
Reference Guide
TGSimpleTableInterface.cxx
Go to the documentation of this file.
1 // Author: Roel Aaij 15/08/2007
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #include "TClass.h"
12 #include "Riostream.h"
13 #include "TSystem.h"
14 #include "TEnv.h"
15 #include "TGSimpleTableInterface.h"
16 #include "TGResourcePool.h"
17 #include "TError.h"
18 
20 
21 //////////////////////////////////////////////////////////////////////////
22 // //
23 // TGSimpleTableInterface //
24 // //
25 // TGSimpleTableInterface is a very simple implementation of a //
26 // TVirtualTableInterface. This interface provides a TGTable with data //
27 // from a two dimensional array of doubles in memory. It is mostly //
28 // meant as an example implementation for a TVirtualTableInterface. //
29 // //
30 //////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// TGSimpleTableInterfac constructor.
34 
36  UInt_t nrows, UInt_t ncolumns)
37  : TVirtualTableInterface(), fData(data), fNRows(nrows), fNColumns(ncolumns)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// TGSimpleTableInterface destructor.
43 
45 {
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Return the value of the double in row,column of the data.
50 
52 {
53  if ((row > fNRows) || (column > fNColumns)) {
54  Error("TGSimpleTableInterface","Non existing value requested.");
55  return 0;
56  } else {
57  Double_t temp = fData[row][column];
58  return temp;
59  }
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Return the value of the double in row,column of the data as a string.
64 
66 {
67  // FIXME use template string for string format instead of hardcoded format
68 
69  return StrDup(TString::Format("%5.2f", GetValue(row, column)));
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Return a name for the header at row.
74 
76 {
77  return StrDup(TString::Format("DRow %d", row));
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Return a name for the header at column.
82 
84 {
85  return StrDup(TString::Format("DCol %d", column));
86 }
virtual const char * GetRowHeader(UInt_t row)
Return a name for the header at row.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2345
virtual const char * GetColumnHeader(UInt_t column)
Return a name for the header at column.
void Error(const char *location, const char *msgfmt,...)
virtual ~TGSimpleTableInterface()
TGSimpleTableInterface destructor.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Double_t GetValue(UInt_t row, UInt_t column)
Return the value of the double in row,column of the data.
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2524
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
virtual const char * GetValueAsString(UInt_t row, UInt_t column)
Return the value of the double in row,column of the data as a string.