StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMessTypeList.cxx
1 // //
3 // StMessTypeList //
4 // //
5 // This class manages the message types in STAR. It is a singleton. //
6 // //
8 
9 #include "StMessTypeList.h"
10 #include "StMessageStream.h"
11 #include <ctype.h>
12 using namespace std;
13 StMessTypePair::StMessTypePair(const char* ty, const char* te) :
14 type(ty),
15 text(te) {}
16 StMessTypePair::~StMessTypePair() {}
17 
18 StMessTypeList* StMessTypeList::mInstance = 0;
19 
20 //________________________________________
21 StMessTypeList::StMessTypeList() : messList() {
22 }
23 //________________________________________
24 StMessTypeList::~StMessTypeList() {
25  for (size_t i=0; i<messList.size(); i++)
26  delete (messList[i]);
27 }
28 //_____________________________________________________________________________
29 StMessTypeList* StMessTypeList::Instance() {
30  if (!mInstance) {
31  mInstance = new StMessTypeList;
32  }
33  return mInstance;
34 }
35 //_____________________________________________________________________________
36 int StMessTypeList::AddType(const char* type, const char* text) {
37  StMessTypePair* temp = FindType(type);
38  if (temp) return 0;
39  if (islower(*type)) {
40  *(const_cast<char*> (type)) = toupper(*type);
41  }
42  temp = new StMessTypePair(type,text);
43  messList.push_back(temp);
44  return messList.size();
45 }
46 //_____________________________________________________________________________
47 int StMessTypeList::FindTypeNum(const char* type) {
48  StMessTypeVecIter iter;
49  char ty=toupper(*type);
50  int j=0;
51  for (iter=messList.begin(); iter!=messList.end(); iter++) {
52  j++;
53  if (*((*iter)->Type())==ty) {return j;}
54  }
55  return 0;
56 }
57 //_____________________________________________________________________________
58 StMessTypePair* StMessTypeList::FindType(const char* type) {
59  StMessTypeVecIter iter;
60  char ty=toupper(*type);
61  for (iter=messList.begin(); iter!=messList.end(); iter++) {
62  if (*((*iter)->Type())==ty) {return (*iter);}
63  }
64  return 0;
65 }
66 //_____________________________________________________________________________
67 const char* StMessTypeList::FindNumType(size_t typeNum) {
68  if ((typeNum < 1) || (typeNum > messList.size())) return 0;
69  return messList[(typeNum - 1)]->Type();
70 }
71 //_____________________________________________________________________________
72 const char* StMessTypeList::FindNumText(size_t typeNum) {
73  if ((typeNum < 1) || (typeNum > messList.size())) return 0;
74  return messList[(typeNum - 1)]->Text();
75 }
76 //_____________________________________________________________________________
77 int StMessTypeList::ListTypes() {
78  StMessTypeVecIter iter;
79  myout << "List of StMessage types:\n"
80  << "--------------------------------------------------------"
81  << endl;
82  for (iter=messList.begin(); iter!=messList.end(); iter++) {
83  StMessTypePair* current = (*iter);
84  myout << " " << current->Type() << " : " << current->Text() << endl;
85  }
86  return messList.size();
87 }
88 
89 //_____________________________________________________________________________
90 // $Id: StMessTypeList.cxx,v 1.11 2012/06/11 15:05:34 fisyak Exp $
91 // $Log: StMessTypeList.cxx,v $
92 // Revision 1.11 2012/06/11 15:05:34 fisyak
93 // std namespace
94 //
95 // Revision 1.10 2003/09/25 21:19:22 genevb
96 // Some new cout-like functions and friend functions, some doxygen-ization
97 //
98 // Revision 1.9 2003/09/02 17:59:20 perev
99 // gcc 3.2 updates + WarnOff
100 //
101 // Revision 1.8 1999/09/14 15:42:02 genevb
102 // Some bug fixes, workaround for nulls in strings
103 //
104 // Revision 1.7 1999/09/10 21:05:55 genevb
105 // Some workarounds for RedHat6.0
106 //
107 // Revision 1.6 1999/07/01 01:24:45 genevb
108 // Fixed FORTRAN character string bug on linux, removed a memory leak from Summary()
109 //
110 // Revision 1.4 1999/06/29 17:37:30 genevb
111 // Lots of fixes...
112 //
113 // Revision 1.3 1999/06/26 00:24:51 genevb
114 // Fixed const type mismatches
115 //
116 // Revision 1.2 1999/06/24 16:30:41 genevb
117 // Fixed some memory leaks
118 //
119 // Revision 1.1 1999/06/23 15:17:44 genevb
120 // Introduction of StMessageManager
121 //
122 // Revision 1.0 1999/01/27 10:28:29 genevb
123 //