00001 /*************************************************************************** 00002 * 00003 * $Id: StDbElementIndex.hh,v 1.1 2001/01/22 18:37:53 porter Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Simple name-value pair index set for selecting elementID's 00009 * from the database 00010 * 00011 *************************************************************************** 00012 * 00013 * $Log: StDbElementIndex.hh,v $ 00014 * Revision 1.1 2001/01/22 18:37:53 porter 00015 * Update of code needed in next year running. This update has little 00016 * effect on the interface (only 1 method has been changed in the interface). 00017 * Code also preserves backwards compatibility so that old versions of 00018 * StDbLib can read new table structures. 00019 * -Important features: 00020 * a. more efficient low-level table structure (see StDbSql.cc) 00021 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00022 * c. environment variable override KEYS for each database 00023 * d. StMessage support & clock-time logging diagnostics 00024 * -Cosmetic features 00025 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00026 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00027 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00028 * and mysqlAccessor became StDbSql) 00029 * 00030 * 00031 **************************************************************************/ 00032 #ifndef STDBELEMENTINDEX_HH 00033 #define STDBELEMENTINDEX_HH 00034 00035 #define N_MAX_INDEXVALS 10 00036 #include <string.h> 00037 00038 struct indexNameVals { 00039 00040 char iname[64]; 00041 int ival; 00042 00043 }; 00044 00045 class StDbElementIndex { 00046 00047 int mnumIndeces; 00048 indexNameVals mnvals[N_MAX_INDEXVALS]; 00049 int mcurrent; 00050 00051 public: 00052 00053 StDbElementIndex(); 00054 StDbElementIndex(StDbElementIndex& inval); 00055 virtual ~StDbElementIndex(){}; 00056 00057 virtual void clearIndex(); 00058 00059 virtual void addElementIndex(StDbElementIndex* inval); 00060 virtual int addNameValuePair(const char* name, int ival); 00061 virtual int getNumIndeces() const; 00062 virtual int getIndexVal(int indexNumber); 00063 virtual char* getIndexName(int indexNumber); 00064 virtual char* printIndexName(int indexNumber); 00065 00066 virtual void resetCounter(); 00067 virtual char* getNextIndex(int& indexVal); 00068 virtual char* printNextIndex(int& indexVal); 00069 00070 }; 00071 00072 inline void StDbElementIndex::clearIndex() { 00073 mcurrent=0; mnumIndeces=0; 00074 memset(&mnvals,0,N_MAX_INDEXVALS*sizeof(indexNameVals)); 00075 } 00076 inline int StDbElementIndex::getNumIndeces() const { return mnumIndeces; } 00077 00078 inline int StDbElementIndex::getIndexVal(int indexNum) { 00079 if(indexNum>=N_MAX_INDEXVALS)return -1; 00080 return mnvals[indexNum].ival; 00081 } 00082 inline char* StDbElementIndex::printIndexName(int indexNum) { 00083 if(indexNum>=N_MAX_INDEXVALS)return (char*)0; 00084 return (char*)mnvals[indexNum].iname; 00085 } 00086 inline void StDbElementIndex::resetCounter() { mcurrent=0; } 00087 00088 #endif 00089 00090