Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / cld_2 / src / internal / cld2_dynamic_data_loader.h
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 <stdint.h>
19 #include "scoreonescriptspan.h"
20 #include "cld2_dynamic_data.h"
21
22 namespace CLD2DynamicDataLoader {
23
24 // Read a header from the specified file and return it.
25 // The header returned is dynamically allocated; you must 'delete' the array
26 // of TableHeaders as well as the returned FileHeader* when done.
27 CLD2DynamicData::FileHeader* loadHeaderFromFile(const char* fileName);
28
29 // Read a header from the specified area of raw memory and return it.
30 // The header returned is dynamically allocated; you must 'delete' the array
31 // of TableHeaders as well as the returned FileHeader* when done.
32 CLD2DynamicData::FileHeader* loadHeaderFromRaw(
33   const void* basePointer, const uint32_t length);
34
35 // Not for public consumption.
36 CLD2DynamicData::FileHeader* loadInternal(
37   FILE* inFile, const void* basePointer, const uint32_t length);
38
39 // Load data directly into a ScoringTables structure using a private, read-only
40 // mmap and return the newly-allocated structure.
41 // The out-parameter "mmapAddressOut" is a pointer to a void*; the starting
42 // address of the mmap()'d block will be written here.
43 // The out-parameter "mmapLengthOut" is a pointer to an int; the length of the
44 // mmap()'d block will be written here.
45 // It is up to the caller to delete the data at a later time using
46 // unloadData(...).
47 CLD2::ScoringTables* loadDataFile(const char* fileName,
48   void** mmapAddressOut, uint32_t* mmapLengthOut);
49
50 // Load data directly into a ScoringTables structure from an arbitrary region
51 // of memory, which is assumed to be a pointer to an mmap-ed region of memory
52 // backed by a valid data file that could alternatively be read (if access
53 // were allowed or desired) using loadDataFile(...). 
54 CLD2::ScoringTables* loadDataRaw(const void* basePointer, const uint32_t length);
55
56 // Not for public consumption.
57 CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const void* basePointer, const uint32_t length);
58
59 // Given pointers to the data from a previous invocation of loadDataFile,
60 // unloads the data safely - freeing and deleting any malloc'd/new'd objects.
61 // When this method returns, the mmap has been deleted, as have all the scoring
62 // tables; the pointers passed in are all zeroed, such that:
63 //   *scoringTables == NULL
64 //   *mmapAddress == NULL
65 //   mmapLength == NULL
66 // This is the only safe way to unload data that was previously loaded, as there
67 // is an unfortunate mixture of new and malloc involved in building the
68 // in-memory represtation of the data.
69 void unloadDataFile(CLD2::ScoringTables** scoringTables,
70   void** mmapAddress, uint32_t* mmapLength);
71
72 // Given a pointer to the data from a previous invocation of loadDataRaw,
73 // unloads the data safely just like unloadDataFile does. This method doesn't
74 // deal with mmaps, since it is assumed that the memory for the data is managed
75 // external to this library.
76 void unloadDataRaw(CLD2::ScoringTables** scoringTables);
77
78 } // End namespace CLD2DynamicDataExtractor
79 #endif  // CLD2_INTERNAL_CLD2_DYNAMIC_DATA_EXTRACTOR_H_