BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtStringHash< T > Class Template Reference

#include <EvtStringHash.hh>

Public Member Functions

 EvtStringHash (int size)
 
void add (const std::string &str, T *data)
 
T * get (const std::string &str)
 
 ~EvtStringHash ()
 

Detailed Description

template<class T>
class EvtStringHash< T >

Definition at line 13 of file EvtStringHash.hh.

Constructor & Destructor Documentation

◆ EvtStringHash()

template<class T >
EvtStringHash< T >::EvtStringHash ( int  size)
inline

Definition at line 33 of file EvtStringHash.hh.

33 {
34
35 _size=size;
36
37 typedef std::string** EvtStringPtrPtr;
38 typedef T** TPtrPtr;
39
40 _strings=new EvtStringPtrPtr[_size];
41 _data=new TPtrPtr[_size];
42 _entries=new int[_size];
43
44 int i;
45
46 for(i=0;i<_size;i++){
47 _entries[i]=0;
48 }
49
50}

◆ ~EvtStringHash()

template<class T >
EvtStringHash< T >::~EvtStringHash
inline

Definition at line 53 of file EvtStringHash.hh.

53 {
54
55 int i;
56 for(i=0;i<_size;i++){
57 int j;
58 for(j=0;j<_entries[i];j++){
59 delete _strings[i][j];
60 }
61 if (_entries[i]>0){
62 delete [] _strings[i];
63 delete [] _data[i];
64 }
65 }
66
67 delete [] _strings;
68 delete [] _data;
69 delete [] _entries;
70
71}

Member Function Documentation

◆ add()

template<class T >
void EvtStringHash< T >::add ( const std::string &  str,
T *  data 
)
inline

Definition at line 74 of file EvtStringHash.hh.

74 {
75
76 int ihash=hash(str);
77
78 typedef std::string* EvtStringPtr;
79 typedef T* TPtr;
80
81 std::string** newstrings=new EvtStringPtr[_entries[ihash]+1];
82 T** newdata=new TPtr[_entries[ihash]+1];
83
84 int i;
85
86 for(i=0;i<_entries[ihash];i++){
87 newstrings[i]=_strings[ihash][i];
88 newdata[i]=_data[ihash][i];
89 }
90
91 newstrings[_entries[ihash]]=new std::string;
92 *(newstrings[_entries[ihash]])=str;
93 newdata[_entries[ihash]]=data;
94
95
96 if(_entries[ihash]!=0){
97 delete [] _strings[ihash];
98 delete [] _data[ihash];
99 }
100
101 _entries[ihash]++;
102
103 _strings[ihash]=newstrings;
104 _data[ihash]=newdata;
105
106}
TTree * data

◆ get()

template<class T >
T * EvtStringHash< T >::get ( const std::string &  str)
inline

Definition at line 109 of file EvtStringHash.hh.

109 {
110
111 int ihash=hash(str);
112
113 int i;
114
115 for (i=0;i<_entries[ihash];i++){
116 if (*(_strings[ihash][i])==str) return _data[ihash][i];
117 }
118
119 return 0;
120
121
122}

The documentation for this class was generated from the following file: