browser/components/translation/cld2/internal/cld2_dynamic_data_loader.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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.
    15 #ifndef CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
    16 #define CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
    18 #include "scoreonescriptspan.h"
    19 #include "cld2_dynamic_data.h"
    21 namespace CLD2DynamicDataLoader {
    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);
    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);
    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);
    51 } // End namespace CLD2DynamicDataExtractor
    52 #endif  // CLD2_INTERNAL_CLD2_DYNAMIC_DATA_EXTRACTOR_H_

mercurial