|
1 // Copyright 2014 Google Inc. All Rights Reserved. |
|
2 // |
|
3 // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 // you may not use this file except in compliance with the License. |
|
5 // You may obtain a copy of the License at |
|
6 // |
|
7 // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 // |
|
9 // Unless required by applicable law or agreed to in writing, software |
|
10 // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 // See the License for the specific language governing permissions and |
|
13 // limitations under the License. |
|
14 |
|
15 #ifndef CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_ |
|
16 #define CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_ |
|
17 |
|
18 #include "scoreonescriptspan.h" |
|
19 #include "cld2_dynamic_data.h" |
|
20 |
|
21 namespace CLD2DynamicDataLoader { |
|
22 |
|
23 // Read a header from the specified file and return it. |
|
24 // The header returned is dynamically allocated; you must 'delete' the array |
|
25 // of TableHeaders as well as the returned FileHeader* when done. |
|
26 CLD2DynamicData::FileHeader* loadHeader(const char* fileName); |
|
27 |
|
28 // Load data directly into a ScoringTables structure using a private, read-only |
|
29 // mmap and return the newly-allocated structure. |
|
30 // The out-parameter "mmapAddressOut" is a pointer to a void*; the starting |
|
31 // address of the mmap()'d block will be written here. |
|
32 // The out-parameter "mmapLengthOut" is a pointer to an int; the length of the |
|
33 // mmap()'d block will be written here. |
|
34 // It is up to the caller to delete |
|
35 CLD2::ScoringTables* loadDataFile(const char* fileName, |
|
36 void** mmapAddressOut, int* mmapLengthOut); |
|
37 |
|
38 // Given pointers to the data from a previous invocation of loadDataFile, |
|
39 // unloads the data safely - freeing and deleting any malloc'd/new'd objects. |
|
40 // When this method returns, the mmap has been deleted, as have all the scoring |
|
41 // tables; the pointers passed in are all zeroed, such that: |
|
42 // *scoringTables == NULL |
|
43 // *mmapAddress == NULL |
|
44 // mmapLength == NULL |
|
45 // This is the only safe way to unload data that was previously loaded, as there |
|
46 // is an unfortunate mixture of new and malloc involved in building the |
|
47 // in-memory represtation of the data. |
|
48 void unloadData(CLD2::ScoringTables** scoringTables, |
|
49 void** mmapAddress, int* mmapLength); |
|
50 |
|
51 } // End namespace CLD2DynamicDataExtractor |
|
52 #endif // CLD2_INTERNAL_CLD2_DYNAMIC_DATA_EXTRACTOR_H_ |