StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbElementIndex.cc
1 /***************************************************************************
2  *
3  * $Id: StDbElementIndex.cc,v 1.1 2001/01/22 18:37:53 porter Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Simple name-value pair index set for selecting elementID's
9  * from the database
10  *
11  ***************************************************************************
12  *
13  * $Log: StDbElementIndex.cc,v $
14  * Revision 1.1 2001/01/22 18:37:53 porter
15  * Update of code needed in next year running. This update has little
16  * effect on the interface (only 1 method has been changed in the interface).
17  * Code also preserves backwards compatibility so that old versions of
18  * StDbLib can read new table structures.
19  * -Important features:
20  * a. more efficient low-level table structure (see StDbSql.cc)
21  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
22  * c. environment variable override KEYS for each database
23  * d. StMessage support & clock-time logging diagnostics
24  * -Cosmetic features
25  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
26  * f. removed codes that have been obsolete for awhile (e.g. db factories)
27  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
28  * and mysqlAccessor became StDbSql)
29  *
30  *
31  **************************************************************************/
32 #include "StDbElementIndex.hh"
33 #include <string.h>
34 
35 StDbElementIndex::StDbElementIndex() { clearIndex(); };
36 
37 StDbElementIndex::StDbElementIndex(StDbElementIndex& inval) {
38 
39  clearIndex();
40  mnumIndeces = inval.getNumIndeces();
41  inval.resetCounter();
42  char* ctest;
43  int ival;
44  while ( (ctest=inval.printNextIndex(ival)) ){
45  strcpy(mnvals[mcurrent].iname,ctest);
46  mnvals[mcurrent].ival = ival;
47  mcurrent++;
48  }
49  resetCounter();
50  inval.resetCounter();
51 }
52 
54 void
55 StDbElementIndex::addElementIndex(StDbElementIndex* inval) {
56 
57  if(!inval) return;
58  clearIndex();
59  mnumIndeces = inval->getNumIndeces();
60  inval->resetCounter();
61  char* ctest;
62  int ival;
63  while ( (ctest=inval->printNextIndex(ival))){
64  strcpy(mnvals[mcurrent].iname,ctest);
65  mnvals[mcurrent].ival = ival;
66  mcurrent++;
67  }
68 
69  resetCounter();
70  inval->resetCounter();
71 
72 }
74 
75 int
76 StDbElementIndex::addNameValuePair(const char* name, int ival){
77 
78  strcpy(mnvals[mnumIndeces].iname,name);
79  mnvals[mnumIndeces].ival = ival;
80  int retVal=mnumIndeces;
81  mnumIndeces++;
82  return retVal;
83 };
84 
86 
87 char*
88 StDbElementIndex::getIndexName(int indexNumber){
89  char* retVal=0;
90  if(indexNumber<mnumIndeces){
91  retVal = new char[strlen((char*)mnvals[indexNumber].iname)+1];
92  strcpy(retVal,(char*)mnvals[indexNumber].iname);
93  }
94  return retVal;
95 }
96 
98 
99 char*
100 StDbElementIndex::getNextIndex(int& indexVal) {
101  char* retVal=0;
102  if(mcurrent<mnumIndeces){
103  retVal = new char[strlen((char*)mnvals[mcurrent].iname)+1];
104  strcpy(retVal,(char*)mnvals[mcurrent].iname);
105  indexVal=mnvals[mcurrent].ival;
106  mcurrent++;
107  }
108  return retVal;
109 }
110 
112 char*
113 StDbElementIndex::printNextIndex(int& indexVal) {
114  char* retVal=0;
115  if(mcurrent<mnumIndeces){
116  retVal = (char*)mnvals[mcurrent].iname;
117  indexVal=mnvals[mcurrent].ival;
118  mcurrent++;
119  }
120  return retVal;
121 }
123 
124 
125 
126