michael@0: // Copyright 2014 Google Inc. All Rights Reserved. michael@0: // michael@0: // Licensed under the Apache License, Version 2.0 (the "License"); michael@0: // you may not use this file except in compliance with the License. michael@0: // You may obtain a copy of the License at michael@0: // michael@0: // http://www.apache.org/licenses/LICENSE-2.0 michael@0: // michael@0: // Unless required by applicable law or agreed to in writing, software michael@0: // distributed under the License is distributed on an "AS IS" BASIS, michael@0: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: // See the License for the specific language governing permissions and michael@0: // limitations under the License. michael@0: michael@0: #ifndef CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_ michael@0: #define CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_ michael@0: michael@0: #include "scoreonescriptspan.h" michael@0: #include "cld2_dynamic_data.h" michael@0: michael@0: namespace CLD2DynamicDataLoader { michael@0: michael@0: // Read a header from the specified file and return it. michael@0: // The header returned is dynamically allocated; you must 'delete' the array michael@0: // of TableHeaders as well as the returned FileHeader* when done. michael@0: CLD2DynamicData::FileHeader* loadHeader(const char* fileName); michael@0: michael@0: // Load data directly into a ScoringTables structure using a private, read-only michael@0: // mmap and return the newly-allocated structure. michael@0: // The out-parameter "mmapAddressOut" is a pointer to a void*; the starting michael@0: // address of the mmap()'d block will be written here. michael@0: // The out-parameter "mmapLengthOut" is a pointer to an int; the length of the michael@0: // mmap()'d block will be written here. michael@0: // It is up to the caller to delete michael@0: CLD2::ScoringTables* loadDataFile(const char* fileName, michael@0: void** mmapAddressOut, int* mmapLengthOut); michael@0: michael@0: // Given pointers to the data from a previous invocation of loadDataFile, michael@0: // unloads the data safely - freeing and deleting any malloc'd/new'd objects. michael@0: // When this method returns, the mmap has been deleted, as have all the scoring michael@0: // tables; the pointers passed in are all zeroed, such that: michael@0: // *scoringTables == NULL michael@0: // *mmapAddress == NULL michael@0: // mmapLength == NULL michael@0: // This is the only safe way to unload data that was previously loaded, as there michael@0: // is an unfortunate mixture of new and malloc involved in building the michael@0: // in-memory represtation of the data. michael@0: void unloadData(CLD2::ScoringTables** scoringTables, michael@0: void** mmapAddress, int* mmapLength); michael@0: michael@0: } // End namespace CLD2DynamicDataExtractor michael@0: #endif // CLD2_INTERNAL_CLD2_DYNAMIC_DATA_EXTRACTOR_H_