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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/translation/cld2/internal/cld2_dynamic_data_loader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +// Copyright 2014 Google Inc. All Rights Reserved.                                                  
     1.5 +//                                                                                                  
     1.6 +// Licensed under the Apache License, Version 2.0 (the "License");                                  
     1.7 +// you may not use this file except in compliance with the License.                                 
     1.8 +// You may obtain a copy of the License at                                                          
     1.9 +//                                                                                                  
    1.10 +//     http://www.apache.org/licenses/LICENSE-2.0                                                   
    1.11 +//                                                                                                  
    1.12 +// Unless required by applicable law or agreed to in writing, software                              
    1.13 +// distributed under the License is distributed on an "AS IS" BASIS,                                
    1.14 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                         
    1.15 +// See the License for the specific language governing permissions and                              
    1.16 +// limitations under the License.
    1.17 +
    1.18 +#ifndef CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
    1.19 +#define CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
    1.20 +
    1.21 +#include "scoreonescriptspan.h"
    1.22 +#include "cld2_dynamic_data.h"
    1.23 +
    1.24 +namespace CLD2DynamicDataLoader {
    1.25 +
    1.26 +// Read a header from the specified file and return it.
    1.27 +// The header returned is dynamically allocated; you must 'delete' the array
    1.28 +// of TableHeaders as well as the returned FileHeader* when done.
    1.29 +CLD2DynamicData::FileHeader* loadHeader(const char* fileName);
    1.30 +
    1.31 +// Load data directly into a ScoringTables structure using a private, read-only
    1.32 +// mmap and return the newly-allocated structure.
    1.33 +// The out-parameter "mmapAddressOut" is a pointer to a void*; the starting
    1.34 +// address of the mmap()'d block will be written here.
    1.35 +// The out-parameter "mmapLengthOut" is a pointer to an int; the length of the
    1.36 +// mmap()'d block will be written here.
    1.37 +// It is up to the caller to delete
    1.38 +CLD2::ScoringTables* loadDataFile(const char* fileName,
    1.39 +  void** mmapAddressOut, int* mmapLengthOut);
    1.40 +
    1.41 +// Given pointers to the data from a previous invocation of loadDataFile,
    1.42 +// unloads the data safely - freeing and deleting any malloc'd/new'd objects.
    1.43 +// When this method returns, the mmap has been deleted, as have all the scoring
    1.44 +// tables; the pointers passed in are all zeroed, such that:
    1.45 +//   *scoringTables == NULL
    1.46 +//   *mmapAddress == NULL
    1.47 +//   mmapLength == NULL
    1.48 +// This is the only safe way to unload data that was previously loaded, as there
    1.49 +// is an unfortunate mixture of new and malloc involved in building the
    1.50 +// in-memory represtation of the data.
    1.51 +void unloadData(CLD2::ScoringTables** scoringTables,
    1.52 +  void** mmapAddress, int* mmapLength);
    1.53 +
    1.54 +} // End namespace CLD2DynamicDataExtractor
    1.55 +#endif  // CLD2_INTERNAL_CLD2_DYNAMIC_DATA_EXTRACTOR_H_

mercurial