-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathlazyInstMgr.h
More file actions
221 lines (178 loc) · 7.4 KB
/
lazyInstMgr.h
File metadata and controls
221 lines (178 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#ifndef LAZYINSTMGR_H
#define LAZYINSTMGR_H
#include <map>
#include <string>
#include <assert.h>
#include "lazyDataSectionReader.h"
#include "lazyFileReader.h"
#include "lazyTypes.h"
#include "Registry.h"
#include "sc_export.h"
#include "judyLArray.h"
#include "judySArray.h"
#include "judyL2Array.h"
#include "judyS2Array.h"
class Registry;
class instMgrAdapter;
class SC_LAZYFILE_EXPORT lazyInstMgr {
protected:
/** multimap from instance number to instances that it refers to
* \sa instanceRefs_pair
*/
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
instanceRefs_t _fwdInstanceRefs;
/** multimap from instance number to instances that refer to it - the majority of these will not be inverse references!
* \sa instanceRefs_pair
*/
instanceRefs_t _revInstanceRefs;
/** multimap from instance type to instance number
* \sa instanceType_pair
* \sa instanceType_range
*/
instanceTypes_t * _instanceTypes;
/** map from instance number to instance pointer (loaded instances only)
* \sa instancesLoaded_pair
*
* TODO should be multimap to allow use of instances in multiple data sections?
* a unique instance ID (containing sectionID and instanceID) would also work
*/
instancesLoaded_t _instancesLoaded;
/** map from instance number to beginning and end positions and the data section
* \sa instanceStreamPos_pair
*
* FIXME to save memory, modify judyL2Array to not use a vector until there are several
* instances with the same instanceID. This will help elsewhere as well.
*/
instanceStreamPos_t _instanceStreamPos;
dataSectionReaderVec_t _dataSections;
lazyFileReaderVec_t _files;
Registry * _headerRegistry, * _mainRegistry;
ErrorDescriptor * _errors;
unsigned long _lazyInstanceCount, _loadedInstanceCount;
int _longestTypeNameLen;
std::string _longestTypeName;
instMgrAdapter * _ima;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
public:
lazyInstMgr();
~lazyInstMgr();
void openFile( std::string fname );
void addLazyInstance( namedLazyInstance inst );
InstMgrBase * getAdapter() {
return ( InstMgrBase * ) _ima;
}
instanceRefs_t * getFwdRefs() {
return & _fwdInstanceRefs;
}
instanceRefs_t * getRevRefs() {
return & _revInstanceRefs;
}
/// returns a vector containing the instances that match `type`
instanceTypes_t::cvector * getInstances( std::string type, bool caseSensitive = false ) { /*const*/
if( !caseSensitive ) {
std::string::iterator it = type.begin();
for( ; it != type.end(); ++it ) {
*it = toupper( *it );
}
}
return _instanceTypes->find( type.c_str() );
}
/// get the number of instances of a certain type
unsigned int countInstances( std::string type ) {
instanceTypes_t::cvector * v = _instanceTypes->find( type.c_str() );
if( !v ) {
return 0;
}
return v->size();
}
instancesLoaded_t * getHeaderInstances( fileID file ) {
return _files[file]->getHeaderInstances();
}
/// get the number of instances that have been found in the open files.
unsigned long totalInstanceCount() const {
return _lazyInstanceCount;
}
/// get the number of instances that are loaded.
unsigned long loadedInstanceCount() const {
return _loadedInstanceCount;
}
/// get the number of data sections that have been identified
unsigned int countDataSections() {
return _dataSections.size();
}
///builds the registry using the given initFunct
const Registry * initRegistry( CF_init initFunct ) {
setRegistry( new Registry( initFunct ) );
return _mainRegistry;
}
/// set the registry to one already initialized
void setRegistry( Registry * reg ) {
assert( _mainRegistry == 0 );
_mainRegistry = reg;
}
const Registry * getHeaderRegistry() const {
return _headerRegistry;
}
const Registry * getMainRegistry() const {
return _mainRegistry;
}
/// get the longest type name
const std::string & getLongestTypeName() const {
return _longestTypeName;
}
/// get the number of types of instances.
unsigned long getNumTypes() const;
sectionID registerDataSection( lazyDataSectionReader * sreader );
ErrorDescriptor * getErrorDesc() {
return _errors;
}
/** returns a pointer to an instance, loading it if necessary.
* \param id the instance number to look for
* \param reSeek if true, reset file position to current position when done. only necessary when loading an instance with dependencies; excessive use will cause a performance hit
*/
SDAI_Application_instance * loadInstance( instanceID id, bool reSeek = false );
//list all instances that one instance depends on (recursive)
instanceSet * instanceDependencies( instanceID id );
bool isLoaded( instanceID id ) {
_instancesLoaded.find( id );
return _instancesLoaded.success();
}
const char * typeFromFile( instanceID id ) {
instanceStreamPos_t::cvector * cv;
cv = _instanceStreamPos.find( id );
if( cv ) {
if( cv->size() != 1 ) {
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ << " - multiple instances (" << cv->size() << ") with one instanceID (" << id << ") not supported yet." << std::endl;
return 0;
}
positionAndSection ps = cv->at( 0 );
//extract p, s, call
long int off = ps & 0xFFFFFFFFFFFFULL;
sectionID sid = ps >> 48;
return _dataSections[sid]->getType( off );
}
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ << " - instanceID " << id << " not found." << std::endl;
return 0;
}
// TODO implement these
// add another schema to registry
//void addSchema( void ( *initFn )() );
//list all instances that one instance depends on (recursive)
//std::vector<instanceID> instanceDependencies( instanceID id ); //set is faster?
/* * the opposite of instanceDependencies() - all instances that are *not* dependencies of one particular instance
same as above, but with list of instances */
//std::vector<instanceID> notDependencies(...)
//renumber instances so that they are numbered 1..N where N is the total number of instances
//void normalizeInstanceIds();
//find data that is repeated and eliminate, if possible
//void eliminateDuplicates();
//tell instMgr to use instances from this section
//void useDataSection( sectionID id );
// TODO support references from one file to another
};
#endif //LAZYINSTMGR_H